akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int dp[10001001][2];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   string s;
   cin >> s;
   reverse(s.begin(), s.end());
   s += '0';
   int n = s.size();
   rep(i, 0, n + 1) rep(j, 0, 2) dp[i][j] = INF;
   dp[0][0] = 0;
   rep(i, 0, n) rep(j, 0, 2) {
      int x = s[i] - '0';
      x += j;
      rep(a, 0, 10) {
         int ni = i + 1, nj = 0;
         int b = a - x;
         if (b < 0) {
            nj = 1;
            b += 10;
         }
         dp[ni][nj] = min(dp[ni][nj], dp[i][j] + a + b);
      }
   }
   int ans = dp[n][0];
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 9500
from collections import deque
n,u,v=map(int,input().split())
u=u-1
v=v-1
G=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  G[a].append(b)
  G[b].append(a)
P=[0]*n #親のノード
P[v]=-1
F=[0]*n
D=deque([v])
V=[0]*n
V[v]=1
GG=[[] for i in range(n)]
while len(D)>0:
  x=D[0]
  D.popleft()
  for i in range(len(G[x])):
    if V[G[x][i]]==0:
      V[G[x][i]]=1
      D.append(G[x][i])
      P[G[x][i]]=x
      GG[x].append(G[x][i])
      F[G[x][i]]=F[x]+1
a=F[u]
ans1=(a-1)//2 #高橋君が上る回数
b=F[u]%2
if b==0:
  b=2 #上り切った後の差(1or2)
for i in range(ans1):
  u=P[u]
V=[0]*n
V[u]=1
V[P[u]]=1
F=[0]*n
D=deque([u])
while len(D)>0:
  x=D[0]
  D.popleft()
  for i in range(len(GG[x])):
    D.append(GG[x][i])
    F[GG[x][i]]=F[x]+1
ans2=max(F)
print(ans1+ans2+b//2)

Measured memory_bytes: 39148
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
ll dp[100][2];
void solve(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin>>n>>k;
  std::vector<ll> a(n);
  rep(i,n) cin>>a[i];
  rep(i,100) dp[i][0] = dp[i][1] = -1;
  dp[45][0] = 0;
  for(int d=44;d>=0;d--){
    ll mask = 1LL<<d;
    ll num = 0;
    rep(i,n) if(a[i]&mask) num++;
    if(dp[d+1][1]>=0) maxch(dp[d][1],dp[d+1][1]+mask*MAX(num,n-num));
    if(dp[d+1][0]>=0) {
      if(k&(1LL<<d)){
        maxch(dp[d][1],dp[d+1][0] + mask*num);
        maxch(dp[d][0],dp[d+1][0]+ mask*(n-num));
      } else {
        maxch(dp[d][0],dp[d+1][0]+mask*num);
      }
    }
  }
  cout<<MAX(dp[0][0],dp[0][1])<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 1024
h, w = gets.split.map(&:to_i)
s = h.times.map{ gets.strip.split("") }
h.times{ |i| w.times{ |j| s[i][j] = s[[0, i - 1].max..i + 1].flat_map{ |t| t[[0, j - 1].max..j + 1] }.count("#") if s[i][j] == "."  }}
puts s.map(&:join)

Measured memory_bytes: 2172
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int A=0;
  while(++A){
    cout<<"? 1";
    for(int i=1;i<A;i++)cout<<0;
    cout<<'\n';
    fflush(stdout);
    char c;
    cin>>c;
    if(c=='N')break;
    if(A>10){
      A=0;
      while(++A){
        cout<<"? 2";
        for(int i=1;i<A;i++)cout<<0;
        cout<<'\n';
        fflush(stdout);
        char c;
        cin>>c;
        if(c=='Y'){
          cout<<"! 1";
          for(int i=0;i<A-1;i++)cout<<0;
          cout<<'\n';
          return 0;
        }
      }
    }
  }
  A--;
  int ok=10,ng=1;
  for(int i=1;i<A;i++)ok*=10,ng*=10;
  while(ok-ng>1){
    int n=(ok+ng)/2;
    cout<<"? "<<n*10<<'\n';
    fflush(stdout);
    char c;
    cin>>c;
    if(c=='Y')ok=n;
    else ng=n;
  }
  cout<<"! "<<ok<<'\n';
}

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

int main() {
  int N, S, E, SA;
  int SUM = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> S >> E;
    SA = E - S + 1;
    SUM += SA;
  }  
  cout << SUM << endl;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int k;
  cin >> k;
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  int result = a[k - 1];

  cout << result << endl;

  return 0;
}


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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair


typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

const int maxn = 1e5 + 5;

LL N,Q;


map<LL , int> row_mp;
map<LL,  int> line_mp;

int main()
{
    cin >> N  >> Q;
    LL take = 0;

    row_mp[N] = N-2;
    line_mp[N] = N-2;

    LL min_row = N;
    LL min_line = N;

    _for(i,0,Q){
        LL a,b;
        cin >> a >> b;
        if(a == 1){
          auto k = line_mp.upper_bound(b);
          take += k->second;
          if(b < min_line){
            min_line = b;
            row_mp[min_row] = b - 2;
           }

        }
        if(a == 2){
          auto k = row_mp.upper_bound(b);
          take += k->second;
          if(b < min_row){
            min_row = b;
            line_mp[min_line] = b - 2;
          }
        }

        //cout << take << endl;

    }

    cout << (N-2)*(N-2) - take << endl;

    return 0;
}


Measured memory_bytes: 9772
#include<bits/stdc++.h>
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<=b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    int t=1;
  
    while(t--){
       int a,b;
       cin>>a>>b;
       int u=__gcd(a,b);
       int count=1;
       for(int i=2;i*i<=u;i++){
            if(u%i==0){
                count++;
                while(u%i==0){
                    u/=i;
                }
            }
       }
       if(u>1){
        count++;
       }
       cout<<count<<endl;
    }   
    return 0;
} 

Measured memory_bytes: 256
#!python3

# input
A, B = list(map(int, input().split()))


def paint1(ans):
    a = 1
    for i in range(0, 49, 2):
        for j in range(0, 100, 2):
            if a == A:
                return
            ans[i][j] = "."
            a += 1


def paint2(ans):
    b = 1
    for i in range(51, 100, 2):
        for j in range(0, 100, 2):
            if b == B:
                return
            ans[i][j] = "#"
            b += 1


def main():
    ans = [["#"] * 100 for _ in range(50)] + [["."] * 100 for _ in range(50)]
    paint1(ans)
    paint2(ans)

    print(100, 100)
    for r in ans:
        print("".join(r))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3188
N,K = map(int, input().split())
S = input()

L0 = []
L1 = []
temp = S[0]
cnt = 1
for i in range(1, N):
    if S[i] == "0":
        if temp == "0":
            cnt += 1
        else:
            L1.append(cnt)
            temp = "0"
            cnt = 1
    else:
        if temp == "1":
            cnt += 1
        else:
            L0.append(cnt)
            temp = "1"
            cnt = 1
if S[-1] == "0":
    L0.append(cnt)
else:
    L1.append(cnt)

ans = 0
if S[0] == "0":
    if K >= len(L0):
        ans += N
    else:
        for i in range(K):
            ans += L0[i]+L1[i]
        i = K
        temp = ans
        while i < len(L0):
            if i-K == 0:
                temp -= L0[i-K]
            else:
                temp -= L0[i-K]+L1[i-K-1]
            if i == len(L1):
                temp += L0[i]
            else:
                temp += L0[i]+L1[i]
            if ans < temp:
                ans = temp
            i += 1
else:
    if K >= len(L0):
        ans += N
    else:
        for i in range(K):
            ans += L0[i]+L1[i]
        ans += L1[K]
        i = K
        temp = ans
        while i < len(L0):
            temp -= L0[i-K]+L1[i-K]
            if S[-1] == "0" and i == len(L1)-1:
                temp += L0[i]
            else:
                temp += L0[i]+L1[i+1]
            if ans < temp:
                ans = temp
            i += 1
            
print(ans)

Measured memory_bytes: 4452
n,k= list(map(int, input().strip().split()))
l=[0]*n
r=[0]*n
mod=998244353
for i in range(k):
    l[i],r[i] = list(map(int, input().strip().split()))

dp = [0]*(n+1)
dp[1] = 1
dpsum = [0]*(n+1)
dpsum[1] = 1
for i in range(2,n+1):
    for j in range(k): # 各kにおいてli~riまでの移動量が＋となる場合の和を計算する
        li = i - r[j] # 遷移元のindexの左端を求める
        ri = i - l[j] # 遷移元のindexの右端を求める
        if ri < 0: # riがﾏｲﾅｽの場合はそもそも以降を考えない
            continue
        li = max(li,1) # li がﾏｲﾅｽの場合があるので、そのときのindexはｽﾀｰﾄの"1"と考える
        dp[i] += dpsum[ri] - dpsum[li-1] # li~riの和を足す
    dpsum[i] = (dpsum[i-1]+dp[i])%mod
    
print(dp[n]%mod)

Measured memory_bytes: 79984
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed dp[2][303][90909];
int d,s;
int l[303];
int mod_pow(int x,int n,int m){
  int res=1;
  while(n){
    if(n&1) (res*=x)%=m;
    x=(x*x)%m;
    n>>=1;
  }
  return res;
}
int dfs(int f,int x,int y){
  if(~dp[f][x][y]) return dp[f][x][y];
  int res=0;
  if(x==d){
    res=mod_pow(y,d,MOD);
    if(f) res=(MOD-res)%MOD;
    return dp[f][x][y]=res;
  }
  (res+=dfs(f,x+1,y))%=MOD;
  if(l[x]<y) (res+=dfs(!f,x+1,y-l[x]))%=MOD;
  return dp[f][x][y]=res;
}
signed main(){
  cin>>d;
  for(int i=0;i<d;i++) cin>>l[i];
  cin>>s;
  memset(dp,-1,sizeof(dp));
  cout<<dfs(0,0,s)<<endl;
  return 0;
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code



int main()
{
	int a, b;
	cin>>a>>b;
	cout<<(6 - a -b)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,b,c,ok,d[1001];
struct edge{ll from,to,cost;};
vector<edge>v;
int main(void){
    cin>>n>>m;
    for(int i=1;i<n;i++)d[i]=-(1LL<<60);
    for(int i=0;i<m;i++){
        cin>>a>>b>>c;
        a--,b--;
        v.push_back({a,b,c});
    }
    for(int i=0;i<n;i++){
        ok=0;
        for(int j=0;j<m;j++){
            edge e=v[j];
            if(d[e.from]!=-(1LL<<60)&&d[e.to]<d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                ok=1;
                if(i==n-1&&e.to==n-1){
                    cout<<"inf"<<endl;
                    return 0;
                }
            }
        }
        if(!ok)break;
    }
    cout<<d[n-1]<<endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n,tmp=0;
	map<string,ll> mp;
	cin >> n;
	vs s(n);
	rep(i,n){
		cin >> s[i];
		mp[s[i]]++;
		chmax(tmp,mp[s[i]]);
	}
	sort(all(s));
	Eunique(s);
	rep(i,SIZE(s)){
		if(mp[s[i]]==tmp) cout << s[i] << endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

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

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 200010
#define MAX_DP 70000000

string S;
int h[MAX_N];       // [0, i) で各アルファベットの偶奇を表す。奇数なら 1
int opt[MAX_N];     // [0, i) の最小分割数
int dp[MAX_DP];

// [r, l) の範囲で回文作成可能かチェック
// 可能なら true
//bool Check(int r, int l) {
//    int odd = 0;
//    REP(i, 32) { if((((h[r] ^ h[l]) >> i) & 1) == 1) { odd++; } }
//    return (odd <= 1) ? true : false;
//}

int main()
{
    cin >> S;

    // ハッシュ作成
    ZERO(h);
    for(int i = 0; i < S.length(); ++i) { h[i+1] = ( h[i] ^ (1 << (S[i] - 'a')) ); }

    REP(i, MAX_DP) { dp[i] = INF; }
    REP(i, MAX_N) { opt[i] = INF; }
    opt[0] = 0;
    dp[0] = 0;
    for(int i = 1; i <= S.length(); ++i) {
        for(int j = 0; j <= 26; ++j) {
            int x = (j < 26) ? (1 << j) : 0;
            opt[i] = min(opt[i], dp[(h[i] ^ x)] + 1);
        }
        //if(opt[i] >= INF)
        //{
        //    for(int j = 0; j < i; ++j) {
        //        if(Check(j, i)) { opt[i] = min(opt[i], opt[j] + 1); }
        //    }
        //}
        dp[h[i]] = min(dp[h[i]], opt[i]);
    }
    printf("%d\n", opt[S.length()]);

    return 0;
}


Measured memory_bytes: 275716
n = int(input())
a = list(map(int, input().split()))

s = set()
count = 0
for i in range(n):
    if a[i] // 400 >= 8:
        count += 1
    else:
        s.add(a[i]//400)

print(len(s) if len(s) > 0 else 1, len(s)+count)

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, T;
	cin >> n >> T;
	int c, t;
	int cost = 10000000;
	int index;

	for(int i = 0; i < n; i++) {
		cin >> c;
		cin >> t;
		if (t <= T) {
			if (cost > c) {
				cost = c;
			}
		}
	}
	
	if (cost != 10000000) {
		cout << cost << endl;
	}
	else {
		cout << "TLE" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[200000];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	
	int f = 1;
	rep(i, n) {
		if (a[i] == f) f++;
	}
	
	if (f == 1) cout << -1 << endl;
	else cout << n + 1 - f << endl;
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            String str = Console.ReadLine();
            var found = str
                .Split(new char[]{' ', '.', ','})
                .Where(i => i.Length >= 3 && i.Length <= 6)
                .ToArray();
            for (int i = 0; i < found.Length; i++)
            {
                Console.Write(found[i] + (i == found.Length - 1 ? "" : " "));
            }
            Console.WriteLine();
        }
    }
}

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

int main() {
  int N,K,X=0;
  cin >> N >> K;
  vector<int>vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  for(int i=0; i<K; i++){
    X += vec[i];
  }
  cout << X << endl;
}


Measured memory_bytes: 3636
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

bool vis[109];

int main()
{
    optimize();

    int a, b, c;
    cin >> a >> b;
    vis[a] = vis[b] = 1;

    for ( int i = 1; i <= 3; i++ ) if ( !vis[i] ) cout << i << endl;


    return 0;
}


















Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
using namespace std;
#define ll long long
int main(){
	ll N, ans=1;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; i++){
		cin >> A[i];
		if (A[i] == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	
	for (int i = 0; i < N; i++){
		if (A[i] <= 1000000000000000000 / ans){
			ans *= A[i];
		}
		else{
			cout << "-1" << endl;
			return 0;
			
		}
	}


	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input_data;
        char arr[];
        try {
            input_data = br.readLine();
            arr = input_data.toCharArray();

            for (int i = 0; i < arr.length; i++) {
                // 대문자
                if (65 <= arr[i] && arr[i] <= 90) {
                    arr[i] = (char) (arr[i] + 32);
                    continue;
                }
                // 소문자
                if (97 <= arr[i] && arr[i] <= 122) {
                    arr[i] = (char) (arr[i] - 32);
                    continue;
                }
            }
            System.out.println(arr);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24152
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define For(i,a,b) for(int (i)=(a); (i)<(b); (i)++)

void solve7b(int a, int b) {
    int cnt = 0;
    for(int i = 1; i < a-1; i++) {
        for(int j = i+1; j < a; j++) {
            int k = b-i-j;
            if (k>=1 && k<=a && k>i && k>j) cnt++;
        }
    }
    cout << cnt << endl;
}

int main() {
    int a, b;
    while(cin >> a >> b, a+b) {
        solve7b(a,b);
    }
    return 0;
}

Measured memory_bytes: 1160
#include "iostream"
using namespace std;
#include <stdio.h>
#include<math.h>

int main(int argc, char const *argv[])
{
	double r = 0;
	double s,l=0;

	cin >> r;
	s = r * r * M_PI;
	l = 2 * M_PI * r;

	printf("%lf %lf\n", s, l);
	return 0;
}


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

vector<int> to[200005];
vector<int> ans(200005);

void dfs(int v, int p=-1) {
    int d = ans[v];
    for (int u : to[v]) {
        if (u == p) continue;
        ans[u] += d;
        dfs(u,v);
    }
} 

int main() {
    int n, q;
    cin >> n >> q;
    rep(i,n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }
    dfs(0);
    rep(i,n) cout << ans[i] << endl;
    return 0;
}

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

int main() {
    int N,X;
    cin >> N >> X;
    vector<int> bound(N);
    for(int z = 0;z<N;z++){
        cin >> bound.at(z);
    }

    int kyori = 0;
    int count = 0;
    int ans = 0;

    for(int i = 0;i<N+1;i++){
        if(i == 0){
          	ans++;
            continue;
        }
        kyori = kyori + bound.at(i-1);
        if(kyori <= X){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int k, ans, sum[N];

main () {
	cin >> k;
	for (int i = 1; i <= k; ++i)
		for (int j = 1; j <= k; ++j)
			sum[i] += __gcd(i, j);


	for (int i = 1; i <= k; ++i)
		for (int j = 1; j <= k; ++j)
			ans += sum[__gcd(i, j)];



	cout << ans << endl;
}


Measured memory_bytes: 3596
import itertools
data = []

while True:
    s = list(map(int, input().split()))
    if s[0] == 0 and s[1] == 0:
        break
    data.append(s)
    
for n, x in data:
    data_1 = []
    a = list(range(1, n + 1))
    for c in itertools.combinations(a, 3):
        d = sum(c)
        if d == x:
            data_1.append(c)
    print(len(data_1))


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

using namespace std;
long long x[10000010], y[10000010];
#define rep(i, n) for (int i = 0; i < (n); i++)
#define lep(j, n) for (int j = 0; j < (n); j++)
#define reps(i, n) for (int i = 1; i < (n); i++)
#define leps(i, n) for (int j = 1; j < (n); j++)
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define int long long
#define gsort(x, n) sort((x), (x) + (n), greater<int>());
#define setout(n, x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10);
const long long mod = 1e9 + 7;

signed main()
{

   cin.tie(0);
   ios::sync_with_stdio(false);

   int a, b, c;
   cin >> a >> b >> c;

   if (b / a >= c)
      cout << c << '\n';
   else
      cout << b / a << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
//sort(a, a + N, greater<ll>())   // descend
//sort(a, a+N)                    //  ascend

/**
void comb(vector<vector <ll> > &v) {
	rep (i,0,v.size()) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	rep (k,1,v.size()) {
		rep (j,1,k) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
/*main内でnCn~nC0 生成 **
vector<vector<ll> > v(n + 1, vector<ll>(n + 1, 0));
comb(v);
*/

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll ans=0;
	if(b>=c) ans=b+c;
	else if(a+b>=c) ans=b+c;
	else ans=a+b+b+1;
	cout<<ans;
}

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


int main() {
	int K, S;
	cin >> K;
	cin >> S;
	int cont = 0;

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

		for (int j = 0; j<=K; j++) {
			int z = S - i - j;
			if (z>= 0 && z <= K) {
				++cont;
			}
		
		}
	}
	cout << cont << endl;

	return 0;
}

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

using namespace std;
int main(void){
    
    int h,m,s;
    int sum=0,ssum=0;
    for(int i=0;i<3;i++){
        cin>>h>>m>>s;
        sum+=h*3600+m*60+s;
        cin>>h>>m>>s;
        ssum+=h*3600+m*60+s;
        
        ssum-=sum;
        cout<<ssum/3600<<" ";
        ssum-=(ssum/3600)*3600;
        cout<<ssum/60<<" ";
        ssum-=(ssum/60)*60;
        cout<<ssum<<endl;
        sum=0;ssum=0;
        
    }
    
    return 0;
}

Measured memory_bytes: 3076
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {

    int n,m;
    
    cin >> n >> m;
    
    int a[n+1][m+1];
    
    for(int i=0; i<n+1; i++){ //n+1 * m+1 の行列初期化
        for(int j=0; j<m+1; j++)
            a[i][j] = 0;
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
            a[i][m] += a[i][j];
            a[n][j] += a[i][j];
        }
        a[n][m] += a[i][m];
    }
    
    for(int i=0; i<n+1; i++){
        for(int j=0; j<m; j++){
            cout << a[i][j] << " ";
        }
        cout << a[i][m];
        cout << endl;
    }
    
    
    return 0;
}



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

int main(void){
    int k,a,b;
    cin >> k >> a >> b;
    bool ok = false;
    for(int i=a;i<=b;i++){
        if(i%k==0) ok = true;
    }
    if(ok) cout << "OK" << endl;
    else cout << "NG" << endl;
}

Measured memory_bytes: 3632
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (int i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=2e6;
const ld PI=acos(-1);

int main(){
    rapgame
    //freopen("brokeday.in", "r", stdin);
    //freopen("richday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        readll(n);
        cout << (n%1000==0 ? 0 : 1000-n%1000);
    }
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const int INF = 1e9+7;
const ll mod = 998244353;


string S;
ll N,ans;


int main() {

	cin >> S;

	int a = (S[0] - '0') * 10 + (S[1] - '0');
	int b = (S[2] - '0') * 10 + (S[3] - '0');

	if (a <= 12 && a >= 1) {
		if (b <= 12 && b >= 1)cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	}
	else if (b <= 12 && b >= 1) {
		cout << "YYMM" << endl;
	}
	else cout << "NA" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

int main(){
    string s;
    cin >> s;
    if (s[2] == s[3] and s[4] == s[5]){
        p("Yes");
    } else {
        p("No");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll dp[1<<18][18];
void Main() {
  ll n;
  cin >> n;
  ll a[n][2];
  rep(i,n) R a[i][0];
  rep(i,n) R a[i][1];
  rep(i,1<<n)rep(j,n) dp[i][j]=MAX;
  rep(i,n) dp[1<<i][i]=i;
  rep(t,1<<n) {
    rep(i,n) {
      if(dp[t][i]==MAX) continue;
      int k=__builtin_popcount(t);
      int x=a[i][abs(k-i+1)%2],c=__builtin_popcount(t);
      rep(j,n) {
        if(t&(1<<j)) {
          c--;
          continue;
        }
        int y=a[j][abs(k-j)%2];
        if(x<=y) dp[t|(1<<j)][j]=min(dp[t|(1<<j)][j],dp[t][i]+abs(k-j-c));
      }
    }
  }
  ll ans=MAX;
  rep(i,n) ans=min(ans,dp[(1<<n)-1][i]);
  if(ans==MAX) ans=-1;
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 37120
#include <stdio.h>
int main(void)
{
    int w, h, x, y, n;
    double s;
    scanf("%d%d%d%d", &w, &h, &x, &y);

if(x+x==w && y+y==h){
    n=1; 
}else{
    n=0;
}

s =(double)w * h / 2; 
printf("%f %d", s, n);

return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.util.function.BiFunction;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        SegmentTree<Integer> tree = new SegmentTree<>(600010, 0, Integer::max);
        for (int i = 0; i < N; i++) {
            int x = A[i];
            int left = Math.max(0, x - K);
            int right = x + K + 1;
            int max = tree.query(left, right);
            tree.update(x, max + 1);
        }
        int ans = tree.query(0, 300001);
        System.out.println(ans);
    }
    
    class SegmentTree<T> {
        int size;
        T initialValue;
        List<T> list;
        BiFunction<? super T, ? super T, ? extends T> biFunction;
        SegmentTree(int n, T initialValue, BiFunction<? super T, ? super T, ? extends T> biFunction) {
            int size = 1;
            while (size < n) {
                size *= 2;
            }
            this.size = size;
            List<T> list = new ArrayList<T>();
            for (int i = 0; i < size * 2; i++) {
                list.add(initialValue);
            }
            this.list = list;
            this.initialValue = initialValue;
            this.biFunction = biFunction;
        }
        void update(int index, T value) {
            index += this.size - 1;
            list.set(index, value);
            while (0 < index) {
                index = (index - 1) / 2;
                list.set(index, biFunction.apply(list.get(2 * index + 1), list.get(2 * index + 2)));
            }
        }
        T query(int start, int end) {
            return query(start, end, 0, 0, this.size);
        }
        T query(int start, int end, int index, int left, int right) {
            if (right <= start || end <= left) {
                return this.initialValue;
            }
            if (start <= left && right <= end) {
                return list.get(index);
            }
            T value_left = query(start, end, index * 2 + 1, left, (left + right) / 2);
            T value_right = query(start, end, index * 2 + 2, (left + right) / 2, right);
            return biFunction.apply(value_left, value_right);
        }
    }
}


Measured memory_bytes: 97316
# your code goes here
mp={-6:0,-5:0,-4:0,-3:0,-2:0,-1:1,0:1}
def func(xx):
    if mp.get(xx,0)!=0:
        return mp[xx]
    mp[xx]=(func(xx-1)+func(xx-2))%1000000007
    return mp[xx]
h,w,k= map(int, input().split())
if w == 1:
    print('1')
    exit(0)
DT = [0 for i in range(w)]
CR =  [0 for i in range(w)]
DT [0]=1
#print(sum(DT),sum(CR))
for _ in range(h):
    for i in range(w-2):
        CR[i]+=DT[i+1]*func(i-1)*func(w-2-i-1)
        CR[i+1]+=DT[i+1]*func(i)*func(w-2-i-1)
        CR[i+2]+=DT[i+1]*func(i)*func(w-2-i-2)
    CR[0]+=DT[0]*func(w-2)
    CR[1]+=DT[0]*func(w-3)
    CR[-2]+=DT[-1]*func(w-3)
    CR[-1]+=DT[-1]*func(w-2)
    for i in range(w):
        DT[i]=CR[i]%1000000007
        CR[i]=0
    #print(sum(DT))
    #print(DT)
print(DT[k-1])

Measured memory_bytes: 38512
A, B, Q = map(int, input().split())
s = []
t = []
x = []
for _ in range(A):
    s.append(int(input()))
for _ in range(B):
    t.append(int(input()))
for _ in range(Q):
    x.append(int(input()))

import sys
INT_MAX = sys.maxsize
s.insert(0, -1 * INT_MAX)
s.append(INT_MAX)
t.insert(0, -1 * INT_MAX)
t.append(INT_MAX)

import bisect
for xi in x:
    #print(xi)
    si = bisect.bisect_right(s, xi)
    #si = 0
    #for si, v in enumerate(s):
    #    if v > xi:
    #        break
    ti = bisect.bisect_right(t, xi)
    #ti = 0
    #for ti, v in enumerate(t):
    #    if v > xi:
    #        break
    #print(si, ti)
    sa = s[si]
    ta = t[ti]
    sb = s[si-1]
    tb = t[ti-1]
    #print(sa, sb,ta,tb)
    ans = min([
        abs(xi-sa)+abs(sa-ta),
        abs(xi-sa)+abs(sa-tb),
        abs(xi-sb)+abs(sb-ta),
        abs(xi-sb)+abs(sb-tb),
        abs(xi-ta)+abs(ta-sa),
        abs(xi-ta)+abs(ta-sb),
        abs(xi-tb)+abs(tb-sa),
        abs(xi-tb)+abs(tb-sb)
    ])
    print(ans)

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

int main(void) {
  long long N;
  cin >> N;

  vector<long long> staff(N);
  staff[N-1] = 0;
  for (long long si = 1; si < N; si++) { cin >> staff[si]; }

  vector<long long> res(N+1, 0);
  for (long long si = 0; si < N; si++) {
    res[staff[si]]++;
  }

  for (long long si = 1; si <= N; si++) {
    cout << res[si];
    if (si < N) cout << " ";
    else cout << endl;
  }

  return 0;
}


Measured memory_bytes: 6428
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h,w;
    cin >> h >> w;
    string s[h];
    char answer[h][w];
    REP(i,h)cin >> s[i];
    REP(i,h){
        REP(j,w){
            int cnt = 0;
            if(s[i][j] == '.'){
                for(int k = -1;k < 2;k++){
                    for(int l = -1;l < 2;l++){
                        if(i == 0 && k==-1)continue;
                        if(i == h-1 && k == 1)continue;
                        if(j == 0 && l == -1)continue;
                        if(j == w-1 && l == 1)continue;
                        if(s[i+k][j+l] == '#') cnt++;
                    }
                }
                answer[i][j] = cnt+'0';
            }
            else{
                answer[i][j] = '#';
            }
        }
    }
    REP(i,h){
        REP(j,w){
            cout << answer[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
	int res = 0;
	string s;
	cin >> s;
	if (s.at(0)=='1') {
		for (int i = 1; i < s.size(); i++) {
			if (i%2 != 0 && s.at(i)=='1') {
				res++;
			}
			else if (i % 2 == 0 && s.at(i) == '0') {
				res++;
			}
		}
	}
	else {
		for (int i = 1; i < s.size(); i++) {
			if (i % 2 != 0 && s.at(i) == '0') {
				res++;
			}
			else if (i % 2 == 0 && s.at(i) == '1') {
				res++;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0, i_l = (int)n; i < i_l; i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


int main() {
    int W, H, N;
    cin >> W >> H >> N;
    int p[] = {0, W, 0, H};
    int top = H;
    rep(i, N) {
        int x, y, a;
        cin >> x >> y >> a;
        a--;
        int v = (a / 2 == 0) ? x : y;
        if (a % 2 == 0) {
            p[a] = max(p[a], v);
        } else {
            p[a] = min(p[a], v);
        }
    }
    int dx = max(p[1] - p[0], 0);
    int dy = max(p[3] - p[2], 0);
    int ans = dx * dy;
    cout << ans << endl;
    return 0;
}



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

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    for(int i = 1; i < 10; i++){
        for( int j = 1; j < 10; j++){
            cout << i << "x" << j << "=" << i * j << "\n";
        }
    }
    

    return 0;
}

Measured memory_bytes: 3160
def main():
    N, X, Y = map(int, input().split())

    ans = [0]*(N-1)

    for i in range(1, N):
        for j in range(i+1, N+1):
            if j <= X or Y <= i:
                tmp = j - i
            elif i <= X and j <= Y:
                tmp = (X - i) + min(j - X, Y - j + 1)
            elif i <= X and Y <= j:
                tmp = (X - i) + (j - Y) + 1
            elif i <= Y and Y <= j:
                tmp = (j - Y) + min(Y - i, i - X + 1)
            else:
                tmp = min(j - i, i - X + Y - j + 1)

            ans[tmp - 1] += 1

    print(*ans, sep="\n")


main()


Measured memory_bytes: 44508
use std::io::{stdin, BufRead, BufReader};

fn main() {
    let mut lines = BufReader::new(stdin()).lines();
    let n = lines.next().unwrap().unwrap().parse::<u32>().unwrap();
    for _ in 0..n {
        let line = lines.next().unwrap();
        let values: Vec<f64> = line
            .unwrap()
            .split_whitespace()
            .filter_map(|x| x.parse::<f64>().ok())
            .collect();
        let d = distance(values[0], values[1], values[3], values[4]);
        let sum_r = values[2] + values[5];
        let diff_r = values[2] - values[5];
        match d {
            x if x > sum_r => println!("0"),
            x if x < diff_r.abs() => {
                if diff_r < 0.0 {
                    print!("-");
                }
                println!("2");
            }
            _ => println!("1"),
        }
    }
}

fn distance(xa: f64, ya: f64, xb: f64, yb: f64) -> f64 {
    ((xa - xb).powf(2.0) + (ya - yb).powf(2.0)).sqrt()
}



Measured memory_bytes: 5052
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'

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

  int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) print(":(");
  else print("Yay!");


  return 0;
}

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

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

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

  vector<int64_t> A(N);
  vector<int64_t> B(N);
  vector<int64_t> C(N);
  rep(i, N) cin >> A.at(i);
  rep(i, N) cin >> B.at(i);
  rep(i, N) cin >> C.at(i);

  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  int64_t ans=0;

  int j=0;
  int k=0;

  vector<int64_t> D(N);
  vector<int64_t> E(N);
  int l=0;
  int64_t sum=0;
  for(int i=0; i<N; i++){
    while(B.at(i)>=C.at(l)&&l<N-1) l++;
    if(l==N-1&&B.at(i)>=C.at(l)) D.at(i)=0;
    else D.at(i) = N-l;
    sum += D.at(i);
  }

  rep(i,N){
    E.at(i) = sum;
    sum-=D.at(i);
  }
  
  E.push_back(0);

  for(int i=0; i<N; i++){
    if(j==N-1&&A.at(i)>=B.at(j)) break;
    while(A.at(i)>=B.at(j)&&j<N-1) j++;
    if(j==N-1&&A.at(i)>=B.at(j)) break;
    ans += E.at(j);
    //cout << E.at(j) << endl;
  }
  

  cout << ans;
}

Measured memory_bytes: 4992
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args){
        Deque<String> formula = new ArrayDeque<String>();
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String input = scan.next();
            if(input.equals("+")) input = String.valueOf(Integer.parseInt(formula.poll())+Integer.parseInt(formula.poll()));
            else if(input.equals("-")) input = String.valueOf(-1*Integer.parseInt(formula.poll())+Integer.parseInt(formula.poll()));
            else if(input.equals("*")) input = String.valueOf(Integer.parseInt(formula.poll())*Integer.parseInt(formula.poll()));
            formula.push(input);
        }
        System.out.println(formula.poll());
    }
}

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

int main() {
  int a, b, k;
  cin >> a >> b >> k;
  
  int ans;
  int c = 0;
  for(int i = 100; i > 0; i--){
    if(a%i == 0 && b%i == 0) c++;
    if(c == k){
      ans = i;
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>
#define MAXN 100000

using namespace std;
int a[MAXN+80];
deque<int>q;
int main()
{
	int n,i,j,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",a+i);
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++)
		q.push_back(a[i]);
	while(q.size())
	{
		do{
			i=q.front();
			q.pop_front();
			ans++;
		}while(q.size()&&i^q.front());
		if(q.empty())
			break;
		do{
			j=q.back();
			q.pop_back();
			ans++;
		}while(q.size()&&j^q.back());
		if(q.empty()||(i==q.front()&&j==q.back()))
			ans-=2;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024