akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI=acos(-1);
const int INF = numeric_limits<int>::max();

int main(){
    string s, t;
    cin >> s >> t;

    cout << t << s << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
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;
    int ans = 0;
    REPP(i,1,N+1){
        if(to_string(i).size() % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import itertools
n = int(input())
a = list(map(int,input().split()))

four = len([1 for i in a if i%4 == 0])
two = len([1 for i in a if i%2 == 0]) - four
four += two//2
if four >= n-four-1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14100
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int x, y;
    cin >> x >> y;
    swap(x, y);
    for (int a = 0; a <= y; a++) {
        if (x == 2 * a + (y - a) * 4) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

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

int main() {
	int n;
	cin >> n;
	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;
	rep(i, n) {
		string s;
		cin >> s;
		if(s=="AC") ac++;
		if(s=="WA") wa++;
		if(s=="TLE") tle++;
		if(s=="RE") re++;
	}
	
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
	return 0;
}

Measured memory_bytes: 3720
S = input()
fh = int(S[:2])
of = int(S[2:])
if 1 <= fh <= 12:
    if 1<= of <= 12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 1 <= of <= 12:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [int(input()) for _ in range(N-1)]

graph = [[] for _ in range(N+1)]
for i,x in enumerate(A,2):
    graph[x].append(i)

def dfs(x):
    arr = [dfs(y) for y in graph[x]]
    if not arr:
        return 0
    arr.sort()
    return max(i+x for i,x in enumerate(arr[::-1],1))

answer = dfs(1)
print(answer)

Measured memory_bytes: 231984
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
namespace mydef {
const int INF = 1ll << 60;
const int MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
void Yes(bool flag = true) {
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}
void No(bool flag = true) {
    Yes(!flag);
}
void YES(bool flag = true) {
    if (flag)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}
void NO(bool flag = true) {
    YES(!flag);
}
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
}  // namespace mydef
using namespace mydef;
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<pair<int, int>>
#define vvp vector<vector<pair<int, int>>>
#define pi pair<int, int>
//#define P pair<int, int>
//#define V vector<int>
//#define S set<int>
#define asn ans

int N, A[101010];
vi d;

void solve() {
}

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

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N - 1; i++) {
        int tmp = A[i + 1] - A[i];
        if (tmp)
            d.emplace_back(tmp);
    }

    if (d.size() <= 1) {
        cout << 1 << endl;
        return 0;
    }
    int ans = 1;
    int parity = 0;
    for (int i = 0; i < d.size(); i++) {
        int& x = d[i];
        if (parity == 0) {
            parity = x > 0 ? 1 : -1;
        }
        if (x * parity < 0) {
            ans++;
            parity = 0;
        }
        if (i == d.size())
            ans++;
    }

    cout << ans << endl;


    solve();
    return 0;
}


Measured memory_bytes: 5052
import math
import copy

n=int(input())
originmap=[] #appendのために宣言が必要
while True:
    try:
        originmap.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

length = 0
submap = originmap.copy()
for i,j in originmap:
  del submap[0]
  for a, b in submap:
    #print(submap)
    #print(i,j,a,b)
    length += math.sqrt((i-a)**2 + (j-b)**2)

print(length*2/n)

Measured memory_bytes: 3444
#include<algorithm>
#include<cstdio>
using std::min;
int const maxn = 1e5 + 10;

long N, K, x[maxn];

long labs(long p) {
  if(p < 0) return (-1)*p;
  return p;
}

int main()
{
  scanf("%ld%ld", &N, &K);

  long ans = 1e13 + 10;

  for(int i = 1; i <= N; i++) scanf("%ld", &x[i]);
  for(int i = 1; i <= N; i++) {
    if(i-0 >= K) ans = min(ans, labs(x[i])+labs(x[i]-x[i-(K-1)]));
    if((N-i+1) >= K) ans = min(ans, labs(x[i])+labs(x[i]-x[i+(K-1)]));
  }

  printf("%ld", ans);

  return 0;
}


Measured memory_bytes: 896
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}


int a[MAXN];
int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 1; i <= 2*n; i++) {
    	a[i] = readInt();
    }
    sort(a + 1, a + 1 + 2*n);
    int ans = 0;
    for (int i = 2; i <= 2 * n; i += 2) {
   		ans += min(a[i], a[i - 1]);
   	}
   	cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        int cd=0;
        if(i%2==1){
            for(int j=1;j<=i;j++){
                if(i%j==0){
                    cd++;
                }
            }
            if(cd==8){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

# Segment Tree
# 一点更新・範囲集約
# 1-indexed
# update(i,x)   :ai を x に変更する
# add(i,x)      :ai に x を加算する
# query(l,r)    :半開区間 [l,r) に対してモノイド al・…・ar−1 を返す
# モノイドとは、集合と二項演算の組で、結合法則と単位元の存在するもの
# ex. +, max, min
# [ 1] a0 ・ a1  ・ a2 ・ a3 ・ a4 ・ a5 ・ a6 ・ a7  ->[0]
# [ 2] a0 ・ a1  ・ a2 ・ a3       [ 3] a4 ・ a5 ・ a6・ a7
# [ 4] a0 ・ a1    [ 5] a2 ・ a3   [ 6] a4 ・ a5   [ 7] a6 ・ a7
# [ 8] a0 [ 9] a1  [10] a2 [11] a3 [12] a4 [13] a5 [14] a6 [15] a7

#                      [0001]
#          [0010]                  [0011]
#    [0100]      [0101]      [0110]      [0111]
# [1000][1001][1010][1011][1100][1101][1110][1111]

# size = 8  元の配列数の２べき乗値
# 親のインデックス         i//2 or i>>=1 bitで一個右シフト
# 左側の子のインデックス    2*i
# 右側の子のインデックス    2*i+1
# aiの値が代入されているインデックス    i+size

class SegmentTree:
    # 初期化処理
    # f     : SegmentTreeにのせるモノイド
    # idele : fに対する単位元
    def __init__(self, size, f=lambda x,y : min(x, y), idele=float('inf')):
        self.size = 2**(size-1).bit_length()    # 簡単のため要素数nを2冪にする
        self.idele = idele                      # 単位元
        self.f = f                              # モノイド
        self.dat = [self.idele]*(self.size*2)   # 要素を単位元で初期化

## one point
    def update(self, i, x):
        i += self.size  # 1番下の層におけるインデックス
        self.dat[i] = x
        while i > 0:    # 層をのぼりながら値を更新
            i >>= 1     # 1つ上の層のインデックス(完全二分木における親)
            # 下の層2つの演算結果の代入(完全二分木における子同士の演算)
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
## one point
    def add(self, i, x):
        i += self.size  # 1番下の層におけるインデックス
        self.dat[i] += x
        while i > 0:    # 層をのぼりながら値を更新 indexが0になれば終了
            i >>= 1     # 1つ上の層のインデックス(完全二分木における親)
            # 下の層2つの演算結果の代入(完全二分木における子同士の演算)
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])
## range
    def query(self, l, r):
        l += self.size  # 1番下の層におけるインデックス
        r += self.size  # 1番下の層におけるインデックス
        lres, rres = self.idele, self.idele # 左側の答えと右側の答えを初期化
        while l < r:    # lとrが重なるまで上記の判定を用いて加算を実行
            # 左が子同士の右側(lが奇数)(lの末桁=1)ならば、dat[l]を加算
            if l & 1:
                lres = self.f(lres, self.dat[l])
                l += 1
            # 右が子同士の右側(rが奇数)(rの末桁=1)ならば、dat[r-1]を加算
            if r & 1:
                r -= 1
                rres = self.f(self.dat[r], rres) # モノイドでは可換律は保証されていないので演算の方向に注意
            l >>= 1
            r >>= 1
        res = self.f(lres, rres)
        return res

    def init(self, a):
        for i, x in enumerate(a):
            # 1番下の層におけるインデックス
            self.dat[i + self.size] = x
        for i in range(self.size-1, -1, -1):
            self.dat[i] = self.f(self.dat[i*2], self.dat[i*2+1])

n, q = map(int, input().split())
a = list(map(int, input().split()))
sgt = SegmentTree(n, lambda x,y : x+y, 0)
sgt.init(a)
for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        sgt.add(u, v)
    else:
        print(sgt.query(u, v))


Measured memory_bytes: 177900
require 'set'

N = gets.to_i
a = gets.split.map(&:to_i)
a.unshift(0)

b = Set.new

for i in 1..N
    target = N - i + 1

    s = 0
    r = target * 2
    while r <= N
        if b.include?(r)
            s += 1
        end
        r += target 
    end

    if s % 2 != a[target]
        b.add(target)
    end
end

if b.size == 0
    puts 0
else
    puts b.size
    puts b.to_a.join(' ')
end


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 1005;

/* ...o(^-^)o... */
const lint mod = MOD;
class mint{
    public:
        long long x;

    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

mint dp[MAX][MAX];

int main(){
    int h, w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    
    
    rep(i, h) rep(j, w){
        if(s[i][j] == '#'){
            dp[i][j] = 0;
            continue;
        }
        if(i==0 && j==0) dp[i][j] = 1;
        if(i>0) dp[i][j] += dp[i-1][j];
        if(j>0) dp[i][j] += dp[i][j-1];
    }

    out(dp[h-1][w-1]);
}

Measured memory_bytes: 9216
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int[] L = new int[N + 1];
        for (int i = 0; i < N; i++) {
            L[i] = sc.nextInt();
        }
        L[N] = 10000;
        Arrays.sort(L);
        long ans = 0;
        for (int i = 0; i < N; i++) {
            int upper = i;
            for (int j = i + 1; j < N; j++) {
                while (L[upper] < L[i] + L[j]) {
                    upper++;
                }
                ans += upper - 1 - j;
            }
        }
        System.out.println(ans);
    }

}


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

#define int long long
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sum = 0;
    if(a<k) {
        sum+=a;
        k-=a;
    } else {
        sum+=k;
        k=0;
    }
    if(b<k) {
        k-=b;
    } else {
        k = 0;
    }
    if(c<k) {
        sum-=c;
    } else {
        sum-=k;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define LL long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
struct Q{
	int x,y,z,w;
}q[255555];
int n,m,a[505][505],tot;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cin>>a[i][j];
	for(int i=1;i<n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j]&1){
				a[i][j]--; a[i+1][j]++;
				q[++tot]=(Q){i,j,i+1,j};
//				cout<<i<<' '<<j<<' '<<i+1<<' '<<j<<endl;
			}
		}
	}
	for(int j=1;j<m;j++){
		if(a[n][j]&1){
			a[n][j]--; a[n][j+1]++;
			q[++tot]=(Q){n,j,n,j+1};
//			cout<<n<<' '<<j<<' '<<n<<' '<<j+1<<endl;
		}
	}
	cout<<tot<<endl;
	for(int i=1;i<=tot;i++) cout<<q[i].x<<' '<<q[i].y<<" "<<q[i].z<<" "<<q[i].w<<endl;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
void in(){}
template<typename F, typename... R>
bool in(F& f, R&... r){
    if(cin >> f){in(r...);return true;}
    else return false;
}
#define out(x) cout << (x)
#define space() cout << " "
#define indent() cout << '\n'
void print(){}
template<typename F, typename... R>
void print(F f, R... r){out(f), indent(), print(r...);}
#define debughead(x) cerr << "Line " << __LINE__ << ": " << #x << ": "
#define debugout(x) cerr << (x) << " "
#define debugindent() cerr << '\n'
#define debug(x) debughead(x), debugout(x), debugindent()
const int INF = 1e18, MOD = 1e9 + 7;
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
bool isPrime(int n){
    rep(i, 2, sqrt(n) + 1){
        if(i > 3){
            i++;
        }
        if(!(n % i)){
            return false;
        }
    }
    return true;
}
main(){
    INCANT;
    int q, l, r, tmp, res = 0;
    string s;
    int v[111111] = {};
    for(int i = 3; i < 111111; i += 2){
        v[i] = v[i - 2];
        if(isPrime(i) && isPrime(i / 2 + 1)){
            v[i]++;
        }
    }
    in(q);
    while(q--){
        in(l, r);
        print(v[r] - v[max(0LL, l - 2)]);
    }
}


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

const ll MAXN = 200000;

ll N, M, ans=0, tmp=0;
vector<ll> X(MAXN, 0), Y(MAXN, 0), Z(MAXN, 0), color;
vector<vector<ll>> G;

void bfs(ll start) {    
    queue<ll> Q;
    Q.push(start);
    color[start]=1;
    while(!Q.empty()) {
        ll u = Q.front();
        Q.pop();
        for(int i=0;i<G[u].size();i++) {
            if(color[G[u][i]]==1) continue;
            else {
                Q.push(G[u][i]);
                color[G[u][i]]=1;
                ans--;
            }
        }
    }
}

signed main(){
    cin >> N >> M;
    G.resize(N);
    color.resize(N);
    for(int i=0;i<N;i++) color[i]=0;
    for(int i=0;i<M;i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    ans = N;
    for(int i=0;i<N;i++) {
        if(color[i]==0) bfs(i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12788
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define LL long long
#define fgx cerr<<"--------------"<<endl;
#define dgx cerr<<"=============="<<endl;

inline LL read(){
	LL x=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const LL MAXN = 500010;
const LL INF = 2147483600;

LL N; LL a[MAXN+1];
LL s[2];

inline bool check(LL T){
	LL mxp=0; bool fg=0;
	for(LL i=1;i<=N;i++){
		if((i&1)&&fg) mxp=max(mxp,0LL),fg=0;
		mxp+=((i&1)?1:-1)*a[i];
		if((i&1)&&mxp>=T) fg=1;
	} return fg;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read();
	for(LL i=1;i<=N;i++) a[i]=read(),s[i&1]+=a[i];
	if(!(N&1)){ printf("%lld %lld\n",max(s[0],s[1]),min(s[0],s[1])); return 0; }
	LL ad=0,l=1,r=s[0]+s[1];
	while(l<=r){
		LL mid=(l+r)>>1LL;
		if(check(mid)) ad=mid,l=mid+1;
		else r=mid-1;
	} printf("%lld %lld\n",ad+s[0],s[1]-ad);
	return 0;
}




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

int main () {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  vector<bool> b(8, false);
  int count = 0;
  for (int i = 0; i < N; i++) {
    if(a.at(i) < 400) b.at(0) = true;
    else if(a.at(i) < 800) b.at(1) = true;
    else if(a.at(i) < 1200) b.at(2) = true;
    else if(a.at(i) < 1600) b.at(3) = true;
    else if(a.at(i) < 2000) b.at(4) = true;
    else if(a.at(i) < 2400) b.at(5) = true;
    else if(a.at(i) < 2800) b.at(6) = true;
    else if(a.at(i) < 3200) b.at(7) = true;
    else count++;
  }
  int ans = 0;
  for (int i = 0; i < 8; i++) {
    if (b.at(i)) ans++;
  }
  
  cout << max(ans,1) << ' ' << ans + count << endl;
}

Measured memory_bytes: 256
//AnkitCode99 here....
#include<bits/stdc++.h>
#define endl "\n"
typedef long long int ll;
#define MOD 1000000007
#define mp make_pair
#define pll pair<ll,ll>
#define pb push_back
//max xor btw range of two numbers..
#define max_XOR(a,b) (1 << int(log2(a ^ b) + 1)) - 1
#define vl vector<ll>
#define inf ll(1e18)
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(long long int i=a;i<b;i++)
#define nrep(i,a,b) for(long long int i=a;i>=b;i--)
#define ceil(a,b) a/b+((a%b ==0 )?0:1)
using namespace std;

const ll sz=100005;
const ll szz=1000006;

int main()
{
	fast;
    
	string s,t,u;
	ll a,b;
	cin>>s>>t>>a>>b>>u;
	
	if(s==u)
		a--;
	else
		b--;
	cout<<a<<" "<<b;
}
//Goodbye...

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

ll groupingRec(vector<vector<ll>> &arr, int n, int mask, vector<ll> &dp,
               vector<ll> &scores){

    if(dp[mask] != -1)
        return dp[mask];
    // Pick a subset of not chosen rabbits among 2^n possible subsets
    // and take that as one group
    ll ans = 0;
    for(int group = 1; group<(1<<n); group++){
        if(!(group&mask)){
            ll currGroupScore = scores[group];
            ll currRecAns = groupingRec(arr, n, mask|group, dp, scores) +
                            currGroupScore;
            if(currRecAns > ans)
                ans = currRecAns;
        }
    }
    dp[mask] = ans;
    return ans;
}

void precalculateScores(vector<vector<ll>> &arr, int n, vector<ll> &scores){

    for(int group=0; group<(1<<n); group++){
        ll score = 0;
        for(int i=0; i<n; i++)
            if((group&(1<<i)))
                for(int j=i+1; j<n; j++)
                    if((group&(1<<j)))
                        score += arr[i][j];
        scores[group] = score;
    }
}

ll grouping(vector<vector<ll>> &arr, int n){

    vector<ll> dp(1<<(n+1), -1);
    vector<ll> scores(1<<(n+1));
    precalculateScores(arr, n, scores);
    ll ans = groupingRec(arr, n, 0, dp, scores);
    return ans;
}

int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 int n;
 cin>>n;
 vector<vector<ll>> arr(n, vector<ll>(n));
 for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
        cin>>arr[i][j];
 ll ans = grouping(arr, n);
 cout<<ans;
 return 0;
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n)  for (int i = 0; i < n; i++)
#define loop(i,a,n)  for (int i = a; i <= n; i++)
#define deb(x) cout << #x << " = " << x <<'\n'
typedef long long ll;

const int N = 2e+5+1;
int main(){
    int n;
    int sub[N];
    cin >> n;
    memset(sub,0,sizeof sub);
    rep(i,n-1){
        int x;
        cin >> x;
        sub[x]++;
    }
    loop(i,1,n){
        cout << sub[i] << endl;
    }
}

Measured memory_bytes: 4420
#!/usr/bin/env python3
a, b, c, d = map(int, input().split())
for i in range(210):
    if i % 2 == 0:
        c -= b
        if c <= 0:
            print('Yes')
            exit()
    else:
        a -= d
        if a <= 0:
            print('No')
            exit()


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

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

    int cnt = N.size();
    string Na = N.substr(cnt-1, 1);

    if (Na == "1"|| Na == "0"|| Na == "6"|| Na == "8") {
        cout << "pon" << endl;
    }
    else if(Na == "3"){
        cout << "bon" << endl;
    }
    else {
        cout << "hon" << endl;
    }



}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll n,arr[10005],x,k,d;

int main()
{
    cin>>x>>k>>d;
    x=abs(x);
    ll e = x/d;
    ll left=0;
    ll update=0;

    if(e<=k){
        update=x%d;
        left=k-e;
        if(left%2!=0 && left!=0){
            ll a=abs(d+update);
            ll b=abs(update-d);

            ll c = min(a,b);
            update= c;
        }

    }
    else{
        update=x-(k*d);
    }
    cout<<update<<endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

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

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

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

    map<int, int> mp;
    rep(i, n){
        mp[a[i]+i+1]++;
    }

    ll ans = 0;
    rep(i, n){
        ans += mp[(i+1)-a[i]];
    }


    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 21152
read x y
 
if [ "${x::1}" != "-" -a ${y::1} != "-" ] || [ "${x::1}" = "-" -a ${y::1} = "-" ]
then
	if [ $x -lt $y ]
	then
		ans=$((y - x))
	elif [ $x -gt $y ]
	then
		ans=$((x - y + 2))
	fi
 
	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi
	
	echo $ans
	exit
fi
 
if [ "${x::1}" != "-" -a ${y::1} = "-" ]
then
	if [ "${x}" = "${y/-/}" ]
	then
		echo 1
		exit
	fi
	
	yy="${y/-/}"
	
	if [ $x -gt $yy ]
	then
		ans=$((x - yy + 1))
	elif [ $x -lt $yy ]
	then
		ans=$((yy - x + 1))
	fi
  
	echo $ans
	exit
fi
 
if [ "${y::1}" != "-" -a ${x::1} = "-" ]
then
	if [ "${y}" = "${x/-/}" ]
	then
		echo 1
		exit
	fi
	
	xx="${x/-/}"
	
	if [ $y -gt $xx ]
	then
		ans=$((y - xx + 1))
	elif [ $y -lt $xx ]
	then
		ans=$((xx - y + 1))
	fi
 
	if [ $y -eq 0 ]
	then
		ans=$((ans - 1))
	fi
 
	echo $ans
	exit
fi


Measured memory_bytes: 376
#include <iostream>
using namespace std; 
bool na=true;
void uruu(int a){
    if(a%4==0&&a%100==0&&a%400==0){cout<<a<<endl;na=false;return;}
    else if(a%4==0&&a%100==0){return;}
    else if(a%4==0){cout<<a<<endl;na=false;return;}
    else return;
}


int main ()
{
    int a,b;
    bool first=true;
    while(cin>>a>>b){
        
        if(a==0&&b==0){return 0;}
        if(first)first=false;
        else cout<<endl;
        na=true;
        while(a<=b){
            uruu(a);
            a++;
        }
        if(na)cout<<"NA"<<endl;
        
        
    }
    }

Measured memory_bytes: 0
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
using ll = long long;
using ld = long double;
// const int MAXMEM = 200 * 1000 * 1024;
// char _memory[MAXMEM];
// size_t _ptr = 0;
// void* operator new(size_t _x) { _ptr += _x; return _memory + _ptr - _x; }
// void operator delete (void*) noexcept {}
const string FILENAME = "input";



int h, w, n;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  	//read(FILENAME);     
    cin >> h >> w >> n;
    int res  = 1e9;
    for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= w; j++) {
            int cnt = i * w + j * h - i * j;
            if (cnt >= n) {
                chkmin(res, i + j);
            }
        }
    }
    cout << res << endl;
    return 0;
}            	


Measured memory_bytes: 256
Res=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
N=int(input())
i=0
while i<N:
    b,f,r,v=map(int,input().split())
    Res[b-1][f-1][r-1] += v
    i += 1

    

x = 0
for k in range(4):
    if x != 0:
        print("#"*20)
    x += 1

    for j in range(3):
        for i in range(10):
              print(" {}".format(Res[k][j][i]),end="")
        print()


Measured memory_bytes: 5628
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
abc113 B
"""

n = int(input())
t, a = map(int, input().split())
hli = list(map(int, input().split()))

hli2 = map(lambda x: (x[0]+1, abs(t-x[1]*0.006-a)), enumerate(hli))
print(min(hli2, key=lambda x: x[1])[0])




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

int main()
{
    ll A,B;
    cin >> A >> B;
    if(A >=10 || B >= 10)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << A*B << endl;
    }
    

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b,c,x,n,i,j,k;
    while(1){
    scanf("%d%d",&n,&x);
    if(x==0&&n==0)break;
    c=0;
    for(i=1;i<n+1;i++){
        for(j=1;j<n+1;j++){
            for(k=1;k<n+1;k++){
                b=i+j+k;
                if(b==x&&i!=j&&j!=k&&k!=i){
                    c=c+1;
                }
            }
        }
    }
    printf("%d\n",c/6);
    }
    return 0;
}

Measured memory_bytes: 600
N = gets.to_i
a = Hash.new(0)
N.times do
  a[gets.chomp] += 1
end
puts 'AC x %d' % a['AC']
puts 'WA x %d' % a['WA']
puts 'TLE x %d' % a['TLE']
puts 'RE x %d' % a['RE']


Measured memory_bytes: 14368
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D, XY):
    D2 = D**2
    ans = 0
    for x, y in XY:
        d2 = x**2 + y**2
        if d2 <= D2:
            ans += 1
    return ans


def main():
    N, D = read_int_n()
    XY = [read_int_n() for _ in range(N)]
    print(slv(N, D, XY))


if __name__ == '__main__':
    main()


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

void solve(int W, int H) {
	vector<vector<int>>s(H, vector<int>(W));
	rep(i, 0, H)rep(j, 0, W) { cin >> s[i][j]; }
	auto inrange = [&](int x, int y) { return 0 <= x and x < H and 0 <= y and y < W; };
	vector<int>c(4); rep(i, 0, 4) { cin >> c[i]; }

	vector<vector<vector<int>>>dist(H, vector<vector<int>>(W, vector<int>(4, INF)));
	const int dx4[4] = { 1, 0, -1, 0 }, dy4[4] = { 0, 1, 0, -1 };
	dist[0][0][0] = 0;
	using State = tuple<int, int, int, int>;// cost, h,w,dir
	priority_queue < State, vector<State>, greater<State >> pq;
	pq.emplace(0, 0, 0, 0);
	while (pq.size()) {
		int cost, h, w, dir;
		tie(cost, h, w, dir) = pq.top(); pq.pop();
		if (cost > dist[h][w][dir])continue;
		dump(cost, h, w, dir);
		rep(i, 0, c.size()) {
			int a = (s[h][w] != i)*c[i];
			int nd = (dir + i + 4) % 4;
			dump(i, nd);
			int x = w + dx4[nd], y = h + dy4[nd];
			if (not inrange(y, x))continue;
			if (chmin(dist[y][x][nd], cost + a)) {
				//printf("(%d,%d,%d) -> (%d,%d,%d)\n", h, w, dir, y, x, nd);
				pq.emplace(cost + a, y, x, nd);
			}
		}
	}
	int ans = INF;
	rep(i, 0, 4) {
		chmin(ans, dist[H - 1][W - 1][i]);
	}
	cout << ans << endl;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	while (1) {
		int W, H; cin >> W >> H;
		if (W == 0 and H == 0)break;
		solve(W, H);
	}


	return 0;
}



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

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


Measured memory_bytes: 5012
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    vector<int> S(3);
    rep(i, 3) cin >> S[i];
    sort(S.begin(), S.end());
    
    int cnt = 0;
    rep(i, 2) {
        cnt += (S[2] - S[i]) / 2;
        S[i] += (S[2] - S[i]) / 2 * 2;
    }
    if (S[0] == S[1] && S[1] != S[2]) ++cnt;
    if (S[0] != S[1]) cnt += 2;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
from collections import Counter

lines = stdin.readlines()

N, K, Q = map(int, lines[0].split())
ans = [0] * N
A = Counter((int(i) - 1 for i in lines[1:]))
for k in A.keys():
    ans[k] += A[k]
print("\n".join(("Yes" if Q < K + a
                 else "No" for a in ans)))


Measured memory_bytes: 17252
#include <stdio.h>
 
int main()
{
	int n;
    bool having[2][201];
	int have[2];
    int in,ba;
    bool turn;

    scanf("%d",&n);
    while(n != 0){

		for(int i = 0; i <= n*2; i++){
			for(int j = 0; j < 2; j++){
				having[j][i] = false;
			}
		}
    having[0][0] = false;
    having[1][0] = false;
    for(int i = 0; i < n; i++){
        scanf("%d",&in);
        having[0][in] = true;
    }
    for(int i = 1; i <= 2*n; i++){
        if(having[0][i] == true){
            having[1][i] = false;
        }
        else{
            having[1][i] = true;
            having[0][i] = false;
        }
    }
 
    for(int i = 0; i <= 2*n; i++){
      //  printf("[%d]太郎:%d 花子:%d\n",i,having[0][i],having[1][i]);
    }
 
 
    have[0] = n; have[1] = n;
    ba = 0; turn = 0;
    while(have[0] > 0 && have[1] > 0){
       // printf("%dのターン:場%d\n",turn,ba);
        while(!having[turn][ba] && ba <= n*2){
            ba++;
        }
        if(ba > n*2){
       //     printf("場に出せない\n");
            ba = 0;
        }
        else{
       //     printf("出す:%d\n",ba);
            having[turn][ba] = false;
            have[turn]--;
        }
        turn = !turn;
    }
 
    printf("%d\n%d\n",have[1],have[0]);
 
    scanf("%d",&n);
    }
 
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ppll pair<pll,ll>
#define vi vector <ll>
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define f(i,x,n) for(ll i=x;i<n;i++)
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;} 
const ll N = 2e5 + 5, M = 1e9 + 7;

int main(){
    FAST;
    ll n, x = 0, m, k, i, t, ans = 0, j, y = 0, z = 0, c = 0;
    cin >> k >> n;
    ll a[n];
    f(i, 0, n){
        cin >> a[i];
    }
    ans = (a[n - 1] - a[0]);
    f(i, 1, n){
        ans = min(ans, k - (a[i] - a[i - 1]));
    }
    cout << ans;
}

Measured memory_bytes: 1792
#include <iostream>

int main(){
	std::ios::sync_with_stdio(false);
    while(true){
    int n, a_score = 0, b_score = 0;
    std::cin >> n;
    
    if(n == 0)
        break;

    for(int i = 0; i < n; ++i){
        int a, b;
        std::cin >> a >> b;
        if(a > b)
            a_score += a + b;
        else if(a < b)
            b_score += a + b;
        else
            a_score += a, b_score += b;
    }

    std::cout << a_score << " " << b_score << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <string>
#include <algorithm>
#include <climits>
#include <utility>

#define PRINT(STR) cout << STR << endl;
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define REG(i, a, b) for (int (i) = ((int)(a)); (i) < ((int)(b)); i++)
#define ALL(V) (V).begin(), (V).end()

typedef long long ll;

using namespace std;

int nextInt() { int n = -1; cin >> n; return n; }
double nextDouble() { double d = -1; cin >> d; return d; }
ll nextll() { ll n = -1; cin >> n; return n; }
string nextString() { string str; cin >> str; return str; }

int INF = 1LL << 25;
double EPS = 1e-9;

// BEGIN //////////////////////////////////////////////////////////////

int main() {
	while (true) {
		int N = nextInt();
		if (N == 0) break;
		int score_max = -INF, score = 0;
		REP(i, N) {
			int d = nextInt();
			score += d;
			score_max = max(score, score_max);
			score = max(score, 0);
		}
		PRINT(score_max);
	}

	return 0;
}

// END   //////////////////////////////////////////////////////////////

Measured memory_bytes: 1160
S = str(input())
if S[0] == "A":
    S = "a" + S[1:]
    if "C" in S[2:-1]:
        cs = False
        for i,s in enumerate(S[2:-1]):
            if not(cs) and s == "C":
                S = S[:i+2] + "c" + S[i+3:]
                cs = True
        if S.islower():
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int mod = 1e9+7;



int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n+1, 0), b(m+1, 0);
    rep (i, n) {
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    rep (i, m) {
        cin >> b[i+1];
        b[i+1] += b[i];
    }
    int ans = 0;
    rep (i, n+1) {
        ll time_a = a[i];
        ll time_left = k - time_a;
        if (time_left < 0) {
            break;
        }
        auto it = upper_bound(all(b), time_left);
        int b_books = distance(b.begin(), it) - 1;
        chmax(ans, b_books+i);
    }
    cout << ans << endl;
}




Measured memory_bytes: 6360
/*  chuckie   */
#include <bits/stdc++.h>
//#define CHUCKIE
 
#define cint(d) scanf("%d", &d)
#define cint2(a, b) scanf("%d %d", &a, &b)
#define cint3(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define cint4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
 
#define clong(d) scanf("%lld", &d)
#define clong2(a, b) scanf("%lld %lld", &a, &b)
#define clong3(a, b, c) scanf("%lld %lld %lld", &a, &b, &c)
#define clong4(a, b, c, d) scanf("%lld %lld %lld %lld", &a, &b, &c, &d)
 
const long long MOD = 10e9 + 7;
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODR(d) ((d)>=MOD?(d)%MOD:(d))
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define MODADDSET(d) if ((d) >= MOD) d -= MOD;
#define MODADDWHILESET(d) while ((d) >= MOD) d -= MOD;
 
#define foreach(it,c) for(__typeof((c).begin()) it = (c).begin(); it!=(c).end(); it++) 
#define MAX 1000000
#define ll long long
#define mp make_pair
#define pb push_back
 
using namespace std;

ll negmod(ll number, ll mod)
{
    if(number >= 0) return number % mod;
    return (mod + (number % mod)) % mod;
}



// To compute (a * b) % mod
ll mulmod(ll a, ll b, ll mod)
{
    ll res = 0; // Initialize result
    a = a % mod;
    while (b > 0)
    {
        // If b is odd, add 'a' to result
        if (b % 2 == 1)
            res = (res + a) % mod;
 
        // Multiply 'a' with 2
        a = (a * 2) % mod;
 
        // Divide b by 2
        b /= 2;
    }
 
    // Return result
    return res % mod;
}
 
 
int main()
{
	#ifdef CHUCKIE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string odd,even;
	cin>>odd;
	cin>>even;
	
	int lo=odd.length();
	int le=even.length();
	
	int minn=min(lo,le);
	
	for(int i=0;i<minn;i++)
	{
		
		cout<<odd[i]<<even[i];
	}
	
	
	if(lo==le) {cout<<endl;return 0;}
	if(minn==lo)cout<<even[minn];
	else cout<<odd[minn];
	
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string strKai;
    cin >> strKai;
    string strAnswer;
    
    //Joken1
    int a;
    a = (int)(strKai.length());
    for(int i=0; i<a/2;i++)
    {
        if(strKai[i] == strKai[a - i - 1])
        {
            continue;
        }
        else
        {
            strAnswer = "No";
            cout << strAnswer;
            return 0;
        }
    }
    
    for(int i=0; i<a/4;i++)
    {
        if(strKai[i] == strKai[a/2 - i - 1])
        {
            continue;
        }
        else
        {
            strAnswer = "No";
            cout << strAnswer;
            return 0;
        }
    }
    
    for(int i=0; i<a/4;i++)
    {
        if(strKai[i + a/2 + 1] == strKai[a - i - 1])
        {
            continue;
        }
        else
        {
            strAnswer = "No";
            cout << strAnswer;
            return 0;
        }
    }
    
    strAnswer = "Yes";
    
    cout<< strAnswer;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};



int main(){
    
    int x,a,b;
    
    cin>>x>>a>>b;
    if(a>=b)cout<<"delicious"<<endl;
    else{
        if(b-a<=x)cout<<"safe"<<endl;
        else cout<<"dangerous"<<endl;
    }
    
        
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from functools import lru_cache

T=int(input())
for tests in range(T):
    N,A,B,C,D=map(int,input().split())

    DP=[N*D]*(10**5)
    DP[0]=0

    for i in range(10**5):
        for k in range(i-10,i+10):
            if 0<=k<10**5 and DP[k]>DP[i]+abs(i-k)*D:
                DP[k]=DP[i]+abs(i-k)*D
        #if 0<=i+1<10**5 and DP[i+1]>DP[i]+D:
        #    DP[i+1]=DP[i]+D
            
        #if 0<=i-1<10**5 and DP[i-1]>DP[i]+D:
        #    DP[i-1]=DP[i]+D

        if 0<=2*i<10**5 and DP[2*i]>DP[i]+A:
            DP[2*i]=DP[i]+A

        if 0<=3*i<10**5 and DP[3*i]>DP[i]+B:
            DP[3*i]=DP[i]+B

        if 0<=5*i<10**5 and DP[5*i]>DP[i]+C:
            DP[5*i]=DP[i]+C

    @lru_cache(maxsize=None)
    def calc(x):
        if x<=10:
            return DP[x]

        ANS=x*D

        two=x//2*2

        ANS=min(ANS,abs(two-x)*D+A+calc(two//2))
        ANS=min(ANS,abs(two+2-x)*D+A+calc(two//2+1))

        three=x//3*3
        ANS=min(ANS,abs(three-x)*D+B+calc(three//3))
        ANS=min(ANS,abs(three+3-x)*D+B+calc(three//3+1))

        five=x//5*5
        ANS=min(ANS,abs(five-x)*D+C+calc(five//5))
        ANS=min(ANS,abs(five+5-x)*D+C+calc(five//5+1))

        return ANS

    print(calc(N))

    
        


Measured memory_bytes: 158012