akhauriyash/Code-Regression huggingface dataset:
[N,D] = map(int,input().split())
Z = [input() for i in range(N)]
c = 0

for i in range(N):
    W = Z[i].split()
    x = int(W[0])
    y = int(W[1])
    dxy = x**2+y**2
    if D**2 >= dxy :
        c = c + 1

print(c)

Measured memory_bytes: 23020
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

s = input()[:-1]

if s[0] == "1" and s[-1] == "0":
	k = (len(s)-2)//2

	for i in range(k):
		if s[i] != s[-(2 + i)]:
			print(-1)
			exit()
	else:
		
		la = len(s)

		for i in range(la-2,-1,-1):
			if s[i] == "1":
				print(i+1,la)
				la = i+1
			else:
				print(i+1,la)
else:
	print(-1)

Measured memory_bytes: 75612
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    long ans;
    foreach (i; 1 .. N)
        if (A[i - 1] == A[i])
        {
            A[i] = 0;
            ans++;
        }
    writeln(ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    int A = s1.length();
    int B = s2.length();
    int C = s3.length();

    char ans;
    int a = 0, b = -1, c = -1;
    bool f = true;
    string S = s1;
    int i = a;
    while (f == true){
        if (S == s1 && i == A){
            ans = 'A';
            f = false;
        }else if(S == s2 && i == B){
            ans = 'B';
            f = false;
        }else if(S == s3 && i == C){
            ans = 'C';
            f = false;
        }else if(S[i] == 'a'){
            a ++;
            S = s1;
            i = a;
        }else if(S[i] == 'b'){
            b ++;
            S = s2;
            i = b;
        }else if(S[i] == 'c'){
            c ++;
            S = s3;
            i = c;
        }   
    }
    
    
    cout << ans << endl;


    return 0;
}

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

int main(){
	map<string, set<int> > index;
	string s;
	int n;
	while(cin >> s >> n)
		index[s].insert(n);
		
	map<string,set<int> >::iterator it = index.begin();
	while(it != index.end()){
		cout << it->first << endl;
		set<int>::iterator its = (it->second).begin();
		while(its != (it->second).end()){
			cout << *its;
			cout << (++its != (it->second).end() ? " " : "\n");
		}
		++it;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
  ll X;
  cin >> X;
  for(ll i = 1;;i++){
    ll sum = i * (i + 1) / 2;
    if(X <= sum){
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<

const int MOD = 1000000007;

long long max(long long a,long long b){
	if(a<b)return b;
	else return a;	
}
long long min(long long a,long long b){
	if(a>b)return b;
	else return a;	
}
long long gcd(long long a,long long b){
	if(a<b)swap(a,b);
	if(a%b==0)return b;
	else return gcd(a%b,b);
}

long long lcm(long long a,long long b){
	return a*b/gcd(a,b);
}

long long com(long long n,long long k){
	
}
long long getDigit(long long n){
	if(n==1)return 1;
	else return log10(n)+1;
}

class Point{
public:
	long long x;
	long long y;
};


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N;
	cin>>N;
	vector<int>T(N+1);
	long long sum=0;
	for(int i=1;i<=N;i++){
		cin>>T[i];
		sum+=T[i];
	}
	int M;
	cin>>M;
	long long ans=0;
	for(int i=0;i<M;i++){
		int p,x;
		cin>>p>>x;
		ans=T[p]-x;
		cout<<sum-ans<<endl;
	}
}


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

int main(){
    string s;cin>>s;
    int acc = 0;
    string previous_word = "";
    string current_word = "";

    for (int i=0;i<s.size();i++){
        current_word += s[i];
        if (previous_word != current_word){
            acc++;
            previous_word = current_word;
            current_word = "";
        }
    }
    cout << acc << endl;
    return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll gcd(ll a, ll b)
{
    return (b ? gcd(b, a % b) : a);
}
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    int n;
    cin >> n;
    map<int, int> a; //I,love
    rep(i, n)
    {
        int x;
        cin >> x;
        a[i] = x - 1;
    }
    int counter = 0;
    rep(i, n)
    {
        if (a[a[i]] == i)
        {
            counter++;
            //cout << "(" << a[i] << "," << a[a[i]] << ")";
            //ed;
        }
    }
    counter /= 2;
    c(counter);
    return 0;
}


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

int main(){
  int N;
  long long Li = 1;
  long long Lp = 2;
  long long L = 1;
  cin >> N;
  for(int i=2; i<=N; i++){
    L = Li + Lp;
    Lp = Li;
    Li = L;
  }
  cout << L << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
using LL = long long;
LL N;
LL P, Q;
LL C[567890];
LL E[567890];

int main() {
	cin >> N >> P >> Q;
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
		E[i] = C[i] - P * (Q + i + 2 * (N - 1 - i));
	}
	sort(E, E + N);
	for (int i = N - 1; i >= 0; --i) {
		E[i] += E[i + 1];
	}
	LL V = P * (Q * N + (N - 1) * N / 2);
	LL ans = V;
	for (LL K = 1; K <= N; ++K) {
		ans = max(ans, V + K * (K - 1) * P + E[N - K]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10976
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int N;

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

	if(N >= 1000) printf("ABD\n");
	else printf("ABC\n");

	return 0;
}

Measured memory_bytes: 256
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int ans[223456];
int s[212345],e[212345],x[212345];
int d[212345];

int main(){
    std::ios::sync_with_stdio(false); cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    int i;
    vii vec;
    rep(i,n){
    	cin>>s[i]>>e[i]>>x[i];
    	e[i]--;
    	vec.pb(mp(x[i],i));
    }
    sort(all(vec));
    set<pii> seti;
    rep(i,q){
    	ans[i]=-1;
    	cin>>d[i];
    	seti.insert(mp(d[i],i));
    }
    set<pii> ::iterator it;
    int ind;
    rep(i,n){
    	ind=vec[i].ss;
    	while(1){
    		it=seti.lower_bound(mp(s[ind]-x[ind],0));
    		if(it==seti.end())
    			break;
    		if(it->ff>e[ind]-x[ind])
    			break;
    		ans[it->ss]=vec[i].ff;
    		seti.erase(it);
    	}
    }
    rep(i,q){
    	cout<<ans[i]<<endl;
    }
    return 0;   
}


Measured memory_bytes: 17520
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    cout << (K%2==0 ? A-B : B-A) << endl;
    
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
n = int(input())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append([a+b, a, b])
AB.sort(reverse=True)

t = 0
for ab in AB[0::2]:
    t += ab[1]

a = 0
for ab in AB[1::2]:
    a += ab[2]
    
print(t - a)

Measured memory_bytes: 23260
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        if ((i + 1) % 5 != 0 && (i + 1) % 3 != 0) {
            sum += i + 1;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int main() {
	int a,b;
	cin>>a>>b;
	if(a+b==15)cout<<'+'<<endl;
    if(a*b==15)cout<<'*'<<endl;
    if(a*b!=15 && a+b!=15)cout<<'x'<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
As = list(map(int, input().split()))
As.sort()
S = sum(As)
#print(S)
ds = []
for d in range(1, 30000):
  if S%d == 0:
    ds.append(d)
    ds.append(S//d)
ds.sort()
#print(ds)
for d in reversed(ds):
  Rs = [a%d for a in As]
  Rs.sort()
  s = sum(Rs)
  count = s//d
  r = 0
  for i in range(N-count):
    r += Rs[i]
  if r <= K:
    print(d)
    exit()


Measured memory_bytes: 3188
import sys
from bisect import bisect_left

def main():
    X,N=map(int,input().split())
    P=list(map(int,input().split()))

    if N==0:
        print(X)
        sys.exit()

    P.sort()

    ind=bisect_left(P,X)

    if (P[ind]!=X):
        print(X)
    else:
        left=ind-1
        right=ind+1
        leftX=X-1
        rightX=X+1

        flag=0
        while left>=0 or right<=N-1:
            if left>=0:
                if P[left]!=leftX:
                    print(leftX)
                    flag=1
                    break
            if right<=N-1:
                if P[right]!=rightX:
                    print(rightX)
                    flag=1
                    break

            left-=1
            right+=1
            leftX-=1
            rightX+=1

        if flag==0:
            left=ind+1
            right=(N-1)-ind+1
            if left<=right:
                print(X-left)
            else:
                print(X+right)


if __name__=="__main__":
    main()

Measured memory_bytes: 62352
n = gets.to_i
a = gets.split.map(&:to_i)

t = Array.new(n+1,0)
(1..n).reverse_each do |i|
    flg = 0;
    j = 2;
    while i*j<=n
        flg = flg ^ t[i*j]
        j+=1
    end
    t[i] = flg ^ a[i-1]
end

b = [];
(1..n).each do |i|
    b.push(i) if t[i]>0
end

puts b.size
puts b.join(" ")


Measured memory_bytes: 23484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for(int i=m; i<n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0; }
template <typename T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1;} return 0; }

struct UnionFind
{
    vi par;
    vi sizes;
    UnionFind(int n) : par(n), sizes(n,1){
        rep(i,0,n) par[i] = i;
    }
    int find(int x){
        if(par[x]==x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return;
        if(sizes[x]<sizes[y]) swap(x,y);
        par[y] = x;
        sizes[x] += sizes[y];
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
    int size(int x){
        return sizes[find(x)];
    }
};
int main() {
    int n,m; cin>>n>>m;
    UnionFind uf(n);
    rep(i,0,m){
        int x,y,z; cin>>x>>y>>z;
        x--,y--;
        uf.unite(x,y);
    }
    int ans[n]={0};
    rep(i,0,n){
        ans[uf.find(i)]++;
    }
    int res=0;
    rep(i,0,n) if(ans[i]>0) res++;
    cout<<res<<endl;
}

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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d = a / b;
    int r = a % b;
    double f = double(a) / double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
}


Measured memory_bytes: 3268
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	int N;
	cin >> N;
	set<int> dat;
	for (int i = 0; i < N; ++i) {
		int tmp;
		cin >> tmp;
		dat.insert(tmp);
	}
	puts(dat.size() == N ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/


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

	int n, k;
	cin >> n >> k;

	if (k == 1) cout << 0 << endl;
	else 
		cout << n - k << endl;


	return 0;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
if (H*W)%3==0:
    print(0)
    exit()
S=[H, W]
x=H//3
a=x*W;b=(H-x)*(W//2);c=(H*W)-a-b
S.append(max([a,b,c])-min([a,b,c]))
x+=1
a=x*W;b=(H-x)*(W//2);c=(H*W)-a-b
S.append(max([a,b,c])-min([a,b,c]))
y=W//3
a=y*H;b=(W-y)*(H//2);c=(H*W)-a-b
S.append(max([a,b,c])-min([a,b,c]))
y+=1
a=y*H;b=(W-y)*(H//2);c=(H*W)-a-b
S.append(max([a,b,c])-min([a,b,c]))
print(min(S))


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

using lli = int64_t;
using vi = vector<lli>;
using vvi = vector<vi>;

int main()
{
    ios_base::sync_with_stdio(0);

    lli n; cin >> n;

    vvi v(3, vi(n));

    for(int i = 0; i < 3; i++)
    for(int j = 0; j < n; j++)
        cin >> v[i][j];

    for(int i = 0; i < 3; i++)
        sort(begin(v[i]), end(v[i]));

    vvi dp(3, vi(n));

    for(int i = n - 1; i >= 0; i--)
    {
        lli prev = i < n - 1 ? dp[2][i + 1] : 0;
        dp[2][i] = prev + 1;
    }

    for(int i = 1; i >= 0; i--)
    {
        for(int j = n - 1; j >= 0; j--)
        {
            auto it = lower_bound(begin(v[i + 1]), end(v[i + 1]), v[i][j]);

            if(it == end(v[i + 1])) continue;

            if(*it == v[i][j])
                it = lower_bound(begin(v[i + 1]), end(v[i + 1]), v[i][j] + 1);

            if(it == end(v[i + 1])) continue;

            int ndx = it - begin(v[i + 1]);

            lli prev = j < n - 1 ? dp[i][j + 1] : 0;

            dp[i][j] = prev + dp[i + 1][ndx];
        }
    }

    cout << dp[0][0] << endl;
    return 0;
}

Measured memory_bytes: 5744
from collections import defaultdict

def main():
    n = int(input())
    l = defaultdict(int)
    r = defaultdict(int)
    for i, ai in enumerate(map(int, input().split())):
        l[i - ai] += 1
        r[i + ai] += 1
    print(sum(l[i] * r[i] for i in range(1, n - 1)))

if __name__ == '__main__':
    main()

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

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector< std::pair< int, int > > DT(N);
    for(int i=0; i<N; i++){
        std::cin >> DT[i].second >> DT[i].first;
        DT[i].second--;
    }
    
    std::sort(DT.begin(), DT.end());
    
    std::vector< bool > eat_type(N, false);
    long long eat_type_num = 0;
    std::deque< int > next;
    std::deque< int > dup;
    long long score = 0;
    
    for(int i=0; i<K; i++){
        score += DT[N - i - 1].first;
        if(eat_type[DT[N - i - 1].second]){
            dup.push_back(DT[N - i - 1].first);
        }else{
            eat_type[DT[N - i - 1].second] = true;
            eat_type_num++;
        }
    }
    
    for(int i=K; i<N; i++){
        if(eat_type[DT[N - i - 1].second]){
        }else{
            next.push_back(DT[N - i - 1].first);
            eat_type[DT[N - i - 1].second] = true;
        }
    }
    
    long long score_max = score + eat_type_num * eat_type_num;
    while(!next.empty() && !dup.empty()){
        int cur_next = *next.begin();
        int cur_dup = *dup.rbegin();
        next.pop_front();
        dup.pop_back();
        
        score = score - cur_dup + cur_next;
        eat_type_num++;
        score_max = std::max(score_max, score + eat_type_num * eat_type_num);
    }
    
    
    std::cout << score_max << std::endl;
    
    return 0;
    
}


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

int main(){
    ll n, a, b;
    cin>> n >> a >> b;

    ll ans;
    ans = n/(a+b)*a;

    n = n%(a+b);
    
    if(n-a >= 0){
        ans += a;
    }else{
        ans += n;
    }

    cout<< ans << endl;

    return 0;
}

Measured memory_bytes: 3640
/***

   Author : Md. Jashim Uddin
   From   : RMSTU

 ***/
#include<bits/stdc++.h>
using namespace std;
#define     sf(a)           scanf("%d",&a)
#define     sff(a,b)        scanf("%d %d",&a,&b)
#define     sfff(a,b,c)     scanf("%d %d %d",&a,&b, &c)
#define     pb              push_back
#define     ll              long  long int
#define     fast            ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define     pi              2*acos(0)
#define     sp              fixed<<setprecision
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     gcd(a,b)        _gcd(a,b)
#define     forn(i,n)       for(int i=1;i<=n;i++)
#define      mx               10001
int main()
{

    ll n;
    cin>>n;string s;
    cin>>s;
    if(n>=3200)cout<<s<<endl;
    else cout<<"red"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), fprintf(), scanf()
#include <stdlib.h>         // exit()
#include <string.h>         // strlen(), strcpy()

#define QUE_SIZE 100000
#define L_STRINGS (11 * 100000)

typedef struct que_tbl
{
	const char* name;
	int time;
} que_t;

int que_in;
int que_out;
que_t queue[QUE_SIZE];
char strings[L_STRINGS];
int ix;

void
cleanup(int ecode)
{
	exit(ecode);
}

int
que_size()
{
	if (que_in >= que_out)
		return que_in - que_out;

	return que_in + QUE_SIZE - que_out;
}

void
que_push(que_t* que)
{
	queue[que_in].name = que->name;
	queue[que_in].time = que->time;
	que_in++;
	if (que_in >= QUE_SIZE)
		que_in = 0;

	if (que_in == que_out)
	{
		fprintf(stderr, "Queue area overflow. size:%d\n", QUE_SIZE);
		cleanup(1);
	}
}

void
que_pop()
{
	if (que_out != que_in)
	{
		que_out++;
		if (que_out >= QUE_SIZE)
			que_out = 0;
	}
}

void
que_front(que_t* que)
{
	que->name = queue[que_out].name;
	que->time = queue[que_out].time;
}

int
main(int argc, char** argv)
{
	char name[11];
	int time;
	que_t que;
	int q;
	int n, i;
	int t;

	ix = 0;
	que_in = 0;
	que_out = 0;

	scanf("%d %d", &n, &q);
	for (i = 0; i < n; ++i)
	{
		scanf("%s %d", name, &t);
		que.name = &strings[ix];
		que.time = t;
		strcpy(&strings[ix], name);
		ix += strlen(name) + 1;
		que_push(&que);
	}

	time = 0;
	while (que_size() != 0)
	{
		que_front(&que); que_pop();
		if (que.time <= q)
		{
			time += que.time;
			printf("%s %d\n", que.name, time);
		}
		else
		{
			que.time -= q;
			time += q;
			que_push(&que);
		}
	}

	return 0;
}

Measured memory_bytes: 2504
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var N = int.Parse(inputs[0]);
        var K = int.Parse(inputs[1]);
        var x = new long[N];
        inputs = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
        {
            x[i] = long.Parse(inputs[i]);
        }

        long min = 1000000000;
        for (int i = 0; i < N - K + 1; i++)
        {
            var xl = x[i];
            var xr = x[i + K - 1];
            var lr = Math.Abs(xl) + Math.Abs(xr - xl);
            var rl = Math.Abs(xr) + Math.Abs(xr - xl);
            min = Math.Min(min, lr);
            min = Math.Min(min, rl);
        }

        Console.WriteLine(min);
    }

}



Measured memory_bytes: 22240
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    C = Counter(S)
    if C.most_common()[0][1]==1:
        print("yes")
    else:
        print("no")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main(){
	char masu[9][9]={""};
	for(int i=0;i<8;i++){
		for(int j=0;j<8;j++){
			cin>>masu[i][j];
		}
	}
	cout<<"90"<<endl;
	for(int i=0;i<8;i++){
		for(int j=7;j>=0;j--){
			cout<<masu[j][i];
		}
		cout<<endl;
	}
	cout<<"180"<<endl;
	for(int i=7;i>=0;i--){
		for(int j=7;j>=0;j--){
			cout<<masu[i][j];
		}
		cout<<endl;
	}
	cout<<"270"<<endl;
	for(int i=7;i>=0;i--){
		for(int j=0;j<8;j++){
			cout<<masu[j][i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3072
/* 
    @author : srinathbalaji_99
*/


#include<bits/stdc++.h>

#define PB push_back
#define MP make_pair
#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define PLL pair<long long, long long>
#define VL vector<long long>
#define VS vector<string>
#define VLL vector<PLL>
#define VVL vector<VL>
#define MPLL map<long long, long long>
#define UMPLL unordered_map<long long, long long>
#define SETL set<long long>
#define MSETL multiset<long long>
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) (a * b)/GCD(a, b)
#define ff first
#define ss second
#define pall(a) REP(i, sizeof(a)/sizeof(a[0]))cout << a[i] << " ";cout << endl;
#define pvall(v) REP(i, v.size())cout << v[i] << " ";cout << endl;
#define gall(a, n) REP(i, n)cin >> a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef unsigned long long ULL;
typedef long long LL;
typedef long double LD;


using namespace std;

void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

LL dp[100001], h[100001];

int main()
{
    fast();

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    LL t,n,i,j,k,x,y,c;
    cin >> n;
    gall(h, n);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    rep(i, 2, n, 1){
        dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
    }
    cout << dp[n - 1];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll a,b,ans;
  cin>>a;
  b=a/1000;
  ans=(b+1)*1000-a;
  if(ans==1000){
    cout<<0<<endl;
  }else{
    cout<<ans<<endl;
  }

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
#define loop(i,a,n) for (int i = (a); (i) < (n); ++ (i))
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF (int)1e9
#define MOD 0
//#define int ll
using namespace std;
typedef vector<long long> vl;

signed main() {
  int N,ai;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  vl a(N,0);
  rep(i,N-1) {
    cin >> ai;
    a[ai-1]++;
  }
  rep(i,N) {
    cout << a[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 4780
#include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	int p,q;
	for(;cin>>p>>q,p;){
		vector<string>P(p),Q(q);
		vector<int>indent(p),a(q,-2);
		getline(cin,P[0]);
		for(int i=0;i<p;i++){
			getline(cin,P[i]);
			for(;P[i][indent[i]]=='.';indent[i]++);
		}
		for(int i=0;i<q;i++){
			getline(cin,Q[i]);
		}
		for(int R=1;R<21;R++)for(int C=1;C<21;C++)for(int S=1;S<21;S++){
			int k=0;
			auto f=[&](const string &s){
				for(auto &x:s){
					if(x=='(')k+=R;
					if(x==')')k-=R;
					if(x=='{')k+=C;
					if(x=='}')k-=C;
					if(x=='[')k+=S;
					if(x==']')k-=S;
				}
			};

			if(![&]{
				for(int i=0;i<p;i++){
					if(k!=indent[i])return false;
					f(P[i]);
				}
				return true;
			}())continue;
			k=0;
			for(int i=0;i<q;i++){
				if(a[i]==-2)a[i]=k;
				if(a[i]!=k)a[i]=-1;
				f(Q[i]);
			}
		}
		for(int i=0;i<a.size();i++)printf(i<a.size()-1?"%d ":"%d\n",a[i]);
	}
}

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

int main(){
	ll a,v;	cin>>a>>v;
 	ll b,w;	cin>>b>>w;
  	ll t;	cin>>t;
  if(v>w){
  	double temp=abs(b-a)*(1.0);
    double tm=v-w;
   	double p=(temp/tm);
    if(p<=t){
    	cout<<"YES"<<endl;
    }
    else{
    	cout<<"NO"<<endl;
    }
  }
  else{
  	cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define N 200010
using namespace std;
const int p=1e9+7;
int n,cnt,x,a[N],pre;
long long dp[N],ans[N];
inline int read(){
	int x=0,sgn=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')sgn=-1;
	for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
return sgn*x;
}
int main(){
	n=read();pre=-100;
	for(int i=1;i<=n;i++){
		x=read();
		if(x==pre) continue;
		pre=x;a[++cnt]=x;
	}dp[1]=1;ans[a[1]]=1;
	for(int i=2;i<=cnt;i++){
		dp[i]=(dp[i-1]+ans[a[i]])%p;
		ans[a[i]]=dp[i];
	}
	printf("%d",dp[cnt]); 
return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define gcd __gcd

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

ll a[SIZE];
int main() {
	start = clock();
	int n;
	scanf("%d", &n);
	for (int i = 0 ; i < n ; ++i) scanf("%lld", &a[i]);
	if (a[n - 1] != 2) {
		cout << -1 << endl;
		return 0;
	}
	ll curr0 = 2, curr1 = 2;
	bool poss = true;
	a[n] = 2;
	for (int i = n ; i > 0 ; --i) {
		curr0 = ((curr0 % a[i - 1] == 0) ? curr0 / a[i - 1] : curr0 / a[i - 1] + 1);
		curr0 *= a[i - 1];
		curr1 = (curr1 / a[i - 1]) * a[i - 1] + a[i - 1] - 1;
		if (curr0 > curr1) {
			poss = false;
			break;
		}
	}
	if (!poss) cout << -1 << endl;
	else cout << curr0 << " " << curr1 << endl;

	Time(false);
	return 0;
}

Measured memory_bytes: 1024
S = list(input())

def judge(s):
    if s == "A" or s == "C" or s =="G" or s =="T":
        return True
    else:
        return False

pt_l,pt_r,ans = 0,0,0
while pt_r < len(S):
    if judge(S[pt_r]):
        pt_r += 1
    else:
        ans = max(ans,pt_r - pt_l)
        pt_l = pt_r+1
        pt_r = pt_l
ans = max(ans,pt_r - pt_l)
print(ans)


Measured memory_bytes: 3060
import java.util.*;
public class Main {

    
    public static void main(String[] args) {
   Scanner sc=new Scanner(System.in); 
    int n=sc.nextInt();
    int a[]=new int[n];
    for(int i=0;i<n;i++)
    {
     a[i]=sc.nextInt(); 
    }
   int dp[]=new int[n];
   dp[0]=0;
   dp[1]=Math.abs(a[1]-a[0]);
   for(int i=2;i<n;i++)
   {
       dp[i]=Math.min(dp[i-1]+(Math.abs(a[i]-a[i-1])) , dp[i-2]+Math.abs(a[i]-a[i-2]));
   }
        System.out.println(dp[n-1]);
    
  }
    
}


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

string R;
bool success = true;
int main() {
	cin >> R;
	int num = 0;
	for (int i = 0; i < R.length(); i++){
		if (i == 0 && R[i] != 'A'){
			success = false;
			break;
		} else if ((i == 1 || i == R.length()-1) && (R[i] >= 'A' && R[i] <= 'Z')) {
			success = false;
			break;
		} else if ((i > 1 && i < R.length() - 1) && (R[i] >= 'A' && R[i] <= 'Z') && R[i] != 'C'){
			success = false;
			break;
		}
		if (R[i] == 'C') num++;
	}
	if (num == 1 && success) {
		cout << "AC" << endl;
	} else {
		cout << "WA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

template<typename T>
void p(T elem) {cout << elem << endl;}
template<typename T>
void ps(vector<T>& arr) { for(T e: arr) p(e); }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

int main(void) {
    int num, k;
    cin >> num >> k;
    vector<int> arr(num);
    cins(arr);
    int sum = 0;
    for(int elem: arr) {
        sum += elem;
    }
    int sum_2 = sqrt(0.5+sum);
    vector<int> divs;
    for(int i = 1; i <= sum_2; i++) {
        if(sum%i) continue;
        divs.push_back(i);
        if(i*i==sum) continue;
        divs.push_back(sum/i);
    }
    sort(divs.begin(), divs.end(), greater<int>());

    vector<int> diffs(arr.size());
    int ans = 0;
    for(int div: divs) {
        int64_t sum_diff = 0;
        for(int i = 0; i < arr.size(); i++) {
            diffs[i] = arr[i]%div;
            sum_diff += diffs[i];
        }

        sort(diffs.begin(), diffs.end(), greater<int>());
        int64_t sum_upper = 0;
        for(int i = 0; i < diffs.size(); i++) {
            if(sum_diff <= k) break;
            sum_diff -= diffs[i];
            sum_upper += (div-diffs[i]);
        }
        if(sum_diff <= k && sum_upper <= k) {
            ans = div;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int>>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int cnt = 0;
    int N = S.length();
    int n = N / 2;
    rep(i, n)
    {
        if (S[i] != S[N - 1 - i])
            cnt++;
    }
    cout << cnt << endl;
 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
n, m, k = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

a, b = [0], [0]
for i in range(n):
    a.append(a[i]+a_list[i])
for i in range(m):
    b.append(b[i]+b_list[i])

ans, j = 0, m	
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)

print(ans)

Measured memory_bytes: 47408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
    int n;
    string color;
    cin >> n;
    bool is_three = true;
    rep(i, n) {
        cin >> color;
        if (color == "Y") {
            is_three = false;
            cout << "Four" << endl;
            break;
        }
    }

    if (is_three) {
        cout << "Three" << endl;
    }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,y,ans,ic,uc,hc;
int main(){
    cin>>n>>y;


    for(int i=0;i<n+1;i++){
        if(1000*i>y||i>n)break;
        for(int u=0;u<n+1;u++){
            if(1000*i+5000*u>y||i+u>n)break;
            for(int h=0;h<n+1;h++){
                if(1000*i+5000*u+10000*h>y||i+u+h>n)break;
                if(1000*i+5000*u+10000*h==y&&i+u+h==n){
                    ic=h;
                    uc=u;
                    hc=i;
                    ans=1;
                    break;
                }
            }if(ans)break;
        }if(ans)break;
    }

    for(int i=0;i<1000000000*8;i++){
        int aho;
    }








    if(ans==1){
        cout<<ic<<" "<<uc<<" "<<hc<<endl;
    }else{
        cout<<"-1 -1 -1"<<endl;
    }
}


Measured memory_bytes: 256
using System;

namespace TEST
{
    class Program
    {
        private static void Main(string[] arg)
        {
            string[] x = Console.ReadLine().Split();
            ulong a = ulong.Parse(x[0]);
            decimal b = decimal.Parse(x[1]);
            decimal y = a * b;
            Console.WriteLine(Math.Truncate(y));

        }

    }
}

Measured memory_bytes: 27588
//Karol Kaszuba

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double D;
typedef long double LD;
typedef vector<PII> VII;
typedef unordered_set<int> USI;
typedef unordered_set<LL> USLL;

#define FOR(i,x,y) for(auto i=(x);i<=(y);++i)
#define REP(i,x) FOR(i,0,(x)-1)
#define FORD(i,x,y) for(auto i=(x);i>=(y);--i)
#define VAR(i,c) __typeof(c) i=(c)
#define FORE(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)
#define SIZE(c) (int)((c).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define EB emplace_back
#define IN insert
#define ER erase
#define MP make_pair
#define ST first
#define ND second
#define IOSYNC ios_base::sync_with_stdio(0)
#define FREOPEN(f) freopen(f, "r", stdin),freopen(f, "w", stdout)

int paga(int i) {
	cout << i << endl;
	string s;
	cin >> s;
	if (s == "Vacant") exit(0);
	return (s == "Male");
}

void jebaj() {
	int n;
	cin >> n;
	VI v(n, -1);
	int pocz = 0;
	int kon = n - 1;
	while (true) {
		int mid = (pocz + kon + 1) / 2;
		if (v[pocz] == -1) v[pocz] = paga(pocz);
		if (v[kon] == -1) v[kon] = paga(kon);
		if (v[mid] == -1) v[mid] = paga(mid);
		if ((mid + pocz + v[mid] + v[pocz]) % 2 == 1) {
			kon = mid;
		} else {
			pocz = mid;
		}
	}
}

int main() {
	//IOSYNC;
	int t;
	t = 1;
	while(t--) jebaj();
	return 0;
}


Measured memory_bytes: 1236
N = int(input())
A = list(map(int,input().split()))

MOD = 10**9+7

ans = sum(A)%MOD
ans *= sum(A)
ans %= MOD

temp = 0
for i in range(N):
    X = A[i]%MOD
    Y = X**2
    Y %= MOD
    temp += Y
    

    
print(((ans-temp)*pow(2, MOD-2, MOD)%MOD))

Measured memory_bytes: 31752
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 3005;

double p[N];
double dp[N][N];

signed main(){
    IOS;
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
    	cin >> p[i];
    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];
    for (int i = 2; i <= n; i++)
    	dp[i][0] = dp[i-1][0] * (1 - p[i]);
    for (int i = 1; i <= n; i++) {
    	for (int j = 1; j <= i; j++) {
    		if (i == 1 && j == 1) continue;
    		if (j > i) {dp[i][j] = 0; continue;}
    		dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
    	}
    }
    double ans = 0;
    for (int i = (n+1)/2; i <= n; i++)
    	ans += dp[n][i];
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 69120
#include<iostream>
using namespace std;
long long N,A,S,ans;
int main(void){
    cin>>N;
    for(int i=0;i<N;i++){cin>>A;if(A)S+=A;else ans+=S/2LL,S=0LL;}
    cout<<ans+S/2LL<<endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  string ans = "";
  if(a < b) {
    for(int i = 0; i < b; i++)
    {
      ans += to_string(a);
    }
  } else {
    for (int i = 0; i < a; i++)
    {
      ans += to_string(b);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
	long long int a, b;
	cin >> a >> b;
	if (a - b < 0) {
		b = a;
	}
	cout << a - b << endl;
	return 0;
}

Measured memory_bytes: 256
//abc047b
using System;

class program
{
	static void Main(string[] args)
	{
        int Xmin = 0, Ymin = 0, Xmax, Ymax;
        string[] input = Console.ReadLine().Split(' ');
        Xmax = int.Parse(input[0]);
        Ymax = int.Parse(input[1]);
        int N = int.Parse(input[2]);

        for(int k=1; k <= N; k++)
        {
            input = Console.ReadLine().Split(' ');
            int Ai = int.Parse(input[2]);
            switch (Ai)
            {
                case 1:
                    if (int.Parse(input[0]) > Xmin) Xmin = int.Parse(input[0]);
                    break;
                case 2:
                    if (int.Parse(input[0]) < Xmax) Xmax = int.Parse(input[0]);
                    break;
                case 3:
                    if (int.Parse(input[1]) > Ymin) Ymin = int.Parse(input[1]);
                    break;
                case 4:
                    if (int.Parse(input[1]) < Ymax) Ymax = int.Parse(input[1]);
                    break;
            }
        }
        int S = (Xmax - Xmin) * (Ymax - Ymin);
        if (Xmax - Xmin <0 || Ymax - Ymin <0) S = 0;
        Console.WriteLine(S);
    }
}


Measured memory_bytes: 2648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
            bool result = false;

            s = Console.ReadLine();

            Dictionary<char, int> dic = new Dictionary<char, int>();
            char key =(char)0;
            foreach (char c in s)
            {
                if (!dic.ContainsKey(c))
                {
                    dic.Add(c, 1);
                    key = c;
                }
                else
                {
                    dic[c]++;
                }
                if(dic.Count > 2)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            if(dic[key] ==2)            
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}



Measured memory_bytes: 13268
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>
#include <sstream>
#include <set>
#include <tuple>
#include <iomanip>

using namespace std;
#define MAX 1LL << 60

typedef long long ll;

#define rep(i, s, e) for(ll i = s; i < e; i++)
#define repR(i, s, e) for(ll i = s; i > e; i--)
#define reft0(i, j) setfill('0') << setw(i) << j

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; }

int main(){
    string S;
    string a, b;
    cin >> S;
    a = S.substr(0, 2);
    b = S.substr(2, 2);
    int ai, bi;
    ai = stoi(a);
    bi = stoi(b);

    if (ai <= 12 && bi <= 12 && 0 < ai && 0 < bi){
        cout << "AMBIGUOUS" << endl;
    }
    else if ((ai > 12 || 0 == ai) && bi <= 12 && 0 < bi){
        cout << "YYMM" << endl;
    }
    else if (ai <= 12 && (bi > 12 || 0 == bi) && 0 < ai){
        cout << "MMYY" << endl;
    }
    else{
        cout << "NA" << endl;
    }
 	return 0;
}


Measured memory_bytes: 256