akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

const double rate=380000;

int main(){
  int n;
  cin >> n;
  double x;
  string u;
  double ret=0;
  for(int i=0; i<n; i++){
    cin >> x >> u;
    if(u=="JPY")ret+=x;
    else ret+=rate*x;
  }
  cout << ret;
  return 0;
}


Measured memory_bytes: 888
n,m,x,y = map(int, input().split())
xi = list(map(int, input().split()))
yi = list(map(int, input().split()))
for i in range(x+1,y+1):
    if all(a<i for a in xi) and all(b>=i for b in yi):
        print("No War")
        break
else:
    print("War")

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();

		if(str.equals("Sunny")){
			System.out.println("Cloudy");
		}

		else if(str.equals("Cloudy")){
			System.out.println("Rainy");
		}
		else {
			System.out.println("Sunny");
		}
	}

}


Measured memory_bytes: 20564
a,b,m=map(int, input().split())
al=list(map(int, input().split()))
bl=list(map(int, input().split()))
tmp=[]
tmp.append(min(al)+min(bl))
for i in range(m):
    x,y,c=map(int, input().split())
    tmp.append(al[x-1]+bl[y-1]-c)
print(min(tmp))


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
void solve(void)
{
    int a, b;
    cin >> a >> b;
    if (b >= a)
        cout << a << endl;
    else
        cout << --a << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main()
{
char str[21] = { 0 };
int length;
cin >> str;
for (int i = 20; i >= 0; i--){
if (str[i] != 0){
length = i;
break;
}
}
	for (; length >= 0; length--)
		cout << str[length];
	cout << endl;
	return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define pb push_back

using namespace std;
using ll=long long;
using pii= pair<int, int>;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... T> void rd(T&... args) {((cin>>args), ...);}
template<typename... T> void wr(T... args) {((cout<<args<<" "), ...);cout<<endl;}

template <int MOD>
struct ModInt {
    int val;
    // constructor
    ModInt(ll v = 0) : val(int(v % MOD)) {
        if (val < 0) val += MOD;
    };
    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }
    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(ll n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }
    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = int(ll(val) * x.val % MOD);
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};
using mint=ModInt<int(1e9+7)>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    string s;
    cin>>k>>s;
    int n=sz(s);
    vector<mint> fac(2e6+5);
    fac[0]=1;
    for(int i=1;i<=2e6;i++) fac[i]=fac[i-1]*i;
    mint ans=0;
    auto C=[&](int n,int r)->mint{
        if(r>n) return 0;
        return fac[n]/fac[r]/fac[n-r];
    };
    for(int i=0;i<=k;i++){
        ans+=mint(25).pow(k-i)*mint(26).pow(i)*C(n-1+k-i,n-1);
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 12204
#include <bits/stdc++.h>
 
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main(){
 int N,a=300,count=0,first=-1,last=-1;
cin >>N;  int M[N];
rep(i,N){
cin >> M[i];
a=min(a,M[i]);
}
rep(i,N){
            M[i]-=a;
            
        }
count+=a;
   rep(i,N){
        a=300;
        rep(i,N){
            if(M[i]!=0&&first==-1){first=i;
        last=first;
            }
            else if(M[i]!=0)last++;
            else if(M[i]==0&&first!=-1)break;
        }
        for(int i=first;i<=last;i++){
            a=min(a,M[i]);
        }
           for(int i=first;i<=last;i++){
         M[i]-=a;
        }
        count+=a;
        first=-1;
        
    }
    cout<<count;
}



Measured memory_bytes: 256
use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).expect("Failed to read line");
    let n: i32 = n.trim().parse().expect("Please type a number!");
    
    if n % 2 == 0 {
        println!("{}", n);
    } else {
        println!("{}", n * 2);
    }
}


Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

//
#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double PI = (double)acos(-1);
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N, K;
  cin >> N >> K;

  if (2 * K - 1 <= N) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
from collections import Counter

N = int(input())
V = list(map(int, input().split()))

s1 = Counter(V).most_common(2)[0]
s2 = Counter(V).most_common(2)[0]
V1 = V[0::2]
V2 = V[1::2]
x1, c1 = Counter(V1).most_common(1)[0]
x2, c2 = Counter(V2).most_common(1)[0]
if x1 == x2:
    if c1 > c2:
        x2, c2 = Counter(V2).most_common(2)[1]
    elif c1 < c2:
        x1, c1 = Counter(V1).most_common(2)[1]
    elif c1 == c2 == N // 2:
        c1, c2 = N//2, 0
    else:

        x2, c2 = Counter(V2).most_common(2)[1]
        x3, c3 = Counter(V1).most_common(2)[1]
        c2 = max(c2, c3)

print(N - c1 - c2)

Measured memory_bytes: 21456
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[212345];
ll a[12345] = {1};

int main(){
	int n, p; scanf("%d%d%s", &n, &p, s);
	ll ans = 0;
	if(p == 2 || p == 5){
		REP(i, n) if((s[i] - '0') % p == 0) ans += i+1;
	} else {
		ll y = 1, z = 0;
		for(int i = n-1; i >= 0; i--){
			z += (s[i] - '0') * y;
			z %= p;
			a[z]++;
			y = y * 10 % p;
		}
		REP(i, p) ans += a[i] * (a[i] - 1) / 2;
	}
	printf("%lld\n", ans);
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,a,b,c;
ll dp[100010][3];

void input(){
	cin>>n;
	return;
}

void solve(){
	cin>>a>>b>>c;
	dp[0][0]=a;
	dp[0][1]=b;
	dp[0][2]=c;
	for(int i=1;i<n;i++){
		cin>>a>>b>>c;
		dp[i][0]=max(dp[i-1][1]+a,dp[i-1][2]+a);
		dp[i][1]=max(dp[i-1][0]+b,dp[i-1][2]+b);
		dp[i][2]=max(dp[i-1][0]+c,dp[i-1][1]+c);
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdint>
using namespace std;
 
int main(){
    int N, K;
 
    cin >> N >> K;
 
    long long residue_zero = N / K;
    
    long long ans = residue_zero * residue_zero * residue_zero;

    if(K % 2 == 0) {
        long long residue_k_half = (N + K / 2) / K;
        ans += residue_k_half * residue_k_half * residue_k_half;
    }
 
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
require 'mathn'
loop do
    x = gets.to_f
    break if x < 0
    if x >= 2 ** 8
        puts 'NA'
        next
    end
    t = 1
    until x == x.to_i
        x *= 10
        t *= 10
    end
    x = x.to_i / t
    k = 7
    s = ''
    until k < -4
        if x >= 2 ** k
            x -= 2 ** k
            s += ?1
        else
            s += ?0
        end
        s += ?. if k == 0
        k -= 1
    end
    if x > 0
        puts 'NA'
    else
        puts s
    end
end


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

lli n, T;

int main(void){
	cin >> n >> T;
	lli d = n*T;
	vector<lli> t(n);
	rep(i, n) cin >> t[i];
	rep(i, n-1){
		d-=max(t[i]+T-t[i+1], 0LL);
	}
	cout << d << endl;
	return 0;
}


Measured memory_bytes: 4816
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  	int N;
  	cin >> N;
  	vector<int> d(N);
  	for(int i = 0; i < N; i++){
      	cin >> d.at(i);
    }
	sort(d.begin(), d.end());
  	int ans = N;
  	for(int i = 0; i < N - 1; i++){
      	if(d.at(i) == d.at(i + 1)){
          	ans--;
        }
    }
  	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {

    private static final int MOD = 998244353;

    public Main(FastScanner in, PrintWriter out, int test) {
        int a = in.nextInt();
        int b = in.nextInt();
        int h = in.nextInt();
        int m = in.nextInt();

        double theta = PI * 2 * (h / 12.0 + m / (60.0 * 12) - m / 60.0);
        double csq = a * a + b * b - 2.0 * a * b * cos(theta);
        out.println(sqrt(csq));
    }

    private long pow(int x, int p) {
        long res = 1, a = x;
        while (p > 1) {
            if (p % 2 == 1)
                res = res * a % MOD;

            a = a * a % MOD;
            p /= 2;
        }
        res  = res * a % MOD;
        return res;
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        // int T = in.nextInt();
        for (int t = 1; t <= 1; t++) {
            Main sol = new Main(in, out, t);
        }

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}


Measured memory_bytes: 33340
import itertools

n = int(input())
p = [i for i in input().split()]
q = [i for i in input().split()]
ans = 0

r = [str(i) for i in range(1,n+1)] 

x = [list(i) for i in itertools.permutations(r)]
  
if x.index(p) >= x.index(q):
  ans = x.index(p) - x.index(q)
else:
  ans = x.index(q) - x.index(p)

print(ans)


Measured memory_bytes: 10228
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static ArrayList<Integer> rail = new ArrayList<Integer>();
	public static void main(String[] args) {

		while (sc.hasNext()) {
			train_rail( sc.nextInt() );
		}

	}

	private static void train_rail(int nextInt) {

		if (nextInt == 0) {
			System.out.println( rail.get(rail.size() -1) );
			rail.remove(rail.size() -1);
		} else {
			rail.add(nextInt);
		}

	}

}


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

#define ll              long long
#define pb              push_back
#define ff              first
#define ss              second
#define mp              make_pair

#define scan(a)         scanf("%d", &a)
#define scanl(a)        scanf("%lld", &a)
#define scand(a)        scanf("%lf", &a)
#define scan2(a, b)     scanf("%d %d", &a, &b)
#define scanl2(a, b)    scanf("%lld %lld", &a, &b)
#define scand2(a, b)    scanf("%lf %lf", &a, &b)

#define yes             cout << "yes\n"
#define no              cout << "no\n"
#define Case(i)         cout << "Case " << int(i) << ": "

#define lop(n)          for(int i = 0; i < n; i++)
#define lopj(n)         for(int j = 0; j < n; j++)
#define lopr(a, n)      for(int k = a; k < n; k++)
#define lrev(n, a)      for(int i = n; i >= a; i--)

#define all(x)          x.begin(), x.end()
#define mem(a, b)       memset(a, b, sizeof(a))

#define vin             vector <int>
#define vll             vector <ll>
#define vst             vector <string>
#define pll             pair <ll, ll>
#define pss             pair <string, string>
#define vpll            vector <pll>

#define fread           freopen("input.txt", "r", stdin)
#define fwrite          freopen("output.txt", "w", stdout)
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define mod             1000000007
#define PI              acos(-1.0)
#define inf             999999999999


using namespace std;


int main()
{
    fastio;

    int tt, n;

    cin >> tt;

    int x = 7 % tt;

    lop(tt)
    {
        if(!x)
        {
            cout << i + 1 << '\n';
            return 0;
        }

        x = (x * 10 + 7) % tt;
    }

    cout << -1 << '\n';

    return 0;
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, Q, str := ReadInt(), ReadInt(), ReadString()
	sum := make([]int, N+1)
	for i := 0; i < N-1; i++ {
		incr := 0
		if str[i:i+2] == "AC" {
			incr++
		}
		sum[i+1] = sum[i] + incr
	}
	for q := 0; q < Q; q++ {
		l, r := ReadInt(), ReadInt()
		fmt.Println(sum[r-1] - sum[l-1])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 6292
#include <iostream>
#include <set>

using namespace std;

int n;
set<string> gifts;

int main(int argc, char const *argv[]) {
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        gifts.insert(s);
    }
    cout << gifts.size() << endl;
    return 0;
}


Measured memory_bytes: 15720
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>m;

    for(int i=1;i<=n;i++){
        cin>>A[i];
        sum+=A[i];
    }

    a = (sum+(m<<2)-1)/(m<<2);

    for(int i=1;i<=n;i++)
        if(A[i]>=a)cnt++;

    if(cnt>=m)cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, ans = 0;
	cin >> nn;
	for(int64 ii = 1;ii <= nn;ii++)
	{
		int64 tmp = nn / ii;
		ans += tmp * (ii + ii * tmp) / 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("unroll-loops")
using namespace std;
using ll = long long;
#define rep(i, n) for(int i=0;i<(int)(n);++i)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<ll> vec(3 * n);
  for (ll i = 0; i < 3 * n; ++i) {
    cin >> vec[i];
  }
//  sort(vec, vec+3*n);
  sort(vec.begin(), vec.end(), greater<int>());
  ll ans = 0;
  for (ll i = 1; i < 2 * n; i+=2) {
    ans += vec[i];
  }
//  debug(ans);
  cout << ans << '\n';
}



Measured memory_bytes: 2560
#include <iostream>
#include <unordered_map>

int main(void) {
    int N, buf;
    std::unordered_map<int, int> m;

    std::cin >> N;

    for(int i = 0; i < N; i++) {
        std::cin >> buf;
        m[buf]++;
    }

    int ans = 0;
    for(auto i : m) {
        if(i.first > i.second)
            ans += i.second;
        else
            ans += i.second - i.first;
    }

    std::cout << ans << std::endl;
}


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

// NOTE : there's get and sum method.
// NOTE : access i < n only
/// --- BIT Library {{{ ///

template<class T = long long>
struct BIT{
  vector<T> data;
  int n;
  BIT(int n): n(n){
    data.resize(n, 0);
  }
  void clear(int sz=0) {
    if(sz > 0) n = sz;
    data.resize(n, 0);
  }
  void add(int i, T x) {
    i++;
    while(i <= n){
      data[i - 1] += x;
      i += i & -i;
    }
  }
  T sum(int i) {
    if(i < 0) return 0;
    i++;
    T s = 0;
    while(i > 0){
      s += data[i - 1];
      i -= i & -i;
    }
    return s;
  }
  T get(int i) {
    return sum(i) - sum(i - 1);
  }
  T range(int a, int b) {
    return sum(b) - sum(a - 1);
  }
};

/// }}}--- ///

BIT<> ecasdqina(212345);

ll a[212345];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  // バブルソートの交換回数（いつもの
  int n; ll k; cin >> n >> k;
  ll sum = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    ll s = sum;
    sum += a[i];
    a[i] = -s + k * i;
  }
  a[n] = -sum + k * n;
  vector<int> ord(n + 1);
  iota(begin(ord), end(ord), 0);
  sort(begin(ord), end(ord), [&](int x, int y) {
      return make_pair(a[x], y) < make_pair(a[y], x);
      });
  ll ans = 0;
  for(int i = 0; i <= n; i++) {
    ans += i - ecasdqina.sum(ord[i]);
    ecasdqina.add(ord[i], 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
int n;
string s,t;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>s>>t;
	for(int i=0;i<n;i++)
		cout<<s[i]<<t[i];
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define f first
#define mp make_pair
using namespace std;

bool check(ll n,ll i, ll s)
{
	 ll h =0;
	 while(n)
	 {
	 	h += n%i;
	 	n /= i;
	 }
	return h==s;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,s;
	cin>>n>>s;
	if(n<s)
	{
		cout<<-1<<endl;
		exit(0);
	}
	else if(s==n)
	{
		cout<<n+1<<endl;
		exit(0);
	}
	ll g = sqrt(n);
	for(ll i =2;i<=g; i++)
	{
		bool f = check(n,i,s);
		if(f)
		{
			cout<<i<<endl;
			exit(0);
		}
	}
	ll t=n-s,k=-1;
	for(ll i = 1; i<=g; i++)
	{
		if(t%i==0)
		{
			bool g = check(n,t/i+1,s);
			if(g)
			{
				ll r = t/i+1;
				if(k>r || k==-1)
					k=r;
			}
		}
	}
	cout<<k<<endl;
	return 0;
}

Measured memory_bytes: 256
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

void sieve(vector<bool> &isPrime, int n) {
    isPrime.resize(n + 1, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i * i <= n; ++i) {
        if (isPrime[i]) {
            for (int j = i * i; j <= n; j += i) {
                isPrime[j] = false;
            }
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    vector<bool> isPrime;
    sieve(isPrime, 200005);
    int x;
    cin >> x;
    while(true) {
        if (isPrime[x]) {
            cout << x << '\n';
            return 0;
        }
        ++x;
    }

}

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

int main()
{
    int d;
    while (std::cin >> d) {
        double s = 0.0;
        for (int i = 1; i < 600 / d; ++i) {
            s += d * d * d * i * i;
        }
        std::cout << (int)s << std::endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <stack>

void insertionSort(std::vector<int> &a, int n, int g, int &cnt){
    for(int i = g; i < n; i++){
        int v = a[i];
        int j = i - g;
        while( j >= 0 && a[j] > v){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        if(j + g == i) continue;
        a[j+g] = v;
    }
}

int main(){
    int num;
    std::cin >> num;
    std::vector<int> v;
    std::stack<int> m;
    for(int i = 0; i < num; ++i){
        int val;
        std::cin >> val;
        v.push_back(val);
    }

    int h = 0;
    while(3*h + 1 <= num){
        h = 3 * h + 1;
        m.push(h);
    }
    std::cout << m.size() << std::endl;
    int cnt = 0;
    while(1){
        int g = m.top();
        m.pop();
        insertionSort(v, num, g, cnt);
        std::cout << g;
        if(m.empty()){
            std::cout << std::endl;
            break;
        } else {
            std::cout << ' ';
        }
    }
    std::cout << cnt << std::endl;

    for(int i = 0; i < num; ++i){
        std::cout << v[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 6988
package main

import (
	"fmt"
)

func main() {
	var N, P, i uint
	fmt.Scan(&N, &P)
	A := make([]int, N)
	var cntEven uint
	for i = 0; i < N; i++ {
		fmt.Scan(&A[i])
		if A[i]%2 == 0 {
			cntEven++
		}
	}
	if cntEven == N {
		if P == 0 {
			fmt.Println(1 << N)
		} else if P == 1 {
			fmt.Println(0)
		}
	} else {
		fmt.Println(1 << (N - 1))
	}

}


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

typedef long long int ll;


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

	int n;
	cin>>n;

	int A[n];
	int B[n];

	for(int i=0;i<n-1;++i)	cin>>B[i];

	A[0] = B[0];
	for(int i=1;i<n-1;++i)
	{
		A[i] = min(B[i-1],B[i]);
	}
	A[n-1] = B[n-2];
	ll sum = 0;
	for(int i=0;i<n;++i)	
		{
			sum += A[i];
			// cout<<A[i]<<" ";
		}
	// cout<<"\n";
	cout<<sum<<"\n";

	return 0;
}

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

void printArray(int a[], int n) {
    string sep = "";
    for (int i = 0; i < n; i++) {
        cout << sep << a[i];
        sep = " ";
    }
    cout << endl;
}

int bubbleSort(int a[], int n) {
    int numOfSwap = 0;
    bool flag = true;
    for (int i = 0; flag; i++) {
        flag = false;
        for (int j = n - 1; j > i; j--) {
            if (a[j - 1] > a[j]) {
                swap(a[j - 1], a[j]);
                numOfSwap++;
                flag = true;
            }
        }
    }
    return numOfSwap;
}

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

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

    int numOfSwap = bubbleSort(a, n);

    printArray(a, n);
    cout << numOfSwap << endl;
}

Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int h, w;
    cin >> h >> w;;
    map<char, int> v;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            v[s[j]]++;
        }
    }
    if(w % 2) swap(h, w);
    using PQ = priority_queue<int>;
    PQ q;
    vector<int> v2;
    for (auto &&i : v) {
        if(i.second) q.emplace(i.second);
    }
    v2.reserve((h / 2) * (w / 2));
    for (int i = 0; i < (h/2)*(w/2); ++i) {
        v2.emplace_back(4);
    }
    for (int i = 0; i < (h%2) * (w/2) +  (w%2) * (h/2); ++i) {
        v2.emplace_back(2);
    }
    if((h%2)*(w%2)) v2.emplace_back(1);
    for (int i = 0; i < v2.size(); ++i) {
        int x = q.top(); q.pop();
        if(x < v2[i]){
            cout << "No\n";
            return 0;
        }else {
            x -= v2[i];
            q.emplace(x);
        }
    }
    cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
 int i,c;
 c=0;
 string s,t;
 cin >> s;
 cin >> t;
 for(i=0;i<=2;i++)
 {
  if(s.at(i)==t.at(i))
  c++;
 }
 cout << c;
 return 0;
}

Measured memory_bytes: 256
/*
 * Author: Dumbear
 * Created Time:  2011/8/31 12:46:59
 * File Name: I.cpp
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size())
const int maxint = -1u>>1;
template <class T> bool get_max(T& a, const T &b) {return b > a? a = b, 1: 0;}
template <class T> bool get_min(T& a, const T &b) {return b < a? a = b, 1: 0;}

int n;

bool solve();

int main() {
    while (solve());
    return 0;
}

bool solve() {
    scanf("%d", &n);
    if (n == 0)
        return false;
    int sum = 0;
    for (int i = 0; i < n * (n - 1) / 2; ++i) {
        int num;
        scanf("%d", &num);
        sum += num;
    }
    printf("%d\n", sum / (n - 1));
    return true;
}

Measured memory_bytes: 0
import sys
input=sys.stdin.readline

def main():
    D,G = map(int, input().split())
    P = []
    C = []
    for i in range(D):
        p,c = map(int, input().split())
        P.append(p)
        C.append(c)
    min_n = 100*D
    for i in range(2**D):
        s = 0
        n = 0
        max_zero_index = -1
        for j in range(D):
            if (i >> j) & 1:
                s += (j+1)*100*P[j] + C[j]
                n += P[j]
            else:
                max_zero_index = max(max_zero_index, j)
        if max_zero_index != -1:
            tmp = P[max_zero_index]
            while s < G and tmp > 0:
                tmp -= 1
                n += 1
                s += (max_zero_index+1)*100
        if s >= G:
            min_n = min(min_n, n)
    print(min_n)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
from collections import deque
H, W = map(int, input().split())
X = [1,0,-1,0]
Y = [0,-1,0,1]
num = 0
D = []
for i in range(H):
  s = list(input())
  num += s.count(".")
  D.append(s)
Q = deque()
Q.append((0,0))
dist = [[-1]*W for i in range(H)]
dist[0][0] = 0

while Q:
  y,x = Q.popleft()
  for i in range(4):
    nx = x + X[i]
    ny = y + Y[i]
    if 0 <= nx < W and 0 <= ny < H and dist[ny][nx] == -1 and D[ny][nx] == ".":
      dist[ny][nx] = dist[y][x] + 1
      Q.append((ny,nx))

if dist[H-1][W-1] == -1:
  print(-1)
else:
  print(num-dist[H-1][W-1]-1)

Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


//author   cthanh.brycen
public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    String str = br.readLine();
	    int n = Integer.parseInt(str);
	    str = br.readLine();
	    String [] ary = str.split(" ");
//	    int[] kaka = new int[n];
//	     for (int i=0 ; i<n ; i++){
//	    	 kaka[i] = Integer.parseInt(ary[i]);
//	     }

    //     Collection.reverse(ary);
	   //  System.out.println(Arrays.toString(kaka));
	    
	    for (int i= n-1; i>=0 ; i--){
	    	if (i !=0 ){
	    	 System.out.print(ary[i]+" ");}
	    	else { System.out.print(ary[i]);
	    	       System.out.print("\n");
	    	}
	     }

	}

	}

Measured memory_bytes: 24476
N, K = map(int, input().split())
h_s = list(map(int, input().split()))+[0]*K
# print(h_s)
dp = [float("inf")]*(N+K)
dp[0] = 0

for i in range(N):
    for j in range(1, K+1):
        dp[i+j] = min(dp[i+j], dp[i]+abs(h_s[i]-h_s[i+j]))

print(dp[N-1])


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

#define ll long long

using namespace std;

const int MAXN = 1e5 + 10;
const int MAXM = 1e5 + 10;
const int INF = 0x3fffffff;
const int MOD = 1e9 + 7;

int n, m, k;
int tot, cnt, ans;

int a[MAXN];

string s;

int main() {
	int T;
	scanf("%d", &n);
	printf("%d\n", n * n * n + n * n + n);
	return 0;
}


Measured memory_bytes: 3764
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,x,y) for(int i=x;i<y;i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Template ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));

    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);

    string s;
    cin>>s;
    int n=s.size();
    --n;
    int ans=0,d=10;
    rep(i,0,1<<n){
        ans+=(int)(s[n]-'0');
        d=10;
        rep(j,0,n){
            if(i&(1<<j)){
                ans+=(int)(s[n-(j+1)]-'0');
                d=10;
            }
            else{
                ans+=(int)(s[n-(j+1)]-'0')*d;
                d*=10;
            }
        }
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int N;
    cin >> N;
    int T[N];
    REP(i,N){
        cin >> T[i];
    }
    int sum=0;
    REP(i,N){
        sum += T[i];
    }
    int M;
    cin >> M;
    int P[M],X[M];
    REP(i,M){
        cin >> P[i] >> X[i];
    }
    int ans[M];
    REP(i,M){
        ans[i] = sum;
    }
    REP(i,M){
        ans[i] = ans[i] - T[P[i]-1] + X[i];
    }
    REP(i,M){
        cout << ans[i];
        if(i!=M-1){
            cout << "\n";
        }
    }

}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c < min(a, b) || max(a, b) < c) {
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <climits>

using namespace std;

const int MIN=-INT_MAX;

typedef long long ll;


int main(){
  int n, t; cin >> n >> t;
  int a[n];
  for(int i=0;i<n;i++) cin >> a[i];
  priority_queue<int> PQ;
  int maxP=MIN, cnt=1;
  for(int i=n-2;i>=0;i--){
    PQ.push(a[i+1]);
    int t = PQ.top()-a[i];
    if(t == maxP){
      cnt++;
    }else{
      maxP = max(t, maxP);
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1276
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
q.sort()
r.sort()

ans = 0
while x != 0 or y != 0:
    if r != []:
        if x > 0 and y > 0:
            maxi = max(p[-1], q[-1], r[-1])
            if maxi == p[-1]:
                ans += p.pop()
                x -= 1
            elif maxi == q[-1]:
                ans += q.pop()
                y -= 1
            else:
                ans += r.pop()
                if p[-x] > q[-y]:
                    y -= 1
                else:
                    x -= 1
        elif x == 0:
            maxi = max(q[-1], r[-1])
            if maxi == q[-1]:
                ans += q.pop()
                y -= 1
            else:
                ans += r.pop()
                y -= 1
        else:
            maxi = max(p[-1], r[-1])
            if maxi == p[-1]:
                ans += p.pop()
                x -= 1
            else:
                ans += r.pop()
                x -= 1
    else:
        if x > 0 and y > 0:
            maxi = max(p[-1], q[-1])
            if maxi == p[-1]:
                ans += p.pop()
                x -= 1
            elif maxi == q[-1]:
                ans += q.pop()
                y -= 1
        elif x == 0:
            ans += q.pop()
            y -= 1
        else:
            ans += p.pop()
            x -= 1

print(ans)

Measured memory_bytes: 105444
/*
[tenka1-2018] C - Align
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100000;

int N;
int a[MAX_N];

ll solve() {
    sort(a, a + N);

    ll ans = 0;
    if (N % 2 == 0) {
        // -2, -2, ..., -1, 1, 2, 2, ..., 2
        for (int i = 0; i < N / 2 - 1; i++) {
            ans += -2 * a[i] + 2 * a[N - i - 1];
        }
        ans += -a[N / 2 - 1] + a[N / 2];
    } else {
        ll ans1 = 0, ans2 = 0;
        // -2, -2, ..., -2, -1, -1, 2, 2, ..., 2
        for (int i = 0; i < N / 2; i++) {
            ans1 += -2 * a[i] + 2 * a[N - i - 1];
        }
        ans1 += a[N / 2 - 1] - a[N / 2];

        // -2, -2, ..., -2, 1, 1, 2, 2, ..., 2
        for (int i = 0; i < N / 2; i++) {
            ans2 += -2 * a[i] + 2 * a[N - i - 1];
        }
        ans2 += a[N / 2] - a[N / 2 + 1];

        ans = max(ans1, ans2);
    }
    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define INF 1000000000000000
#define fi first
#define se second
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
struct edge{int to,cost;};
typedef pair<int,int> P;
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
int kaijo(int n){
	int ans=1;
	for(int i=2;i<=n;i++){
		ans*=i;
		ans%=MOD;
	}
	return ans;
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
	return kaijo(a)*modpow(kaijo(a-b),MOD-2)%MOD*modpow(kaijo(b),MOD-2)%MOD;
}

signed main(){
	int k,n;
	cin>>n>>k;
	cout<<n-k+1<<endl;
	return 0;
}


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

using namespace std;
using ll =long long;
using db = double;

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

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;

ll ans;
//ここから書き始める
int main()
{
	cout << setprecision(10);
	int a,b;
	cin >> a >> b;
	if(a>9||b>9) cout << -1 << endl;
	else cout << a * b << endl;

}


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

int main(){
  int A,B;
  int i = 0;
  int sum = 0;
  
  cin >> A >> B;
  
  for(i = A ; i <= B; i++){
    int a,b,c,d,e;
    
    //1の桁の値
    a = i % 10;
    //10の桁の値
    b = (i % 100 - a) / 10;
    //100の桁の値
    c = (i % 1000 - 10 * b - a) / 100;
    //1000の桁の値
    d = (i % 10000 - 100 * c - 10 * b - a) / 1000;
    //10000の桁の値
    e = (i % 100000 - 1000 * d - 100 * c -10 * b - a) / 10000;
    
    if (a == e && b == d){
      sum++;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe

ll gcd(ll c, ll d) { return d ? gcd(d, c%d) : c;}
ll lcm(ll c, ll d) { return c / gcd(c,   d) * d;}


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
int n,w[1000]={},s=0,s1=0,s2=0,s3 = INF;
cin >> n;
rep(i,n){
    cin >> w[i];
}
rep(i,n){
    s += w[i];
}
rep(i,n){
    s1 += w[i];
    s2 = s-s1;
    s3 = min(abs(s1-s2),s3);
}

cout << s3 << endl;




//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
 
from collections import Counter
c=Counter(a)
 
max_c=0			# max combination
for i in c.values():
    max_c+=i*(i-1)//2     # 6+1+1 = 8
 
for num in a:
    k=c[num]      # 4 2 4 2 2 4 2 4
 
    print(max_c-(k*(k-1)//2)+((k-1)*(k-2)//2)) # different from max combination
                # 8 - 6 + 3
                # 5

Measured memory_bytes: 26140
dp = [[0 for _ in range(5 * (10 ** 4))] for _ in range(3)]
dp[1][0], dp[0][1], dp[1][1] = 1, 1, 1
for i in range(5, 10 ** 5, 2):
    c = 0
    if (i % 5 == 0 and i != 5) or (i % 3 == 0 and i != 3):
        c = 1
    if c == 0:
        for j in range(2, int(i ** (1 / 2)) + 1):
            if i % j == 0:
                c = 1
                break
    if c == 0:
        dp[0][i // 2] = 1
for i in range(5, 10 ** 5, 2):
    c = (i + 1) // 2
    if dp[0][c // 2] == 1 and c % 2 == 1:
        dp[1][i // 2] = 1
for i in range(1, 5 * (10 ** 4)):
    if dp[0][i] == dp[1][i] == 1:
        dp[2][i] = dp[2][i - 1] + 1
    else:
        dp[2][i] = dp[2][i - 1]

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    l, r = l // 2 - 1, r // 2
    if l == -1:
        l = 0
    print(dp[2][r] - dp[2][l])


Measured memory_bytes: 5168
#include<iostream>
#include<vector>
using namespace std;
void pl(vector<int> &l){
	l[0]++;
	for(int i=0;i<l.size()-1;i++){
		if (l[i]>3){
			l[i]=0;
			l[i+1]++;
		}
	}
	return;
}
int d(int a,int b){
	if (a<b) return b-a;
	else return a-b;
}
int main(){
	int n,a,b,c;
	cin>>n>>a>>b>>c;
	vector<int>l(n);
	vector<int>ho(n,0);
	for(int i=0;i<n;i++) cin>>l[i];
	vector<int> ans(3);
	int rslt,min=1e9+1,cnt;
	while (ho[n-1]<4){
		for (int i=0;i<4;i++) ans[i]=0;
		cnt=0;
		for(int i=0;i<n;i++){
			if(ans[ho[i]]!=0&&ho[i]<3) cnt++;
			ans[ho[i]]+=l[i];
		}
		if (ans[0]>0&&ans[1]>0&&ans[2]>0){
			rslt=d(a,ans[0])+d(b,ans[1])+d(c,ans[2])+cnt*10;
			if (min>rslt) min=rslt;
		}
		pl(ho);
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	string S;
	cin>> S;
	
	string t;
	for(int i=S.size()-1; i>=0; i--){
		t=S[i]+t;
		if(t.size()==5){
			if(t=="raser"||t=="eamer"){
				;;
			}else if(t!="dream"&&t!="erase"){
				cout<< "NO"<< endl;
				return 0;
			}else{
				t="";
			}
		}else if(t.size()==6){
			if(t=="reamer"){
				;;
			}else if(t!="eraser"){
				cout<< "NO"<< endl;
				return 0;
			}else{
				t="";
			}
		}else if(t.size()==7){
			if(t!="dreamer"){
				cout<< "NO"<< endl;
				return 0;
			}
		t="";
		}
	}
	
	cout<< (t.empty()? "YES": "NO")<< endl;
	
	return 0;
}


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

const int mod = 1e9 + 7;
int dp[305][305][305], n;
vector<pair<int, int>> a[305];
int yo(int i, int r, int g, int b) {
	int &ret = dp[r][g][b];
	if (ret != -1) return ret;
	for (auto x: a[i - 1]) {
		int l = x.first;
		int cnt = (l <= r) + (l <= g) + (l <= b);
		if (cnt != x.second) return ret = 0;
	}
	if (i == n + 1) return 1;
	ret = yo(i + 1, i, g, b) + yo(i + 1, r, i, b);
	if (ret >= mod) ret -= mod;
	ret += yo(i + 1, r, g, i);
	if (ret >= mod) ret -= mod;
	return ret;
}
int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int m; cin >> n >> m;
	while (m--) {
		int l, r, k; cin >> l >> r >> k;
		a[r].push_back({l, k});
	}
	memset(dp, -1, sizeof dp);
	cout << yo(1, 0, 0, 0) << '\n';
    return 0;
}

Measured memory_bytes: 114408
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
int dp[100100];
int main()
{
    int n,i,j,k,x,y,ans,m,sum,rose;
    int q;
    string a;
    cin >> n >> q;
    cin >> a;
    int len = a.length();
    dp[0] = 0;
    dp[1] = 0;
    for(i=1;i<len;i++)
    {
        if(a[i] == 'C' && a[i-1] == 'A')
        {
            dp[i+1] = dp[i] + 1;
        }
        else
        {
            dp[i+1] = dp[i];
        }
    }
    while(q--)
    {
        cin >> x >> y;
        cout << dp[y] - dp[x] << endl;
    }
    return 0;
}


Measured memory_bytes: 1408