akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//exist x map o setconst ll MOD = 1e9+7;return fac[n]*(finv[k]*finv[n-k] % MOD) % MOD;

ll powmod(ll x, ll n, ll MOD){
    ll ret=1;
    while(n>0){
        if(n&1){
            ret*=x;
            ret%=MOD;
            n-=1;
        }
        else{
            x*=x;
            x%=MOD;
            n>>=1;
        }
    }
    return ret;
}

signed main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n; cin >> n;
    string s; cin >> s;
    int cnt=0;
    rep(i,n){
        if(s[i]=='1') cnt++;
    }
    ll num=0;
    ll num2=0;
    rep(i,n){
        if(s[i]=='1'&&cnt-1>0) num+=powmod(2LL,(n-1-i),cnt-1); //0->1
        if(s[i]=='1') num2+=powmod(2LL,(n-1-i),cnt+1); //1->0
    }
    rep(i,n){
        int ans=0;
        if(s[i]=='0'){
            ll x=num2;
            x=(x+powmod(2LL,(n-1-i),cnt+1))%(cnt+1);
            ans++;
            while(x!=0){
                ans++;
                int md=__builtin_popcountll(x);
                x%=md;
            }
            cout<<ans<<endl;
        }else{
            if(cnt==1){
                cout<< 0 <<endl;
            }else{
                ll x=num;
                x=(x-powmod(2LL,(n-1-i),cnt-1)+(cnt-1))%(cnt-1);
                ans++;
                while(x!=0){
                    ans++;
                    int md=__builtin_popcountll(x);
                    x%=md;
                }
                cout<<ans<<endl;
            }
        }
    }
    
}



Measured memory_bytes: 3720
# -*- coding: utf-8 -*-
"""
AtCoder C
"""

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column

# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']

def main():
    N, M = list(map(int,input().split()))
    K=[]
    S=[]
    for i in range(M):
        k, *s = list(map(int,input().split()))
        K.append(k)
        S.append(s)
    P = list(map(int,input().split())) # N row 1 column
    out=0
    for n in range(2**N):
        on=bin(n)[2:].zfill(10)[::-1]
        whileon=True
        while whileon:
            for i,ss in enumerate(S):
                numon=0
                for s in ss:
                    numon+=int(on[s-1])
                if numon%2!=P[i]:
                    whileon=False
            if whileon:
                out+=1
                whileon=False


    print(out)

    # print(N,M,K,S,P)
    
if __name__ == "__main__":
    main()

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

int main()
{
	ll A,B,N;
	cin >> A >> B >> N;
	if (B == 1)
	{
		cout << "0" << endl;
		return 0;
	}
	if (N < B-1)
	{
		cout << (A*N)/B - A*(N/B) << endl;
	}
	else
	{
		cout << (A*(B-1))/B << endl;
	}
	return 0;
}

Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<tuple<string, int , int>> a(n);

  for(int i = 1; i <= n; ++i) {
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    a[i-1] = make_tuple(s, p ,i); 
  }

  sort(a.begin(), a.end());
  rep(i, n) cout << get<2>(a[i]) << endl;
  return 0;
}

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

int main(){
    int s;cin>>s;
    int num1,num2;
    num1 = s/100;
    num2 = s%100;

    if(1<=num1&&num1<=12){
        if(1<=num2&&num2<=12){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if(1<=num2&&num2<=12){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;

#define MOD (1000000007)
typedef long long ll;

ll comb[5001][5001];

void InitComb(void) {
  comb[0][0] = 1;
  for (int i = 1; i <= 5000; ++i) {
    comb[i][0] = 1;
    comb[i][i] = 1;
    for (int j = 1; j < i; ++j) {
      comb[i][j] = (comb[i - 1][j - 1] + comb[i - 1][j]) % MOD;
    }
  }
}  

ll func(int x, int y) {
  if (x < 0) return 0;
  if (x == 0) return 1;
  return comb[x + y - 1][y - 1];
}

int main() {
  int N, K;
  cin >> N >> K;
  InitComb();
  for (int i = 1; i <= K; ++i) {
    ll val1 = func(K - i, i);
    ll val2 = func(N - K - i + 1, i + 1);
    ll ans = val1 * val2 % MOD;
    cout << ans << endl;
  }
  return 0;
}


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



int main(){
	int n;
	cin>>n;
	
	if(n%2!=0){
		float p=(n/2)+1;
		p=(p/(float)(n));
		cout << fixed;
		cout << setprecision(10) << p <<endl;
	}
	else{
		float p=0.5;
		cout <<fixed;
   		cout <<setprecision(10) << p <<endl;
	}
	return 0;
}

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

typedef unsigned long long ll;
#define Inf 1 << 20
#define MInf -(1 << 20)
 
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define Rep(i,n,m) for(int i = (int)(n); i < (int)(m);i++)
#define rrep(i,n) for(int i = (int)(n - 1); i > -1;i--)
#define RRep(i,n,m) for(int i = (int)(n - 1); i > (int)(m);i--)
#define trav(a, x) for(auto& a : x)
 
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REVERSE(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REVERSE(V)
 
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define yes(n) cout << ((n) ? "yes" : "no") << endl;


int main()
{
    int N,D;
    cin >> N >> D;
    cout << (N % (2 * D + 1) == 0 ? N / (2 * D  + 1) : N / (2 * D +1) + 1);
}



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

using namespace std;

#define ops cout<<"ops"<<endl;
#define freopens freopen("cowpatibility.in", "r", stdin);freopen("cowpatibility.out", "w", stdout);
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define DIM 27
#define DIMM 2100007
#define INF 1000000000007.0
#define X (ll)(1<<32)
#define eps 0.0000001
#define PI 3.14159265358979323846
#define MAX 25
#define MODULO (long long)1000000007

const long double gr=(1+sqrt(5))/2;

typedef int I;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<I,I> pII;
typedef pair<ll,ll> pllll;
typedef pair<ld,ld> pldld;

typedef vector<I> vI;
typedef vector<ll> vll;
typedef vector<pllll> vpllll;

typedef char cr;
typedef string str;

ll n;
ll z,sum,k,d[DIMM];
ll a[DIM][DIM];

bool isbit(int mask, int b) {
    return (mask &  (1<<(b-1))) != 0;
}

int main()
{
    //ops;
    //freopens;
    fast;
    //ll x1,y1,xs,ys,x2,y2,x3,x4,y3,y4;

    cin>>n;
    z=1;
    for(int i=1;i<=n;i++){
     z*=2;
     for(int j=1;j<=n;j++){
      cin>>a[i][j];
     }
    }
    d[0]=1;
    for(ll m=1;m<z;m++){
     sum=0;
     k=__builtin_popcount(m);
     for(ll i=1;i<=n;i++)
      if(isbit(m,i) && a[k][i]==1){
       d[m]+=d[m-(1<<(i-1))];
       d[m]%=MODULO;
      }
    }
    cout<<d[z-1]<<endl;
    return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}

constexpr ll LNF = 1LL<<50;

constexpr int INF = 1e9+7;

const long double PI=3.14159265358979323846;


vector<int> dx = {1,0,-1,1,-1,0};
vector<int> dy = {1,1,1,0,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll x = 1ll, y = 1ll;
    rep(i,0,n){
        ll t,a; cin >> t >> a;
        ll p = (x+t-1ll)/t;
        if(p*a<y){
            p = (y+a-1ll)/a;
        }
        x = p*t;
        y = p*a;
    }
    cout << x+y << endl;
}


Measured memory_bytes: 256
n = int(input())

t = []

for i in range(n):
    t.append(int(input()))

buy = t[0]
val = t[-1] - buy

for i in range(1, n):
    if t[i] - buy > val:
        val = t[i] - buy
    if t[i] < buy:
        buy = t[i]

print(val)



Measured memory_bytes: 13592
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  int M = INF;
  long long ans = 0;
  int cnt = 0;
  for (int i = 0; i < N; i++){
    ans += abs(A[i]);
    M = min(M, abs(A[i]));
    if (A[i] < 0){
      cnt++;
    }
  }
  if (cnt % 2 == 0){
    cout << ans << endl;
  } else {
    cout << ans - M * 2 << endl;
  }
}

Measured memory_bytes: 640
h,w=map(int,input().split())
g=[input() for _ in range(h)]
from collections import *
def bfs(sx,sy):
  d=[[-1]*w for _ in range(h)]
  d[sx][sy]=0
  q=deque([(sx,sy)])
  while q:
    x,y=q.popleft()
    for dx,dy in [(1,0),(0,1),(-1,0),(0,-1)]:
      nx,ny=x+dx,y+dy
      if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and d[nx][ny]<0:
        r=d[nx][ny]=d[x][y]+1
        q.append((nx,ny))
  return r
print(max(bfs(x,y) for x in range(h) for y in range(w) if g[x][y]=='.'))

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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...) 
#endif

int n, x;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i < 2e6; i++) {
        x = (x * 10 + 7) % n;
        if (x == 0) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << "-1\n";
    return 0;
}

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

int main()
{
  int N,K;
  vector<int> d(200);
  vector<vector<int>> A(200,vector<int>(200));
  vector<int> cont(200);
  cin >> N >>K;
  for(int i=0; i<K; i++)
  {
    cin >> d.at(i);
      for(int j=0; j<d.at(i); j++)
      {
        cin >> A.at(i).at(j);
      }
  }
  int count=0;
  for(int i=0; i<K; i++)
  {
    for(int j=0; j<d.at(i); j++)
      {
        cont.at(A.at(i).at(j))++;
      }
  }
    for(int i=1; i<=N; i++)
  {
    if (!(cont.at(i)==0)) 
    {count++;}
  }
  cout << N-count <<endl;
}

Measured memory_bytes: 3760
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int N, X; cin >> N >> X;
    vector<int> m(N, 0);
    int sum = 0;
    for (int i = 0; i < N; ++i) {
        cin >> m[i]; sum += m[i];
    }
    sort(m.begin(), m.end());
    int cnt = N;
    X -= sum;
    while (X >= m[0]) {
        X -= m[0];
        cnt++;
    }
    printf("%d\n", cnt);
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n, m;
  std::vector<std::string> xs;
  Solver() {
    S002 reader;
    reader >= n >= m >n>= xs;      
  }
  void solve() {
    long count = 0;
    for(long i = 0; i < n; ++i) {
      for(long j = 0; j < m; ++j) {
        if( xs[i][j] == '#' ) count += 1;
      }
    }
    puts(count == n + m - 1 ? "Possible" : "Impossible");        
  }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    a={}
    for i in range(n):
        s,p = input().split()
        if s not in a:
            a[s] = []
        a[s].append((int(p), i))
    for e in sorted(a.keys()):
        for i in sorted(a[e], key=lambda x: x[0], reverse=True):
            print(i[1]+1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
<?php

$max = 0.0;
$min = INF;
while (true) {
    fscanf(STDIN, '%f', $h);
    if (feof(STDIN)) {
        break;
    }
    if ($h > $max) {
        $max = $h;
    }
    if ($h < $min) {
        $min = $h;
    }
}

echo $max - $min;
echo PHP_EOL;

Measured memory_bytes: 6588
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
    //入力を受け取る
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    //計算する
    int ans = (H - h) * (W - w);
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define Max 45

int fib(int);

int main(){
  int n;

  scanf("%d",&n);

  n=fib(n);

  printf("%d\n",n);

  return 0;
}


int fib(int n){
  int i,F[Max];

  F[0]=1;
  F[1]=1;
  if(n==1||n==0){
    return 1;
  }else{
    for(i=2;i<=n;i++){
      F[i]=F[i-1]+F[i-2];
    }
    return F[n];
  }
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
#define ll long long

using namespace std;

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

    ll n;
    cin>>n;
    ll x=n/500;
    ll y=n%500;
    y/=5;
    cout<<(x*1000+y*5)<<endl;
}


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); \
                cin.tie(0); \
                cout.tie(0)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(_v)             _v.begin(), _v.end()
#define sz(_v)              (int) _v.size()
#define first(_obj)         (*_obj.begin())
#define last(_obj)          (*prev(_obj.end()))
#define FIND(_obj, _val)    (_obj.find(_val) != _obj.end())
#define RESET(_a, _v)       fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define REP(_i, _n)         for (int _i = 0; _i < (int) _n; _i++)
#define FOR(_i, _a, _b)     for (int _i = (int) _a; _i <= (int) _b; _i++)
#define FORD(_i, _a, _b)    for (int _i = (int) _a; _i >= (int) _b; _i--)
#define FORIT(_it, _obj)    for (auto _it = _obj.begin(); _it != _obj.end(); _it++)

// DEBUG UTIL
template<typename TF>
void debug(ostream &out, TF const &f) {
    out << f << std::endl;
}
 
template<typename TF, typename ... TR>
void debug(ostream &out, TF const &f, TR const& ... rest) {
    out << f << " ";
    debug( out, rest... );
}
 
#define DEBUG(...) debug(cerr, "[", #__VA_ARGS__, "]:", __VA_ARGS__)

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<double,double>;
using vi = vector<int>;
using vii = vector<pii>;
using vll = vector<ll>;
using vs = vector<string>;

const int DR[] = {-1, 0, 1, 0, -1, 1, 1, -1}; // ccw
const int DC[] = {0, -1, 0, 1, -1, -1, 1, 1};
const double PI = acos(-1.0);
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = 1073741823;
const ll INFLL = 4e18;
const int MAX = 1e3;

int R, C, dp[MAX+5][MAX+5];
char grid[MAX+5][MAX+5];

void read() {
    cin >> R >> C;
    FOR(r, 1, R)
        FOR(c, 1, C)
            cin >> grid[r][c];
}

void solve() {
    dp[1][1] = 1;

    FOR(r, 1, R)
        FOR(c, 1, C) {
            if (grid[r][c] == '#' || (r == 1 && c == 1)) continue;
            
            if (grid[r - 1][c] == '.') dp[r][c] = dp[r - 1][c];
            if (grid[r][c - 1] == '.') dp[r][c] += dp[r][c - 1];

            dp[r][c] %= MOD;
        }

    cout << dp[R][C] << "\n";
}

int main() {
    FAST_IO;
    int TC = 1;
    FOR(tc, 1, TC) {
        read();
        solve();
    }
}

Measured memory_bytes: 5120
#include<iostream>
#include<string.h>
#define MAX_NUMBER 2000010
 
struct Data{
    int num;
    int next;
    int before;
};
 
Data data[MAX_NUMBER];
int head = -1,tail = -1,cp = 0;
 
void insert(int x){
    data[cp].num = x;
    data[cp].next = head;
    data[cp].before = -1;
    if(head!=-1){
        data[head].before = cp;
    }else{
        tail = cp;
    }
    head = cp++;
}
 
void delete1(int x){
    int p = head;
    if(data[p].num == x){
        head = data[p].next;
        data[data[p].next].before = -1;
    }else{
        while(p != -1){
            int tmp = data[p].next;
            if(tmp == tail && data[tmp].num == x){
                data[p].next = -1;
                tail = p;
            }else if(data[tmp].num == x){
                data[p].next = data[tmp].next;
                data[data[tmp].next].before = p;
                return;
            }
            p = data[p].next;
        }
    }
}
             
 
void deleteFirst(){
    int tmp=data[head].next;
    if(tmp==-1){
        head=-1;
        tail=-1;
    }else{
        data[tmp].before = -1;
        head = tmp ;
    }
}
 
void deleteLast(){
    int tmp = data[tail].before;
    if(tmp==-1){
        head = -1;
        tail = -1;
    }else{
        data[tmp].next = -1;
        tail = tmp;
    }
}
 
int main(){
    int n,x;
    char command[20];
    std::cin >> n;
    for(int i=0;i<n;i++){
        std::cin >> command ;
        if(strcmp(command,"insert")==0){
            std::cin >> x;
            insert(x);
        }else if(strcmp(command,"delete")==0){
            std::cin >> x;
            delete1(x);
        }else if(strcmp(command,"deleteFirst")==0){
            deleteFirst();
        }else if(strcmp(command,"deleteLast")==0){
            deleteLast();
        }
    }
    int p = head;
    if(p!=-1){
        std::cout << data[p].num ;
    }
    p = data[p].next;
    while(p!=-1){
        std::cout << ' ' << data[p].num ;
        p = data[p].next;
    }
    std::cout << '\n';
    return 0;
}


Measured memory_bytes: 15840
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = [0]*(2*(10**5)+100)
ind = 0
if S[0] == '0':
    len_list[0] = 0
    ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        len_list[ind] = cnt
        ind += 1
        cnt = 1
    else:
        cnt += 1
len_list[ind] = cnt

#print(len_list[:30])
i = 0
wa = 0
sum_l = sum(len_list[:2*K+1])
while True:
    if len_list[i+2*K+1] != 0:
        wa = max(wa, sum_l)
    else:
        wa = max(wa, sum_l)
        break
    sum_l -= (len_list[i] + len_list[i+1])
    sum_l += (len_list[i+2*K+1] + len_list[i+2*K+2])
    i += 2
print(wa)


        



Measured memory_bytes: 42480
# (160-c)
a = input()
b = input()
a_list = list(map(int, a.split()))
b_list = list(map(int, b.split()))
edges = []
for num in range(len(b_list)):
  if num == 0:
    edges.append(b_list[num])
  else:
    edges.append(b_list[num] - b_list[num - 1])

edges[0] = a_list[0] - b_list[-1] + b_list[0] 
edges[edges.index(max(edges))] = 0
print(sum(edges))

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N, M;
    std::cin >> N >> M;

    vector<vector<pair<int, int>>> city(N);
    REP(i, M) {
        int P, Y;
        std::cin >> P >> Y;
        city[P - 1].emplace_back(Y, i);
    }

    vector<ll> out_l(M);
    vector<ll> out_r(M);
    REP(i, N) {
        SORT(city[i]);
        REP(j, city[i].size()) {
            out_l[city[i][j].second] = i + 1;
            out_r[city[i][j].second] = j + 1;
        }
    }

    REP(i, M) {
        std::cout << setw(6) << setfill('0') << out_l[i];
        std::cout << setw(6) << setfill('0') << out_r[i] << std::endl;
    }

    return 0;
}


Measured memory_bytes: 8576
#include<stdio.h>

struct dice{
    int d[6],tmp[6];
};
struct dice dice1;
struct dice dice2;

void init1(int n[6]){
    int i;
    for(i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for(i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void rooldice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}

int compare(){
    int i;
    for (i=0; i<6; i++) {
        if(dice1.d[i]!=dice2.d[i]){
    
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n[6];
    int i,j;
    int ok=0;
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init1(n);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init2(n);
    for(i=0;i<4;i++){
        for(j=0;j<4;j++){
            rooldice('N');
            rooldice('E');
            rooldice('S');
            if(compare()) ok=1;
        }
        rooldice('N');
    }
    rooldice('E');
    for(i=0;i<2;i++){
        for(j=0;j<4;j++){
            rooldice('N');
            rooldice('E');
            rooldice('S');
            if(compare()) ok=1;
        }
        rooldice('W');
        rooldice('W');
    }
    if(ok) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 580
#include<stdio.h>

#define NMAX 100000

int binarySearch(int);

int N[NMAX],n;

int main(){
  int i,q,a,cnt=0;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(i=0; i<q; i++){
    scanf("%d",&a);
    cnt += binarySearch(a);
  }

  printf("%d\n",cnt);

  return 0;
}

int binarySearch(int key){
  int left=0,right=n,mid;

  while(left < right){
    mid = (left + right)/2;
    if(N[mid] == key) return 1;
    else if(key < N[mid]) right = mid;
    else left = mid + 1;
  }
  
  return 0;
}
      
   
    

  



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(ll a,ll v1,ll b,ll w1,ll t)
{
    ll s1,s2;
    s1 = v1*t;
    s2 = w1*t;
    if(abs(b-a)+s2 <= s1)
        cout<<"YES";
    else
        cout<<"NO";
}
int main()
{
    ll a,v1,b,w1,t;
    cin>>a>>v1;
    cin>>b>>w1;
    cin>>t;
    solve(a,v1,b,w1,t);
    return 0;
}

Measured memory_bytes: 3672
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String a = sc.next();
	    String b = sc.next();
	    String c = sc.next();
	    
	    System.out.println("" + a.charAt(0) + b.charAt(1) + c.charAt(2));
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
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/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll N = S.length();

    ll ans = 0;
    char now;
    REP(i, N){
        if(i==0){
            now = S[0];
            continue;
        }
        if(now != S[i]){
            ans++;
            now = S[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
//#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=405;
//i_am_noob
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	str[1]=int('B')+int('R')-str[1];
	print1(str);
	return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
int N; cin >> N;
vector<int> B(N-1);
vector<int> A(N);
rep(i,N-1){
  cin >> B[i];
}
A[0] = B[0];
A[N-1] = B[N-2];
for(int i = 1; i < N - 1; i++){
  if(B[i-1] > B[i]){
    A[i] = B[i];
  }
  else{
    A[i] = B[i-1];
  }
}
int sum = 0;
  for(int j = 0; j < N; j++){
    sum+= A[j];
    //cout << A[j] << endl;
  }
  cout << sum << endl;
}


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

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


Measured memory_bytes: 3576
#include <iostream>

using namespace std;

char x, y;

int main()
{
	cin >> x >> y;
	int a = x - 'A' + 10, b = y - 'A' + 10;
	char c;
	if (a < b) c = '<';
	else if (a > b) c = '>';
	else c = '=';
	cout << c << endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  if (N / 1000 == (N % 1000) / 100 && (N % 1000) / 100 == (N % 100) / 10) {
    cout << "Yes" << endl;
  }
  else if (N % 10 == (N % 100) / 10 && (N % 100) / 10 == (N % 1000) / 100) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const double EPS = 1E-10;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)


//ここから編集
 
ll modPow(ll x, ll n, ll mod = MOD){
    ll res = 1;
    while(n){
        if(n&1) res = (res * x)%mod;
 
        res %= mod;
        x = x * x %mod;
        n >>= 1;
    }
    return res;
}
const int MAX = 2000010;
long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  vector<int> a(N+1);

  int ans = 0;
  for(int i=1; i<=N; i++){
    cin >> a[i];
    if(i%2 == 1 && a[i]%2 == 1)ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  if(n % 2 == 1){
    cout << "No";
    return 0;
  }
  for(int i = 0; i < n / 2; i++){
    if(s.at(i) != s.at(n / 2 + i)){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)

int n, A[50];

int solve(int i, int m) {
  if(m == 0) return 1;
  if(i >= n) return 0;
  return solve(i+1, m) || solve(i+1, m-A[i]);
}

int main() {
  cin >> n;
  int q, m;
  for(int i = 0; i < n; i++) cin >> A[i];
  cin >> q;

  for(int i = 0; i < q; i++) {
    cin >> m;
    if(solve(0, m)) cout << "yes" << endl;
    else cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 3096
# -*- coding: utf-8 -*-
x, y = map(int, input().split())
animal = [0, 0]
animal[1] = (y - 2*x)/2
animal[0] = x - animal[1]

result = True
if (y - 2*x) % 2 != 0 or animal[1] < 0:
    print('No')
elif animal[0] < 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 9188
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    int H, W;
    cin >> H >> W;

    char a[H+2][W+2];
    for(int height = 0; height < H+2; height++)
    {
        for(int width = 0; width < W+2; width++)
        {
            if (height == 0 or height == H+1)
            {
                cout << '#';
                if (width == W+1)
                {
                    cout << endl;
                }
            }
            else if (width == 0 or width == W+1)
            {
                cout << '#';
                if (width == W+1)
                {
                    cout << endl;
                }
            }
            else
            {
                char temp;
                cin >> temp;
                cout << temp;
            }
            
        }
        
    }
    
}

Measured memory_bytes: 256
// #Sazaの1日1AC
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int INF=mod;
const double PI=3.14159265358979323846;

//マクロ
//型エイリアス
using ll = long long;
using P=pair<int, int>;
using vl=vector<long long>;
using vvl=vector<vector<long long>>;
using vP=vector<pair<long long, long long>>;
//ショートカット
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,k,n) for(int i = k; i < n; i++) //半開区間
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mkp make_pair
//入力
#define vin(v,N) for(long long id=0;id<N;id++) cin>>v.at(id)
#define lin(n) long long n;cin>>n
#define chin(x) char x;cin>>x;
#define sin(s) string s;cin>>s;
#define vlin(v,N) vector<long long>v(N);for(long long i=0;i<N;i++)cin>>v.at(i)


//関数
//最大公約数
long long gcd(long long m, long long n){
  long long a=max(m,n);
  long long b=min(m,n);
  long long r=a%b;
  while(r!=0){
    a=b; b=r; r=a%b;
  }
  return b;
}
// 最小公倍数
long long lcd(long long m, long long n){
  return m*n/gcd(m,n);
}
//繰り返し二乗法
long long repeat_squaring(long long x, long long n){
  if(n==0) return 1;
  else if(n%2==0){
    long long t=repeat_squaring(x,n/2);
    return t*t%mod;
  }
  else
    return x*repeat_squaring(x,n-1);
}
//素因数分解(mapで返す)
map<long long,long long> factor(long long p){
  ll p1=p;
  map<long long,long long>ret;
  for(long long i=2;i*i<=p1;i++){
     while(p%i==0){
      ret[i]++;
      p/=i;
    }
  }
  if(p!=1)
  ret[p]++;
  return ret;
}
//素数判定
bool is_prime(long long N){
  for(long long i=2;i*i<=N;i++){
    if(N%i==0)
      return false;
  }
  return true;
}
//最大値更新
void chmax(long long &a,long long b){
  a=max(a,b);
}
//最小値更新
void chmin(long long &a,long long b){
  a=min(a,b);
}

//構造体

/////////////////⊂('ω'⊂ )))Σ≡GO!/////////////////
int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};


int main(){
  int H, W; cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  rep(i, H) rep(j, W) cin >> grid[i][j];

  vector<vector<int>> table(H, vector<int>(W, -1));

  queue<P> Q;
  rep(i, H){
    rep(j, W){
      if(grid[i][j] == '#'){
        Q.push(mkp(i, j));
        table[i][j] = 0;
      } 
    }
  }

  while(Q.size() > 0){
    int h, w;
    tie(h, w) = Q.front(); Q.pop();

    rep(i, 4){
      int nh = h + dh[i], nw = w + dw[i];
      if(0 <= nh && nh < H && 0 <= nw && nw < W && table[nh][nw] == -1){
        table[nh][nw] = table[h][w] + 1;
        Q.push(mkp(nh, nw));
      }
    }
  }

  int res = -1;

  rep(i, H){
    rep(j, W){
      res = max(res, table[i][j]);
      //cout << table[i][j];
    }
  }

  cout << res << endl;
}



Measured memory_bytes: 13456
program ABC175A
    implicit none
    character(3)S
    read*,S
    if(S=="RRR")then
        print'(i0)',3
    else if(S=="SRR".or.S=="RRS")then
        print'(i0)',2
    else if(S=="SSS")then
        print'(i0)',0
    else
        print'(i0)',1
    end if
end program ABC175A

Measured memory_bytes: 2924
n,t=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(n)]
AB.sort()
ma=AB[-1][0]
dp=[0]*(t+ma)    
for a,b in AB:
    for i in range(t+ma-1,a-1,-1):
        if i-a<t:
            dp[i]=max(dp[i],dp[i-a]+b)

print(max(dp))

Measured memory_bytes: 48104
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  long long n,k;
  cin >> n >> k;
  long long a,b;
  a = n - n/k*k;
  b = llabs(a - k);
  cout << ((a<b)? a:b) << "\n";
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)
#define fs first
#define sc second

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

int main(){
	int n; cin >> n;
	vector<int> a(n);
	int m = 0;
	int mm = 0;
	rep(i,n){
		cin >> a[i];
		if(a[i] > m) m=a[i];
		else if(a[i] > mm) mm=a[i];
	}
	rep(i,n){
		if(a[i] == m) cout << mm << endl;
		else cout << m << endl;
	}
}

Measured memory_bytes: 4024
import sys
for i in sys.stdin.readlines(): 
    nums = list(map(int,i.split()))
    h = nums[0]
    w = nums[1]
    if h == 0 and w == 0:
        break
    for j in range(1,h+1):
        if j == 1 or j == h:
            print("#"* w)
        else:
            print("#" + "."*(w-2) + "#")
    print("")

Measured memory_bytes: 7648
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    char c;
    string s;
    int y=0,m=0;
    for(int i=3;i>=0;i--){
        cin >> c;
        s = c;
        y += pow(10,i) * stoi(s);
    }
    if(y < 2019){ cout << "Heisei" << endl; return 0;}
    if(y > 2019){ cout << "TBD" << endl; return 0;}
    cin >> c;

    for(int i=1;i>=0;i--){
        cin >> c;
        s = c;
        m += pow(10,i) * stoi(s);
    }
    if(m <= 4){cout << "Heisei" << endl; return 0;}
    else {cout << "TBD" << endl; return 0;}


    return 0;
}



Measured memory_bytes: 256
//f1
#include<bits/stdc++.h>
using namespace std;
int dp[1000000];
int h[1000000];

int recfn(int n)
{
    if(n == 1) return dp[1] = 0;
}

void it(int n)
{
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for(int i = 3; i <= n; i++)
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]) , dp[i-2] + abs(h[i] - h[i-2]));

}

int main() {
    //int T;
    //cin>>T;
    memset(dp,-1,sizeof(dp));

    int n;
    cin>>n;

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

    it(n);

    cout<<dp[n];
   //eturn 0;
}


Measured memory_bytes: 6400
#include <iostream>
using namespace std;
int n;
int a[1000000];
int Max = 0;
int max_i = 0;
int  nmax = 0;
int nmax_i =0; 

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i] >= Max){
            nmax = Max;
            nmax_i = max_i;
            Max = a[i];
            max_i = i;
        }
        else if(a[i] >= nmax){
            nmax = a[i];
            nmax_i = i;
        }
    }
    for(int i = 0;i<n;i++){
            if(i == max_i){
                cout << nmax << endl;
            }
            else{
                cout << Max << endl;
        }
 
}
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e18+7;
const ll mod = 1e9+7;


int main() {
    int n,m;
    cin>>n;

    map<string,int>cnt;

    rep(i,n){
        string s;
        cin>>s;

        cnt[s]++;
    }

    cin>>m;

    rep(i,m){
        string t;
        cin>>t;

        cnt[t]--;
    }

    int ans=0;

    for(auto x:cnt){
        ans=max(ans,x.second);
    }

    cout<<ans<<endl;
}


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

bool check(int v[300][300], int N) {
	for (int k = 0; k < N; k++)
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				if (v[i][j] > v[i][k] + v[k][j]) return true;
	return false;
}

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

	if (check(v, N)) {
		cout << -1 << endl;
		return 0;
	}

	int bad[300][300];
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			bad[i][j] = false;
	for (int k = 0; k < N; k++)
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				if (i != k && j != k && v[i][j] >= v[i][k] + v[k][j])
					bad[i][j] = true;

	long long ans = 0;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < i; j++)
			if (!bad[i][j]) ans += v[i][j];

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 896
//============================================================================
// Name        : 0000.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	for(int i=1; i<=9; i++){
		for(int j=1; j<=9; j++){
			int y= i*j;
			cout <<i<<"x"<<j<<"="<<y<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	string s; cin >> s;
	int p = 0;
	for (char x : s)if (x == 'p')++p;
	cout << s.size() / 2 - p << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void)
{
    int N, cnta = 0, cntb = 0;
    string S;
    cin >> S;
    N = S.length();
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] == '1')
            {
                cnta++;
            }
        }
        else
        {
            if (S[i] == '0')
            {
                cnta++;
            }
        }
    }
    for (int i = 0; i < N; i++)
    {
        if (i % 2 == 1)
        {
            if (S[i] == '1')
            {
                cntb++;
            }
        }
        else
        {
            if (S[i] == '0')
            {
                cntb++;
            }
        }
    }
    cout << min(cnta, cntb) << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val v = (0 until n).map { sc.next().toInt() }
    println(problem138c(n, v))
}

fun problem138c(n: Int, v: List<Int>): Double {
    val list = v.map { it.toDouble() }.sorted().toMutableList()
    var i = 0
    while (list.size > 1) {
        val new = (list[0] + list[1]) / 2.0
        list.removeAt(0)
        list.removeAt(0)
        list.add(0, new)
        i++
    }
    return list[0]
}


Measured memory_bytes: 34252