akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#ifdef ONLINE_JUDGE
  #define debug(x)
  #define debug2(x,y)
  #define debug3(x,y,z)
  #define assert(e) if(!(e)){stod("");}
#else
  #define debug(x) std::cerr<<#x<<": "<<x<<"\n"
  #define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
  #define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
#endif

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

void solve() {
  int k;
  scan(k);
  string s;
  scan(s);
  string ans = s;
  if ((int)s.size() > k) {
    ans = s.substr(0, k) + "...";
  }
  print(ans);
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++){
		int l;
		cin >> l;
		a[i] = l;
	}
	int ans = 0;
	sort(ALL(a));
	for (int i = n-1; i >= 0; i--){
		if (i % 2 == (n - 1) % 2){
			ans += a[i];
		}
		else{
			ans -= a[i];
		}
	}
	cout << ans << endl;
	
	
	return 0;
}

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

int main(){
    int f[101], n, max = 0;
    fill(f, f+101, 0);
    while( scanf(" %d", &n) != EOF ){
        f[n]++;
        if( f[n] > max ) max = f[n];
    }
    for(int i = 1;i < 101; i++){
        if( f[i] == max ) printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 1024
if __name__ == '__main__':
    s = int(input())
    dic = {s:0}
    count = 2
    while True:
        if s%2 == 0:
            s = int(s/2)
        else:
            s = 3*s+1
        try:
            a=dic[s]
            print(count)
            exit()
        except KeyError:
            dic[s] = 0
            count+=1


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;


const int mod = 998244353;

const int N = 307;

int dp[N][N][2*N][2];

inline int sum(int x, int y) {
	if (x+y < 0) return x+y+mod;
	if (x+y >= mod) return x+y-mod;
	return x+y;
}
 
inline int mult(int x, int y) {
	return ((ll) x * y) % mod;
}

int main(){
#ifdef LOCAL
	freopen("I_input.txt", "r", stdin);
	//freopen("I_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string s;
	cin >> s;

	int k;
	cin >> k;

	vector<int> arr;

	int R = 0;

	int now = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '1') {
			R++;
			now++;
		}
		else {
			arr.push_back(now);
			now = 0;
		}
	}

	arr.push_back(now);

	dp[0][0][0][0] = 1;

	int cur = 0;

	for (int i = 0; i < arr.size(); ++i) {

		for (int was = 0; was <= R; ++was) {
			for (int delta = 0; delta <= 2*s.size(); ++delta) {
				int T = sum(dp[i][was][delta][0], dp[i][was][delta][1]);
				if (T == 0) continue;

				for (int be = 0; be <= arr[i] && was+be <= R; ++be) {
					dp[i+1][was + be][delta + arr[i] - be][0] = sum(dp[i+1][was + be][delta + arr[i] - be][0], T);
				}

				if (i + 1 < arr.size() && was + arr[i] + 1 <= R) {
					dp[i+1][was+arr[i]+1][delta+1][1] = sum(dp[i+1][was+arr[i]+1][delta+1][1], T);
				}
			}
		}

		for (int was = 0; was <= R; ++was) {
			for (int delta = 0; delta <= 2*s.size(); ++delta) {
				if (dp[i+1][was][delta][1] && was+1 <= R) {
					dp[i+1][was+1][delta+1][1] = sum(dp[i+1][was][delta][1], dp[i+1][was+1][delta+1][1]);
				}
			}
		}

		cur += arr[i];

		for (int was = 0; was < cur; ++was) for (int delta = 0; delta <= 2*s.size(); ++delta) {
			dp[i+1][was][delta][0] = 0;
			dp[i+1][was][delta][1] = 0;
		}

	}

	//cout << dp[3][2][2][0] << " " << R << endl;

	int ans = 0;

	for (int delta = 0; delta <= 2*s.size(); ++delta) if (delta <= 2*k) {

		int T = sum(dp[arr.size()][R][delta][0], dp[arr.size()][R][delta][1]);

		ans = sum(ans, T);
	}

	cout << ans;

}


Measured memory_bytes: 112824
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

struct goods{
  char town[110];
  int point;
  int num;
};

// qsort()に渡すための各種比較関数
int compareName(const void *a, const void *b){
    return strcmp( ((struct goods *)a)->town,  ((struct goods *)b)->town );
}
int compareWeight(const void *a, const void *b){
    int i = (((struct goods *)a)->point - ((struct goods *)b)->point);
    if (i==0){
        return compareName(a,b);
    }
    return -i;
}

//優先度の低い順に、安定化したqsort()をかける。
void tuple_sort(struct goods *A,int n){
        qsort(A,n,sizeof(struct goods),compareWeight);
        qsort(A,n,sizeof(struct goods),compareName);
}

int main(){
  int n; cin >> n;
  struct goods r[n];
  rep(i,n){
    cin >> r[i].town >> r[i].point;
    r[i].num = i+1;
  }
  tuple_sort(r,n);

  rep(i,n){
//    cout << r[i].town <<" "<< r[i].point<<" "<< r[i].num << endl;
    cout <<  r[i].num << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

M = []
M_0 = 0
for i in range(len(A)):
    if i % 2 == 0:
        M_0 += A[i]
    else:
        M_0 -= A[i]
M.append(M_0)
for i in range(len(A)):
    M.append(2*A[i]-M[i])

print(" ".join(map(str, M[:-1])))

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    map<int, int> A;
    REP(i, N) {
        int x;
        cin >> x;
        A[x]++;
    }
    int c = 0;
    int d = 0;
    for(auto i : A) {
        if(1 < i.second) {
            if(i.second%2 == 0) {
                c++;
            }else{
                d++;
            }
        }else{
            d++;
        }
    }
    if(c%2 == 0) {
        cout << c + d << endl;
    }else{
        cout << c + d - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  while(cin>>n,n){
    int m;
    cin>>m;
    int e[n][n];
    memset(e,0,sizeof(e));
    for(int i=0;i<m;i++){
      int a,b;
      cin>>a>>b;
      a--;b--;
      e[a][b]=e[b][a]=1;
    }
    bool used[n];
    memset(used,0,sizeof(used));
    for(int i=0;i<n;i++){
      if(!e[0][i]) continue;
      used[i]=1;
      for(int j=0;j<n;j++) used[j]|=e[i][j];
    }
    int ans=0;
    for(int i=1;i<n;i++) ans+=used[i];
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 5028
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}
ll sq(int x) { ll ans = x*x ; return ans ; }
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
void read(vt<int> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}
void read(vt<ld> &a) {
	rep(i,0,a.size()) 
	cin >> a[i] ; 
}

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	
	int n ; 
	cin >> n ; 
	vt<ld> a(n) ; 
	read(a) ; 
	set<pair<ld,int>> s ; 
	rep(i,0,n) {
		s.insert({a[i],i}) ; 
	}

	rep(i,0,n-1) {
		auto it1 = *s.begin() ; 
		s.erase(it1) ; 
		auto it2 = *s.begin() ; 
		s.erase(it2) ; 
		s.insert(mp((it1.ff+it2.ff)/2, it1.ss )) ; 
	}
	cout << fixed << setprecision(10) << (*s.begin()).ff << endl ;

 	
 	return 0 ; 
 	
}

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

int main() {
  int N;
  cin >> N;
  long double ans = 0;
  for(int i=0; i<N; i++){
    long double x;
    string y;
    cin >> x >> y;
    if(y == "JPY"){
      ans += x;
    }
    else{
      ans += x*380000.0;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3712
//### In The Name Of GOD ###

//%% Remember; (((He))) is The (((Accepter))) %%

// GOD IS GREATER ...

#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;
typedef long double ld ;

//#define int ll
#define pb push_back
#define bp pop_back
#define pf push_front
#define fp pop_front
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())
#define sg(a, b) (a + b - 1) /b

const int MOD = 1000 * 1000 * 1000 + 7;
const int INF = 1 * 1000 * 1000 * 1000 + 200;
const int MAXN = 5 * 100 * 1000 + 10;
const int MLOG = 30;
const int NMAX = 20;

int main() {
	int n;
	cin >> n;
	ll a[n], b[n], ans = 0;
	pair<ll, ll> c[n];
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i], c[i].X = a[i] + b[i], c[i].Y = i;
	sort(c, c + n);
	for(int i = n - 1; i >= 0; i -= 2) ans += a[c[i].Y];
	for(int i = n - 2; i >= 0; i -= 2) ans -= b[c[i].Y];
	cout << ans ;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int x[60];;
long long dp[60][60][2600];
int main()
{
    int n, a;
    scanf("%d%d", &n, &a);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &x[i]);
    for(int i = 0; i <= n; ++i)
        dp[i][0][0] = 1;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= i; ++j)
        {
            for(int k = 0; k <= 2500; ++k)
            {
                if(k - x[i] >= 0)
                    dp[i][j][k] += dp[i - 1][j - 1][k - x[i]];
                dp[i][j][k] += dp[i - 1][j][k];
            }
        }
    }
    long long ans = 0;
    for(int i = 1; i <= n; ++i)
        ans += dp[n][i][a * i];
    printf("%lld\n", ans);
    return 0;
}
/*
3 8
8 8 9

4 8
7 9 8 9

8 5
3 6 2 8 7 6 5 9

33 3
3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

*/


Measured memory_bytes: 26368
#include<stdio.h>
#include<cstdio>
using namespace std;

int main() {
  int N;
  scanf("%d", &N);
  int a[N];
  bool flag[8];
  for (int i=0 ; i<8 ; i++) flag[i] = false;
  int high_score = 0;
  for (int i=0 ; i<N ; i++) {
    int num;
    scanf("%d", &num);
    if (num/400 <= 7) {
      flag[num/400] = true;
    } else {
      high_score++;
    }
  }
  int low_score = 0;
  for (int i=0 ; i<8 ; i++) {
    if (flag[i]) low_score++;
  }
  int res_max = low_score + high_score;
  
  int res_min;
  if (low_score >= 1) res_min = low_score;
  else res_min = 1;
  
  printf("%d %d\n", res_min, res_max);
}

Measured memory_bytes: 128
a = int(input(), 10)
b = int(input(), 10)
c = int(input(), 10)
x = int(input(), 10)
ptn = 0

for i in range(a+1):
    for j in range(b+1):
        for t in range(c+1):
            total = (i * 500) + (j * 100) + (t * 50)
            if x == total:
                ptn += 1
print(ptn)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,p;
  while(cin>>n>>m>>p,n){
    int ma[10][10][10];
    int st[10][10]={};
    memset(ma,-1,sizeof(ma));
    int f=0;
    int ans;
    for(int cn=1;cn<=p;cn++){
      int x,y;
      cin>>x>>y;
      x--,y--;
      int z=st[x][y]++;
      ma[x][y][z]=cn%2;
      if(f)continue;
      for(int dx=-1;dx<2;dx++)
	for(int dy=-1;dy<2;dy++)
	  for(int dz=-1;dz<2;dz++){
	    if(dx==0&&dy==0&&dz==0)continue;
	    int cnt=1;
	    int nx=x,ny=y,nz=z;
	    while(1){
	      nx+=dx,ny+=dy,nz+=dz;
	      if(nx<0||ny<0||nz<0)break;
	      if(nx>=n||ny>=n||nz>=n)break;
	      if(ma[x][y][z]==ma[nx][ny][nz])cnt++;
	      else break;
	    }
	    nx=x,ny=y,nz=z;
	    while(1){
	      nx+=dx*(-1),ny+=dy*(-1),nz+=dz*(-1);
	      if(nx<0||ny<0||nz<0)break;
	      if(nx>=n||ny>=n||nz>=n)break;
	      if(ma[x][y][z]==ma[nx][ny][nz])cnt++;
	      else break;
	    }
	    if(cnt>=m){
	      f=cn%2+1;
	      ans=cn;
	      //cout<<"a"<<endl;
	    }
	  }
    }
    if(f==0)cout<<"Draw"<<endl;
    if(f==1)cout<<"White "<<ans<<endl;
    if(f==2)cout<<"Black "<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3008
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.math;

void main(){

    int ans=0;
    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	s = chomp(s);
	int len = to!int(s.length);
	int l,r;
	if(len%2==1){
	    l = len/2 - 1;
	    r = len/2 + 1;
	}else{
	    l = len/2 - 1;
	    r = len/2;
	}
	bool flg = true;
	for(int i=0;i<to!int(len/2);i++){
	    if(s[l]!=s[r]) {
		flg = false;
		break;
	    }
	    l--;
	    r++;
	}
	if(flg) ans++;
    }
    writeln(ans);
}

Measured memory_bytes: 2352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<ll>
#define pb push_back
#define ff first
#define ss second
#define inf 2e18
#define ull unsigned long long
#define pi acos(-1.0)
#define mod 1000000007
#define lop0(n) for(ll i=0;i<n;i++)
#define lopj(n) for(ll j=0;j<n;j++)
#define lop1(n) for(ll i=1;i<=n;i++)
#define all(v) v.begin(),v.end()
ll Set(ll N,ll pos){ return N=N | (1LL<<pos); }
ll reset(ll N,ll pos){ return N= N & ~(1LL<<pos); }
bool check(ll N,ll pos){ return (bool)(N & (1LL<<pos)); }
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll vis[105][105][105];
main()
{
    ll n;
    cin>>n;
    vi v;
    lop0(n)
    {
        ll a;
        cin>>a;
        v.pb(a);
    }
    ll ans=0;
    for(ll i=0;i<v.size();i++)
    {
        for(ll j=0;j<v.size();j++)
        {
            for(ll k=0;k<v.size();k++)
            {
                if(i!=j and j!=k and k!=i and v[i]!=v[j] and v[j]!=v[k] and v[k]!=v[i])
                {
                    ll x=v[i];
                    ll y=v[j];
                    ll z=v[k];
                    ll mx=max(x,max(y,z));
                    if(mx==x)
                    {
                        if(y+z>x)
                        {
                            if(vis[i][j][k]==0 and vis[i][k][j]==0)
                            {
                                ans+=1;
                                vis[i][j][k]=1;
                                vis[i][k][j]=1;
                            }
                        }
                    }
                    if(mx==y)
                    {
                        if(x+z>y)
                        {
                            if(vis[j][i][k]==0 and vis[j][k][i]==0)
                            {
                                ans+=1;
                                vis[j][i][k]=1;
                                vis[j][k][i]=1;
                            }
                        }
                    }
                    if(mx==z)
                    {
                        if(y+x>z)
                        {
                            if(vis[k][j][i]==0 and vis[k][i][j]==0)
                            {
                                ans+=1;
                                vis[k][j][i]=1;
                                vis[k][i][j]=1;
                            }
                        }
                    }

                }




            }
        }
    }
    cout<<ans;
}



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

int main() {
  int N;
  cin >> N;
  int f = 0;
  int n = N;
  int r = 0;
  int divider = 100000000;
  rep(i, 8) {
    r = n % divider;
    int q = (n-r) / divider;
    f += q;
    
    divider /= 10;
    n = r;
  }
  f += r;
//  cout << f << endl;
  if ( N % f == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
def ave(a)
	a = a.sort
	a.pop
	a.shift
	s = a.size
	mean = 0
	for tmp in a
		mean += tmp
	end
	#puts a,s
	ans = mean / s
	ans
end
n = gets.to_i
while n != 0 
	#a = gets.split.map(&:to_i)
	a = []
	n.times do 
		tmp = gets.to_i
		a.push(tmp)
	end
	
	puts ave(a)
	n = gets.to_i
end

Measured memory_bytes: 8652
N,K=map(int,input().split())
A=list(map(int,input().split()))

#DP[keta][limit]で考える

A01=[[0,0] for i in range(51)]

for keta in range(51):
    A1=0
    A0=0
    for a in A:
        if a & (1<<keta)==0:
            A1+=1<<keta
        else:
            A0+=1<<keta

    A01[keta]=[A0,A1]



def ANS(keta,limit):
    
    if keta==-1:
        return 0

    if limit==1:               
        return max(A01[keta][0],A01[keta][1])+ANS(keta-1,1)

    if limit==0:
        if K & (1<<keta)==0:
            return A01[keta][0]+ANS(keta-1,0)
        else:
            return max(A01[keta][0]+ANS(keta-1,1),A01[keta][1]+ANS(keta-1,0))

print(ANS(50,0))

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

void solve() {
    ll n, k;
    cin >> n >> k;
    cout << min(n%k, k-n%k);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

def calc(ary):
    remain = sorted(ary)

    fact = {}
    for r in remain:
        fact[r] = math.factorial(r)
    fact[0] = 1

    result = 0
    max_length = len(ary)
    for i in range(len(ary)):
        ai = ary[i]
        cnt = 0
        for j in range(len(remain)):
            rj = remain[j]
            if ai == rj:
                result += j * fact[max_length - i-1]
                remain.remove(rj)
                break
            cnt += 1
    return result

print(int(math.fabs(calc(P) - calc(Q))))



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s,t,u;
	ll a,b;
	cin>>s>>t>>a>>b>>u;
	if(u==s)a--;
	else b--;
	cout<<a<<' '<<b;
	
	return 0;
}

Measured memory_bytes: 256
X = int(input())
fives = list(i**5 for i in range(1000))
for i, five in enumerate(fives):
    if five-X in fives:
        print(i, fives.index(five-X))
        break
    if X-five in fives:
        print(fives.index(X-five), -i)
        break


Measured memory_bytes: 9120
#include<iostream>

using namespace std;

int main() {
  string n;
  cin >> n;
  string r;
  for (int i = 0; i < 3; i++ ){
    if(n[i] == n[i+1]){
      r = "Bad";
      break;
    }
    r = "Good";
  }

  cout << r << endl;

  return 0;
}

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

int main() {
  char n, m;
  cin >> n >> m;
  string ans = "";
  
  if(n < m) {
    for(int i = 0; i < (m - '0'); i++) {
      ans.push_back(n);
    }
    cout << ans << endl;
  }
  else{
    for(int i = 0; i < (n - '0'); i++) {
      ans.push_back(m);
    }
    cout << ans << endl;
  }
}

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

#define int unsigned long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N;
int A[11];

int func(int n, bool seki) {
    if ( n == N ) {
        if ( !seki ) return 0;
        else return 1;
    }
    int ret = 0;
    ret += func(n+1, ((A[n]-1) % 2 == 0) || seki);
    ret += func(n+1, (A[n] % 2 == 0) || seki);
    ret += func(n+1, ((A[n]+1) % 2 == 0) || seki);
    return ret;
}

signed main() {
    cin >> N;
    Rep(i, N) cin >> A[i];
    cout << func(0, 0) << endl;
}


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

bool IsPrime(int num);

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

    int x, a = 0;
    cin >> x;
    while(!IsPrime(x)){
        ++x;
    }
    cout << x << endl;

    return 0;
}

bool IsPrime(int num)
{
    if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

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

int main() {
    string s;
    cin >> s;
    bool len_is_even = s.length() % 2 == 0, is_same = s[0] == s[s.length() - 1];
    if (len_is_even ^ is_same) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n);
    vector<int> b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    int mi = 0;
    ll sum = 0;
    int res = 0;
    rep(i, m){
        if(sum + b[i] <= k){
            sum += b[i];
            mi++;
        }else {
          break;
        }
    }
    res = mi;
    rep(i, n){
        sum += a[i];
        while(sum > k){
            if(mi == 0){
                cout << res << endl;
                return 0;
            }
            sum -= b[mi-1];
            mi--;
        } 
        res = max(res, i+1+mi);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4812
N = int(input())

def gcd(p, q):
  if p % q == 0:
    return q
  return gcd(q, p % q)

ans = 0
for x in range(1,N+1):
  for y in range(1,N+1):
    for z in range(1,N+1):
      ans += gcd(gcd(x, y), z)
print(ans)

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

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

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

    return arr
if(N==1):
    print(0)
else:
    prime_factor=factorization(N) 
    nrow=len(prime_factor)
    n=0
    for i in range(nrow):
        order=prime_factor[i][1]
        n+=math.floor((-1.0+math.sqrt(1.0+8.0*order))/2.0)
    print(n)

Measured memory_bytes: 9504
#include <stdio.h>
int main(void){
    int x, i, j, r, c;
    int temp[200][200]={0};
    scanf("%d %d",&r,&c);
    for(j=0;j<r;j++){
        for(i=0;i<c;i++){
            scanf("%d",&x);
            temp[i][j]+=x;
        }
    }
    for(j=0;j<r;j++){
        for(i=0;i<c;i++){
            temp[c][j]+=temp[i][j];
        }
    }
    for(i=0;i<=c;i++){
        for(j=0;j<r;j++){
            temp[i][r]+=temp[i][j];
        }
    }
    for(j=0;j<=r;j++){
        for(i=0;i<=c;i++){
            printf("%d", temp[i][j]);
            if(i!=c) printf(" ");                                     
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2112
S = input()
reverse_S = S[::-1]

while True:
    if reverse_S.startswith('esare'):
        reverse_S = reverse_S[5:]
        continue
    elif reverse_S.startswith('resare'):
        reverse_S = reverse_S[6:]
        continue
    elif reverse_S.startswith('maerd'):
        reverse_S = reverse_S[5:]
        continue
    elif reverse_S.startswith('remaerd'):
        reverse_S = reverse_S[7:]
        continue
    elif reverse_S =='':
        print('YES')
        break
    else:
        print('NO')
        break



Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
 
#define REP2(a,b) for(lo j=(a);j<(b);j++)
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++
#define INF INT_MAX
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
#define sz(x) x.size()
 
 
 
lo cel(lo x,lo y){
	if(x%y<=1)return x/y;
	else return x/y +1;
 }


lo counter(lo n){
	if(n==0)return 0;
	else 
		//cout<<n;
		return counter(n>>1) + (n&1);
}

void solve(){
	
	lo n;
	cin>>n;
	vl a(20,0);
	vector<vl> x(n,vl(20,0));
	vector<vl> y(n,vl(20,0));

	//cout<<sz(x)<<" "<<sz(x[0])<<endl;

	REP(0,n){
		cin>>a[i];
		REP2(0,a[i]){
			cin>>x[i][j]>>y[i][j];
		}
	}

	lo maxi=0;
	for(lo bits=0; bits < (1<<n); ++bits){
		lo flag=0;
		for(lo i=0;i<n;i++){
			if((bits)&(1<<(i))){
				REP2(0,a[i]){
					if( ((bits>>(x[i][j]-1))&1)  ^  (y[i][j]) ){
						flag=1;
						break;
					}
					// else{
					// 	cout<<
					// }
				}
			}
			if(flag)
				break;
		}
		if(flag==0)
		maxi=max(maxi,counter(bits));
	}

	cout<<maxi<<endl;
 }
 
 
int main(){
	
	// lo t;
	// cin>>t;
	// while(t--)
		solve();
	
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n, x, y = gets.split.map(&:to_i)
x -= 1
y -= 1

graph = Array.new(n) { [] }
(n - 1).times { |i| graph[i] << i + 1 }
1.upto(n - 1) { |i| graph[i] << i - 1 }
graph[x] << y
graph[y] << x

result = Array.new(n) { 0 }

n.times do |i|
  dist = Array.new(n) { -1 }
  dist[i] = 0
  queue = [i]

  while queue.any?
    v = queue.shift
    graph[v].each do |j|
      next if dist[j] != -1

      dist[j] = dist[v] + 1
      result[dist[j]] += 1
      queue << j
    end
  end
end

1.upto(n - 1) { |i| puts result[i] / 2 }

Measured memory_bytes: 30232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
#define UNIQUE(v) SORT(v);(v).erase(unique(ALL(v)),(v).end())
template<typename A,typename B> inline bool chmax(A &a,const B &b){if(a<b){a=b;return 1;}return 0;}
template<typename A,typename B> inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;}

const int MOD = (int)1e9 + 7;
const int INF = 1 << 30;
const ll INFF = 1LL << 62;

// 下にy, 右にx
enum {R, U, L, D};
const int dx[] = {1,  0, -1, 0};
const int dy[] = {0, -1,  0, 1};

int highest_bit(int num) {
    int ret = 0;
    while (num) {
        num >>= 1;
        ++ret;
    }
    return ret;
}

int N, K;
ll sum[32];

signed main() {

    cin >> N >> K;

    REP(i, N) {
        int A, B;
        cin >> A >> B;
        int h = highest_bit(A);
        if ((K | A) == K)
            sum[0] += B;
        FOR(j, 1, 32) {
            if (A & (1 << j)) continue;
            int k = K >> (j + 1);
            int a = A >> (j + 1);
            if ((k | a) == k) sum[j] += B;
        }
    }

    ll res = sum[0];
    REP(i, 32) if ((1 << i) & K) chmax(res, sum[i]);
    cout << res << endl;

}

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

int main(int argc, char **argv)
{
	ll N; cin >> N;
	string S; cin >> S;
	vector<ll> w(N, 0), e(N, 0);

	for (ll i = 0; i < N; ++i)
	{
		if (S[i] == 'W')
			w[i] = 1;
		else
			e[i] = 1;
	}

	vector<ll> sumw(N+1, 0), sume(N+1, 0);
	for (ll i = 0; i < N; ++i)
	{
		sumw[i+1] = sumw[i] + w[i];
		sume[i+1] = sume[i] + e[i];
	}

	ll res{1ll<<60};

	for (ll i = 0; i <= N; ++i)
	{
		ll tmp{0};
		tmp += sumw[i] - sumw[0];
		tmp += sume[N] - sume[i];
		res = min(res, tmp);
	}

	std::cout << res << std::endl;
}

Measured memory_bytes: 9988
#include "bits/stdc++.h"
using namespace std;
#define dump(x) cout << (x) << endl
typedef int64_t Int;
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 114514810893364364;

int main() {
  Int n;
  cin >> n;
  map<Int, Int> mp;
  for (Int i = 0; i < n; i++) {
    Int p;
    cin >> p;
    mp[p] = i;
  }
  Int f = 0, b = 0;
  Int mf = 0, mb = 0;
  for (Int i = 1; i <= n - 1; i++) {
    if (mp[i] < mp[i + 1]) {
      f++;
    }
    else {
      f = 0;
    }
    mf = max(mf, f);
  }
  for (Int i = n; i > 1; i--) {
    if (mp[i] > mp[i - 1]) {
      b++;
    }
    else {
      b = 0;
    }
    mb = max(mb, b);
  }
  dump(n - max(mf, mb) - 1);
  return 0;
}


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

using namespace std;

struct  node
{
    int x,id;
}a[110000],b[110000];
bool cmp(node a,node b)
{
    return a.x > b.x;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 1;i <= 100000;i++)
    {
        a[i].id = b[i].id = i;
    }
    for(int i = 1;i <= n;i++)
    {
        int x;
        scanf("%d",&x);
        if(i%2==0) a[x].x++;
        else b[x].x++;
    }
    sort(a+1,a+1+100000,cmp);
    sort(b+1,b+1+100000,cmp);
    int ans;
    if(a[1].id != b[1].id) ans = n - a[1].x - b[1].x;
    else ans = min(n-a[1].x-b[2].x,n-a[2].x-b[1].x);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1792
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())

answer = 0
rest = 10 ** 9 + 7
if N == 1:
  answer = 0
else:
  answer = (10 ** N) - (9 ** N) - (9 ** N) + (8 ** N)
print(answer % rest)


Measured memory_bytes: 11504
#include<cstdio>

int a, b;
int d, r; double f;

int main(void){
	scanf("%d %d", &a, &b);

	d = a / b;
	r = a % b;
	f = (double)a / (double)b;

	printf("%d %d %.5f\n", d, r, f);

	return 0;
}

Measured memory_bytes: 2692
using System;
    using System.Linq;
    using System.Collections.Generic;
    using static System.Console;
    using System.Text;
     
     
    namespace AtCoder_Beginner_Contest_132
    {
        class Program
        {
            static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
            static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
            static void Main(string[] args)
            {
                var ND=Sarray();
                var N = ND[0];
                var D = ND[1];
                var Xij = new List<long>[N];
                for(var i=0;i<N;++i)
                {
                    Xij[i] = Slist();
                }
                var cnt = 0;
                for(var i=0;i<N;++i)
                {
                    for(var j=i+1;j<N;++j)
                    {
                        var sum = 0L;
                        for (var k = 0; k < D;++k)
                        {
                            sum += (long)Math.Pow(Xij[i][k] - Xij[j][k], 2);
                        }
                        if (Math.Sqrt(sum) - (long)Math.Sqrt(sum) < 0.000001)
                            ++cnt;
                    }
                }
                WriteLine(cnt);
            }
        }
    }

Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> X(M), ans(M - 1);
    for (int i = 0; i < M; i++)
    {
        cin >> X[i];
    }
    if (M <= N)
    {
        cout << 0 << endl;
        return 0;
    }
    sort(X.begin(), X.end());
    for (int i = 1; i < M; i++)
    {
        ans[i - 1] = abs(X[i] - X[i - 1]);
    }
    sort(ans.begin(), ans.end());
    cout << accumulate(ans.begin(), ans.end() - N + 1, 0) << endl;

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
public static void main(String[] args){
Map<String,Integer> map=new HashMap<>(7);
  map.put("MON",1);
  map.put("TUE",2);
  map.put("WED",3);
  map.put("THU",4);
  map.put("FRI",5);
  map.put("SAT",6);
  map.put("SUN",7);
  Scanner s=new Scanner(System.in);
  String in=s.next();
  String sun="SUN";
  if(in.equals(sun))
    System.out.println(7);
  else
    System.out.println(7-map.get(in));
}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

int main() {
  string s;
  cin >> s;
  if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) cout << "Yes" << endl;
  else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) cout << "Yes" << endl;
  else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) cout << "Yes" << endl;
  else cout << "No" << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int a,b,c;cin>>a>>b>>c;
  int ans=0;
  bool now=true;
  int now2=0;
  for(int i=0;i<a;i++){
    int n;cin>>n;
    if(now){
      ans+=max(0,n-now2-b);
      now=false;
      now2=n;
    }else{
      ans+=max(0,n-now2-2*b);
      now2=n;
    }
  }
  cout<<ans+max(0,c-now2-b)<<endl;
  return 0;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC093C - Same Integers
  // 
  vector<int> ABC(3, 0);
  for(auto &i : ABC) cin >> i;
  sort(ABC.begin(), ABC.end());
  int oddcnt = 0, evencnt = 0;
  for(int i : ABC){
    if(i % 2 == 1){
      oddcnt++;
    }
    if(i % 2 == 0){
      evencnt++;
    }
  }
  int ans = 0;
  if(oddcnt == 1){
    REP(i, 3){
      if(ABC[i] % 2 == 0){
        ABC[i]++;
      }
    }
    ans++;
  }else if(evencnt == 1){
    REP(i, 3){
      if(ABC[i] % 2 == 1){
        ABC[i]++;
      }
    }
    ans++;
  }
  ans += (ABC[2]-ABC[0])/2 + (ABC[2]-ABC[1])/2;
  cout << ans << endl;
}

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

int main() {
	int n;
	long int ans = 0;
	cin >> n;

	for (int i = 1; i < n+1; i++) {
		if (i % 5 == 0 || i % 3 == 0)continue;
		ans += i;
	}
	cout << ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h> 
using namespace std;
long long a[3],s;
int main(){
	cin>>a[0]>>a[1]>>a[2];
	while(1){
		sort(a,a+3);
		if (a[0]+2<=a[2]){
			a[0]+=2;
			s++;
		}
		else break;
	}
	while(1){
		sort(a,a+3);
		if (a[1]+1<=a[2]){
			a[0]++;
			a[1]++;
			s++;
		}
		else break;
	}
	sort(a,a+3);
	if (a[0]<a[2]&&a[1]==a[2]){
		cout<<s+2;
		return 0;
	}
	cout<<s;
	return 0;
}

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

using vi = std::vector<int>;
using ll = long long;

int main()
{
    int N;
    std::cin >> N;
    vi A(N), B(N);
    for (int i = 0; i < N; i++)
        std::cin >> A[i] >> B[i];

    sort(begin(A), end(A), std::less<int>());
    sort(begin(B), end(B), std::greater<int>());

    ll ans;
    int hN = N / 2;
    if (N % 2 == 0)
    {
        ll kagen0 = A[hN-1];
        ll kagen1 = A[hN];
        ll jogen0 = B[hN-1];
        ll jogen1 = B[hN];
        ans = (jogen0 + jogen1) - (kagen0 + kagen1) + 1;
    }
    else
    {
        int jogen = B[hN];
        int kagen = A[hN];
        ans = jogen - kagen + 1;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 4776
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

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

Measured memory_bytes: 256
#include<stdio.h>

  #define MAX 2000000

  int H,A[MAX+1];

  void maxHeapify(int i){
  int l,r,largest,C;
  l=2*i;
  r=2*i+1;

  if(l<=H && A[l]>A[i]) largest=l;
  else largest = i;

  if(r<=H && A[r]>A[largest])largest=r;

  if(largest != i ){
   C = A[i];
   A[i] = A[largest];
   A[largest] = C;
   maxHeapify(largest);
  }
}

  int main(){
  int i;
  scanf("%d",&H);
  for(i=1; i<=H; i++)scanf("%d",&A[i]);
  for(i=H/2; i>=1; i--)maxHeapify(i);
  for(i=1; i<=H; i++){
   printf(" %d",A[i]);
 }
  printf("\n");
  return 0;
}



Measured memory_bytes: 3804
H, W = map(int, input().split())
S = [input() for _ in range(H)]

M_W = [[0] * W for i in range(H)]
M_H = [[0] * W for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      if j == 0:
        M_W[i][j] = 1
      else:
        M_W[i][j] = M_W[i][j - 1] + 1
  for j in range(W-2,-1,-1):
    if S[i][j] == '.' and S[i][j+1] == '.':
      M_W[i][j] = M_W[i][j+1]

for j in range(W):
  for i in range(H):
    if S[i][j] == '.':
      if i == 0:
        M_H[i][j] = 1
      else:
        M_H[i][j] = M_H[i-1][j] + 1
  for i in range(H-2,-1,-1):
    if S[i][j] == '.' and S[i+1][j] == '.':
      M_H[i][j] = M_H[i+1][j]

#print(M_W)
#print(M_H)

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, M_W[i][j]+M_H[i][j]-1)
print(ans)

Measured memory_bytes: 123608
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define pr(...) GET_MACRO(__VA_ARGS__,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)
#define pr1(a) (#a)<<"="<<(a)
#define pr2(a,b) pr1(a)<<", "<<pr1(b)
#define pr3(a,b,c) pr2(a,b)<<", "<<pr1(c)
#define pr4(a,b,c,d) pr3(a,b,c)<<", "<<pr1(d)
#define pr5(a,b,c,d,e) pr4(a,b,c,d)<<", "<<pr1(e)
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}

vector<int> mkSeq(int n,int S,int W){
  vector<int> a(n);
  int g = S;
  for(int i=0;i<n;i++){
    a[i] += (g/7) % 10;
    g = (g%2==0)? g/2:(g/2)^W; 
  }
  return a;
}

class RollingHash{
public:
  typedef unsigned long long ull;
  const ull B = 10; //ハッシュ基数
  int mod;
  int n;
  vector<int> s;
  vector<ull> hash;
  vector<ull> k;

  RollingHash(){};
  RollingHash(vector<int> s,int mod):mod(mod),n(s.size()),s(s),hash(n+1),k(n+1){
    k[0] = 1;
    for(int i=1;i<=n;i++) k[i] = k[i-1] * B % mod;
    for(int i=0;i<n;i++) hash[i+1] = (hash[i] * B + s[i])%mod;
    for(int i=0;i<n;i++) hash[i+1] = hash[i+1] * k[n-i-1] % mod;
  }

  ull get(int l,int r){assert(0<=l && r<=n);return hash[r] - hash[l] * k[r-l];}//[l,r)
};

int n,Q;
vector<int> A;
int mem[N][10],used[N][10];
int dfs(int idx,int mod){
  if(idx == n) return 0;
  if(used[idx][mod]++) return mem[idx][mod];
  int nmod = (mod*10+A[idx])%Q;
  int res = dfs(idx+1,nmod) + (nmod == 0);
  return mem[idx][mod] = res;
}

signed main(){
  while(1){
    int S,W;
    cin>>n>>S>>W>>Q;
    if(!n && !S && !W && !Q) return 0;
    
    A = mkSeq(n,S,W);
    if(Q == 2 || Q == 5){
      memset(used,0,sizeof(used));
      int ans = 0;
      for(int i=0;i<n;i++) if(A[i]) ans += dfs(i,0);
      cout<<ans<<endl;
      continue;
    };
    
    RollingHash H(A,Q);
    map<int,int> cnt;
    for(int i=0;i<n;i++) cnt[H.hash[i+1]]++;
  
    int ans = 0;
    int ofset = 0;
    for(int i=0;i<n;i++){
      if(A[i] != 0) ans += cnt[ofset];
      cnt[H.hash[i+1]]--;
      ofset += A[i]*H.k[n-i-1];
      ofset %= Q;
    }
    cout<<ans<<endl;
  }  
  return 0;
}



Measured memory_bytes: 23232
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

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

  ll N, X, Y;
  std::cin >> N >> X >> Y;

  std::vector<ll> vcnt(N, 0LL);
  for (ll i = 1; i <= N; i++) {
    for (ll j = i+1; j <= N; j++) {
      ll dist = std::min(j-i, std::abs(X-i) + 1 + std::abs(Y-j));
      vcnt[dist]++;
    }
  }

  for (ll i = 1; i < N; i++) {
    print(vcnt[i]);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define int long long
using namespace std;
typedef pair<ll, ll> pii;
typedef vector<vector<ll>> mat;
const ll mod = 1e9+7;
const int MAXN = 1*1e5+5;

void add_mod(int &a, int b) {
	a += b;
	if(a >= mod)
		a -= mod;
}
void sub_mod(int &a, int b) {
	a -= b;
	if(a < 0)
		a += mod;
}

int32_t main() {
	int n, k;
	cin >> n >> k;
	vector<ll> dp(k+2);
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		int up;
		cin >> up;
		vector<int> fake(k+2);
		for(int j = k; j >= 0; j--) {
			int L = j+1, R = j + min(up, k - j) + 1;
			if(L <= R) {
				add_mod(fake[L], dp[j]);
				if(R <= k)
					sub_mod(fake[R], dp[j]);
			}
		}
		int prefix_sum = 0;
		for(int j = 0; j <= k; j++) {
			add_mod(prefix_sum, fake[j]);
			add_mod(dp[j], prefix_sum);
		}
	}
	cout << dp[k] << endl;   
	


}


Measured memory_bytes: 1792