akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

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; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int h, w, n; cin >> h >> w >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  vector<vector<int>> ans(h, vector<int>(w));

  bool asc = true;
  int idx = 0;
  int num = 0;
  rep(i, h) {
    if (asc) {
      for (int j = 0; j < w; j++) {
        ans[i][j] = idx + 1;
        a[idx]--;
        if (a[idx] == 0) idx++;
      }
      asc = false;
    } else {
      for (int j = w-1; j >= 0; j--) {
        ans[i][j] = idx + 1;
        a[idx]--;
        if (a[idx] == 0) idx++;
      }
      asc = true;
    }
  }

  rep(i, h) {
    rep(j, w) {
      printf("%d%c", ans[i][j], j == w-1 ? '\n' : ' ');
    }
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int ans = 0;
  if(A % 2 || B % 2 || C % 2) ans = 0;
  else if(A == B && B == C) ans = -1;
  else {
    int dif1 = abs(A - B);
    int dif2 = abs(B - C);
    int cnt1 = 0, cnt2 = 0;
    while(dif1 % 2 == 0) {
      dif1 /= 2;
      cnt1++;
    }
    while(dif2 % 2 == 0) {
      dif2 /= 2;
      cnt2++;
    }
    ans = min(cnt1, cnt2);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> dp(N);
    dp[0] = 1000;
    for (int i = 1; i < N; ++i) {
        for (int j = 0; j < i; ++j) {
            chmax(dp[i], dp[j]);
            chmax(dp[i], dp[j] + dp[j] / A[j] * (A[i] - A[j]));
        }
    }

    cout << dp[N - 1] << endl;

}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

int main(){
    string s[3], S;
    cin >> s[0] >> s[1] >> s[2];
    
    if(s[0][s[0].size()-1]==s[1][0] && s[1][s[1].size()-1]==s[2][0]){
        cout << "YES" << endl;
    }
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

const size_t BSIZE = 20;
const size_t SIZE = 1 << BSIZE;
const ll mod = 1e9 + 7;

ll cnt[SIZE + 10][BSIZE + 1];
ll pow2[SIZE + 10] = { 1 };

int main() {
    ll N;
    cin >> N;
    V<ll> A(N);
    ll sum = SIZE - 1;
    for(auto &&e : A) {
        cin >> e;
        cnt[e][0]++;
        sum &= e;
    }

    if(sum) {
        cout << 0 << endl;
        return 0;
    }

    for(ll j = 0; j < BSIZE; j++) for(ll i = 0; i < SIZE; i++) {
        cnt[i][j + 1] = cnt[i][j];
        if(!(i & (1 << j))) cnt[i][j + 1] += cnt[i ^ (1 << j)][j];
    }

    for(ll i = 1; i < SIZE + 10; i++) pow2[i] = 2 * pow2[i - 1] % mod;
    ll ans = pow2[N];
    for(ll i = 1; i < (ll)SIZE; i++) {
        ll bcnt = 0;
        for(ll j = 0; j < BSIZE; j++) if(i & (1 << j)) bcnt++;
        ll val = pow2[cnt[i][BSIZE]];
        ans += (bcnt & 1 ? mod - val : val);
    }

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



Measured memory_bytes: 183872
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
using namespace std;
bool cmp(char a,char b)
{
	return a<b;
}
int main()
{
	char z[200]={'\0'};
	while(~scanf("%s",z))
	{
		int l=strlen(z);
		int total=0,ans1=0;
		int ans2=0;
		sort(z,z+l,cmp);
		char t=z[0];
		for(int i=0;i<l;i++)
		{
			if(t==z[i])
			total++;
			else
			{
				t=z[i];
				total=1;
			}
			if(total==2)
			{
				ans1++;
				if(ans1>=2)
				ans2++;
			}
		}
		if(ans1==2&&ans2==1)
		printf("Yes\n");
		else
		printf("No\n");
	}
}

Measured memory_bytes: 504
from sys import exit, stderr, stdin
input = stdin.readline
def debug(var, name="hoge"):
    print(name +":" + str(type(var)) + " = " + repr(var), file=stderr)
    return


def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    # print(A[1::2])
    X1 = sum(A) - 2*sum([a for a in A[1::2]])
    ans = [str(X1)]
    for i in range(1,N):
        ans.append(str(2*A[i-1]-int(ans[-1])))
    print(" ".join(ans))



if __name__ == "__main__":
    main()


Measured memory_bytes: 17336
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>str;
a=0;b=0;c=0;
  rep(i,str.length()){
    if(str[i]=='a') a++;
    if(str[i]=='b') b++;
    if(str[i]=='c') c++;
    
  }
  n=min(a,min(b,c));
  if(n+1>=a&&n+1>=b&&n+1>=c){
        cout<<"YES"<<endl;
    }
  else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3700
import numpy as np
import sys
i4 = np.int32

if sys.argv[-1] == 'ONLINE_JUDGE':
    adjacency_list = '''
import numpy as np
from numba import njit
from collections import namedtuple

AdjacencyList = namedtuple('AdjacencyList', ['v', 'adj'])

@njit
def adjacency_list(n, a):
    """
    隣接リストの作成
    :param n: vertex の数
    :param a: 2d の ndarray, 各行は、[u, v] u: Edge の始点、v: Edge の終点
    :return: AdjacencyList
    """
    v = np.zeros(n + 1, np.int32)
    for i in range(a.shape[0]):
        v[a[i, 0] + 1] += 1
    for i in range(1, v.shape[0]):
        v[i] += v[i - 1]
    adj = np.empty(a.shape[0], np.int32)
    temp = np.zeros(n, np.int32)
    for i in range(a.shape[0]):
        from_ = a[i, 0]
        adj[v[from_] + temp[from_]] = a[i, 1]
        temp[from_] += 1
    return AdjacencyList(v, adj)


@njit
def at(gc, n):
    return gc.adj[gc.v[n]:gc.v[n + 1]]


@njit
def iter(gc, n):
    for i in range(gc.v[n], gc.v[n + 1]):
        yield gc.adj[i]        
    '''
    import os
    os.makedirs('nbacl/graphs', exist_ok=True)
    with open('nbacl/graphs/adjacency_list.py', 'w') as f:
        f.write(adjacency_list)

    abc138_d_numba = '''
import numpy as np
import nbacl.graphs.adjacency_list as tree
from numba import njit
from numba.types import Array, int32
from numba.pycc import CC
i4 = np.int32
cc = CC('abc138_d_numba')


@njit
def dfs(d, prev, v, adj, u, val):
    y = val[d]
    for i in range(v[d], v[d + 1]):
        x = adj[i]
        if x == prev:
            continue
        val[x] = y + u[x]
        dfs(x, d, v, adj, u, val)


@cc.export('solve', (Array(int32, 2, 'C'), Array(int32, 2, 'C'), int32))
def solve(a, p, N):
    tr = tree.adjacency_list(N, a)
    u = np.zeros(N, i4)
    val = np.zeros(N, i4)
    for i in range(p.shape[0]):
        u[p[i, 0] - 1] += p[i, 1]
    val[0] = u[0]
    dfs(int32(0), int32(-1), tr.v, tr.adj, u, val)
    return val


if __name__ == '__main__':
    cc.compile()
    '''
    with open('abc138_d_numba.py', 'w') as f:
        f.write(abc138_d_numba)
    import subprocess
    cmd = "python3.8 abc138_d_numba.py"
    subprocess.run(cmd.split())
    exit(0)


from abc138_d_numba import solve

def main():
    f = open(0)
    N, Q = [int(x) for x in f.readline().split()]
    ap = np.fromstring(f.read(), i4, sep=' ').reshape((-1, 2))
    a = ap[:N - 1] - 1
    a = np.concatenate((a, a[:, ::-1]))
    p = ap[N - 1:]
    val = solve(a, p, N)
    print(*val.tolist())


if __name__ == '__main__':
    main()


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

int main(){
int n;
cin>>n;
    string s,s2;
    cin>>s;
    int k=s.size();
    if(n%2!=0)cout<<"No\n";
    else
    {
        int t=k/2;
        string m="";
        string w="";
int i,j,k;        for(i=0;i<t;i++)
            m=m+s[i];
        for(i=t;i<s.size();i++)
            w=w+s[i];
            ///cout<<m<<"  "<<w<<endl;
            if(m.compare(w)==0)
                cout<<"Yes\n";
            else cout<<"No\n";

    }

    return 0;
}



Measured memory_bytes: 256
L = list(map(int,input().split()))
M = list(map(int,input().split()))
N = list(map(int,input().split()))
O = [L,M,N]
P = L.count(1)+M.count(1)+N.count(1)
Q = L.count(2)+M.count(2)+N.count(2)
R = L.count(3)+M.count(3)+N.count(3)
S = L.count(4)+M.count(4)+N.count(4)
T = [P,Q,R,S]
T.sort()
if T[0] == T[1] == 1:
  if T[2] == T[3] == 2:
    if [T[1],T[2]] or [T[2],T[1]] in O:
      print('YES')
    else:
      print('NO')
  else:
    print('NO')
else:
  print('NO')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <list>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
 
int main(void)
{
    for (int i = 0; i < 5; ++i)
    {
        int x = 0;
        cin >> x;
        if (x == 0)
        {
            cout << (i+1) << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 3144
n,k=map(int,input().split())
p=list(map(int,input().split()))
a=[0]*n
b=[0]*n
for i in range(n):
  a[i]=(p[i]+1)/2
b[0]=a[0]
for i in range(1,n):
  b[i]=b[i-1]+a[i]
ans=b[k-1]
for i in range(1,n-k+1):
  ans=max(ans,b[i+k-1]-b[i-1])
print(ans)

Measured memory_bytes: 101168
#include <bits/stdc++.h>
using namespace std;
int t;
long long a,b,c,d;
void no(){
	cout<<"No\n";
}
void yes(){
	cout<<"Yes\n";
}
int main(){
	ios_base::sync_with_stdio(0);
	cin>>t;
	while(t--){
		cin>>a>>b>>c>>d;
		if(a<b){
			no();
			continue;
		}
		if(d<b){
			no();
			continue;
		}
		if(c+1>=b){
			yes();
			continue;
		}
		long long p=a%__gcd(b,d);
		p-=__gcd(b,d);
		if(p>=c+1-b){
			no();
		}
		else yes();
	}
}


Measured memory_bytes: 256
from collections import deque
s = input()

q = int(input())
s = deque(s)
r = False
for _ in range(q):
    cmd = input()
    if cmd[0] == '1':
        r = not r
    else:
        cmd, f, c = cmd.split()
        if (f == '2' and not r) or (f=='1' and r):
            s.append(c)
        else:
            s.appendleft(c)
if r:
    s.reverse()
print(''.join(s))


Measured memory_bytes: 74200
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i <(n); i++)
#define rep2(i,l,r) for (int i=(l); i<(r); i++)
#include <bits/stdc++.h>
//~ #include <atcoder/all>
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;
}
//~ int A = (1<<2) | (1<<3) | (1<<5) | (1<<7);
//~ for (int bit=A; ; bit=(bit-1)&A){
    //~ if (!bit) break;
//~ }
int next_combination(int sub){
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}
//~ int n=5;
//~ int k=3; // nCkの組み合わせ、ただしk=0には対応してない
//~ int bit=(1<<k)-1; // 1000 -> 0111
//~ for(; bit < (1<<n); bit=nex_combination(bit){
//~ }
bool isPrime(int a){
    if(a==2) return true;
    if(a<=1 || a%2==0) return false;
  
    for(int i=3; i*i<=a; i+=2){
        if(a%i==0) return false;
    }
    return true;
}
//~ vector<int> a = {1, 14, 32, 51, 51, 51, 243, 419, 750, 910};
vector<int> a;
// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (a[index] >= key) return true;
    else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

long long modpow(long long a, long long n, long long mod){
    long long res = 1;
    while(n>0){
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//~ int v[100100];
//~ int INF = 1 << 30;
//~ vector<vector<int>> dp(310, vector<int>(310));
//~ ll dp[110][100100];
//~ vector<int> dp(100100, 0));

//~ int seen[110];
//~ int ans[110][2];
//~ ll MOD = 1e9 + 7;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    string S;
    cin >> S;
    
    int cnt=0, bcnt=0;
    rep(i, N){
        if(S[i]=='a') {
            if(cnt<A+B){
                cout << "Yes" << endl;
                cnt++;
            }
            else cout << "No" << endl;
            continue;
        }
        if(S[i]=='b') {
            if((cnt<A+B) && (bcnt<B)){
                cout << "Yes" << endl;
                cnt++;
                bcnt++;
            }
            else cout << "No" << endl;
            continue;
        }
        
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3760
from collections import defaultdict
N,  Q = map(int ,input().split())

d = defaultdict(list)
for _ in range(N-1):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

dp = [0]*N
used = [False]*N

for _ in range(Q):
    p, x = map(int, input().split())
    dp[p-1] += x

q = [1]
used[0] = True

while q:
    x = q.pop()
    
    for i in d[x]:
        if used[i-1]==True:
            continue
        dp[i-1] += dp[x-1]
        used[i-1] = True
        q.append(i)

print(*dp)

Measured memory_bytes: 118744
h,w=map(int,input().split())
maze=[input() for i in range(h)]
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [[0,0,1] for i in range(size + first_index)]
        for i in range(size):
            self._parents[i][int(maze[i//w][i%w]==".")]=1
    def find(self, x: int) -> int:
        if type(self._parents[x]) is list:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x][2] < self._parents[y][2]:
            x, y = y, x
        self._parents[x] = [self._parents[x][i]+self._parents[y][i] for i in range(3)]
        self._parents[y] = x
        return True
ans=0
m=[(0,1),(0,-1),(1,0),(-1,0)]
uf=UnionFind(h*w)
for i in range(h):
    for j in range(w):
        for dx,dy in m:
            if 0<=dx+i<h and 0<=dy+j<w and maze[i][j]!=maze[i+dx][j+dy]:
                uf.unite(i*w+j,(i+dx)*w+j+dy)
for i in uf._parents:
    if type(i)is list:ans+=i[0]*i[1]
print(ans)

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int k;
    cin >> k;

    vector<ll> a(k);

    rep(i, k){
        cin >> a[i];
    }

    pair<ll,ll> minmax = mpair(2, 2);

    for(int i = k - 1; i >= 0; i--){

        //cerr << minmax.first << " " << minmax.second << endl;

        if(a[i] > minmax.second){
            minmax.first = -1;
            break;
        }else{

            //min以上max以下の数字の内、a[i]で割り切れる最小値と最大値を求める
            ll tmpmin = minmax.first;
            ll tmp = minmax.first % a[i];

            if(tmp != 0){
                tmpmin = tmpmin + (a[i] - tmp);
            }

            //cerr << tmpmin << endl;

            if(tmpmin > minmax.second){
                minmax.first = -1;
                break;
            }

            tmp = minmax.second % a[i];
            ll tmpmax = minmax.second - tmp;

            //cerr << tmpmax << endl;

            if(tmpmax < minmax.first){
                minmax.first = -1;
                break;
            }

            minmax = mpair(tmpmin, tmpmax + a[i] - 1);

        }
    }

    if(minmax.first == -1){
        cout << -1 << endl;
    }else{
        cout << minmax.first << " " << minmax.second;
    }


}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<functional>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<set>
#include<map>

#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 2e9
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
const double PI = acos(-1);

using namespace std;
int main(void) {
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//	freopen("input.txt", "r", stdin);

	int N; cin >> N;
	vector<pii> p;
	vector<int> plus;
	vector<int> minus;

	for (int i = 1; i <= N; i++) {
		int x, y; cin >> x >> y;
		p.push_back({ x, y });
		plus.push_back(x + y);
		minus.push_back(x - y);
	}
	sort(all(plus));
	sort(all(minus));
	cout << max(plus.back() - plus[0], minus.back() - minus[0]);
}


Measured memory_bytes: 7648
#include <bits/stdc++.h>
#define rep(i,a,n)  for (int i=(int)(a); i<=(int)(n); ++i)
#define rrep(i,a,n) for (int i=(int)(a); i>=(int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(f, 0, (x.size()-1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K,X,Y;
int a,b,c,d;
string S,T;
vector<int> A,B;
//=============================
void input()
{
    cin>>N>>X;
    A.resize(N);
    rep(i,0,N-1){
        cin>>A[i];
    }

}
//=============================
void func(){}
/*
 - 樹形図をかく
*/
//=============================
void solve()
{
    //前から見ていく
    int prev = 0;
    int ans = 0;
    rep(i,0,N-1){
        if (prev + A[i] > X){
            ans += A[i]+prev - X;
            prev = X-prev;
        }
        else {
            prev = A[i];
        }
    }
    cout<<ans<<endl;

}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 1024
/**
*    created: 24.06.2020 13:29:49
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n) cin >> x[i];
    vector<int> ans;
    int l = 0;
    int r = l + k - 1;
    rep(l, n - k + 1) {
        int r = l + k - 1;
        int tmp = min(abs(x[r])+abs(x[r]-x[l]),abs(x[l])+abs(x[r]-x[l]));
        ans.push_back(tmp);
    }
    sort(all(ans));
    cout << ans[0] << endl;
    return 0;
}

Measured memory_bytes: 4684
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<double,double>         pdd;
typedef pair<ld,ld>                 pld;
typedef pair<string , string>       pss;
#define ts(x)                       to_string(x)
#define ti(x)                       stoi(x)
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define tab                         '\t'
#define sep                         ' '
#define mine(v)                     *min_element(all(v))
#define maxe(v)                     *max_element(all(v))
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl                        "\n"
inline ll input(){ll n; cin >> n ; return n;}
ll pw(ll a , ll b)  { return (!b ? 1 : (b & 1 ? a * pw(a * a , b / 2) : pw(a * a , b / 2))); }

const int MAXN = 3e3 + 10;
const int MOD = 1e9 + 7;
const int MOD2 = 998244353;
const ll INF = 8e18;

int dp[MAXN][MAXN];

pair<string, pair<int , int> > last[MAXN][MAXN];

int main(){
    fast_io;
    //cout << fixed << setprecision(15);
    //scanf("%d %d %f %lld %s %c", &x);
    //printf("%d %d %f %lld %s %c", x);
    string s, t, ans;
    cin >> s >> t;
    int n = (int)s.size(), T = (int)t.size();
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= T; j++){
            if(i == 0 || j == 0){
                dp[i][j] = 0;
                continue;
            }
            if(s[i - 1] == t[j - 1]){
                dp[i][j] = dp[i - 1][j - 1] + 1;
                last[i][j] = {string(1, s[i - 1]), {i - 1, j - 1}};
            }
            else{
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
                if(dp[i - 1][j] > dp[i][j - 1]){
                    last[i][j] = {"", {i - 1, j}};
                }
                else{
                    last[i][j] = {"", {i, j - 1}};
                }
            }

        }
    }
    int x = n, y = T;
    while(x != 0 || y != 0){
        int x2, y2;
        x2 = last[x][y].S.F;
        y2 = last[x][y].S.S;
        ans += last[x][y].F;
        x = x2, y = y2;
    }
    for(int i = (int)ans.size() - 1; i >= 0; i--){
        cout << ans[i];
    }
    return 0;
}




Measured memory_bytes: 599040
n=int(input())
s=list(input())
a=[0]*(n+1)
b=[0]*(n+2)
for i in range(n):
  a[i+1]=a[i]
  b[n-i]=b[n-i+1]
  if s[i]=='W':
    a[i+1]+=1
  if s[n-i-1]=='E':
    b[n-i]+=1
print(min(a[i]+b[i]-1for i in range(1,n+1)))

Measured memory_bytes: 19944
#include<iostream>

using namespace std;
#define N 1000000
int main(){

  int f[N];
  cin >> f[0];
  for(int i = 1; i < N; i++){
    if(f[i-1]%2 ==0){
      f[i] = f[i-1]/2;
    }else{
      f[i] = 3*f[i-1] + 1;
    }
    for(int j = 0; j < i; j++){
      if(f[i] == f[j]){
        cout << i+1 << endl;
        return 0;
      }
    }
  }
  return 0;
}


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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;


int main(){
    int n;
    cin >> n;
    ll a[101];
    REP(i,n) cin >> a[i];
    ll m = a[0],M = a[0];

    for(int i = 1;i < n ;i++){
        if(m > a[i]) m = a[i];
        if(M < a[i]) M = a[i];
    }

    cout << M-m << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b, d, r;
    double f;
    scanf("%d %d", &a, &b);
    d=a/b;
    r=a%b;
    f=(double)a/(double)b;
    printf("%d %d %f\n", d, r, f);
    return 0;
}

Measured memory_bytes: 632
n = int(input())
h = list(map(int,input().split()))
dif = [0]*(n-1)
ans = cnt = 0
for i in range(n-1):
    dif[i] =  h[i]-h[i+1]
for i in dif:
    if i>=0:
        cnt+=1
    else:
        ans = max(ans,cnt)
        cnt=0
print(max(ans,cnt))

Measured memory_bytes: 14228
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e5 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

vector<ll> adj[MAXN];
ll n , m , v , u , dist[MAXN][3];

void bfs(ll v , ll s){
    queue<pll> q;
    dist[v][s] = 0;
    q.push({v , s});
    while(!q.empty()){
        v = q.front().X , s = q.front().Y;
        q.pop();

        for(ll u : adj[v]){
            ll t = (s + 1) % 3;
            if(dist[u][t] == INF){
                dist[u][t] = dist[v][s] + 1;
                q.push({u , t});
            }
        }
    }
}

int main() {
    fast_io;
    for(ll i = 0 ; i < MAXN ; i++)  dist[i][0] = dist[i][1] = dist[i][2] = INF;

    cin >> n >> m;
    for(ll i = 0 ; i < m ; i++){
        cin >> v >> u;
        adj[v].push_back(u);
    }

    cin >> v >> u;
    bfs(v , 0);
    cout << (dist[u][0] == INF ? -1 : dist[u][0] / 3) << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 8064
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
  // 整数の入力
  vector<vector<ll>> A(3, vector<ll>(3, 0));
  for (int i = 0; i < 3; i++)
  {
    for (size_t j = 0; j < 3; j++)
    {
      cin >> A[i][j];
    }
  }
  ll N;
  cin >> N;
  for (size_t i = 0; i < N; i++)
  {
    ll b;
    cin >> b;
    for (int i = 0; i < 3; i++)
    {
      for (size_t j = 0; j < 3; j++)
      {
        if (A[i][j] == b)
        {
          A[i][j] = -1;
        }
      }
    }
  }

  bool is_clear = false;
  // 縦
  for (int i = 0; i < 3; i++)
  {
    bool c = true;
    for (size_t j = 0; j < 3; j++)
    {
      if (A[i][j] != -1)
      {
        c = false;
      }
    }
    if (c)
    {
      is_clear = true;
    }
  }

  for (int i = 0; i < 3; i++)
  {
    bool c = true;
    for (size_t j = 0; j < 3; j++)
    {
      if (A[j][i] != -1)
      {
        c = false;
      }
    }
    if (c)
    {
      is_clear = true;
    }
  }

  bool cc = true;
  for (size_t j = 0; j < 3; j++)
  {
    if (A[j][j] != -1)
    {
      cc = false;
    }
  }
  if (cc)
  {
    is_clear = true;
  }

  bool ccc = true;
  for (size_t j = 0; j < 3; j++)
  {
    if (A[2 - j][j] != -1)
    {
      ccc = false;
    }
  }
  if (ccc)
  {
    is_clear = true;
  }

  if (is_clear){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	string s;
	cin >> s;
	int left = 0;
	int right = SZ(s) - 1;

	while (s[left] != 'A')
		++left;

	while (s[right] != 'Z')
		--right;

	cout << right - left + 1 << endl;

}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-

import sys

dic = {}
text = raw_input().split()
max_count = 0
max_length = 0
for i in text:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1
for i in dic:
    max_count = max(max_count, dic[i])
    max_length = max(max_length, len(i))
for i in dic:
    if max_count == dic[i]:
        a = i
    if max_length == len(i):
        b = i
print "%s %s" %(a, b)

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

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



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int X,A,B;cin>>X>>A>>B;
    if(A>=B){
        cout <<"delicious" << "\n";
    }else if(A+X>=B){
        cout <<"safe"<<"\n";
        
    }else{cout <<"dangerous"<<"\n";}
    return 0;
        
}


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

int main() {
  long long int X;
  cin >> X;
  int year = 0;
  long long int sum = 100;
  
  while(sum<X){
    sum += 0.01*sum;
      year++;
  }
  
  cout << year << endl;
}


Measured memory_bytes: 3620
import heapq
def _heappush_max(heap,item):
  heap.append(item)
  heapq._siftdown_max(heap,0,len(heap)-1)
def _heappop_max(heap):
  lastelt=heap.pop()
  if heap:
    returnitem=heap[0]
    heap[0]=lastelt
    heapq._siftup_max(heap,0)
    return returnitem
  return lastelt

n,m=map(int,input().split())
a=list(map(int,input().split()))
heapq._heapify_max(a)
for i in range(m):
    _heappush_max(a,_heappop_max(a)//2)
print(sum(a))


Measured memory_bytes: 14180
//
//  main.cpp
//  topological_sort
//
//  Created by ???????????? on 2017/11/13.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;

static const int MAX = 100000;
static const int WHITE = 0;
static const int GRAY = 1;

vector<int> adjList[MAX];
vector<int> out;
int colors[MAX];
int indeg[MAX];
//int openTable


void bfs(int vertexInd, int numVertex){
    queue<int> Q;
    Q.push(vertexInd);
    colors[vertexInd] = GRAY;
    while(!Q.empty()){
        int u = Q.front();
        Q.pop();
        out.push_back(u);
        
        for(int i = 0; i < adjList[u].size(); i++ ){
            int adjInd = adjList[u][i];
            indeg[adjInd]--;
            if(indeg[adjInd] == 0 && colors[adjInd] == WHITE){
                colors[adjInd] = GRAY;
                Q.push(adjInd);
            }
        }
    }
}

void topologicalSort(int numVertex){
    
    //init
    for(int i = 0; i < numVertex; i++){
        colors[i] = WHITE;
        indeg[i] = 0;
    }
    
    for(int i = 0; i < numVertex; i++){
        for (int j = 0; j < adjList[i].size(); j++) {
            int temp = adjList[i][j];
            indeg[temp]++;
        }
    }
    
    
    for(int i = 0; i < numVertex; i++){
        if (indeg[i] == 0 && colors[i] == WHITE){
            bfs(i, numVertex);
        }
    }
}

int main(int argc, const char * argv[]) {
    int numVertex, numEdge;
    scanf("%d %d", &numVertex, &numEdge);
    
    int x, y;
    for (int i = 0; i < numEdge; i ++){
        scanf("%d %d", &x, &y);
        adjList[x].push_back(y);
    }
    
    topologicalSort(numVertex);
    
    //print "out"
    for(int i = 0; i < out.size(); i ++){
        cout << out[i] << endl;
    }
    
    
//    std::cout << "Hello, World!\n";
    return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= ll(b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
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);
}

int ans = 0;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  cin >> ans;
  if (ans < 1000)
    pr("ABC");
  else
    pr("ABD");
  return 0;
}


Measured memory_bytes: 3520
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

ans = 0
difmin = 10**7

for i in range(N):
    ht = T - H[i] * 0.006
    dif = abs(ht - A)
    
    if dif < difmin:
        difmin = dif
        ans = i+1
        
print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var m, n, s string
	fmt.Scan(&m, &n, &s)
	reg := "[0-9]{" + m + "}-[0-9]{" + n + "}"
	res, _ := regexp.Match(reg, []byte(s))
	if res {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
     	int b = sc.nextInt();
      	int c = sc.nextInt();
      	int d = sc.nextInt();
      	int e = sc.nextInt();
        int order[] = {a,b,c,d,e};
      	Integer time[] = new Integer[order.length];
      	int total = 0;
      
      	//時間の1の位求める
      	for(int i = 0; i < order.length; ++i){
        	time[i] = order[i]%10;
          	order[i] = order[i]-time[i];
        }
      	
      	//時間を足す
      	for(int i = 0; i < time.length; ++i){
          int amari=0;
          	if(time[i]!=0){
          		amari = 10-time[i];
            }
          	total = total+order[i]+time[i]+amari;
        }
      	//最後の時間に余りを引く
      	Arrays.sort(time);
      
      	if(time[0]!=0){
      		total = total - (10-time[0]);
          	 //調理時間出力
      		System.out.println(total);
         }else if(time[1]!=0){
          	total = total - (10-time[1]);
          	System.out.println(total);
         }else if(time[2]!=0){
          	total = total - (10-time[2]);
          	System.out.println(total);
         }else if(time[3]!=0){
          	total = total - (10-time[3]);
          	System.out.println(total);
         }else if(time[4]!=0){
          	total = total - (10-time[4]);
          	System.out.println(total);
         }else if(time[4]==0){
          	System.out.println(total);
        }
      
    }
}

Measured memory_bytes: 35400
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
#define fin {cout<<-1<<endl;return 0;}
//template
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;//res%=MOD;
    n*=n;//n%=MOD;
    k>>=1;
  }
  return res;
}
int dp[51][51];
//main
signed main(){
  int N;cin>>N;
  std::vector<int> a[N],b(N);
  for(int i=0;i<N;i++){int q;cin>>q;a[i].push_back(q);}
  for(int i=0;i<N;i++)cin>>b[i];
  int ans=0;
  for(int i=0;i<51;i++)for(int j=0;j<51;j++)dp[i][j]=LINF;
  for(int i=0;i<N;i++)dp[i][b[i]]=0;
  for(int k=1;k<=50;k++){
    for(int i=0;i<51;i++){
      for(int j=0;j<51;j++){
        if(dp[i][j]==LINF)continue;
        if(j>=k)continue;
        for(int l=1;j+k*l<51;l++)dp[i][j+k*l]=min(k,dp[i][j+k*l]);
      }
    }
  }
  int L=0;
  std::vector<int> ae(N);
  for(int i=0;i<N;i++)ae[i]=dp[i][a[i][0]];
  while(true){
    int out=0;L=0;
    for(int i=0;i<N;i++)L=max(L,ae[i]);
    if(L==0){cout<<ans<<endl;return 0;}
    if(L==LINF)fin;
    ans+=pw(2,L);
    for(int i=0;i<N;i++){
      for(int j=0;j<a[i].size();j++){
        int p=a[i][j]%L;
        if(p==a[i][j])continue;
        if(p<b[i])continue;
        if(dp[i][p]==LINF)continue;
        a[i].push_back(p);
        ae[i]=min(ae[i],dp[i][p]);
      }
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(b - a == c - b) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int M = scanner.nextInt();
		int H[] = new int[N];
		int G[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++) {
			H[i] = scanner.nextInt();
		}
		for(int i = 0; i < M; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			if(H[a-1] > H[b-1]) {
				G[b-1] -= 1;
			} else if (H[a-1] < H[b-1]) {
				G[a-1] -= 1;
			} else {
				G[a-1] -= 1;
				G[b-1] -= 1;
			}
			for (int l = 0; l < N; l++) {
				//System.out.println(G[l]);
			}
			//System.out.println("");
		}

		for (int i = 0; i < N; i++) {
			if (G[i] == 0) {
				count += 1;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 62588
from sys import stdin
s = set()
n = int(stdin.readline())
a = map(int,stdin.readline().split())
ans = 0
for i in xrange(1,n+1):
 x = a[i-1]
 y = i
 if (y,x) in s:
  s.remove((y,x))
  ans+=1
 else:
  s.add((x,y))
print ans


Measured memory_bytes: 20180
N,K=map(int,input().split())
S=input()
for i in range(N):
    if i==K-1:
        if S[i]=='A':
            print('a',end='')
        elif S[i]=='B':
            print('b',end='')
        else:
            print('c',end='')
    else:
        print(S[i],end='')
print()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-12;
const int MAXN = 1e5 + 10;
const int MAXM = 1e6 + 10;
const ll mod = 1e9 + 7;


int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int n,d,x;
    scanf("%d%d%d",&n,&d,&x);
    int ans = 0;
    for(int i=0; i<n; i++) {
        int a;
        scanf("%d",&a);
        for(int j=1; j<=d; j+=a) ans++;
    }
    printf("%d\n",ans+x);
    return 0;
}


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


using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VP vector<pair<int,int>>
#define VPP vector<pair<int,pair<int,int>>>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)
typedef pair <int, int> P;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



VI g[100005];
VI h[100005];



struct UnionFind {
	vector<int> par;
	int cnt;
	UnionFind(int size_) : par(size_, -1), cnt(size_) { }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (par[y] < par[x]) swap(x, y);
			par[x] += par[y]; par[y] = x;
			cnt--;
		}
		return x != y;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int find(int x) {
		return par[x] < 0 ? x : par[x] = find(par[x]);
	}
	int size(int x) {
		return -par[find(x)];
	}
	int size() {
		return cnt;
	}
};



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

	UnionFind uf(n);

	REP(i, m) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
		uf.unite(a, b);

	}

	VI cnt(n, 0);

	REP(i, k) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		h[a].push_back(b);
		h[b].push_back(a);
		if (uf.same(a, b)) {
			cnt[a]--;
			cnt[b]--;
		}
	}



	REP(i, n) {
		cout << uf.size(i) - g[i].size() + cnt[i] - 1 << ' ';
	}
	cout << endl;
	return 0;


}

Measured memory_bytes: 12664
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<double> x(n), y(n);
	rep(i,n) cin >> x[i] >> y[i];
	vector<int> v(n);
	double ans = 0, div = 0;
	rep(i,n) v[i] = i;
	do{
		div++;
		rep(i,n-1){
			ans += sqrt((x[v[i+1]]-x[v[i]])*(x[v[i+1]]-x[v[i]]) + (y[v[i+1]]-y[v[i]])*(y[v[i+1]]-y[v[i]]));
		}
	} while(next_permutation(v.begin(), v.end()));
	if(div != 0) ans /= div;
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}

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

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

   ll total = 0;
   for (int i = 0; i < n; i++)
   {
       if (a[i] <= b[i])
       {
           total += a[i];
           b[i] -=a[i];
           a[i] = 0;
       }else
       {
           total += b[i];
           a[i] -= b[i];
           b[i] = 0;
       }

       if (b[i] > 0)
       {
            if (a[i+1] <= b[i])
            {
                total += a[i+1];
                b[i] -=a[i+1];
                a[i+1] = 0;
            }else
            {
                total += b[i];
                a[i+1] -= b[i];
                b[i] = 0;
            }
       }
   }

   cout << total << "\n";

}
    

Measured memory_bytes: 1792
<?php
  $n = trim(fgets(STDIN));
  $h = explode(" ", trim(fgets(STDIN)));

  $result = "Yes";
  if(count($h) === 1) {
    $result = "Yes";
  } else {
    for($i = 0; $i < $n; $i++) {
        if($i === 0) {
          $h[$i] -= 1;
          continue;
        }
      
        if($h[$i] > $h[$i - 1]) {
          $h[$i] -= 1;
        }
        
        if($h[$i] < $h[$i -1]) {
          $result = "No";
          break;
        }
      }
    }

  echo $result;

Measured memory_bytes: 22076
N, D = map(int, input().split())
X = [tuple(map(int, input().split())) for _ in range(N)]
r = 0
for p in X:
    for q in X:
        if p != q:
            d = sum([(x-y)**2 for x, y in zip(p, q)])**(0.5)
            if int(d) == d:
                r += 1
print(r//2)


Measured memory_bytes: 9372