akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for m in range(M)]

ab.sort(key= lambda x: x[1])
removed = -1
ans = 0

for a, b in ab:
  if a > removed:
    removed = b - 1
    ans += 1

print(ans)

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

using ll = long long;

template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }

    set<int> used;
    for(int i = 1; i <= M; ++i) {
        used.insert(i);
    }
    int res = N;
    for(int i = 0; i < M - 1; ++i) {
        map<int, int> cnt;
        for(int j = 0; j < N; ++j) {
            for(int k = 0; i < M; ++k) {
                if(used.count(A[j][k]) == 1) {
                    cnt[A[j][k]]++;
                    break;
                }
            }
        }
        int t = 0;
        int ma = -1;
        for(auto& p : cnt) {
            if(t < p.second) {
                ma = p.first;
                t = p.second;
            }
        }
        res = min(res, t);
        used.erase(ma);
    }
    cout << res << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef pair<int, int> pii;

const int mod = 998244353;

int n, m;
int A[301][301];
int nCr[301][301];
int p2[601];
int p3[301];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    nCr[0][0] = p2[0] = p3[0] = 1;
    for (int i = 1; i <= 300; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (j > 0) nCr[i][j] += nCr[i - 1][j - 1];
            if (j < i) nCr[i][j] += nCr[i - 1][j];
            nCr[i][j] %= mod;
        }
    }
    for (int i = 1; i <= 600; ++i) p2[i] = p2[i - 1] * 2ll % mod;
    for (int i = 1; i <= 300; ++i) p3[i] = p3[i - 1] * 3ll % mod;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> A[i][j];
        }
    }
    int R = n;
    for (int i = 1; i <= n; ++i) {
        int mnv = m + 1, mni;
        for (int j = i; j <= n; ++j) {
            for (int k = 1; k < mnv; ++k) {
                if (A[j][k]) {
                    mnv = k;
                    mni = j;
                    break;
                }
            }
        }
        if (mnv > m) {
            R = i - 1;
            break;
        }
        for (int j = 1; j <= m; ++j) {
            swap(A[i][j], A[mni][j]);
        }
        for (int j = i + 1; j <= n; ++j) {
            if (A[j][mnv] == 0) continue;
            for (int k = 1; k <= m; ++k) {
                A[j][k] ^= A[i][k];
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= R; i += 2) {
        int v = 1;
        ans += (llong)nCr[R][i] * p2[m + n - R - R] % mod * p3[R - i] % mod;
        ans %= mod;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.SortedMap;
import java.util.TreeMap;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int N = scan.nextInt();
		int[] A = new int[N - 1];

		for (int i = 0; i < N - 1; i++) {
			A[i] = scan.nextInt();
		}

		//WK変数
		SortedMap<Integer, Integer> map = new TreeMap<>();

		for (int i = 0; i < N; i++) {
			map.put(i + 1, 0);
		}

		//演算
		for (int i = 0; i < N - 1; i++) {
			map.put(A[i], map.get(A[i]) + 1);
		}

		//結果出力
		for (int i = 0; i < N; i++) {
			System.out.println(map.get(i + 1));
		}
	}
}

Measured memory_bytes: 73620
#include <stdio.h>

int main(){

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if (x-r<0||y-r<0||x+r>W||y+r>H){

printf("No\n");

} else {

printf("Yes\n");

}

return 0;

}

Measured memory_bytes: 584
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>

using namespace std;
int *s;
int n;
bool exsrc(int p, int value, int i) {
    if(i >= n) return false;
    if(p == 1) {
        value -= s[i];
        if(value == 0) return true;
    }
    i++;
    return exsrc(0, value, i) || exsrc(1, value, i);
}
int main() {
    int q;
    cin >> n;
    s = new int[n];
    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    cin >> q;
    for(int i=0; i<q; i++) {
        int r;
        cin >> r;
        bool result = exsrc(0, r, 0) || exsrc(1, r, 0);
        if(result) {
            cout << "yes" << endl;
        }else {
            cout << "no" << endl;
        }
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
int main(){
    long long n, k;
    cin >> n >> k;
    vector<long long>gcd(k + 3);
    long long ans = 0;
    for(long long i = k; i >= 1; i--){
        gcd[i] = bigmod(k / i, n);
        for(int j = 2 * i; j <= k; j = j + i){
            gcd[i] = (gcd[i] - gcd[j] + mod) % mod;
        }
        ans = (ans + i * gcd[i]) % mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4020
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000






int main() {
	int a[N];
	int n, k;
	k = 0;
	scanf("%d", &n);
	f(i, n) {
		scanf("%d", &a[i]);
		if (a[i] != i + 1)k++;
	}
	if (k <= 2)printf("YES\n");
	else printf("NO\n");


	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 5;
const ll maxn = 5005;
ll m, n, t, T, k, a[N], ans, tong;
string s, ss;
struct dang
{
    ll pos, val, mn, mx, vtri;
};
bool so(const dang& x, const dang& y)
{
    return (x.val < y.val) || (x.val == y.val && x.pos < y.pos);
}
priority_queue<ll> pr;
bool check(ll u)
{
    ll tt = 0;
    if(u <= 0)return true;
    for(int i = 1; i <= n; i ++)
    {
        tt += max((a[i] + u - 1) / u - 1, 0ll);
    }
    if(tt <= k)return true;
    else return false;
}
void sol()
{
    cin >> n >> k;
    for(int i = 1; i <= n; i ++)
    {
        cin >> a[i];
        m = max(m, a[i]);
    }
    ll lf = 0, rt = m, mid;
    while(lf <= rt)
    {
        mid = (lf + rt) / 2;
        if(check(mid))rt = mid - 1;
        else lf = mid + 1;
    }
    cout << max(lf, 1ll);

}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cin >> T; while(T -- > 0)
    sol();
}


Measured memory_bytes: 5172
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cassert>
#include <functional>
#include <string>
using namespace std;


int main(){
  string s; cin >> s;
  int num = 0;
  while(true){
    char tmp = 'a' + num;
    if(find(s.begin(), s.end(), tmp) == s.end()){
      cout << tmp << endl;
      break;
    }
    num++;
    if(num == 26){
      cout << "None" << endl;
      break;
    }
  }
}


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

int main(){
  int64_t N,K;
  cin>>N>>K;
  int64_t N_a,N_b;
  N_a=N%K;
  N_b=abs(N_a-K);
  if (N_a<N_b){
    cout<<N_a<<endl;
  }else{
    cout<<N_b<<endl;
  }
}


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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

int main(int argc, const char* argv[]) {
	ll n, x;
	cin >> n >> x;
	
	ll d = 0;
	ll ret = 1;
	rep(i, n) {
		ll l;
		cin >> l;
		d += l;
		if(d <= x) {
			++ret;
		} else {
			break;
		}
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, const char * argv[]) {
    char W[11],T[1001],end[]="END_OF_TEXT";
    int i,sum=0;
    scanf("%s",W);
    while(1){
        scanf("%s",T);
        if(strcmp(T,end)==0){
            break;
        }else{
            for(i=0;T[i]!='\0';i++){
                if(isupper(T[i])){
                    T[i]=tolower(T[i]);
                }
            }
        }
        if(strcmp(W,T)==0){
            sum++;
        }
        
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 552
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18
#define PI 3.1415926535



int main(){
    int N,M;
    cin >> N >> M;
    vector<long long> A(N);
    rep(i,N)cin >> A[i];
    vector<pair<long long, long long>> T(M);
    rep(i,M)cin >> T[i].second >> T[i].first;
    sort(T.begin(),T.end());
    reverse(T.begin(),T.end());
    priority_queue<long long,vector<long long>,greater<long long>> Q;
    rep(i,N){
        Q.push(A[i]);
    }
    rep(i,M){
        int cnt = 0;
        while(Q.top() < T[i].first && cnt < T[i].second){
            Q.pop();
            Q.push(T[i].first);
            cnt++;
        }
    }
    long long ans = 0;
    while(!Q.empty()){
        ans += Q.top();
        Q.pop();
    }
    cout << ans << endl;

}

Measured memory_bytes: 3832
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
#include <map>
#include <list>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 50
#define LARGENUM 1000000007
#define INF 9223372036854775807
#define ull unsigned long long 
typedef pair <int, int> P;

int main(){
    int X, Y, head, leg;
    cin >> X >> Y;
    rep(t, X + 1){
        rep(k, X + 1){
            head = t + k;
            leg = 2 * t + 4 * k;
            if (head == X && leg == Y){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3152
#include <iostream>
using namespace std;
int main(void){
 
char x,y;
cin >> x >> y;
if (x > y){
    cout << ">" << endl;
}
if (x < y){
    cout << "<" << endl;
}
if (x == y){
    cout << "=" << endl;
} 
 
 return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, m, q;
    cin >> n >> m >> q;
    vector<vector<ll>> z(n+1,vector<ll>(n+1));
    for (int i = 0; i < m; i++) {
        ll a, b;
        cin >> a >> b;
        z[a][b]++;
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            z[i][j + 1] += z[i][j];
        }
    }
    for (int i = 0; i < q; i++) {
        ll a, b;
        cin >> a >> b;
        ll ans = 0;
        for (int j = a; j < b+1; j++) {
            ans += z[j][b];
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 5584
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
	//freopen("in.txt","r",stdin);

	long long a,b,c,d;
	cin>>a>>b>>c>>d;

	cout<<max(a*c ,max(a*d ,max(b*c, b*d)));
	return 0;
}

Measured memory_bytes: 3644
n = gets.to_i
as = gets.split.map(&:to_i)

total = as.inject(:+)
ss = Array.new(n + 1, 0)
ds = Array.new(n + 1, 0)

min = 2020202020
index = 0

as.each_with_index do |a, i|
  ss[i + 1] = ss[i] + a
  ds[i + 1] = total - ss[i + 1]

  if (ss[i + 1] - ds[i + 1]).abs <= min
    index = i
    min = (ss[i + 1] - ds[i + 1]).abs
  end
end

puts (ss[index + 1] - ds[index + 1]).abs


Measured memory_bytes: 19212
# D - Ki
from collections import deque

N, Q = map(int, input().split())
g = [[] for _ in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

# 各頂点に得点を持たせておく
point = [0] * N
for i in range(Q):
    p, x = map(int, input().split())
    p -= 1
    point[p] += x

ans = [0] * N

d = deque()
d.append((0,0,0))

while len(d)>0:
    v = d.popleft()
    ans[v[0]] += v[2] + point[v[0]]
    for gi in g[v[0]]:
        if gi!=v[1]:
            d.append((gi, v[0], ans[v[0]]))

print(' '.join(map(str, ans)))

Measured memory_bytes: 130168
N, x = map(int,input().split())
peaple = list(map(int,input().split()))
peaple.sort()
count = 0
for i in range(N):
    if(x<peaple[i]):
        break
    else:
        x -= peaple[i]
        count += 1
    if(i == N-1 and x > 0):
        count -=1
print(count)


Measured memory_bytes: 3060
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : Monday July 27, 2020
 */

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

#define endl '\n'
#define precise(n,k) fixed << setprecision(k) << n
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define uint  unsigned int
#define ll    long long
#define ull   unsigned long long
#define ld    long double

#define pii   pair<int, int>
#define piii  tuple<int, int, int>
#define pll   pair<ll, ll>
#define plll  tuple<ll, ll, ll>

#define X  first
#define Y  second

#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(bool b) {
    return (b ? "true" : "false");
}
 
template <typename A, typename B>
string to_string(const pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

// add templates here

template <typename T>
string to_string(const vector<T> &v) {
    bool first = true;
    string res = "{";
    for (const T &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string((T)x);
    }
    res += "}";
    return res;
}

template<class T>
void println(const T &data) {
#ifndef ONLINE_JUDGE
    cout << to_string((T)data) << endl;
#endif
}

const int MOD = int(1e9+7);
const ll oo  = (ll)(1e9+20);
const ll lloo  = (ll)(1e18)+40;

class Task {
public:
    
    ll solve(istream &in, ostream &out) {
        ll A, B;
        cin >> A >> B;
        if(A>9 || B > 9) return -1;
        return A*B;  
    }
    
    void run(istream &in, ostream &out) {
        int t;
        in >> t;
        while(t--) {
            out << solve(in, out) << endl;
        }
    }
};
    
auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    cout << solver.solve(in, out) << endl;
    //solver.run(in, out);
    return 0;
}



Measured memory_bytes: 3616
S = input()
N = len(S)
i = 0
cnt = 0
while i < N-1:
    if (S[i] == "0" and S[i+1] == "1") or (S[i] == "1" and S[i+1] == "0"):
        S = S[:i] + S[i+2:]
        N -= 2
        cnt += 2
        if i > 0:
            i -= 1
    else:
        i += 1
print(str(cnt))

Measured memory_bytes: 3428
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		int H, W; 		
		
		do {
			H = stdIn.nextInt();
			W = stdIn.nextInt();
			
			if( W == 0 && H == 0)break;
			
			for(int i = 1; i <= H; i++) {
				for(int j = 1; j <= W; j++) {
					if(j == W ) {
						System.out.println("#");
					}else {
						System.out.print("#");
					}
				}
		
			}
			
			System.out.print("\n");
			
		}while(true);			
	}
}



Measured memory_bytes: 36636
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
//	freopen("B.in", "r", stdin);
//	freopen("B.out", "w", stdout);
	string a, b;
	cin >> a >> b;
	string tmp = a + b;
	int num = 0;
	for(size_t i=0; i<tmp.size(); ++i)
	{
		num *= 10;
		num += tmp[i] - '0';
	}
	for(int i=1; i<=1000; ++i)
		if(i * i == num)
		{
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;
	return 0;
}


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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

constexpr int maxd = 11010;
int dp[maxd];
int main(){
  int N, W;
  cin >> N >> W;
  vector<int> v(N), w(N);
  REP(i, N){
    cin >> v[i] >> w[i];
  }
  REP(i, maxd){
    dp[i] = -1;
  }
  dp[0] = 0;
  REP(i, N){
    REP(j, W+1){
      if(dp[j] == -1) continue;
      dp[j+w[i]] = max(dp[j] + v[i], dp[j+w[i]]);
    }
  }
  int ans = 0;
  REP(i, W+1){
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3152
import java.util.Scanner;


public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);

		int p=sc.nextInt();
		int q=sc.nextInt();
		int r=sc.nextInt();

		System.out.println(Math.min(Math.min(p+q,p+r),q+r));
	}
}

Measured memory_bytes: 21844
N, L = map(int, input().split())
taste = 0
if L >= 0:
    for i in range(2, N + 1):
        taste += L + i - 1
elif L + N - 1 < 0:
    for i in range(1, N):
        taste += L + i - 1
else:
    for i in range(1, N + 1):
        taste += L + i - 1
print(taste)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

// Greatest Common Divisor
// 再帰なしバージョン
int gcd(int x, int y)
{
    if (x < y) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    while (y > 0) {
        int r = x % y;
        x = y;
        y = r;
    }
    return (x);
}

int main()
{
    int x, y;

    cin >> x; cin >> y;

    cout << gcd(x, y) << '\n';
    
    return (0);
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int a[100005], n, m;

int main(){
	int i, j;
	char b;
	cin >> b;
	if(isupper(b)){
		cout << 'A';
	}else {
		cout << 'a';
	}
}


Measured memory_bytes: 3592
n = gets.to_i
array = gets.split(" ").map(&:to_i)
array_sum = array.sum
sum = 0
previous = 0
mod = 10 ** 9 + 7
(array.length-1).times do |i|
  if i == 0
    previous = array[i]
  else
    previous += array[i]
  end
  sum += array[i] * (array_sum - previous)
end
puts sum % mod

Measured memory_bytes: 33912
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  int totalPrice = 700;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'o') totalPrice += 100;
  }
  cout << totalPrice << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if((n|m)==0)
				break;
			int[] cnt = new int[11];
			while (n-- > 0) {
				int d = scanner.nextInt();
				int p = scanner.nextInt();
				cnt[p] += d;
			}
			int ans = 0;
			for (int i = 10; i > 0; i--)
				if (m >= cnt[i])
					m -= cnt[i];
				else {
					ans += i * (cnt[i] - m);
					m = 0;
				}

			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 93784
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  l=I()

  a=l/3
  return a**3

# main()
print(main())


Measured memory_bytes: 5828
#include <stdio.h>

int main() {

  int a, b, c;
  char op;


  while(1) {
    scanf("%d %c %d", &a, &op, &b);

    switch(op) {
    case '+' :
      c = a + b; break;
    case '-' :
      c = a - b; break;
    case '*' :
      c = a * b; break;
    case '/' :
      c = a / b; break;
    case '?' : return 0;
    default: break;
    }

    printf("%d\n", c);
  }
  
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,mod=1e9+7;
int n,a[N],b[N],c[N],d[N];
int vis[N];
ll p[N];
void solve()
{
    reverse(c+1,c+1+n);
    reverse(d+1,d+1+n);
    ll res=0,sum=0,mus=0;
    for(int i=1;i<=n;i++)
    {
        res=(res+(d[i]+1)*p[i])%mod;
        sum=(sum+(c[i]+1)*p[i])%mod;
        mus=(mus+((c[i]^1)+1)*p[i])%mod;
    }
    for(int k=1,i=n;i>=1;k++,i--)
    {
        if(res==sum||res==mus) vis[k]++;
        sum=((sum-(c[i]+1)*p[n])%mod*p[1]%mod+(c[i]+1)*p[1])%mod;
        mus=((mus-((c[i]^1)+1)*p[n])%mod*p[1]%mod+((c[i]^1)+1)*p[1])%mod;
        sum=(sum+mod)%mod;
        mus=(mus+mod)%mod;
    }
}
int main()
{
    p[0]=1;
    for(int i=1;i<N;i++) p[i]=p[i-1]*3%mod;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<30;i++)
    {
        for(int j=1;j<=n;j++)
        {
            c[j]=a[j]>>i&1;
            d[j]=b[j]>>i&1;
        }
        solve();
    }
    for(int i=1;i<=n;i++)
        if(vis[i]==30)
    {
        printf("%d %d\n",i-1,a[i]^b[1]);
    }
}


Measured memory_bytes: 8960
/*  -*- coding: utf-8 -*-
 *
 * 2964.cc: Restore Shortest Path
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<unistd.h>
 
using namespace std;

/* constant */

const int MAX_N = 300;
const int INF = 1 << 29;

/* typedef */

typedef pair<int,int> pii;

/* global variables */

int ds[MAX_N][MAX_N], xs[MAX_N];
pii ps[MAX_N];

/* subroutines */

int getdist(int i, int j) {
  if (ds[i][j] > 0) return ds[i][j];

  printf("? %d %d\n", i + 1, j + 1); fflush(stdout);

  int d;
  scanf("%d", &d);
  if (d < 0) exit(0);
  ds[i][j] = ds[j][i] = d;
  return d;
}

/* main */

int main() {
  int n, st, gl;
  scanf("%d%d%d", &n, &st, &gl);
  st--, gl--;

  //for (int i = 0; i < n; i++) fill(ds[i], ds[i] + n, INF);
  int gd = getdist(st, gl);

  ps[0] = pii(0, st), ps[1] = pii(gd, gl);
  int m = 2;

  for (int i = 0; i < n; i++)
    if (i != st && i != gl) {
      int d0 = getdist(st, i), d1 = getdist(i, gl);
      if (d0 + d1 == gd) ps[m++] = pii(d0, i);
    }
  sort(ps, ps + m);

  xs[0] = st;
  int pd = 0, px = st, k = 1;

  for (int i = 1; i < m; i++) {
    int di = ps[i].first, xi = ps[i].second;
    int dd = getdist(px, xi);
    if (pd + dd == di) {
      xs[k++] = xi;
      pd = di;
      px = xi;
    }
  }

  putchar('!');
  for (int i = 0; i < k; i++) printf(" %d", xs[i] + 1);
  putchar('\n'); fflush(stdout);

  //sleep(1);
  return 0;
}



Measured memory_bytes: 4664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, count = 10000, count_tmp = 0;
  cin >> N;
  for (; N > 0; N--) {
    cin >> A;
    for (; A % 2 == 0; count_tmp++) {
      A /= 2;
	  //cout << count_tmp << endl;
    }
    if (count_tmp < count) {
      count = count_tmp;
    }
    count_tmp = 0;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
/*
 * sepstr("hoge,fuga:piyo/poya", ",:/");    //1つ目の文字列を、2つ目で与えた区切り文字のセットで分割した結果を返す。O(ND)
 *                                          //この例だと、{"hoge", "fuga", "piyo", "poya"}が返る
 * bitstr(100)          //引数の数値をビット列を示す文字列に変換する
 *                      //宣言内のto_string()には引数を入れることが出来、例えば('_','#')とすると、0をアンダーバー、1を#として表示できる
 * bitcnt(100)          //引数の数値が何ビット立っているか返す
 * bitdig(100)          //ビット列が何ビットあるか返す。
 * bitpow(100)          //その数字の約数に2がいくつあるか。8なら3, 16なら4, 20なら2
 */

template<class T>string bitstr(T x){return typeid(T)==typeid(int)?bitset<32>(x).to_string():bitset<64>(x).to_string();}
template<class T>int bitcnt(T x){return typeid(T)==typeid(int)?__builtin_popcount(x):__builtin_popcountll(x);}
template<class T>int bitdig(T x){return x?typeid(T)==typeid(int)?32-__builtin_clz(x):64-__builtin_clzll(x):0;}
template<class T>int bitpow(T x){return x?typeid(T)==typeid(int)?__builtin_ctz(x):__builtin_ctzll(x):0;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
    int n;
    cin>>n;
    cout<<1110-n<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
int main(){
	char h;
	int n,m,c;
	while(cin>>n,n){
		bool jewel[21][21];
		memset(jewel,false,sizeof(jewel));
		int x=10,y=10;
		for(int i=0;i<n;i++){
			int a,b;
			cin>>a>>b;
			jewel[a][b]=true;
		}
		int cnt=0;
		cin>>m;
		for(int j=0;j<m;j++){
			cin>>h>>c;
			if(h=='N'){
				for(int i=0;i<c;i++){
					y++;
					if(jewel[x][y]){
						cnt++;
						jewel[x][y]=false;
					}
				}
			}else if(h=='S'){
				for(int i=0;i<c;i++){
					y--;
					if(jewel[x][y]){
						cnt++;
						jewel[x][y]=false;
					}
				}
			}else if(h=='E'){
				for(int i=0;i<c;i++){
					x++;
					if(jewel[x][y]){
						cnt++;
						jewel[x][y]=false;
					}
				}
			}else{
				for(int i=0;i<c;i++){
					x--;
					if(jewel[x][y]){
						cnt++;
						jewel[x][y]=false;
					}
				}
			}
		}
		if(cnt==n){
			cout<<"Yes"<<endl;
		}else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

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

int main() {
    string s;
    cin >> s;
    int l = s.length();

    int win_count = 0;
    int lose_count = 0;

    rep(i, l) {
        char hand;
        if (i % 2 == 0) {
            hand = 'g';
        } else {
            hand = 'p';
        }

        if (s[i] == 'g' && hand == 'p') {
            win_count++;
        } else if (s[i] == 'p' && hand == 'g') {
            lose_count++;
        }
    }

    cout << win_count - lose_count << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include <complex>

using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef unsigned long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const double EPS = 1e-6;
const int MAX = 2000+ 47;


int L[MAX], R[MAX];
int MX[MAX];

int solve(string& A, string& B)
{
    int n = SZ(A);
    int idx = n - 1;
    while(B[idx] != '1')--idx;
    L[0] = (B[0] == '1') ? 0 : n - idx;
    FOR(i, 1, n)
        L[i] = (B[i] == '1') ? 0 : 1 + L[i - 1];
    idx = 0;
    while(B[idx] != '1')++idx;
    R[n-1] = (B[n-1] == '1') ? 0 : 1 + idx;
    RFOR(i, n-1, 0)
        R[i] = (B[i] == '1') ? 0 : 1 + R[i + 1];
    
    int ans = INF;
    
    FOR(shift, 0, n)
    {
        FOR(i, 0, n)MX[i] = 0;
        
        int k = 0;
        FOR(i, 0, n)
        {
            int idx = i + shift;
            if (idx >= n)idx -= n;
            if (A[i] == B[idx])continue;
            k++;
            MX[L[i]] = max(MX[L[i]], R[i] - shift);
        }
        int r = 0;
        RFOR(l, n, 0)
        {
            int res = (r + l) * 2 + shift;
            ans = min(ans, res + k);
            r = max(r, MX[l]);
        }
    }
    return ans;
    
}

int main()
{
    string A, B;
    cin >> A >> B;
    
    int ca = 0, cb = 0;
    FOR(i, 0, SZ(A)) ca += A[i] == '1';
    FOR(i, 0, SZ(B)) cb += B[i] == '1';
    if (!cb)
    {
        cout << (ca ? -1 : 0) << endl;
        return 0;
    }
    
    int ans = solve(A, B);
    reverse(ALL(A));
    reverse(ALL(B));
    ans = min(ans, solve(A, B));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main() {
  int i, N, D, count=0;
  double distance;
  
  scanf("%d%d", &N, &D);
  
  long long int X[N], Y[N];
  
  for(i=0; i<N; i++) {
    scanf("%lld%lld", &X[i], &Y[i]);
  }
  
  for(i=0; i<N; i++) {
    distance = sqrt(X[i]*X[i] + Y[i]*Y[i]);
    //printf("%lf\n", distance);
    
    if(distance<=D) {
      count++;
    }
    
  }
  
  printf("%d\n", count);
  
  return 0;
  
}

Measured memory_bytes: 5272
n,k=map(int,input().split())
P=[int(i) for i in input().split()]
import collections
from collections import deque
M1,M2=deque(),deque()
A1,A2=[],[]
M1.append(0)
for i in range(1,n):
  while M1:
    if P[M1[-1]]>P[i]:
      M1.pop()
    else:
      M1.append(i)
      break
  if not M1:
    M1.append(i)
  if M1[0]==i-k-1:
    M1.popleft()
  if i<k:
    continue
  else:
    A1.append(P[M1[0]])
M2.append(0)
for i in range(1,n):
  while M2:
    if P[M2[-1]]<P[i]:
      M2.pop()
    else:
      M2.append(i)
      break
  if not M2:
    M2.append(i)
  if M2[0]==i-k-1:
    M2.popleft()
  if i<k:
    continue
  else:
    A2.append(P[M2[0]])
ans=1
for i in range(n-k):
  if A1[i]==P[i] and A2[i]==P[i+k]:
    continue
  else:
    ans+=1
Q=[0]*n
for i in range(1,n):
  if P[i]>P[i-1]:
    Q[i]=Q[i-1]+1
  else:
    continue
count=0
for i in range(n):
  if Q[i]==k-1:
    count+=1
print(ans-max(0,count-1))

Measured memory_bytes: 27112
from collections import deque

H, W = [int(x) for x in input().split()]
cell = [list(input()) for i in range(H)]

painted = deque()
for h in range(H):
    for w in range(W):
        if cell[h][w] == '#':
            painted.append([h, w, 0])

ans = 0
while len(painted) > 0:
    blackcell = painted.popleft()
    for dy, dx in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
        nh = blackcell[0] + dy
        nw = blackcell[1] + dx
        d = blackcell[2]
        if 0 <= nh and nh < H and 0 <= nw and nw < W and cell[nh][nw] == '.':
            cell[nh][nw] = '#'
            painted.append([nh, nw, d + 1])
        ans = d

print(ans)

Measured memory_bytes: 176092
import sys

n = int(input())
money = 0
for i in range(n):
	y = sys.stdin.readline().rstrip('\n')
	a,b = y.split(' ')
	x = float(a)
	if b == 'JPY':
		money = money + x
	else:
		money = money + x * 380000.0

print(money)



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

int main(int argc, char **argv)
{
	ll n; cin >> n;
	vector<ll> a(n), b(n);
	for (ll i = 0; i < n; ++i)
		cin >> a[i] >> b[i];

	ll res{0};
	for (ll i = n-1; i >= 0; --i)
	{
		a[i] += res;
		if (a[i] % b[i] == 0) continue;
		res += b[i] - (a[i] % b[i]);
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 1792
n = int(input())
mass = list(map(int,input().split()))
tmp = 0
ans = 0
for i in range(n-1):
  if mass[i+1]-mass[i]<=0:
    tmp += 1
  else:
    if tmp > ans:
      ans = tmp
    tmp = 0
#  print(tmp,ans)
if tmp > ans:
  ans = tmp
print(ans)

Measured memory_bytes: 15020
def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)

N = int(input())
if digitSum(N)%9 == 0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 10988
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>

using namespace std;

long long mod = 10e8 + 7;

long long powx(long long n) {
    if (n == 1) {
        return 1LL;
    } else {
        return (n * powx(n-1))%mod;
    }
}

void solve(long long n, long long m) {
    if (n > m) {
        long long tmp = n;
        n = m;
        m = tmp;
    }
    if (n == m) {
        long long x = powx(n);
        std::cout << (((x*x)%mod)*2)%mod << std::endl;
    } else if(m-n == 1) {
        long long x = powx(n);
        std::cout << (((x*x)%mod)*m)%mod << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }
}

int main() {
    struct timeval start,end;
    long long span;
    long long n, m;

    gettimeofday(&start,NULL);

    std::cin >> n >> m;
    solve(n, m);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 1792
N, *ds = $<.read.split.map(&:to_i)
ds = (ds+[0,24]).sort
1.step(N,2) {|i| ds[i] = 24-ds[i]}
min = 24
ds.sort.each_cons(2) { |a,b| min=[min,b-a].min }
p min

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

void solve(long long X, long long A, long long B)
{
    cout << (X - A) % B << 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 X;
    scanf("%lld", &X);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(X, A, B);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a[100],c[100],d[100],flag=0;
    a[0]=0;
    int b;
    scanf("%d",&b);
    int i,count=0,j=0;
    for(i=1;i<=b;i++){
        scanf("%d",&a[i]);
        if(a[i]!=i){
            flag=1;
            count++;
            c[j]=i;
            d[j]=a[i];
            j++;
        }
    }
    if(flag==0){
        printf("YES");
        return 0;
    }
    if(count>2){
        printf("NO");
        return 0;
    }
    else{
        if(c[0]==d[1] && c[1]==d[0])
            printf("YES");
        else
            printf("NO");
    }
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a[n];
  int odd_count = 0;
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] % 2 != 0) {
      odd_count++;
    }
  }
  cout << (odd_count % 2 == 0 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main() {
	int x, a, b;
	bool stop = false;
	a = 0;
	b = 0;
	cin >> x;
	while(b <= 1000) {
		while (a<1000) {
			if (a*a*a*a*a == x + b * b*b*b*b) {
				stop = true;
				break;
			}
			else if (-(a*a*a*a*a) == x + b * b*b*b*b) {
				a = -a;
				stop = true;
				break;
			}

			a += 1;
		}
		if (stop) {
			break;
		}
		if (b > 0) {
			b = -b;
		}
		else {
			b = -(b-1);
		}
		a = 0;
	}
	cout << a << " " << b;
}

Measured memory_bytes: 3620
local PairingHeap={}

PairingHeap.merge=function(self,a,b)
	if not a then
		return b
	elseif not b then
		return a
	elseif a[1]<b[1] then
		b[4]=a[3]
		a[3]=b
		return a
	else
		a[4]=b[3]
		b[3]=a
		return b
	end
end

PairingHeap.twopassmerge=function(self,a)
	local b=a and a[4]
	if b then
		local newnode=b[4]
		a[4]=false
		b[4]=false
		return self:merge(self:merge(a,b),self:twopassmerge(newnode))
	else
		return a
	end
end

PairingHeap.empty=function(self)
	return not self.root
end

PairingHeap.pop=function(self)
    local root=self.root
    local value=root[2]
	self.root=self:twopassmerge(root[3])
    for i=1,4 do
        root[i]=false
	end
	table.insert(self,root)
    return value
end

PairingHeap.push=function(self,key,value)
    local root=self.root
	if root and root[1]<key then
		root[3]={
            key,
            value,
            false,
            root[3],
        }
    else
		self.root={
            key,
            value,
            root,
            false,
        }
	end
end

PairingHeap.join=function(self,other)
	local a=self.root
	local b=other.root
	if a[1]<b[1]then
		b[4]=a[3]
		a[3]=b
	else
		a[4]=b[3]
		b[3]=a
		self.root=b
	end
	return self
end

PairingHeap.new=function(self)
    local obj={}
    setmetatable(obj,{__index=PairingHeap})
    return obj
end

----------

local xyz={io.read("n","n","n")}
local k=io.read("n")
local abc={}
for i=1,3 do
    abc[i]={}
    for j=1,xyz[i] do
        abc[i][j]=io.read("n")
    end
    table.sort(abc[i],function(a,b)
        return a>b
    end)
end

local pq=PairingHeap:new()
local map={}

local frstky=abc[1][1]+abc[2][1]+abc[3][1]
pq:push(-frstky,{1,1,1,frstky})

for i=1,k do
    local pop=pq:pop()
    print(pop[4])
    for j=1,3 do
        if pop[j]<xyz[j] then
            local key=pop[4]-abc[j][pop[j]]+abc[j][pop[j]+1]
            local val={pop[1],pop[2],pop[3],key}
            val[j]=val[j]+1
            local mapkey=tostring(key)
            for l=1,3 do
                mapkey=mapkey.." "..val[l]
            end
            if not map[mapkey] then
                map[mapkey]=true
                pq:push(-key,val)
            end
        end
    end
end

Measured memory_bytes: 4668
A,B,K = map(int, input().split())
if B-A+1 >= K:
    s = [i for i in range(A,A+K)]
    l = [j for j in range(B-K+1,B+1)]
    for k in l:
        s.append(k)
    w = sorted(set(s))
else:
    w = [b for b in range(A,B+1)]
for j in w:
    print(j)
    

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int A, B, C;
    cin >> A >> B >> C;
    cout << ((A * 100 + B * 10 + C)%4 == 0 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
import sys

import numpy as np

input = sys.stdin.readline


def main():
    N, W = map(int, input().split())
    wv = [0] * N
    for i in range(N):
        wv[i] = tuple(map(int, input().split()))

    INF = 10 ** 10
    V = sum(v for _, v in wv)
    dp = np.full(shape=(V + 1), fill_value=INF, dtype=np.int64)
    dp[0] = 0
    for w, v in wv:
        dp[v:] = np.minimum(dp[v:], dp[:-v] + w)

    ans = np.where(dp <= W)[0][-1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 29204
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int r,c,n,cnt;
struct node{
	int x,y,t,id;
	node(){};
	node(int xx,int yy,int ii){
		x=xx;y=yy;id=ii;
		if(x==0) t=1;
		else if(y==0) t=2;
		else if(x==r) t=3;
		else if(y==c) t=4;
	}
}a[1000010];
inline bool cmp(node l,node r){
	if(l.t!=r.t) return l.t<r.t;
	else{
		if(l.t==1) return l.y>r.y;
		if(l.t==2) return l.x<r.x;
		if(l.t==3) return l.y<r.y;
		if(l.t==4) return l.x>r.x;
	}
}
int s[1000010],top;
int main(){
	r=read();c=read();n=read();int i,t1,t2,t3,t4;
	for(i=1;i<=n;i++){
		t1=read();t2=read();t3=read();t4=read();
		if((t1==0||t2==0||t1==r||t2==c)&&(t3==0||t4==0||t3==r||t4==c)){
			a[++cnt]=node(t1,t2,i);
			a[++cnt]=node(t3,t4,i);
		}
	}
	sort(a+1,a+cnt+1,cmp);
	for(i=1;i<=cnt;i++){
		if(s[top]==a[i].id) top--;
		else s[++top]=a[i].id;
	}
	if(!top) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(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()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(rAll(A));
    int sum=A[0]/2;
    rep(i,1,N) sum+=A[i];
    cout<<sum<<endl;
}


Measured memory_bytes: 256
n = int(input())
if n == 0:
  print(0)
else:
  ans = ""
  now = 0
  while n:
    r = n % (2**(now+1))
    if r:
      ans = "1" + ans
      n -= (-2)**now
    else:
      ans = "0" + ans
    now += 1
  print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
 
int main(int argc, const char * argv[]) {
 
    string N = "";
    cin >> N;
    
    int result = N.find("7");
    
    if (result == string::npos) {
        cout << "No";
    }else{
        cout << "Yes";
    }
    
    return 0;
}

Measured memory_bytes: 3628
//package test;

import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int sum = 0;
		for (int i = 0; i < 5; i++) {
			sum += sc.nextInt();
		}
		System.out.println(15 - sum);
		sc.close();
	}
}

Measured memory_bytes: 35692
package main

import (
	"fmt"
)

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

	m1 := make(map[byte]map[byte]bool)
	m2 := make(map[byte]map[byte]bool)
	for i := byte('a'); i <= byte('z'); i++ {
		m1[i] = make(map[byte]bool)
		m2[i] = make(map[byte]bool)
	}
	for i := range s {
		m1[s[i]][t[i]] = true
		m2[t[i]][s[i]] = true
	}
	for _, v := range m1 {
		if len(v) > 1 {
			fmt.Println("No")
			return
		}
	}
	for _, v := range m2 {
		if len(v) > 1 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 2304
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int n,d[2];
vvi G;
vi in,used,c;
void dfs(int a){
	rep(i,G[a].size()){
		int to=G[a][i];
		if(c[to]+1)continue;
		c[to]=c[a]^1;
		dfs(to);
	}
}
int main(){
	cin>>n>>d[0]>>d[1];
	rep(i,2*n)rep(j,2*n)in.pb(i*2*n+j);
	used=vi(in.size(),1);
	
	vi sqr(1000000);
	rep(i,1000000)sqr[i]=(sqrt(i)+EPS);
	rep(q,2){
		G=vvi(in.size());
		rep(i,in.size())if(used[i])rep(j,2*n){
			int x=in[i]/(2*n),y=in[i]%(2*n);
			int dis=d[q]-(x-j)*(x-j);
			if(dis<0)continue;
			int t=sqr[dis];
			if(t*t!=dis)continue;
			if(y-t>=0&&used[2*n*j+y-t])G[i].pb(2*n*j+y-t);
			if(t&&y+t<2*n&&used[2*n*j+y+t])G[i].pb(2*n*j+y+t);
		}
		c=vi(in.size(),-1);
		rep(i,c.size())if(used[i]&&c[i]==-1){
			c[i]=0;
			dfs(i);
		}
		int co1=0,co2=0;
		rep(i,c.size())if(c[i]==0)co1++;
		else if(c[i]==1)co2++;
		int t=0;
		if(co1<co2)t=1;
		rep(i,in.size())if(used[i]&&t!=c[i])
			used[i]=0;
		
	}
	int co=n*n;
	rep(i,in.size())if(used[i]&&co){
		cout<<in[i]/(2*n)<<" "<<in[i]%(2*n)<<endl;
		co--;
	}
}







Measured memory_bytes: 84080
import math 
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)] 
count = 0
 
for i in range(n):
  for j in range(i+1, n):
    add,dis = 0,0
    for k in range(d): 
      add += (x[i][k] - x[j][k]) ** 2 
      dis = math.sqrt(add)
    if dis % 1 == 0:
      count += 1
print(count)

Measured memory_bytes: 3064