akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
using namespace std;

typedef long long ll;
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define rerepi(i, a, b) for(int i = int(a)-1; i >= b; --i)
#define rerep(i, n) rerepi(i, n, 0)

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

const long long INF = 1LL << 60;

ll N, W;
std::vector<ll> objs_w;
std::vector<ll> objs_v;
ll DP[110][100010];

// ここから開始だよ！
int main() {
	// 呪文エリア
	cin.tie(0);
	ios::sync_with_stdio(false);
	// 詠唱完了
  
  cin >> N >> W;
  rep(i, N) {
    ll w, v;
    cin >> w >> v;
    objs_w.push_back(w);
    objs_v.push_back(v);
  }
  
  DP[0][0] = 0;
  
  rep(nn, N+1) {
    rep(ww, W+1) {
      ll w = objs_w[nn];
      ll v = objs_v[nn];
      
      chmax(DP[nn+1][ww], DP[nn][ww]);
      if (ww - w >= 0) {
        chmax(DP[nn+1][ww], DP[nn][ww - w] + v);
      }
    }
  }
	
  cout << DP[N][W] << endl;
  
	return 0;
}


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

int main() {
    int n, m;
    long long ans = 0;
    cin >> n >> m;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a+n);
    vector<pair<int, int>> v;
    int b, c;
    for(int i = 0; i < m; ++i) {
        cin >> b >> c;
        v.push_back(make_pair(-c, b));
    }
    sort(v.begin(), v.end());

    int j = 0;
    int C = -v[j].first, B = v[j].second;
    for(int i = 0; i < n; ++i) {
        if(a[i] < C) {
            a[i] = C;
            B--;
        } else {
            break;
        }
        if(B == 0) {
            j++;
            if(j >= m) break;
            C = -v[j].first, B = v[j].second;
        }
    }
    
    for(int i = 0; i < n; ++i) ans += a[i];
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
	using namespace std;
	int main() { 
	    
	    string str,check;
	    cin >> str >> check;

	    str += str;
	    int len = check.size();
	    for(int i=0;i<str.size()-len;i++){
	    	if(str.substr(i,len) == check){
	    		cout << "Yes" << endl;
	    		return 0;
	    	}
	    }

	    cout << "No" << endl;

	    return 0;
	}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll &b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll &b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
ll num=1, ans=0, cnt=0, sum=0;

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

  ll N, M;
  cin >> N >> M;
  vl A(M);
  rep(i, M) {
    cin >> A[i];
    sum += A[i];
  }
  cout << max(N-sum,(ll)(-1)) << '\n';
  return 0;
}


Measured memory_bytes: 3668
#include <stdio.h>
 
int main(void) {
 
  long a,b,c,k,count = 0;
  scanf("%ld %ld %ld %ld", &a, &b, &c, &k);
  while (b <= a) {
    count++;
    b *= 2;
  }
  while (c <= b) {
    count++;
    c *= 2;
  }
  if (count <= k) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
 
  return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>


#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;

 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
typedef pair<int,int> pr; 
 
const ll OOl = LLONG_MAX;
const int N = 1e6+1, M = 1e6+1, OO = INT_MAX,OOmem = 0x4f4f4f4f, MOD = 1e9 + 7;

inline void WRITE_CHAR(char c)  {putchar_unlocked(c);}
 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  while (!isdigit(ch) && ch!=EOF) minus = (ch == '-'? -1 : minus),ch= (char) getchar_unlocked();
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char (&x)[N]) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
inline int add(int x,int y)
{
   x+=y;
   if(x>=MOD) x-=MOD;
   return x;
}
inline int sub(int x,int y)
{
  x-=y;
  if(x<0) x+=MOD;
  return x;
}

int n,m,arr[101];
int dp[101][N],acc[101][N];
int main()
{
  
  READn(n),READn(m);
  for(int i=0;i<n;++i) READn(arr[i]);
  for(int i=0;i<=n;++i) dp[i][0]=acc[i][0]=1;
  for(int i=1;i<=m;++i) acc[0][i] = 1;

  for(int i=1;i<=n;++i)
  {
    for(int k=1;k<=m;++k)
    {
      int R = k,L=k-min(k,arr[i-1]);
      dp[i][k] = add(dp[i][k],acc[i-1][R]);
      if(L>0) dp[i][k] = sub(dp[i][k],acc[i-1][L-1]);
      acc[i][k]=add(acc[i][k-1],dp[i][k]);
    }
  
  }
  WRITEn(dp[n][m]);
  return 0;
}




Measured memory_bytes: 492160
import math
N = int(input())
A = list(map(int, input().split()))
section = [[A[-1], A[-1]]]
for i in range(1, N+1):
    min_section = math.ceil(section[i-1][0] / 2) + A[-i-1]
    max_section = section[i-1][1] + A[-i-1]
    section.append([min_section, max_section])
section = section[::-1]

if section[0][0] > 1:
    print(-1)
    exit()

node = [1]

for i in range(1, N+1):
    node.append(min((node[i-1] - A[i-1]) * 2, section[i][1]))

print(sum(node))

Measured memory_bytes: 33528
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

int n, m;

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  return 1;
}

void solve() {
  int r1 = -1, r2 = -1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      static char s[100];
      scanf("%s", s);
      if (r1 == -1 && !strcmp(s, "snuke")) {
        r1 = i, r2 = j;
      }
    }
  }
  printf("%c%d\n", r2 + 'A', r1 + 1);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE

void solve(void)
{
  int N,M;
  cin>>N>>M;
  vector<vector<int> > vec(N);
  vector<vector<int> > DATA(M,vector<int>(2));
  for (int i = 0; i < M; i++)
  {
    int A,B;
    cin>>A>>B;
    A--;
    DATA[i][0] = A; 
    DATA[i][1] = B; 
    vec[A].push_back(B);
    // DEBUG("call");
  }
  for (int i = 0; i < N; i++)
  {
    sort(ALL(vec[i]));
  }
  
  for (int i = 0; i < M; i++)
  {
    int A = DATA[i][0];
    int B = DATA[i][1];
    auto itr = lower_bound(ALL(vec[A]),B);
    auto iB = vec[A].begin();
    int RANK = (int)distance(iB,itr)+ 1;
    string CITY = to_string(A+1);
    for (int i = 0; i < 6 - CITY.size(); i++)
    {
      cout<<"0";
    }
    cout<<CITY;
    string sRANK = to_string(RANK);
    for (int i = 0; i < 6 - sRANK.size(); i++)
    {
      cout<<"0";
    }
    cout<<sRANK;
    cout<<endl;
    
    
    

  }
  

  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 12416
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    int N, K, X, Y;
    int sum = 0;
    cin >> N >> K >> X >> Y;

    for (int i = 1; i <= N; i++) {
        if (i <= K) {
            sum += X;
        } else if (i >= K + 1) {
            sum += Y;
        }
    }

    cout << sum << endl;

    return 0;
}

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

int main(){
char s[11];cin>>s;
  int ans=0,count=0;
  for(int i=0;i<11;i++)
  {
    
    if(s[i]=='A'||s[i]=='G'||s[i]=='T'||s[i]=='C')
    {
    count++;
    if(i==10)
      ans=max(ans,count);
    }
      
  
  else{
    ans=max(ans,count);
    count=0;
  }
  }
  cout<<ans<<endl;
}

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

int main() {
  int a,b;
  cin >> a>>b;
  int  c[100];
  for (int i =0;i<a; i++)
    
  cin >> c[i];
  
 sort(c,c+a);
  
  int d;
  d =0;
   for(int i=a-1; i >a-1-b ; i--){
       
      d += c[i];
   }
     cout << d << endl;       
            
   }
      
       
     
   

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ")
    var c = 0
    for (i in 0..(n-3)){
        if (p[i + 1].toInt() > p[i].toInt() && p[i + 1].toInt() < p[i + 2].toInt() || p[i + 1].toInt() > p[i + 2].toInt() && p[i + 1].toInt() < p[i].toInt()) c++
    }
    print(c)
}


Measured memory_bytes: 37736
use proconio::input;

fn main() {
    input! {
        a: isize, b: isize, c: isize,
        x: isize, y: isize,
    }

    let mut ans = a*x + b*y;
    let dif = c*2 - (a+b);
    let min = std::cmp::min(x, y);
    if dif < 0 {
        ans += dif * min;
        if x < y && c*2 < b {
            ans += (y-x) * (c*2 - b);
        } else if y < x && c*2 < a {
            ans += (x-y) * (c*2 - a);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int N,K;
    int Ans=0;
    int x;
    cin >> N >> K;
    REP(i,N){cin >> x;Ans+=2*min(x,K-x);}
    cout << Ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int H,W;
int h,w;
int ans;
int main(void)
{
    cin >> H >> W;
    cin >> h >> w;

    int ar[H][W]={};

    for(int i=0;i<H;i++)
    {
        for(int j=0;j<w;j++)
        {
            ar[i][j]=1;
        }
    }

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<W;j++)
        {
            ar[i][j]=1;
        }
    }

    for(int i=0;i<H;i++)
    {
        for(int j=0;j<W;j++)
        {
            if(ar[i][j]==0)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;


    return 0;
}

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

int main(){
  int n,t0=0,x0=0,y0=0,t1,x1,y1,dif=0,dif_t=0;cin>>n;

  for(int i=0;i<n;++i){
    cin>>t1>>x1>>y1;
    dif=abs(x0-x1+y0-y1);
    dif_t=t1-t0;
    if((dif%2!=dif_t%2)||dif>dif_t){
      printf("No\n");
      return 0;
    }
    t1=t0;
    x1=x0;
    y1=y0;
  }printf("Yes\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

string s, t;

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

  cin >> s >> t;

  ll slen = s.size();
  ll tlen = t.size();

  map<char, vector<ll>> mp;
  for (int i = 0; i < slen; i++) {
    mp[s[i]].push_back(i);
  }

  ll ans = 0;
  ll prev = 0;
  for (int i = 0; i < tlen; i++) {
    if (mp.find(t[i]) == mp.end()) {
      ans = -1;
      cout << ans << ln;
      return 0;
    } else {
      auto &v = mp[t[i]];
      auto lb = lower_bound(all(v), prev);
      auto idx = distance(v.begin(), lb);

      if (lb == v.end()) {
        // prev以降になく、先頭に戻る場合
        ll tail = slen - prev;
        ll head = v[0] + 1;
        ans += tail + head;
        prev = head;
      } else {
        // prev以降にあって、そのまま連続してできる場合
        ll sidx = v[idx];
        ll dist = sidx + 1 - prev;
        ans += dist;
        prev = sidx + 1;
      }
    }
  }

  cout << ans << ln;

  return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>
int main(void)
{
	int h,w,i,j;
	scanf("%d%d",&h,&w);
	char a[102][102],b[102][102];
	for(i=0; i<h; i++){
		scanf("%s",&a[i]);
	}
	for(i=0; i<h+2; i++){
		for(j=0; j<w+2; j++){
			b[i][j]='#';
		}
	}
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			b[i+1][j+1]=a[i][j];
		}
	}
	for(i=0; i<h+2; i++){
		for(j=0; j<w+2; j++){
			printf("%c",b[i][j]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const ll mod = 1000000000+7;

int main(){
    int n;  cin >> n;
    vector<ll>a(n);
    rep(i, n)   cin >> a[i];
    ll ans = 0;
    rep(i, 60){
        ll count = 0;  //1の数
        rep(j, n){
            if(a[j] >> i & 1) count++;
        }
        ll tmp = count*(n-count)%mod;
        rep(j, i) tmp = tmp*2%mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;
}


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

int main(){
    int n;
    cin >> n;
    int a = 0;
    if( n <= 111) a = 111;
    else if( 111 < n && n <= 222) a = 222;
    else if( 222 < n && n <= 333) a = 333;
    else if( 333 < n && n <= 444) a = 444;
    else if( 444 < n && n <= 555) a = 555;
    else if( 555 < n && n <= 666) a = 666;
    else if( 666 < n && n <= 777) a = 777;
    else if( 777 < n && n <= 888) a = 888;
    else a = 999;

    cout << a << endl;
}

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

import itertools
Ruisekiwa = list(itertools.accumulate(A))

count = 1

Dekiru = [0]*N
Dekiru[N-1] = 1

for i in range (1, N):
	if 2*Ruisekiwa[N-i-1] >= A[N-i] and Dekiru[N-i] == 1:
		count+=1
		Dekiru[N-i-1]=1
        
print(count)

Measured memory_bytes: 20592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<char,int> pci;
typedef vector<pair<int,int>> vpii;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
#define sci(a) scanf("%d",&a)
#define scii(a,b) scanf("%d %d",&a,&b)
#define sciii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sciiii(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define scl(a) scanf("%lld",&a)
#define scll(a,b) scanf("%lld %lld",&a,&b)
#define sclll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c
#define scllll(a,b,c,d) scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define print(a) printf("%d ",a)
#define println(a) printf("%d\n",a)
#define ln printf("\n")
#define pb(a) push_back(a)
#define m_p(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define rep(i,s,n) for(int i=s;i<=n;i++)
#define rrep(i,e,s) for(int i=e;i>=s;i--)
#define repv(i,m) for(auto i = m.begin();i != m.end();i++)
#define FileIO freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const long long INF = 4000000000000000000LL;
/************************************* Chocolate *************************************/
const int mod = 1e9+7;
int number_of_ones(int mask){
    int c = 0;
    while(mask){
        c++;
        mask &= (mask-1);
    }
    return c;
}
int main(){
    int n;
    sci(n);
    vvi can(n,vi(n));
    rep(i,0,n-1){
        rep(j,0,n-1){
            sci(can[i][j]);
        }
    }
    int MAX = (1<<n);
    vi dp(MAX,0);
    dp[0] = 1;
    for(int mask = 1;mask < MAX;++mask){
        int ones = number_of_ones(mask);
        for(int i=0;i<n;i++){
            int j = 1<<i;
            if(can[ones-1][i] && (mask&j)){
                dp[mask] = (dp[mask] +dp[mask^j])%mod;
            }
        }
    }
    cout << dp[MAX-1] << endl;
}

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

#define p(i,a,b) for(int i=a;i<b;++i)

int main(){
    int n,b;
    cin >> n;
    b = n/2;
    vector<int> a(n);
    p(i,0,n) cin >> a[i];
    sort(a.begin(),a.end());
    int64_t s = a[n-1] - a[0];
    p(i,1,b) s += a[n - i] - a[i] + a[n-i-1] - a[i-1];
    if(n & 1) s += max(a[b] - a[b - 1],a[b+1] - a[b]);
    cout << s << '\n';
}

Measured memory_bytes: 3796
#include <stdio.h>
void trace(int A[],int N)
{
  int i;
  for(i=0;i<N;i++)
    {
      if(i > 0) printf(" ");
      printf("%d",A[i]);
    }
  printf("\n");
}
  void insertionSort(int A[],int N)
  {
    int j,i,v;
    for(i=1;i<N;i++)
      {
	v=A[i];
	j=i-1;
	while (j >= 0 && A[j] > v)
	  {
	    A[j+1] =A[j];
	    j--;
	  }
	A[j+1] = v;
	trace(A,N);
      }
  }

  int main(){
    int N,i,j;
    int A[100];

    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    trace(A,N);
    insertionSort(A,N);


    return 0;
  }



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e3 + 10;
const ll mod = 1e9 + 7;
ll f[2][N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    f[1][0] = 1;
    ll ans = 0;
    for (int i = 0; i < n / 3; ++i)
    {
        int cur = i % 2, lst = 1 - cur;
        memset(f[cur], 0, sizeof(f[cur]));
        for (int j = 3 * i; j <= n - 3; ++j)
        {
            for (int k = 3; j + k <= n; ++k)
                f[cur][j + k] = (f[cur][j + k] + f[lst][j]) % mod;
        }
        ans = (ans + f[cur][n]) % mod;
    }
    cout << ans;
}

Measured memory_bytes: 3676
S = list(input())
T = list(input())

res = len(T)

for i in range(len(S) - len(T) + 1):
    cnt = 0
    smallS = S[i:i+len(T)]
    for s, t in zip(smallS, T):
        if s == t:
            cnt += 1
    if (len(T) - cnt) < res:
        res = len(T) - cnt

print(res)

Measured memory_bytes: 9052
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int MAX_N = 500, MAX_C = 30;
int N, C;
int D[MAX_C+1][MAX_C+1];
int field[MAX_N+1][MAX_N+1];
int num[3][MAX_C+1];

int main() {
  cin >> N >> C;
  for (int i = 1; i <= C; ++i) {
    for (int j = 1; j <= C; ++j) {
      cin >> D[i][j];
    }
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      cin >> field[i][j];
    }
  }

  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if ((i+j)%3 == 0) num[0][field[i][j]]++;
      if ((i+j)%3 == 1) num[1][field[i][j]]++;
      if ((i+j)%3 == 2) num[2][field[i][j]]++;
    }
  }

  ll ans = 1e18;
  for (int a = 1; a <= C; ++a) {
    for (int b = 1; b <= C; ++b) {
      for (int c = 1; c <= C; ++c) {
        if (a == b || a == c || b == c) continue;

        ll tmp = 0;
        for (int i = 1; i <= C; ++i) {
          tmp += D[i][a] * num[0][i];
        }
        for (int i = 1; i <= C; ++i) {
          tmp += D[i][b] * num[1][i];
        }
        for (int i = 1; i <= C; ++i) {
          tmp += D[i][c] * num[2][i];
        }

        ans = min(ans, tmp);
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int c[200005], d[200005], q[200005], l[200005], r[200005], s[200005], o = 0;
vector<int> g[200005], b[200005], y[200005];
vector<pii> e[200005];

void dfs(int x, int p) {
    q[x] = p;
    l[x] = ++o;
    d[x] = 1;
    if (b[c[x]].size()) e[b[c[x]].back()].push_back({x, s[b[c[x]].back()]});
    b[c[x]].push_back(x);
    for (int i : g[x]) if (i != p) {
        dfs(i, x);
        d[x] += d[i];
        s[x]++;
    }
    b[c[x]].pop_back();
    r[x] = o;
}

int main() {
    ios::sync_with_stdio(false);
    int n, u, v, t[200005] = {};
    ll z[200005] = {};
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i], t[c[i]]++;
    for (int i = 1; i < n; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    dfs(1, 1);
    for (int i = 1; i <= n; i++) {
        vector<int> f;
        for (int j : g[i]) if (j != q[i]) f.push_back(d[j]);
        for (pii j : e[i]) f[j.second] -= d[j.first];
        for (int j : f) t[c[i]] += j, z[c[i]] += 1ll * j * (j + 1) / 2;
    }
    for (int i = 1; i <= n; i++) z[i] += 1ll * (n - t[i]) * (n - t[i] + 1) / 2;
    for (int i = 1; i <= n; i++) cout << 1ll * n * (n + 1) / 2 - z[i] << '\n';
}


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

using namespace std;

using ll = long long;

constexpr char newl = '\n';

ll solve(int n, const vector<ll>& a, const vector<ll>& b, int num) {
    ll ng = 0, ok = 1e9 + 1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;

        int le = 0, cnt = 0;
        for (int i = 0; i < n; i++) {
            if (b[i] < mid) ++le;
            else if (mid >= a[i]) ++cnt;
        }

        if (num <= le + cnt) {
            ok = mid;
        } else {
            ng = mid;
        }
        //cerr << ok << "," << ng << newl;
    }
    return ok;
}

ll solve2(int n, const vector<ll>& a, const vector<ll>& b, int num) {
    ll ok = 0, ng = 1e9 + 1;
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;

        int le = 0, cnt = 0;
        for (int i = 0; i < n; i++) {
            if (b[i] < mid) ++le;
            else if (mid >= a[i]) ++cnt;
        }

        if (le < num) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    return ok;
}

void solve3(int n, const vector<ll>& a, const vector<ll>& b) {
    map<ll, vector<int> > memo;
    for (int i = 0; i < n; i++) {
        memo[a[i]].push_back(0);
        memo[b[i]].push_back(1);
    }
 
    int le = 0, cnt = 0;
    ll minv = -1, maxv = -1;
    for (auto& p : memo) {
        for (int i : p.second) {
            if (i == 0) {
                ++cnt;
            } else {
                --cnt;
                ++le;
            }
        }
 
        if (le <= n / 2 + 1 && n / 2 + 1 <= le + cnt) {
            if (minv == -1) minv = p.first;
            maxv = max(maxv, p.first);
        }
    }
 
    cout << maxv - minv + 1 << newl;
}

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

    int n;
    cin >> n;

    vector<ll> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    if (n % 2 == 1) {
        cout << solve2(n, a, b, (n + 1) / 2) - solve(n, a, b, (n + 1) / 2) + 1 << newl;
    } else {
        ll foo = solve(n, a, b, (n + 1) / 2 + 1);
        ll bar = solve(n, a, b, (n + 1) / 2);
        ll foo2 = solve2(n, a, b, (n + 1) / 2 + 1);
        ll bar2 = solve2(n, a, b, (n + 1) / 2);
        cout << (foo2 + bar2) - (foo + bar) + 1 << newl;
    }
    return 0;
}


Measured memory_bytes: 6336
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


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

int N;cin>>N; 
  int sum=0;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
    sum+=vec[i];
  }
  vsort(vec);
  int m=0;
  for(int i=0;i<N;i++){
    if(vec[i]%10!=0){
      m=vec[i];
      break;
    }
  }
  
  if(sum%10==0&&m==0){
    cout<<0<<endl;
  }
  if(sum%10==0&&m!=0){
    cout<<sum-m<<endl;
  }
  if(sum%10!=0){
    cout<<sum<<endl;
  }
  
 // cout<<m<<endl;
  //cout<<sum<<endl;
}



Measured memory_bytes: 256
using System;

public class Test
{
	public static void Main( )
	{
		double[] nums = Array.ConvertAll( Console.ReadLine().Split( ' ' ), double.Parse );
		var a = nums[0];
		var b = nums[1];
		var C = nums[2]*Math.PI/180.0;
		var h = Math.Sin( C )*b;
		var ta = Math.Cos( C )*b;
		var c = Math.Sqrt( Math.Pow( a-ta, 2 )+Math.Pow( h, 2 ) );
		var S = (a*h)/2;
		var L = a+b+c;
		Console.WriteLine( "{0}\n{1}\n{2}", S, L, h );
	}
}

Measured memory_bytes: 9412
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      a[i]--;
    }

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

    System.out.println(ans / 2);
  }
}


Measured memory_bytes: 50084
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

//#define int long long

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/*----------------------------------------------/
/- char         : %c  | char *       : %s  | short        : %hd
/- int          : %d  | long         : %ld | long long    : %lld
/- unsigned short:%hu | unsigned int : %u  | unsigned long: %lu
/- u_long long  : %llu| (octal)      : %o  | (hexadecimal): %x
/- float        : %f  | double       : %lf |
/----------------------------------------------*/

/*----------------------------------------------/
/- INT_MAX, LONG_MAX   : 1<<15 = 2.1*pow(10, 9)       (= 2147483647)
/- UINT_MAX, ULONG_MAX : 1<<16 = 4.2*pow(10, 9)       (= 4294967295)
/- LLONG_MAX           : 1<<63 = 9.2*pow(10, 18)      (= 9223372036854775807)
/- ULLONG_MAX          : 1<<64 = 1.8*pow(10, 19)      (= 18446744073709551615)
/----------------------------------------------*/

int sl, tl;
string s, t;

int main() {
    cin >> s >> t;
    sl = s.size();
    tl = t.size();
    if (tl > sl) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    bool b;
    int i_;
    for (int i = sl - 1; i >= tl - 1; i--) {
        b = true;
        rep(j, tl) {
            if (s[i - tl + 1 + j] != t[j] && s[i - tl + 1 + j] != '?') {
                b = false;
                break;
            }
        }
        if (b) {
            i_ = i;
            break;
        }
    }
    if (!b) {
        cout << "UNRESTORABLE";
    } else {
        rep(i, sl) {
            if (i_ - tl < i && i <= i_) {
                cout << t[i - (i_ - tl + 1)];
            } else {
                if (s[i] == '?')
                    cout << 'a';
                else
                    cout << s[i];
            }
        }
    }

    /* ====================================== */
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    int N; cin>>N;
    string s; cin>>s;
    vector<vector<int>> pos(10);
    for(int i=0;i<N;i++) pos[s[i]-'0'].push_back(i);
    for(int i=0;i<10;i++) pos[i].push_back(N),pos[i].push_back(N+1),pos[i].push_back(N+2);

    int ans=0;
    for(int i=0;i<10;i++) for(int j=0;j<10;j++) for(int k=0;k<10;k++){
        int l=pos[i][0];
        l=*upper_bound(pos[j].begin(),pos[j].end(),l);
        l=*upper_bound(pos[k].begin(),pos[k].end(),l);
        if(l<N) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

struct NODE{
	string now;
	vector<string> words;
};

int main(){
	int table[26]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
	int n;
	while(cin >> n ,n ){
		vector< pair<string,string> > data;
		string s;
		set< vector<string> > ret;
		for(int i=0;i<n;i++){
			cin >> s;
			string tmp = s;
			for(int j=0;j<s.length();j++){
				s[j] = table[s[j]-'a']+'0';
			}
			data.push_back( make_pair(tmp,s) );
		}
		string hoge;
		cin >> hoge;
		
		queue<NODE> Q;
		NODE t;
		Q.push(t);
		
		//set<string> done;
		
		while(Q.size()){
			NODE q = Q.front();Q.pop();
			//cout << q.now << endl;
			if( q.now == hoge){
				ret.insert(q.words);
			}
			
			for(int i=0;i<data.size();i++){
				NODE next = {q.now + data[i].second,q.words};
				next.words.push_back(data[i].first);
				if( hoge.find(next.now) != 0)continue;
				//if( done.find(next.now) != done.end() )continue;
				//done.insert(next.now);
				Q.push(next);
			}
		}
		//sort(ret.begin(),ret.end(),greater<string>());
		for( set<vector<string> >::iterator it = ret.begin(); it != ret.end(); ++it){
			for(int i=0; i<(*it).size();i++)
				cout << (*it)[i] << (i == (*it).size()-1?".\n":" ");
		}
		cout << "--" << endl;
	}
}

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

int main(void) {
  long long N;
  cin >> N;
  long long ans = 0;
  for (long long i = 1; i <= N; i++) {
    for (long long j = i; j <= N; j += i) {
      ans += j;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#define PI 3.1415926535897932384626

int
main(int argc, char *argv[])
{
        double r;
        double S, l;

        scanf("%lf", &r);
        S = PI * r * r;
        l = 2 * PI * r;
        printf("%f %f\n", S, l);

        return 0;
}

Measured memory_bytes: 648
// review
#include <iostream>

using namespace std;

int n, m;

void solve() {
  int second = m & 1 ? m + 1 : m + 2;
  int cnt = 1;
  int cnt2 = 0;
  for (int i=0;i<m;i++) {
    if (i < m / 2) {
      cout << cnt << " " << (second - cnt) << endl;
      cnt++;
    } else {
      cout << cnt2 + second << " " << (2 * m + 1 - cnt2) << endl;
      cnt2++;
    }
  }
}

int main() {
  cin >> n >> m;
  solve();
}


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


int main() {
  long long A,B;
  cin >> A >> B;
  long long a = max(A,B);
  long long b = min(A,B);
  long long r = a%b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  cout << A*B/b << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int x1, x2, x3, x4;
    int y1, y2, y3, y4;
    int diffx, diffy;

    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);

    diffx = x2-x1;
    diffy = y2-y1;

    x3 = x2 - diffy;
    x4 = x3 - diffx;
    y3 = y2 + diffx;
    y4 = y3 - diffy;

    printf("%d %d %d %d", x3, y3, x4, y4);

    return 0;
}

Measured memory_bytes: 128
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Char (ord)
import Data.Vector.Unboxed.Mutable (IOVector, STVector)
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = solve <$> readLn <*> B.getLine <*> B.getLine >>= print

solve :: Int -> ByteString -> ByteString -> Int
solve n bs bt = runST $ do
  dp <- VM.replicate 26 0 :: ST s (STVector s Int)
  let Just (s0, bs0) = B.uncons bs
  let Just (_, bt0) = B.uncons bt
  VM.write dp (idx s0) 1
  (_, btn) <- foldM (\(bs, bt) _ -> do
                        let Just (s, bs') = B.uncons bs
                        let Just (t, bt') = B.uncons bt
                        x <- VM.read dp (idx s)
                        y <- VM.read dp (idx t)
                        VM.write dp (idx s) ((x + y) `mod` 1000000007)
                        return (bs', bt')
                    ) (bs0, bt0) [1 .. n-2]
  let Just (tn, _) = B.uncons btn
  VM.read dp (idx tn)

idx :: Char -> Int
idx c = ord c - ord 'a'



Measured memory_bytes: 5092
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>


int main() {
	int n, t;
	std::cin >> n >> t;
	long long ans = 0;
	int a;
	int lastpoint = 0;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		if (a < lastpoint) {
			ans += a + t - lastpoint;
		}
		else {
			ans += t;
		}
		lastpoint = a + t;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import itertools
N, M, Q = map(int, input().split())
S = [list(map(int, input().split())) for i in range(Q)]
sum_list = []
A_list = list(itertools.combinations_with_replacement(range(1, M+1), N))
for k in range(len(A_list)):
    A = A_list[k]
    sum = 0
    for i in range(Q):
        #S = list(map(int, input().split()))
        if A[S[i][1] - 1] - A[S[i][0] - 1] == S[i][2]:
        #if A[S[1] - 1] - A[S[0] - 1] == S[2]:
            sum += S[i][3]
    sum_list.append(sum)
print(max(sum_list))

Measured memory_bytes: 86304
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, a;
    cin>>a>>n;
    int s = a*3 + n;
    cout<<s/2;
}

Measured memory_bytes: 256
S = input()
#a,b = map(int,input().split())

ans = "Yes"
if len(S) % 2 == 1:
    ans = "No"

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != "h":
            ans = "No"
    else:
        if S[i] != "i":
            ans = "No"

print(ans)

Measured memory_bytes: 2940
import java.util.*;
public class Main{
  public static void main(String[] args)
  {
    Scanner input = new Scanner(System.in);
    int n = input.nextInt();
    String s = input.next();
    if(n%2!=0)
    {
      System.out.println("No");
    }
    else{
      HashMap<Character,Integer> map = new HashMap<>();
      for(int i=0;i<n;i++)
      {
        char c = s.charAt(i);
        if(map.containsKey(c))
        {
          int p = map.get(c);
          p++;
          map.put(c,p);
        }
        else
          map.put(c,1);
      }
      boolean flag = true;
      for(char c:map.keySet())
      {
        if(map.get(c)%2==0)
          flag = true;
       	else{
          flag = false;
          break;
        }
      }
      if(flag)
        System.out.println("Yes");
      else
        System.out.println("No");
    }
  }
}

Measured memory_bytes: 22868
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
using namespace std;
int main() {
	string s; cin >> s;
	int flag = 1;
	for (int i = 0; i < s.length(); ++i) {
		if (i % 2 == 0) {
			if (s[i] == 'L') flag = 0;
		}
		else {
			if (s[i] == 'R') flag = 0;
		}
	}
	cout << (flag ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define double long double
using namespace std;
const int MOD=1000000007;

int main(){
    ll H,W,ans;
    ans=0;
    cin>>H>>W;
    vector<string> s(H);
    for(ll h=0;h<H;h++) cin>>s[h];
    vector<vector<ll> > L(H,vector<ll>(W,0));
    vector<vector<ll> > R(H,vector<ll>(W,0));
    vector<vector<ll> > U(H,vector<ll>(W,0));
    vector<vector<ll> > D(H,vector<ll>(W,0));
    for(ll h=0;h<H;h++){
        for(ll w=0;w<W;w++){
            if(w==0){
                if(s[h][w]!='#') L[h][w]=1;
            }else{
                if(s[h][w]!='#') L[h][w]=L[h][w-1]+1;
            } 
        }
    }
    for(ll h=0;h<H;h++){
        for(ll w=W-1;w>=0;w--){
            if(w==W-1){
                if(s[h][w]!='#') R[h][w]=1;
            }else{
                if(s[h][w]!='#') R[h][w]=R[h][w+1]+1;
            } 
        }
    }
    for(ll w=0;w<W;w++){
        for(ll h=0;h<H;h++){
            if(h==0){
                if(s[h][w]!='#') U[h][w]=1;
            }else{
                if(s[h][w]!='#') U[h][w]=U[h-1][w]+1;
            }
        }
    }
    for(ll w=0;w<W;w++){
        for(ll h=H-1;h>=0;h--){
            if(h==H-1){
                if(s[h][w]!='#') D[h][w]=1;
            }else{
                if(s[h][w]!='#') D[h][w]=D[h+1][w]+1;
            }
        }
    }

    for(ll h=0;h<H;h++){
        for(ll w=0;w<W;w++){
            //cout<<h<<","<<w<<" "<<L[h][w]<<" "<<R[h][w]<<" "<<U[h][w]<<" "<<D[h][w]<<endl;
            ll sub=L[h][w]+R[h][w]+U[h][w]+D[h][w]-3;
            ans=max(ans,sub);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 129664
#include "bits/stdc++.h"
using namespace std;
const int N = 200010;
const int offset = 100000;
 
int tree[N];
int in[N + 5];
int n;
 
int query(int k) {
    int s = 0;
    while(k >= 1) {
        s += tree[k];
        k -= k&-k;
    }
    return s;
}
 
void add(int k, int v) {
    while(k < N) {
        tree[k] += v;
        k += k&-k;
    }
}
 
 
bool f(int x) {
    memset(tree, 0, sizeof tree);
    long long cnt = 0;
    int sum = offset;
    for(int i = 1; i <= n; i++) {
        add(sum, 1);
        if(in[i] >= x) sum++;
        else sum--;
        cnt += query(sum);
    } 
 
    long long tot = n * 1LL * (n + 1) / 2;
    long long m = (tot + 1) / 2;
    cerr << cnt << endl;
    return cnt >= m;
}
 
int main() {
    scanf("%d", &n);
    int maxa = 0;
    for(int i = 1; i <= n; ++i) {
        scanf("%d", in + i);
        maxa = max(in[i], maxa);
    }
 
    int ans = 0;
    for(int b = maxa; b >= 1; b /= 2) {
        while(ans + b <= maxa and f(ans + b)) ans += b;
    }
 
    printf("%d\n", ans);
}

Measured memory_bytes: 1408
use std::io::stdin;

fn main() {
    let n : i64 = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    let a : Vec<i64>= {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.split_whitespace().filter_map(|x| x.parse().ok()).collect()
    };
    let mut count = vec![0; 100001];
    let mut sum : i64 = 0;
    for x in a {
        count[x as usize] += 1;
        sum += x;
    }
    let q = {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };
    for _ in 0..q {
        let v : Vec<_>= {
            let mut buf = String::new();
            stdin().read_line(&mut buf).unwrap();
            buf.split_whitespace()
                .filter_map(|x| x.parse::<i64>().ok())
                .collect()
        };
        if let &[b, c, ..] = v.as_slice() {
            sum -= count[b as usize] * b;
            sum += count[b as usize] * c;
            count[c as usize] += count[b as usize];
            count[b as usize] = 0;
            println!("{}", sum);
        }
    }

}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>> a >>b>>c;
  
  
  for(int i =0; i<b ;i++){
    if ((a*i)%b == c){
      cout <<"YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}
   

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//関数
const long INF=1000000000000000;

int main(void){
    long N;
    cin>>N;
    
    vector<pair<long,long>> list;
    for(int i=0;i<N;i++){
        long a,b;
        cin>>a>>b;
        list.push_back(make_pair(b,a));
    }
    
    sort(list.begin(),list.end());
    long tim=0;
    for(int i=0;i<N;i++){
        tim+=list.at(i).second;
        if(tim>list.at(i).first){
            cout<<"No"<<endl;
            return 0;
        }
    }
    
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 6384
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
const int p = (int)1e9+7;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N), s(N,0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < N; i++) {
		if (i != 0) s[i] = s[i - 1] + A[i];
		else s[i] = A[i];
	}

	ll ans=1;
	for (int i = 0; i < N-1; i++) {
		if (s[i] * 2 >= A[i + 1]) {
			ans++;
		}
		else {
			ans = 1;
		}
	}

	cout << ans << endl;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (ll i = 0; i < n - k; ++i) {
    if (a[i] < a[i + k]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 4788
using System;

class _0056 {
    static readonly int N = 50000;
    public static void Main() {
        int c, n;
        bool[] e = new bool[N + 1];
        int[] p = new int[5133];
        e[0] = e[1] = false;
        for (int i = 2; i <= N; i++) e[i] = true;
        for (int i = 2; i <= N; i++) if (e[i]) for (int j = 2; i * j <= N; j++) e[i * j] = false;
        c = 0;
        for (int i = 0; i <= N; i++) if (e[i]) p[c++] = i;
        while ((n = int.Parse(Console.ReadLine())) != 0) {
            c = 0;
            if (n % 2 == 0) for (int i = 0; p[i] <= n / 2; i++) if (e[n - p[i]]) c++; else { } else c = (e[n - 2]) ? 1 : 0;
            Console.WriteLine(c);
        }
    }
}

Measured memory_bytes: 9556
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>
#include<set>
#include <queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	string S, T;
	cin >> S >> T;
	int cnt = 0;
	for (int i = 0; i < 3; i++) if (S[i] == T[i])cnt++;
	cout << cnt;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx") 
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F2(i,a,b) for(int i=(a);i<(b);++i)
#define dF(i,a,b) for(int i=(a);i>=(b);--i)
#define dF2(i,a,b) for(int i=(a);i>(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define INF 0x3f3f3f3f
#define INFll 0x3f3f3f3f3f3f3f3f
#define y0 _lxybz_
#define y1 _ljmnzyzhhhoscartxdy_
typedef long double ld;
typedef long long ll;
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define lo(x) ((x)&(-(x)))
#define trav(a, x) for (auto &a : x)
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
const ld Pi = 4*atan((ld)1);
template<class T> void chmin(T &a,const T&b) { a = min(a, b); }
template<class T> void chmax(T &a,const T&b) { a = max(a, b); }
namespace IO{
template<class T> inline void read(T&ret)
{
	ret=0; int f=1; char c=getchar();
	while(c<48||c>57){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	ret*=f;
}
template<class T> inline void prin(const T&ret)
{
	if(!ret){putchar(48);return;} static T o; o=ret;
	if(o<0){putchar('-');o=-o;}
	static int op[25],tt; tt=0;
	while(o){
		op[++tt]=o%10;
		o/=10;
	}
	for(int i=tt;i;--i)putchar(op[i]+48);
}
template<class T> inline void pri_(const T&ret)
{
	prin(ret);putchar(' ');
}
template<class T> inline void priE(const T&ret)
{
	prin(ret);putchar('\n');
}
}
using namespace IO;

#define N 
#define MO 
int h,n,a;
inline void _Sol_()
{
	read(h);read(n);
	F(i,1,n) read(a),h-=a;
	if(h>0)puts("No");else puts("Yes");
}

int main()
{
	int T=1; //read(T);
	while(T--)_Sol_();
}

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

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

typedef long long ll;

using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    int min_taste = 500;
    int no_taste_apple;
    rep(i, n) {
        if (min_taste > abs(l+i)) {
            min_taste = abs(l+i);
            no_taste_apple = i;
        }
    }
    int pie_val = 0;

    rep(i, n) {
        if (i != no_taste_apple) pie_val += (l+i);
    }

    cout << pie_val << endl;
    return 0;
}

Measured memory_bytes: 256