akhauriyash/Code-Regression huggingface dataset:
class Card
  include Comparable

  attr_reader :suit, :value

  def self.parse(str)
    suit = str[0].to_sym
    value = str[1].to_i

    new(suit, value)
  end

  def initialize(suit, value)
    @suit = suit
    @value = value
  end

  def <=>(other)
    @value - other.value
  end

  def ==(other)
    @suit == other.suit && @value == other.value
  end

  def to_s
    "#{@suit}#{@value}"
  end
end

def bubble_sort(arr)
  n = arr.size

  n.times do |i|
    (n - 1).downto(i + 1) do |j|
      if arr[j] < arr[j - 1]
        arr[j - 1], arr[j] = arr[j], arr[j - 1]
      end
    end
  end
end

def selection_sort(arr)
  n = arr.size

  n.times do |i|
    min_pos = i

    i.upto(n - 1) do |j|
      if arr[j] < arr[min_pos]
        min_pos = j
      end
    end

    arr[i], arr[min_pos] = arr[min_pos], arr[i]
  end
end

def is_stable(arr1, arr2)
  return false unless arr1.size == arr2.size

  arr1.size.times do |i|
    return false unless arr1[i] == arr2[i]
  end

  return true
end

n = gets.to_i

arr1 = gets.split.map do |str|
  Card.parse(str)
end

arr2 = arr1.dup

bubble_sort(arr1)
selection_sort(arr2)

puts arr1.join(' ')
puts 'Stable'

puts arr2.join(' ')
puts is_stable(arr1, arr2) ? 'Stable' : 'Not stable'

Measured memory_bytes: 8676
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
        // TODO: メモリの使用量がやばいので Token ごとに読む
        // Reference: https://atcoder.jp/contests/abc148/submissions/9067537
        bufsize := 100 * 1024 * 1024
        sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
}
func readInt() int              { return readIntArray()[0] }
func readInt2() (int, int)      { a := readIntArray(); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(); return a[0], a[1], a[2] }
func readIntArray() []int {
        a := make([]int, 0, 1000)
        sc.Scan()
        for _, v := range strings.Split(sc.Text(), " ") {
                vv, _ := strconv.Atoi(v)
                a = append(a, vv)
        }
        return a
}
func readString() string            { return readStringArray()[0] }
func readString2() (string, string) { a := readStringArray(); return a[0], a[1] }
func readStringArray() []string     { sc.Scan(); return strings.Split(sc.Text(), " ") }

func main() {
        x := readInt()
        big := 10000000
        var result int
prime:
        for p := x; p < big; p++ {
                result = p
                for i := 2; i <= p; i++ {
                        if p%i == 0 {
                                if p == i {
                                        // finish
                                        break prime
                                }
                                break
                        }
                }
        }

        fmt.Println(result)
}

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

int main(){
    int a,b;
    char op;
    
    while(1){
        cin>>a>>op>>b;
        if(op=='?') break;
        
        if(op=='+') cout<<a+b<<endl;
        else if(op=='-') cout<<a-b<<endl;
        else if(op=='*') cout<<a*b<<endl;
        else if(op=='/') cout<<a/b<<endl;
        
        
        
        
    }
    
    return 0;
}


Measured memory_bytes: 3084
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e17
using namespace std;
typedef pair<ll, ll> P;

ll dp[110][100010];

int main(void) {
	ll n, W;
	cin >> n >> W;
	vector<ll>v(n), w(n);
	fill(dp[0], dp[110], INF);
	dp[0][0] = 0;
	for (ll i = 0;i < n;i++)cin >> w[i] >> v[i];
	for (ll i = 0;i < n;i++) {
		for (ll j = 0;j <= 100000;j++) {
			if (j >= v[i])dp[i+1][j] = min(dp[i][j - v[i]] + w[i], dp[i][j]);
			else dp[i+1][j] = dp[i][j];
		}
	}
	ll ans = 0;
	for (ll i = 0;i <= 100000;i++) {
		if (dp[n][i] <= W)ans = max(ans, i);
	}
	cout << ans << endl;
	return 0;
}

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

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

	int n, m, k;
	cin >> n >> m;
	int a[n + 1] = {};
	for (int i = 0; i < m; ++i)
	{
		cin >> k;
		a[k] = 1;
	}
	ll dp[n + 1] = {};
	dp[0] = 1;dp[1] = (a[1] ? 0 : 1);
	dp[2] = a[2] ? 0 :dp[1] + 1; 
	for (int i = 3; i <= n; ++i)
	{
		if(!a[i])
			dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
	}

	cout << dp[n] << "\n";
	return 0;
}

Measured memory_bytes: 1408
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int N,a,b,d,comp[100001],hei[100001],numadj[100001];
pair<pii,int> pin[100000];

int getcomp(int x) {
    if (comp[comp[x]] != comp[x]) comp[x] = getcomp(comp[x]);
    return comp[x];
}

void unite(int a,int b) {
    a = getcomp(a), b = getcomp(b);
    if (hei[a] < hei[b]) swap(a,b);
    hei[a] = max(hei[a],hei[b]+1);
    comp[b] = a;
}

void asdf() {
    int cum[N]; F0R(i,N) cum[i] = 0;
    sort(pin,pin+N);
	F0R(i,N) {
	    int i1 = lb(pin,pin+N,mp(mp(pin[i].f.f-d,pin[i].f.s-d),0))-pin;
	    int i2 = lb(pin,pin+N,mp(mp(pin[i].f.f-d,pin[i].f.s+d),MOD))-pin;
	    if (i1 == i2) continue;
	    unite(pin[i1].s,pin[i].s);
	    cum[i1] ++, cum[i2-1] --;
	}
	F0R(i,N) {
	    if (i) cum[i] += cum[i-1];
	    if (cum[i]) unite(pin[i].s,pin[i+1].s);
	}
}

void gendist() {
    sort(pin,pin+N);
	F0R(i,N) {
	    int i1 = lb(pin,pin+N,mp(mp(pin[i].f.f-d,pin[i].f.s-d),MOD))-pin;
	    int i2 = lb(pin,pin+N,mp(mp(pin[i].f.f-d,pin[i].f.s+d),0))-pin;
	    numadj[pin[i].s] += (i2-i1);
	    i1 = lb(pin,pin+N,mp(mp(pin[i].f.f+d,pin[i].f.s-d),MOD))-pin;
	    i2 = lb(pin,pin+N,mp(mp(pin[i].f.f+d,pin[i].f.s+d),0))-pin;
	    numadj[pin[i].s] += (i2-i1);
	    //cout << "DARN " << i1 << " " << i2 << " " << pin[i].s << " " << numadj[pin[i].s] << "\n";
	    //cout << pin[i1].f.f << " " << pin[i1].f.s << " " << pin[i2].f.f << " " << pin[i2].f.s << " " << pin[i].f.s+d << "\n";
	}
	F0R(i,N) swap(pin[i].f.f,pin[i].f.s);
    sort(pin,pin+N);
	F0R(i,N) {
	    int i1 = lb(pin,pin+N,mp(mp(pin[i].f.f-d,pin[i].f.s-d),0))-pin;
	    int i2 = lb(pin,pin+N,mp(mp(pin[i].f.f-d,pin[i].f.s+d),MOD))-pin;
	    numadj[pin[i].s] += (i2-i1);
	    i1 = lb(pin,pin+N,mp(mp(pin[i].f.f+d,pin[i].f.s-d),0))-pin;
	    i2 = lb(pin,pin+N,mp(mp(pin[i].f.f+d,pin[i].f.s+d),MOD))-pin;
	    numadj[pin[i].s] += (i2-i1);
	}
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N >> a >> b; 
	F0R(i,N) {
	    cin >> pin[i].f.f >> pin[i].f.s;
	    pin[i].s = i+1;
	}
	d = abs(pin[a-1].f.f-pin[b-1].f.f)+abs(pin[a-1].f.s-pin[b-1].f.s);
	F0R(i,N) {
	    int x = pin[i].f.f+pin[i].f.s, y = pin[i].f.f-pin[i].f.s;
	    pin[i].f.f = x, pin[i].f.s = y;
	    //cout << "HI " << x << " " << y << " " << pin[i].s << "\n";
	}
	gendist();
	
	FOR(i,1,N+1) hei[i] = 1, comp[i] = i;
	asdf();
	F0R(i,N) swap(pin[i].f.f,pin[i].f.s);
	asdf();
	ll ans = 0;
	FOR(i,1,N+1) if (getcomp(i) == getcomp(a)) {
	    // cout << i << " " << numadj[i] << "\n";
	    ans += numadj[i];
	}
	cout << ans/2;
}

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

using namespace std;

typedef long long ll;

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<bool> b(10);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        b[d] = true;
    }
    while(true){
        string s = to_string(n);
        bool flag = true;
        for(int i = 0; i < 10; i++){
            int res = s.find(to_string(i));
                if(b[i] == true && res != -1){
                    flag = false;
                    break;
            }
        }
        if(flag){
            break;
        }
        n++;
    }
    cout << n << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

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

	map<int, int> mp;

	for (int i = 0; i < n; i++) {
		mp[a[i]]++;
	}
	int ans = 0;
	for(auto i : mp){
		if(i.second % 2 == 1) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
const long long LLINF = 1LL<<60;
const int INF = 1e9;
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; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, k, r, s, p; cin >> n >> k >> r >> s >> p;
    string t; cin >> t;
    ll siz = t.size();

    ll allnum = 0;
    rep(i,t.size()) {
        if(t[i]=='r') allnum += p;
        else if(t[i]=='s') allnum += r;
        else allnum += s;
    }

    ll r2=0,s2=0,p2=0;
    ll cnt = 0;
    for(int i = 0; i+k < siz; i++) {
        if(t[i]=='z') continue;
        if(t[i]==t[i+k]) {
            if(t[i]=='r') r2++;
            else if(t[i]=='s') s2++;
            else p2++;
            t[i+k] = 'z';
        }
    }
    allnum -= r2*p + s2*r + p2*s;

    cout << allnum << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

bool is_sym(const vector<string>& S, int A){
    const int N = S.size();
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            int k = j+A, l = i-A;
            if(k>=N) k -= N;
            if(l<0) l += N;
            if(S[i][j]!=S[k][l]) return false;
        }
    }
    return true;
}

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    for(auto& s: S) cin >> s;

    ll ans = 0;
    for(int i=0; i<N; i++){
        if(is_sym(S, i)) ans += N;
    }

    cout << ans << endl;
}

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

//TO_STRING
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(char ch){
  string s;
  s += ch;
  return s;
}

string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + 
    to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + 
    to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

//DEBUG 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL //compile with -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<pi> vpi;
typedef vector<char> vch;
typedef vector<string> vstr;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vvi> vvvi;
typedef vector<vch> vvch;
typedef vector<vstr> vvstr;

#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second  
#define sz(x) ((ll)x.size())

void solve() {
  set<string> s;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
  	string x;
  	cin >> x;
  	s.insert(x);
  }
  cout << sz(s) << endl;
}

int main() {
  ios::sync_with_stdio(false);  
  cin.tie(0);cout.tie(0); 
  
  int t = 1;
  for (int tc = 1; tc <= t; tc++) {
  	solve();
  }
}

Measured memory_bytes: 19144
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10;
int n , cnt , cntt , a[MAXN];
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i < n ; i ++)
		cin >> a[i];
	sort(a , a + n);
	if(a[0] == a[n - 1])
	{
		if(a[0] == n - 1 || (a[0] and a[0] <= n / 2))
			return cout << "Yes" << endl , 0;
		return cout << "No" << endl , 0;
	}
	if(a[n - 1] - a[0] > 1)
		return cout << "No" << endl , 0;
	for(int i = 0 ; i < n ; i ++)
		if(a[i] == a[0])
			cnt ++;
		else
			cntt ++;
	if(a[n - 1] - cnt >= 1 and a[n - 1] <= cnt + cntt / 2)
		return cout << "Yes" << endl , 0;
	return cout << "No" << endl , 0;
}




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

cnt = 0
right = 0
acc = a[0]
xor = a[0]
for left in range(n):
    while right < n:
        if right + 1 >= n or acc + a[right+1] != xor ^ a[right+1]:
            break
        right += 1
        acc += a[right]
        xor ^= a[right]
    if acc == xor:
        # print(left, right, acc, xor, cnt, right - left + 1)
        cnt += (right - left + 1)
    acc -= a[left]
    xor ^= a[left]
print(cnt)


Measured memory_bytes: 25220
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();
		int d = sc.nextInt();
		sc.close();
		int result = 0;
		if (a < c && c < b && b < d) {
			result = b - c;
		} else if (c < a && a < d && d < b) {
			result = d - a;
		} else if (c <= b && d <= b && c >= a && d >= a) {
			result = d - c;
		} else if (a <= d && b <= d && a >= c && b >= c) {
			result = b - a;
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 22100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.math.*;
import java.math.BigDecimal;

public class Main {

    private static Scanner sc;

    public static void main(final String[] args) {
        final Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null)
                br.close();
        }

        public String next() throws IOException {
            if (i < s.length)
                return s[i++];
            String st = br.readLine();
            while (st == "")
                st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }

    }

    private void solve() {
        try {
            long a;
            a = sc.nextLong();
            String b = sc.next();
            BigDecimal bd_a = new BigDecimal(a);
            BigDecimal bd_b = new BigDecimal(b);

            BigDecimal ans = bd_a.multiply(bd_b);
            System.out.println(ans.setScale(0, BigDecimal.ROUND_DOWN));

        } catch (

        final Exception e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 33080
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

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

int main() {
	int W, H;
	while (cin >> W >> H, W) {
		vs field(H);
		pii s;
		REP(i, H) {
			cin >> field[i];
			REP(j, W) {
				if (field[i][j] == '@') {
					s = pii(j, i);
				}
			}
		}

		int ans = 0;
		queue<pii> Q;
		Q.push(s);
		while (!Q.empty()) {
			pii p = Q.front();
			Q.pop();
			ans++;
			
			REP(d, 4) {
				int nx = p.first + dx[d], ny = p.second + dy[d];
				if (nx < 0 || W <= nx || ny < 0 || H <= ny) {
					continue;
				}
				if (field[ny][nx] == '.') {
					field[ny][nx] = '#';
					Q.push(pii(nx, ny));
				}
			}
		}

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

Measured memory_bytes: 1236
def m(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n=int(input())
ans=len(m(n-1))-1
A=m(n)
for i in range(1,len(A)):
  s=n
  while s%A[i]==0:
    s=s//A[i]
  if s%A[i]==1:
    ans=ans+1
print(ans)

Measured memory_bytes: 39408
s = gets.chomp
s.split("").uniq!

c = 0
c += 1 if s.count('N') > 0
c -= 1 if s.count('S') > 0
d = 0
d += 1 if s.count('W') > 0
d -= 1 if s.count('E') > 0

if c != 0 || d != 0
  puts 'No'
else
  puts 'Yes'
end

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.length(); ++i){
        if (s[i] == '1') s[i] = '9';
        else s[i] = '1';
    }

    cout << s << endl;

    return 0;
}

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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

string v;

void nxt() {
	int pp = 0;
	for(int i=v.length()-1; i>=1; i--) if(v[i] != '9' && v[i] != v[i-1]+1) { pp = i; break; }
	if(!pp && v[0] == '9') {
		for(char& k:v) k = '0';
		v = '1' + v;
	} else {
		v[pp]++;
		for(int i=pp+1; i<v.length(); i++) v[i] = max(v[i-1]-1, (int)'0');
	}
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    v = "1";
	int k; gi(k); k--;
	while(k--) {
		nxt();
		//cout << v << endl;
	}
	cout << v << endl;	
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch ConsecutiveIntegers | diff ConsecutiveIntegers.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address ConsecutiveIntegers.cpp && ./a.out

/*
 
 5/11/2019
 
 5:16-
 
 */

int N,K;

void solve() {
  cout<<(N-K+1)<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>K;
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b)
{
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}




int main(){
  double N;
  cin >> N;
  cout << ceil(N/2) / N << endl;
}


Measured memory_bytes: 256
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;

int main() {
    int ans=0;
    int n;
    cin>>n;
    vector<int>b(n+1);
    for(int i=1;i<n;i++)
    cin>>b[i];
    ans+=b[1],ans+=b[n-1];
    for(int i=1;i<n-1;i++)
    ans+=min(b[i],b[i+1]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int DP[200010];
  REP(i,200010) DP[i]=0;
  string S;
  cin>>S;
  
  DP[0]=1;
  if(S.size()==1){
    co(DP[0]);
    return 0;
  }
  
  if(S[0]!=S[1]) DP[1]=2;
  else DP[1]=1;
  
  if(S.size()==2){
    co(DP[1]);
    return 0;
  }
  
  if(S[1]!=S[2]) DP[2]=DP[1]+1;
  else DP[2]=2;
  
  if(S.size()==3){
    co(DP[2]);
    return 0;
  }
  
  for(int i=3; i<S.size(); ++i){
    if(S[i]!=S[i-1]) DP[i]=DP[i-1]+1;
    else DP[i]=DP[i-3]+2;
  }
  
  co(DP[S.size()-1]);
  return 0;
}

Measured memory_bytes: 1408
N, P = map(int,input().split())
A = list(map(int,input().split()))
B = [A[k]%2 for k in range(N)]
dp = [[0,0] for k in range(N+1)]
dp[0][0] = 1

for k in range(N):
    if B[k] == 0:
        dp[k+1][0] = dp[k][0]*2
        dp[k+1][1] = dp[k][1]*2
    else:
        dp[k+1][0] = dp[k][0] + dp[k][1]
        dp[k+1][1] = dp[k][0] + dp[k][1]

print(dp[N][P])


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int arr[5];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    int val=arr[2]*10+arr[1];
    val+=arr[0];
    cout<<val<<endl;

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003;
const ll INF=1LL<<60;
vector<int> G[MAX];
int cnta[MAX],cntb[MAX],out[MAX];
string S;

void DFS(int u,int p){
    for(int to:G[u]){
        if(out[to]||to==p) continue;
        if(S[u]=='A'){
            cnta[to]--;
        }else{
            cntb[to]--;
        }
        
        if(cnta[to]&&cntb[to]) continue;
        
        out[to]=1;
        DFS(to,u);
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;cin>>N>>M;
    cin>>S;
    for(int i=0;i<M;i++){
        int u,v;cin>>u>>v;
        u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
        
        if(S[u]=='A'){
            cnta[v]++;
        }else{
            cntb[v]++;
        }
        
        if(S[v]=='A'){
            cnta[u]++;
        }else{
            cntb[u]++;
        }
    }
    
    for(int i=0;i<N;i++){
        if(cnta[i]==0||cntb[i]==0){
            if(out[i]==0){
                out[i]=1;
                DFS(i,-1);
            }
        }
    }
    
    bool ok=false;
    
    for(int i=0;i<N;i++){
        if(cnta[i]&&cntb[i]) ok=true;
    }
    
    if(ok) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 19024
import sys
import numpy as np


def main():
    n, x = [int(e) for e in input().split()]
    boxes = [int(e) for e in input().split()]
    boxesrev = list(reversed(boxes))
    ans1 = 0
    ans1 += max(0, boxes[0] - x)
    boxes[0] = min(boxes[0], x)
    ans1 += max(0, boxes[n - 1] - x)
    boxes[n - 1] = min(boxes[n - 1], x)
    for i in range(1, n - 2):
        ans1 += max(0, (boxes[i] + boxes[i - 1]) - x)
        boxes[i] = min(boxes[i], x - boxes[i - 1])
    if n > 2:
        ans1 += max(0, (boxes[n - 2] + max(boxes[n - 3], boxes[n - 1])) - x)
        boxes[n - 2] = min(boxes[n - 2], x - max(boxes[n - 3], boxes[n - 1]))
    else:
        ans1 += max(0, boxes[n - 2] + boxes[n - 1] - x)
        boxes[n - 1] = min(boxes[n - 1], x - boxes[n - 2])
    print(ans1)


main()


Measured memory_bytes: 23472
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

#define POS(i,j) ((i)*n+(j))

void sieve(char *p,int n){
  int i,j;
  for(i=2;i<=n;i++) p[i]=1;
  p[0]=p[1]=0;
  for(i=2;i*i<=n;i++){
    if(!p[i]) continue;
    for(j=i*i;j<=n;j+=i) p[j]=0;
  }
  return;
}

char *buf=NULL;
int pointer=0;
inline void print(char c){
  buf[pointer++]=c;
}

inline void printInt(int64 n){
  char s[20];
  int p=0;
  while(n>0){
    s[p++]='0'+n%10;
    n/=10;
  }
  while(p>0) print(s[--p]);
}

void run(void){
  const int n=500;
  char *p=(char *)malloc(sizeof(char)*5001);
  sieve(p,5000);
  int *l=(int *)malloc(sizeof(int)*(n+1));
  int *r=(int *)malloc(sizeof(int)*(n+1));
  int lp=0;
  int rp=0;
  int i=2;
  while(lp<n+1){
    l[lp++]=i++;
  }
  while(rp<n+1){
    if(p[i]) r[rp++]=i;
    i++;
  }
  int64 *board=(int64 *)malloc(sizeof(int64)*n*n);
  int j;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if((i+j)%2==0){
	board[POS(i,j)]=l[(i+j)/2]*r[((n-i)+j)/2];
      } else {
	int64 lcm=(int64)l[(i+j)/2]*l[(i+j)/2+1]*r[((n-i)+j)/2]*r[((n-i)+j)/2+1];
	board[POS(i,j)]=lcm+1;
      }
    }
  }
  buf=(char *)calloc(2500000,sizeof(char));
  int m;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    printInt(board[POS(i,0)]);
    for(j=1;j<m;j++){
      print(' ');
      printInt(board[POS(i,j)]);
    }
    print('\n');
  }
  puts(buf);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(x) setprecision(x)<<fixed
#define ss second
#define fori(v) for(lli i=0; i<v; i++)
#define forj(v) for(lli j=0; j<v; j++)
#define fork(v) for(lli k=0; k<v; k++)
#define forl(v) for(lli l=0; l<v; l++)
#define fort(v) for(lli t=0; t<v; t++)
#define forz(v) for(lli z=0; z<v; z++)
#define lli long long int
#define MAX 100004
#define double long double
#define ch 75
#define pb push_back
lli inf = 8*pow(10,18);
lli modulo = pow(10,9)+7;
double eps = 1e-11;
ifstream in;
ofstream out;
//#define cin in
//#define cout out
void deal(){
	int n;
	cin>>n;
	int dp[n][2]; // 0 no change ,1 change
	int arr[n];
	fori(n)
		cin>>arr[i];
	dp[0][0] = 0, dp[0][1] = 1;
	for(int i=1; i<n; i++){
		if(arr[i] == arr[i-1])
			dp[i][1] = min(dp[i-1][0], dp[i-1][1]) + 1, dp[i][0] = dp[i-1][1];
		else
			dp[i][1] = min(dp[i-1][0],dp[i-1][1]) +1, dp[i][0] = min(dp[i-1][0],dp[i-1][1]);
			
	}
	cout<<min(dp[n-1][0],dp[n-1][1]);
}
int main(){
	deal();
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,T,c,t,ans=1e9;
main(){
	cin>>n>>T;
	for(int i=0;i<n;i++)
	{
		cin>>c>>t;
		if(t<=T&&c<ans)ans=c;
	}
	if(ans<1e9)cout<<ans<<endl;
	else cout<<"TLE"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
 
int main(){
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	set<int> puni, muni;
	for(int i = 0; i * 100 * a <= f; i++){
		for(int j = 0; i * 100 * a + j * 100 * b <= f; j++){
			puni.insert(i * 100 * a + j * 100 * b);
		}
	}
	for(int i = 0; i * c <= f; i++){
		for(int j = 0; i * c + j * d <= f; j++){
			muni.insert(i * c + j * d);
		}
	}
	pair<int, int> ans(-1, -1);
	for(int x:puni){
		for(int y:muni){
			if(f < x + y) continue;
			if(100 * y <= e * x){
				if(ans.first == -1){
					ans = make_pair(x, y);
					continue;
				}
				if(ans.second * (x + y) <= y * (ans.first + ans.second)){
					ans = make_pair(x, y);
				}
			}
		}
	}
	cout << ans.first + ans.second << ' ' << ans.second << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimization("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#define prev fuckkkkk
using namespace std;
using pi = pair<int,int>;
using pii = pair<pi,int>;
vector<pi> v;
vector<pii> w;
int n,sqrtn,m,a[555555],check[555555],ans[555555],ret;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n>>m;
    sqrtn = sqrt(n);
    for(int i=1; i<=n; i++) cin>>a[i];
    for(int i=0,x,y; i<m; i++){
        cin>>x>>y;
        v.push_back({x,y});
        w.push_back({{x/sqrtn,y},i});
    }
    sort(w.begin(),w.end());
    for(int j=0; j<m; j++){
        pi prev = {0,0},now = v[w[j].second];
        if(j) prev = v[w[j-1].second];
        for(int i=prev.first-1; i>=now.first; i--) if(++check[a[i]]==1) ret++;
        for(int i=prev.second+1; i<=now.second; i++) if(++check[a[i]]==1) ret++;
        for(int i=prev.first; i<now.first; i++) if(!--check[a[i]]) ret--;
        for(int i=prev.second; i>now.second; i--) if(!--check[a[i]]) ret--;
        ans[w[j].second] = ret;
    }
    for(int i=0; i<m; i++) cout<<ans[i]<<'\n';
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()
#define Foreach(item,collection) for(auto item : collection)

using pii=pair<int,int>;
using vb=vector<bool>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
using ulong=unsigned long;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
#define OCB(c) (c&1)|(c&2)<<2|(c&4)<<4|(c&8)<<6|(c&16)<<8|(c&32)<<10|(c&64)<<12|(c&128)<<14

int main(){
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    out((abs(b-a)<=d&&abs(c-b)<=d)||(abs(c-a)<=d)?"Yes":"No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};


void solve(int N, int W, vi w, vi v){
    int v_max = accumulate(all(v), 0);
    vvll dp(N+1, vll(v_max+1, 1e12));
    rep(i, N+1) dp[i][0] = 0;
    reps(i,N) reps(j,v_max) {
        chmin(dp[i][j], dp[i-1][j]);
        if (j-v[i-1] >= 0) chmin(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1]);
    }
    ll ans;
    RFOR(j, v_max, 0) {
        if(dp[N][j] <= W){
            ans = j;
            break;
        }
    }
    cout << ans << endl;
}

int main(){
    int N, W;
    cin >> N >> W;
    vi w(N), v(N);
    rep(i,N) cin >> w[i] >> v[i];
    solve(N, W, w, v);
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long N, std::vector<long long> A){
    cout << (H <= accumulate(A.begin(), A.end(), 0) ? "Yes" : "No") << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(H, N, std::move(A));
    return 0;
}


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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
  
  if(op == "+"){
    cout << A + B << endl;
  }
  else if(op == "-"){
    cout << A - B << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int m, n;
double mat[18][18];
bool visited[(1<<16)][16];
double memo[(1<<16)][16];

double dfs(int used, int stage){
    if(stage == n) return 1;
    if(used == (1 << m)-1) return 0;
    if(visited[used][stage]) return memo[used][stage];
    double ret = 0;
    for(int i=0;i<m;i++){
        if((used>>i)&1) continue;
        double path = 1;
        double suc = 0;
        int nused = used | (1 << i);
        for(int j=stage;j<n;j++){
            suc += path * (1 - mat[i][j]) * dfs(nused, j);
            path *= mat[i][j];
        }
        suc += path;
        ret = max(ret, suc);
    }
    visited[used][stage] = true;
    memo[used][stage] = ret;
    return ret;
}

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

    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            cin >> mat[i][j];
        }
    }

    memset(visited, 0, sizeof(visited));
    printf("%.10f\n", dfs(0, 0));

    return 0;
}

Measured memory_bytes: 12512
#include<bits/stdc++.h> 
#define Rg register 
#define i60 long long 
#define fp( i , x , y ) for(Rg int i=(x); i<=(y); ++i) 
#define fq( i , x , y ) for(Rg int i=(y); i>=(x); --i)  
#define Show fp( i , 1 , n ) cout << inv[i] << " " ;   
const int hgs = 1e9+7 , P = 2005 , N = 200005 ; 
using namespace std ; 
i60 f[P<<1][P<<1] , inv[P<<2] , fac[P<<2] , Ans1 , Ans2 , Ans ; 
int a[N] , b[N] , n ;  
i60 power( i60 A , int B ) { 
    i60 tep = 1 ; 
    for( ; B ; B >>= 1 ) { 
       if( B&1 ) tep = tep * A % hgs ; 
       A = A * A % hgs ; 
	}  return tep ; } 
i60 C( int A , int B ) { return fac[B] * inv[A] % hgs * inv[B-A] % hgs ; }  
signed main( ) { 
    ios::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ;  
	cin >> n ; fac[0] = 1 ; 
	fp( i , 1 , n ) cin >> a[i] >> b[i] , f[P-a[i]][P-b[i]] ++ ; 
	fp( i , 1 , 2*P-5 ) fp( j , 1 , 2*P-5 ) 
	  f[i][j] = ( f[i][j] + f[i-1][j] + f[i][j-1] ) % hgs ; 
	fp( i , 1 , n ) Ans1 = ( Ans1 + f[P+a[i]][P+b[i]] ) % hgs ; 
    fp( i , 1 , 4*P-10 ) fac[i] = fac[i-1] * i % hgs ; 
	fp( i , 1 , 4*P-10 ) inv[i] = power( fac[i] , hgs-2 ) ; 
	fp( i , 1 , n ) Ans2 = ( Ans2 + C( a[i]+a[i] , 2*(a[i]+b[i]) ) ) % hgs ; 
	Ans = ( Ans1 - Ans2 + hgs ) % hgs ; 
	cout << Ans * inv[2] % hgs << endl ; 
	return 0 ; 
} 

Measured memory_bytes: 127488
#include<bits/stdc++.h>
#define mx 3007
using namespace std;

double dp[mx][mx];
bool vis[mx][mx];
double p[mx];
int n;

double rec( int i, int x )
{
    if( i>=n )
    {
        if(x>=(n+1)/2)
            return 1.00;
        return 0.00;
    }

    if( vis[i][x] )
        return dp[i][x];

    double ret= 0;

    ret+= p[i]*rec( i+1, x+1 );
    ret+= (1.00-p[i])*rec( i+1, x );

    vis[i][x]= 1;

    return dp[i][x]= ret;
}

int main()
{
    cin>>n;

    for( int i=0;i<n;i++ )
        cin>>p[i];

    cout<<setprecision(12)<<fixed<< rec( 0, 0 ) <<endl;
}


Measured memory_bytes: 79744
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#define N 100005 ////////////////////////////////////
using namespace std;

int n, m, Q, d[N], gi[N], di[N], num[N], ans[N];
vector<int> a[N];
void f(int p, int q, int w) {
	int i;
	if (d[p] >= q) return;
	d[p] = q;
	if (ans[p] == 0) ans[p] = w;
	for (i = 0; i < a[p].size(); i++) f(a[p][i], q - 1, w);
}
int main()
{
	int i, t1, t2;
	cin >> n >> m;
	while (m--) {
		scanf ("%d %d", &t1, &t2);
		a[t1].push_back(t2);
		a[t2].push_back(t1);
	}
	cin >> Q;
	for (i = 1; i <= Q; i++) {
		scanf ("%d %d %d", &gi[i], &di[i], &num[i]);
	}
	memset(d, -1, sizeof(d));
	for (i = Q; i >= 1; i--) {
		f(gi[i], di[i], num[i]);
	}
	for (i = 1; i<= n; i++) printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 8440
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9+7;
 
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}
 
int main() {
	int K,A,B;
  	cin >> K>>A>>B;
  	bool frag = false;
  	for(int i = A;i<=B;i++){
    if(i%K == 0) frag = true;
    }
  	if(frag) cout << "OK" << endl;
  	else cout << "NG" << endl;
}

Measured memory_bytes: 3624
package main

import "fmt"

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n, &s)

	ans := 0
	x := 0
	for _, r := range s {
		if r == 'I' {
			x++
		} else {
			x--
		}
		ans = max(ans, x)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
#define N 100010
char a[N],b[N];
LL gcd(LL x,LL y)
{
    return x%y==0?y:gcd(y,x%y);
}
int main()
{
    LL n,m,d,s,k1,k2,x,y,t1,t2;
    scanf("%lld%lld",&n,&m);
    scanf("%s%s",a,b);
    d=gcd(n,m);
    s=n*m/d;
    k1=s/n;
    k2=s/m;
    x=0;
    y=0;
    t1=0;
    t2=0;
    while(x<n&&y<m)
    {
        if(t1*k1==t2*k2)
        {
            if(a[x]!=b[y])
            {
                printf("-1\n");
                return 0;
            }
            x++;
            y++;
            t1++;
            t2++;
        }
        else
        if(t1*k1<t2*k2)
        {
            t1++;
            x++;
        }
        else
        if(t1*k1>t2*k2)
        {
            t2++;
            y++;
        }
    }
    printf("%lld\n",s);
    return 0;
}


Measured memory_bytes: 384