akhauriyash/Code-Regression huggingface dataset:
import math
N, M = map(int, input().split())
mod = 10**9 + 7
if abs(N-M) >= 2:
    print(0)
    exit()
elif N == M:
    print(2*(math.factorial(N)**2) % mod)
else:
    print(math.factorial(N)*math.factorial(M) % mod)

Measured memory_bytes: 54640
#include<iostream>
#include<string>
using namespace std;
int main() {
 int N;
  cin >> N;
  
  double c=0;
  string a;
  double count=0;
  
  int i=1;
  while (i<N+1) {
    cin >> c;
    cin >> a;
    
    if (a=="JPY") {
      count = count + c;
      
    } else {
      count = count + 380000*c;
    }
    
    i=i+1;
  }
  
  cout << count;
  cout << endl;

  
}




Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  int n,i;
  long long a,b,x,xb,res=0;
  cin >> n >> a >> b;
  cin >> xb;
  for(i=1;i<n;i++){
    cin >> x;
    res+=min((x-xb)*a,b);
    xb=x;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
        }
        for (int i = 0; i < n - 1; i++) {
            c[i] = in.nextInt();
        }

        int result = 0;

        int lastPlace = -1;
        for (int i = 0; i < n; i++) {
            result += b[a[i] - 1];
            if (lastPlace != -1) {
                if (a[i] == lastPlace + 1) {
                    result += c[lastPlace - 1];
                }
            }
            lastPlace = a[i];
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[][] saitanro = new long[n][n];
//		long sum = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				saitanro[i][j] = sc.nextLong();
//				sum += saitanro[i][j];
			}
		}
//		sum /= 2;
		for(int k = 0; k < n; k++) {
			for(int i = 0; i < n; i++) {
				for(int j = 0; j < n; j++) {
					if(saitanro[i][j] > saitanro[i][k]+saitanro[k][j]) {
						System.out.println(-1);
						return;
					}
				}
			}
		}
		long ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				boolean nec = true;
				for (int k = 0; k < n; k++) {
					if (i != k && j != k && saitanro[i][k] + saitanro[k][j] == saitanro[i][j]) {
						nec = false;
					}
				}
				if(nec) ans += saitanro[i][j];
			}
		}
		System.out.println(ans/2);
	}
}

Measured memory_bytes: 59060
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll long long
#define pi pair<ll,ll>
ll a[300008], b[400000], c[3][300];
string s, s1;
map<ll, ll>mp;

int main()
{
    IO;
    ll i, j, k=0, l, n, m, t, h, cnt=0, curr, mx=0;
    cin>>s>>s1;
    for(i=0; i<s.size(); i++) if(s[i]!=s1[i]) cnt++;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
  string s;
  cin >> s;
  if (s[1] == 'R') {
    cout << "ABC";
  } else {
    cout << "ARC";
  }
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#define N 1000000 

using namespace std;

bool sosu[N];

void sosuhyo()
{
	sosu[0]=true;
	sosu[1]=true;

	for(int i=2;i<N;i++){
		if(!sosu[i]){
			for(int j=2;j<=(N/i);j++){
				sosu[i*j]=true;
			}
		}
	}

}


int main(){
	
	sosuhyo();

	int a,count;

	while(cin>>a && a){
		count=0;
		for(int i=0;i<=a;i++){
			if(!sosu[i])count++;
		}
		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
char c[5];
int main() {
	scanf("%s", c);
	bool ans = true;
	if (c[0] == c[1]) ans = false;
	if (c[1] == c[2]) ans = false;
	if (c[2] == c[3]) ans = false;
	puts(ans ? "Good" : "Bad");
}

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

public class WelcometoAtCoder
{
   static void Main(string[] args) 
   {
     var b = Console.ReadLine().Split(' ');
     int N = int.Parse(b[0]);
     int M = int.Parse(b[1]);
     
     if(M==0){Console.WriteLine("0 0");return;}
     bool[] flg = new bool[N+1];
     int[] s = new int[N+1];
     int[,] A = new int[M,2];
     
     for(int i=0;i<M;i++)
     {
       b = Console.ReadLine().Split(' ');
       A[i,0] =  int.Parse(b[0]);
       A[i,1] = b[1] =="AC"?1:0;
     }

     for(int i=0;i<M;i++)
     {
       	int p = A[i,0];
        int r = A[i,1];
       	if(!flg[p]){
            if(r==1){flg[p]=true;}
     		else{s[p]++;}
        }
     }
      
     
     int ACCnt=0;
     int WACnt=0;

     for(int i=0;i<=N;i++)
     {
       if(flg[i]){ACCnt++;WACnt+=s[i];}
     }
     
     Console.WriteLine(ACCnt + " " + WACnt);
   }  
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  long long int L[100001];
  for(int i=0;i<100001;i++){
    L[i]=0;
  }
  int A;
  for(int i=0;i<N;i++){
    cin >> A;
    L[A]++;
  }
  
  
  
  long long int O = 0;
  
  for(long long int i=0;i<100001;i++){
    O = O + L[i] * i;
  }
  
  int Q;
  cin >> Q;
  
  long long int B,C;
  
  
  for(int i=0;i<Q;i++){
    cin >> B >> C;
    O = O - L[B]*B + L[B]*C;
    L[C] = L[C] + L[B];
    L[B] = 0;
    cout << O << endl;;
    
  }
  
  return 0;
}


Measured memory_bytes: 4400
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		List<Integer> vals = new ArrayList<Integer>();
		while (in.hasNext()) {
			int val = in.nextInt();
			int keta = in.nextInt();
			if (val == 0 && keta == 0)
				break;
			vals.clear();
			int[] array = new int[keta];
			// Arrays.fill(array, 0);
			while (!vals.contains(val)) {
				vals.add(val);
				for (int k = 0; k < keta; k++) {
					array[k] = val % 10;
					val /= 10;
				}
				Arrays.sort(array);
				// System.out.println(Arrays.toString(array));
				int smal = 0;
				int big = 0;
				for (int k = 0; k < keta; k++) {
					smal *= 10;
					smal += array[k];
					big *= 10;
					big += array[keta - 1 - k];
				}
				val = big - smal;
			}
			int i = vals.indexOf(val);
			int j = vals.size() - i;
			System.out.print(i);
			System.out.print(" ");
			System.out.print(val);
			System.out.print(" ");
			System.out.println(j);
		}
	}
}

Measured memory_bytes: 20404
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;


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

int main(){

    long long N;
    vector<long long> arr;
    cin >> N;
    long long M = 1000000007;
    long long sum =0;
    
    for(int i =0; i < N; ++i){
        long long tmp;
        cin >> tmp;
        //tmp %= M;
        sum += tmp;
        //sum %= M;
        arr.push_back(tmp);
    }
    long long ans = 0;
    for(int i=0; i < N-1; ++i){
        long long A = arr[i];
        sum -= A;
        //sum %= M;
        ans += (sum%M)*A%M;
        ans %= M;
        
    }
    //ans %=M;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5360
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;


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




int main() {
    int a, b;
    cin >> a >> b;
    if(b % a == 0) {
        cout << a + b << endl;
    }
    else {
        cout << b - a << endl;
    }
}


Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):
    def __init__(self):
        pass

    def solve(self, x: int, y: int):
        if (x + y) % 3 != 0:
            return 0
        A = np.matrix([[1, 2],
                       [2, 1]])
        Y = np.matrix([[x],
                       [y]])
        m, n = np.linalg.solve(A, Y)
        if m < 0:
            return 0
        if n < 0:
            return 0
        return self.cmb(int(m)+int(n), int(n)) % (10**9 + 7)

    def cmb(self, n, r):
        if n - r < r:
            r = n - r
        if r == 0:
            return 1
        if r == 1:
            return n

        numerator = [n - r + k + 1 for k in range(r)]
        denominator = [k + 1 for k in range(r)]

        for p in range(2, r+1):
            pivot = denominator[p - 1]
            if pivot > 1:
                offset = (n - r) % p
                for k in range(p-1, r, p):
                    numerator[k - offset] /= pivot
                    denominator[k] /= pivot

        result = 1
        for k in range(r):
            if numerator[k] > 1:
                result *= int(numerator[k])

        return result


def main():
    X, Y = [int(i) for i in input().split()]

    solver = Solver()
    print(solver.solve(X, Y))


if __name__ == "__main__":
    main()

Measured memory_bytes: 55400
fun main(args: Array<String>) {
    val (L, R) = readLine()!!.split(" ").map(String::toInt)
    if (L / 2019 != R / 2019) {
        println(0)
        return
    }
    val D = (L..R).map { it % 2019 }.toTypedArray()
    var min = Int.MAX_VALUE
    for (i in 0 until D.size - 1) {
        for (j in i + 1 until D.size) {
            min = min.coerceAtMost((D[i] * D[j]) % 2019)
        }
    }
    println(min)
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> k;
    ll cnt = 0;
    queue<ll> que;
    for(i = 1; i <= 9; i++) {
        que.push(i);
    }
    ll x;
    while(cnt != k) {
        x = que.front();
        cnt++;
        que.pop();
        if(x % 10 == 0) {
            que.push(x * 10);
            que.push(x * 10 + 1);
        } else if(x % 10 == 9) {
            que.push(x * 10 + 8);
            que.push(x * 10 + 9);
        } else {
            que.push(x * 10 + (x % 10) - 1);
            que.push(x * 10 + (x % 10));
            que.push(x * 10 + (x % 10) + 1);
        }
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 1792
import sys


def rec(j,s):
    if s > n:
        return 0
    if s == n:
        return 1
    if j == 0:
        return 0
    v = 0
    for i in range(10):
        v += rec(j-1, s + i)
    return v

n = sys.stdin.readline()
while n:
    n = int(n)
    print(rec(4,0))
    n = sys.stdin.readline()

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


int main()
{   int N,i,s=1;
    scanf("%d",&N);
    int a[N];
    for(i=0;i<N;i++)
      {

        scanf("%d",&a[i]);
        if(a[i]==s) s++;
}
    if(s==1) printf("-1");
    else printf("%d",N-s+1);
    return 0;
}


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

using namespace std;


void solve() {
    string s; cin >> s;
    int n = s.size();
    set<char> box;

    vector<int> cut;
    cut.emplace_back(n);
    for (int i = n-1; i >= 0; i--) {
        box.insert(s[i]);
        if (box.size() == 26) {
            box.clear();
            cut.emplace_back(i);
        }
    }
    box.clear();
    reverse(cut.begin(), cut.end());
    string res;
    int crt = 0;
    int m = cut.size();
    for (int i = 0; i < m; i++) {
        box.clear();
        for (int j = crt; j < cut[i]; j++) {
            box.insert(s[j]);
        }
        char ans = 0;
        for (int k = 0; k < 26; k++) {
            if (box.find('a'+k) == box.end()) {
                ans = 'a'+k;
                res.push_back(ans);
                break;
            }
        }
        assert(ans);
        crt = cut[i];
        while (crt < n && s[crt] != ans) {
            crt++;
        }
        crt++;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 720
#include<cstdio>
using namespace std;
int n,a,b,t,ans;
int main(){
    scanf("%d%d%d",&n,&a,&b);
    for(int i=1;i<=n;++i){
        scanf("%d",&t);
        if(t<a || t>=b)++ans;
    }
    printf("%d\n",ans);
    return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 1000006;

i64 n;
i64 a[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    string s, t;
    cin >> s >> t;
    cout << t << s << endl;

    return 0;
}

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

template<Int Mod = 1000000007> class modint{
public:
	Int val;
	constexpr modint(const Int x = 0) : val(x % Mod) {if(val < 0) val += Mod;}
	constexpr modint operator+(const modint rhs) const {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const {
		return modint(*this) /= rhs;
	}
	constexpr modint operator-() const {
		return modint(Mod - val);
	}
	constexpr modint &operator+=(const modint rhs){
		val += rhs.val;
		if(val >= Mod) val -= Mod;
		return *this;
	}
	constexpr modint &operator-=(const modint rhs){
		if(val < rhs.val) val += Mod;
		val -= rhs.val;
		return *this;
	}
	constexpr modint &operator*=(const modint rhs){
		val *= rhs.val;
		val %= Mod;
		return *this;
	}
	constexpr modint &operator/=(const modint rhs){
		return *this *= inv(rhs);
	}
	constexpr modint &operator++(){
		++val;
		if(val == Mod) val = 0;
		return *this;
	}
	constexpr modint &operator--(){
		--val;
		if(val == -1) val = Mod - 1;
		return *this;
	}
	constexpr modint operator<<(const Int rhs) const {
		return modint(*this) << rhs;
	}
	constexpr modint operator>>(const Int rhs) const {
		return modint(*this) >> rhs;
	}
	constexpr modint &operator<<=(const Int rhs){
		val <<= rhs;
		val %= Mod;
		return *this;
	}
	constexpr modint &operator>>=(const Int rhs){
		val >>= rhs;
		val %= Mod;
		return *this;
	}
	constexpr bool operator==(const modint rhs) const {
		return val == rhs.val;
	}
	constexpr bool operator!=(const modint rhs) const {
		return val != rhs.val;
	}
	constexpr bool operator<(const modint rhs) const {
		return val < rhs.val;
	}
	constexpr bool operator>(const modint rhs) const {
		return val > rhs.val;
	}
	constexpr bool operator<=(const modint rhs) const {
		return val <= rhs.val;
	}
	constexpr bool operator>=(const modint rhs) const {
		return val >= rhs.val;
	}
	friend ostream& operator<<(ostream& os, const modint<Mod>& m){
		return os << m.val;
	}
	friend istream& operator>>(istream& is, modint<Mod>& m){
		return is >> m.val;
	}
	static constexpr modint inv(modint m){
		Int a = m.val, b = Mod, u = 1, v = 0;
		while(b){
			Int t = a / b;
			a -= t * b;
			swap(a, b);
			u -= t * v;
			swap(u, v);
		}
		u %= Mod;
		if(u < 0) u += Mod;
		return modint(u);
	}
	constexpr operator Int() const {
		return val;
	}
};

modint<> comb(Int n, Int r){
	modint<> res(1);
	for(Int i=0; i<r; ++i){
		res *= n-i;
		res /= i+1;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, k; cin >> n >> k;
	using mint = modint<>;
	for(Int i=1; i<=k; ++i){
		mint ans = comb(n-k+1, i) * comb(k-1, i-1);
		cout << ans << "\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;
int n,x[1010],y[1010];
void solve(vector<int> v,int tx,int ty){
	int x=0,y=0;
	for(int len:v){
		if(abs(tx-x)>abs(ty-y)){
			if(tx>x) putchar('R'),x+=len;
			else putchar('L'),x-=len;
		}
		else{
			if(ty>y) putchar('U'),y+=len;
			else putchar('D'),y-=len;
		}
	}
	assert(x==tx&&y==ty);
	puts("");
}
main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i]>>y[i];
	int flag=x[1]+y[1]&1;
	for(int i=2;i<=n;i++)
		if((x[i]+y[i]&1)!=flag){puts("-1");return 0;}
	vector<int> v;
	for(ll i=1ll<<32;i;i>>=1)
		v.push_back(i);
	if(!flag) v.push_back(1);
	cout<<v.size()<<'\n';
	for(int x:v) cout<<x<<' ';
	cout<<'\n';
	for(int i=1;i<=n;i++)
		solve(v,x[i],y[i]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N =  200100;
inline ll read()
{
  ll p=0; ll f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}
ll a[N],s[N];
ll calc(ll l,ll r){return s[r] - s[l-1];}
int main()
{
  ll n = read(); ll x = read();
  for(ll i=1;i<=n;i++) a[i] = read();
  for(ll i=1;i<=n;i++) s[i] = s[i-1] + a[i];
  ll minx = (ll)1e55;
  for(ll k=1;k<=(n+1)/2;k++)
  {
    ll l = 0; ll r = n; ll ans = 0; ll v = 5;
    for(ll i=1;r>=1;i++)
    {
      l = max(1ll , r - k + 1);
      ans += calc(l,r) * v;
      if(ans + k*x > minx) break;
      r = l-1; if(i==1) continue;
      else v+=2;
    }
    minx = min(minx , ans + k*x);
    // printf("%lld %lld\n",k , ans + k*x);
  }
  return printf("%lld\n",minx + n*x),0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define MAXN 100010
#define INF 1E15
#define LL long long
typedef pair<LL,int> PLI;
struct node
{
	int v,a,b;
};
vector<node>G[MAXN];
int n,m,s,t,u,v,a,b;
bool vis[MAXN];
LL d1[MAXN],d2[MAXN];
LL ans[MAXN];
void Solve()
{
	priority_queue<PLI,vector<PLI>,greater<PLI> >Q;
	fill(d1+1,d1+n+1,INF);
	fill(d2+1,d2+n+1,INF);
	d1[s]=0,d2[t]=0;
	Q.push(PLI(0,s));
	while(!Q.empty())
	{
		PLI q=Q.top();Q.pop();
		int u=q.second;
		if(d1[u]<q.first) continue;
		for(int i=0;i<G[u].size();i++)
		{
			node e=G[u][i];
			if(d1[e.v]>d1[u]+e.a)
			{
				d1[e.v]=d1[u]+e.a;
				Q.push(PLI(d1[e.v],e.v));
			}
		}
	}
	Q.push(PLI(0,t));
	while(!Q.empty())
	{
		PLI q=Q.top();Q.pop();
		int u=q.second;
		if(d2[u]<q.first) continue;
		for(int i=0;i<G[u].size();i++)
		{
			node e=G[u][i];
			if(d2[e.v]>d2[u]+e.b)
			{
				d2[e.v]=d2[u]+e.b;
				Q.push(PLI(d2[e.v],e.v));
			}
		}
	}
	for(int i=1;i<=n;i++)
		ans[i]=d1[i]+d2[i];
	for(int i=n-1;i>=1;i--)
		ans[i]=min(ans[i],ans[i+1]);
}
int main()
{
	node e;
	scanf("%d%d%d%d",&n,&m,&s,&t);
	for(int i=0;i<m;i++)
	{
		scanf("%d%d%d%d",&u,&v,&e.a,&e.b);
		e.v=v;G[u].push_back(e);
		e.v=u;G[v].push_back(e);
	}
	Solve();
	for(int i=1;i<=n;i++)
		printf("%lld\n",1000000000000000-ans[i]);
}

Measured memory_bytes: 10808
#include <iostream>

using namespace std;

int main()
{
  int K, A, B;
  cin >> K >> A >> B;
  
  bool ret = false;
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      ret = true;
      break;
    }
  }
  
  if(ret){
    cout << "OK" << endl;
  }else{
    cout << "NG" << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MOD = 1e9 + 7;struct ModularInt{int n;ModularInt(int n_=0):n(n_){}};
ModularInt operator-(ModularInt a){return -a.n+MOD*(a.n!=0);}
ModularInt operator+(ModularInt a,ModularInt b){int x=a.n+b.n;return x-(x>=MOD)*MOD;}
ModularInt operator-(ModularInt a,ModularInt b){int x=a.n-b.n;return x+(x<0)*MOD;}
ModularInt operator*(ModularInt a,ModularInt b){return (long long)a.n*b.n%MOD;}
ModularInt &operator+=(ModularInt &a,ModularInt b){return a=a+b;}
ModularInt &operator-=(ModularInt &a,ModularInt b){return a=a-b;}
ModularInt &operator*=(ModularInt &a,ModularInt b){return a=a*b;}
istream &operator>>(istream &i,ModularInt &a){return i>>a.n;}
ostream &operator<<(ostream &o,ModularInt a){return o<<a.n;}

int n, m;
int A[3005];
int B[3005];

ModularInt dp[2][3005];

int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for(int i = 1; i <= n; i++)
    cin >> A[i];
  for(int i = 1; i <= m; i++)
    cin >> B[i];
  
  for(int i = 1; i <= n; i++) {
    int step = i % 2;
    for(int j = 1; j <= m; j++) {
      dp[step][j] = 0;
      if(A[i] == B[j])
        dp[step][j] += 1 + dp[!step][j - 1];
      dp[step][j] += dp[!step][j] + dp[step][j - 1] - dp[!step][j - 1];
    }
  }
  cout << dp[n % 2][m] + 1 << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;


int main(){
    fast_io
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    ll sub=0;
    ll r=0, g=0, b=0;

    rep(i,n) {
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }
    ans=r*g*b;

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(s[i]==s[j]) continue;
            int k=j*2-i;
            if(k>=n || s[k]==s[i]||s[k]==s[j]) continue;
            sub++;
        }
    }
    
    cout<<ans-sub<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n,m,x,y,d,k;
string str;
int main() {
	cout<<setprecision(10);
	cin>>n>>str;
	long long int res=0;
	for(int i=0;i<n-2;i++){
		if(str.substr(i,3)=="ABC"){res++;}
	}
	cout<<res;
} 


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

int h, w, a[85][85], b[85][85], grid[85][85][16000], ans;

void input(void) {
	cin >> h >> w;
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)cin >> a[i][j];
	for (int i = 0; i < h; i++)for (int j = 0; j < w; j++)cin >> b[i][j];
	ans = 1000000000;
	memset(grid, -1, sizeof grid);
}

void solve(int x, int y, int diff) {
	if (x == h - 1 && y == w - 1) {
		ans = min(ans, abs(diff + (a[x][y] - b[x][y])));
		ans = min(ans, abs(diff - (a[x][y] - b[x][y])));
		return;
	}
	if (x > h || y > w)return;
	if (grid[x][y][diff] != -1)return;
	grid[x][y][diff] = 1;
	solve(x + 1, y, abs(diff + (a[x][y] - b[x][y])));
	solve(x + 1, y, abs(diff - (a[x][y] - b[x][y])));
	solve(x, y + 1, abs(diff + (a[x][y] - b[x][y])));
	solve(x, y + 1, abs(diff - (a[x][y] - b[x][y])));
}

int main() {
	input();
	solve(0, 0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 451968
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fin(x) freopen(x,"r",stdin)
#define fout(x) freopen(x,"w",stdout)
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll inf=0xc0c0c0c0c0c0c0c0;
const double pi=acos(-1);
const int MAX=305;
const ll mod=1e9+7;
ll dp[2][MAX][MAX];//len,maxid,connectone
ll N,M;
void add(ll &a,ll b){a=(a+b)%mod;}
ll fact(ll x)
{
	ll res=1;
	while(x)
	{
		res=res*x%mod;
		x--;
	}
	return res;
}
int main()
{
	scanf("%lld%lld",&N,&M);
	dp[0][1][1]=1;
	for(int i=0;i<M;i++)
	{
		int last=i&1;
		int now=last^1;
		mem(dp[now],0);
		for(int j=0;j<=N;j++)
			for(int k=0;k<=j;k++)
				if(dp[last][j][k])
				{
					add(dp[now][j][j],dp[last][j][k]*k%mod);//connect 1
					if(j<N)
						add(dp[now][j+1][k],dp[last][j][k]);//new
					add(dp[now][j][k],dp[last][j][k]*(j-k)%mod);//connect not 1
				}
	}
	printf("%lld\n",dp[M&1][N][N]*fact(N-1)%mod);
	return 0;
}

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

namespace A__Can_tbWate_for_Holiday
{
    class Program
    {
        static void Main(string[] args)
        {
            string SUN = "SUN";
            string MON = "MON";
            string TUE = "TUE";
            string WED = "WED";
            string THU = "THU";
            string FRI = "FRI";
            string SAT = "SAT";

            var today = Console.ReadLine();
            if (today == SUN)
            {
                Console.WriteLine(7);
            }
            else if (today == MON)
            {
                Console.WriteLine(6);
            }
            else if (today == TUE)
            {
                Console.WriteLine(5);
            }
            else if (today == WED)
            {
                Console.WriteLine(4);
            }
           else  if (today == THU)
            {
                Console.WriteLine(3);
            }
            else if (today == FRI)
            {
                Console.WriteLine(2);
            }
            else if (today == SAT)
            {
                Console.WriteLine(1);
            }
            
        }
    }
}


Measured memory_bytes: 11092
n,k = map(int, input().split())
r,s,p = map(int, input().split())
st=list(input())
for i in range(n-k):
    if st[i] == st[i+k]:
        st[i+k] = 'no'
win = r*st.count('s')+s*st.count('p')+p*st.count('r')
print(win)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,a) for(int i=start[(a)];i;i=e[i].next)
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
inline int read()
{
	int sum=0,p=1;char ch=getchar();
	while(!(('0'<=ch && ch<='9') || ch=='-'))ch=getchar();
	if(ch=='-')p=-1,ch=getchar();
	while('0'<=ch && ch<='9')sum=sum*10+ch-48,ch=getchar();
	return sum*p;
}

const int maxn=1e5+20;

/*struct node {
	int v,next;
};
node e[maxn<<1];
int cnt,start[maxn];
inline void addedge(int u,int v){ e[++cnt]=(node){v,start[u]};start[u]=cnt;}*/

vector<int>to[maxn];

int n,m;

inline void init()
{
	n=read();m=read();
	if(n&1)puts("-1"),exit(0);
	REP(i,1,m)
	{
		int u=read(),v=read();
		to[u].push_back(v); to[v].push_back(u);
	}
}

#define pii pair<ll,ll>


pii f[maxn];
//inline pii operator +(pii a,pii b){ return mkr(a.fi+b.fi,a.se+b.se);}

namespace p1 {

	void dfs(int u,int fa)
	{
		for(int v:to[u])
		{
			if(v==fa)continue;
			dfs(v,u);
			f[u].fi+=f[v].fi+abs(f[v].se);
			f[u].se+=f[v].se;
		}
		f[u].se=-f[u].se+1;
	}

	inline void doing() {
		dfs(1,0);
		if(f[1].se)puts("-1");
		else printf("%lld\n",f[1].fi);
	}
};

namespace p2 {
	int cir[maxn],len;
	int vis[maxn];
	int cx,cy;
	
	void dfs(int u,int fa) {
		vis[u]=1;
		for(int v:to[u])
		{
			if(v==fa)continue;
			if(vis[v]){ cx=u,cy=v; continue;}
			dfs(v,u);
		}
	}

	void find_cir(int u,int fa) {
		cir[++len]=u; if(cir[len]==cy)return;
		for(int v:to[u])
		{
			if(v==fa)continue;
			find_cir(v,u);
			if(cir[len]==cy)return;
		}
		--len;
	}

	void dfs1(int u,int fa)
	{
		for(int v:to[u])
		{
			if(v==fa || vis[v])continue;
			dfs1(v,u);
			f[u].fi+=f[v].fi+abs(f[v].se);
			f[u].se+=f[v].se;
		}
		f[u].se=-f[u].se+1;
	}
	
	int st[maxn],x[maxn];
	
	inline void doing() {
		dfs(1,0);
		to[cx].erase(find(to[cx].begin(),to[cx].end(),cy));
		to[cy].erase(find(to[cy].begin(),to[cy].end(),cx));
		find_cir(cx,0);
		REP(i,1,n)vis[i]=0;
		REP(i,1,len)vis[cir[i]]=1;
		ll ans=0;
		REP(i,1,len)dfs1(cir[i],0),ans+=f[cir[i]].fi;

		if(len&1)
		{
			x[1]=0;
			REP(i,2,len)
			{
				x[i]=-x[i-1]+f[cir[i]].se;
			}
			ll a1=(f[cir[1]].se-x[len])/2;
			REP(i,1,len)x[i]+=(i&1?1:-1)*a1;
			REP(i,1,len)ans+=abs(x[i]);
			printf("%lld\n",ans);
		}else
		{
			ll sum1=0,sum2=0;
			REP(i,1,len)if(i&1)sum1+=f[cir[i]].se;else sum2+=f[cir[i]].se;
			if(!(sum1==sum2))puts("-1"),exit(0);

			x[1]=0;
			REP(i,2,len)
			{
				x[i]=-x[i-1]+f[cir[i]].se;
			}
			REP(i,3,len)if(i&1)x[i]=-x[i];
			sort(x+1,x+len+1);
			REP(i,1,len)ans+=abs(x[i]-x[len+1>>1]);
			
			printf("%lld\n",ans);
		}
	   
	}
};

inline void doing()
{
	if(m==n-1)p1::doing();
	else p2::doing();
}

int main()
{
	init();
	doing();
	return 0;
}



Measured memory_bytes: 14848
#include <iostream>
#include <sstream>
#include <fstream>

#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>

#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>

#define MAX_V 110
#define INF 1000000

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
        os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair

string const resstr[] = {"Impossible","Possible","No","Yes"};

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;

int prom(){
	for(int i=0; i < V; ++i){
		mincost[i] = INF;
		used[i] = false;
	}
	mincost[0] = 0;
	int res = 0;
	
	while(true){
		int v = -1;
		for(int u=0; u < V; u++){
			if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
		}
		if(v == -1) break;
		used[v] = true;
		res += mincost[v];
		
		rep(u,V)
			mincost[u] = min(mincost[u], cost[v][u]);	
	}
	return res;
}

int main(){
	int E;
	while(cin >> V >> E, V+E){
		rep(i, V)
			rep(j, V) cost[i][j] = INF;
	
		rep(i, E){
			int a, b ,c;
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
		}
		cout << prom() << endl;
	}
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N, M; cin >> N >> M;
    vector<i64> X(M);
    REP(i, M) cin >> X[i];
    sort(X.begin(), X.end());

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    i64 len = X[M - 1] - X[0];
    vector<i64> d(M - 1);
    REP(i, M - 1) {
        d[i] = X[i + 1] - X[i];
    }
    sort(d.rbegin(), d.rend());
    REP(i, N - 1) len -= d[i];

    cout << len << endl;

    return 0;
}

Measured memory_bytes: 1792
#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <cassert>
#include <complex>
#include <time.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define FILL(A,val) memset(A,val,sizeof(A))
#define ITER(it,a) for(__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define DBG1(a) cerr<<#a<<"="<<(a)<<"\n"
#define DBG2(a,b) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"

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

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

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


int main() 
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(0);cin.tie(0);

	int n;
	cin >> n;
	LL x = 1, y = 1;
	FOR(i, 0, n)
	{
		int a, b;
		cin >> a >> b;
		LL d1 = (x + a - 1) / a;
		LL d2 = (y + b - 1) / b;
		LL d = max(d1, d2);
		x = a * d;
		y = b * d;
	}

	cout << x + y << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;

int max(int a, int b) { return (a > b) ? a : b; }

const int MAXN = 100000;

int a[MAXN];
int b[MAXN];


const int INF = 1e9;

vector<int> e[MAXN];
vector<int> ret[MAXN];
int p[MAXN];
int tin[MAXN];
int tout[MAXN];
bool root[MAXN];
bool used[MAXN];

int tim = 0;
vector<int> top;


void dfs(int u)
{
    used[u] = true;
    for (int v : e[u])
    {
        if (!used[v])
        {
            dfs(v);
        }
    }
    top.push_back(u);
}

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

    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n + m - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        e[x].emplace_back(y);
        ret[y].emplace_back(x);
        root[y] = 1;
    }

    int r = -1;
    for (int i = 0; i < n; i++)
    {
        if (root[i] == 0) r = i;
        p[i] = -1;
        used[i] = false;
    }

    p[r] = -1;
    dfs(r);
    
    tin[r] = 0;
    reverse(top.begin(), top.end());
    for (int x : top)
    {
        p[x] = -1;
        int t = -1;
        for (int y : ret[x])
        {
            if (tin[y] > t)
            {
                t = tin[y];
                p[x] = y;
            }
        }
        if (t != -1)
        {
            tin[x] = t + 1;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << p[i] + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 18044
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  cin >> S;
  print(count(ALL(S), 'o') * 100 + 700);
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N;
  cin >> N;
  unordered_set<string> S(N);
  REP(i, 0, N) {
    string s;
    cin >> s;
    S.emplace(s);
  }
  cout << S.size() << endl;

  return 0;
}


Measured memory_bytes: 17160
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
    int n, l;
    vector<string> arr;
    cin >> n >> l;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        arr.emplace_back(s);
    }
    sort(arr.begin(), arr.end());
    for(int i = 0; i < n; i++)
        cout << arr[i];
    return 0;
}

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

using namespace std;
typedef long long ll;
int const maxn = 2e5 + 10;

// 等价于 p * 2
inline int lc(int p) {return p << 1;}
// 等价于 p * 2 + 1
inline int rc(int p) {return p << 1 | 1;}
int n;
struct segt {
    struct Tree {
        int l, r;
        ll sum;
        void update(ll v) {
            sum += v * (r - l + 1);
        }
    } tree[maxn << 2];

    void pushup(int p) {
        tree[p].sum = tree[lc(p)].sum + tree[rc(p)].sum;
    }

    void build(int p, int l, int r) {
        tree[p].l = l, tree[p].r = r;
        tree[p].sum = 0;
        if (l == r) return;
        int mid = (l + r) >> 1;
        build(lc(p), l, mid);
        build(rc(p), mid + 1, r);
        pushup(p);
    }

    void update(int p, int x, ll v) {
        int L = tree[p].l, R = tree[p].r;
        if (L == x && L == R) {
            tree[p].update(v);
            return;
        }
        int mid = (L + R) >> 1;
        if (x <= mid) update(lc(p), x, v);
        else  update(rc(p), x, v);
        pushup(p);
    }
    ll query(int p, int l, int r) {
        int L = tree[p].l, R = tree[p].r;
        // if (L <= 0 || R > n || L == 0 || R == 0) return 0;
        // if (L > r || R < l) return 0;
        int mid = (L + R) >> 1;
        if (l <= L && r >= R) {
            return tree[p].sum;
        }
        ll res = 0;
        if (l <= mid) res += query(lc(p), l, r);
        if (r > mid) res += query(rc(p), l, r);
        return res;
    }
}seg;

struct node {
    int pos;
    ll val;
    bool operator<(const node &__) const {
        if (val == __.val) return pos < __.pos;
        return val < __.val;
    }
} pre[maxn];

int main(void) {
    ll k;
    scanf("%d %lld", &n, &k);
    for (int i = 1; i <= n; i++) {
        ll x;
        scanf("%lld", &x);
        pre[i].val = pre[i - 1].val + x - k;
        pre[i].pos = i;
    }
    seg.build(1, 1, n);
    sort(pre + 1, pre + 1 + n);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (pre[i].val >= 0) ans++;
        ans += seg.query(1, 1, pre[i].pos - 1);
        seg.update(1, pre[i].pos, 1);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 15208
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

// qsort(array, size, sizeof(int),comp);
int comp(const int *a,const int *b){
	return (*a - *b);
}

int main(int argc, char const *argv[]){
	int n,x;
	int *m,ans;
	scanf("%d%d",&n,&x);
	ans = n;
	m = (int *)malloc(sizeof(int) * n);
	for (int i = 0; i < n; ++i){
		scanf(" %d",&m[i]);
		x -= m[i];
	}
	qsort(m,n,sizeof(int),comp);
	ans += (x / m[0]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
		  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
return (a % b + b) % b; }

#define P(p) const point &p
#define L(p0, p1) P(p0), P(p1)
#define C(p0, r) P(p0), double r
#define PP(pp) pair<point,point> &pp
typedef complex<double> point;
double dot(P(a), P(b)) { return real(conj(a) * b); }
double cross(P(a), P(b)) { return imag(conj(a) * b); }
point rotate(P(p), double radians = pi / 2,
             P(about) = point(0,0)) {
  return (p - about) * exp(point(0, radians)) + about; }
point reflect(P(p), L(about1, about2)) {
  point z = p - about1, w = about2 - about1;
  return conj(z / w) * w + about1; }
point proj(P(u), P(v)) { return dot(u, v) / dot(u, u) * u; }
point normalize(P(p), double k = 1.0) {
  return abs(p) == 0 ? point(0,0) : p / abs(p) * k; }
double ccw(P(a), P(b), P(c)) { return cross(b - a, c - b); }
bool collinear(P(a), P(b), P(c)) {
  return abs(ccw(a, b, c)) < EPS; }
double angle(P(a), P(b), P(c)) {
  return acos(dot(b - a, c - b) / abs(b - a) / abs(c - b)); }
double signed_angle(P(a), P(b), P(c)) {
  return asin(cross(b - a, c - b) / abs(b - a) / abs(c - b)); }
double angle(P(p)) { return atan2(imag(p), real(p)); }
point perp(P(p)) { return point(-imag(p), real(p)); }
double progress(P(p), L(a, b)) {
  if (abs(real(a) - real(b)) < EPS)
    return (imag(p) - imag(a)) / (imag(b) - imag(a));
  else return (real(p) - real(a)) / (real(b) - real(a)); }
// vim: cc=60 ts=2 sts=2 sw=2:


int main()
{
    int a, b;
    double h, m;
    cin >> a >> b >> h >> m;
    h = (h*60 + m)/720.0 * 2*pi;
    m = m/60.0 * 2*pi;
    point p = rotate(point(0,a), h);
    point q = rotate(point(0,b), m);
    cout << setprecision(15) << fixed << abs(p-q) << endl;

    return 0;
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
#define INF 0X3f3f3f3f
#define M 1000000007
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back 
#define fi first
#define se second
#define endl "\n"
#define PI acos(-1)
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;
#define fastcin ios_base::sync_with_stdio(false)

const int N = 100002;
int n;
int a[N], b[N], c[N];
ll up[N], acum[N];

int main(void){
	//fastcin;
	scanf("%d", &n);

	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}

	for(int i = 0; i < n; i++){
		scanf("%d", &b[i]);
	}

	for(int i = 0; i < n; i++){
		scanf("%d", &c[i]);
	}

	sort(a, a+n);
	sort(b, b+n);
	sort(c, c+n);

	for(int i = 0; i < n; i++){
		int j = lower_bound(a, a+n, b[i]) - a;
		up[i] = j;
	}

	acum[0] = up[0];
	for(int i = 1; i < n; i++){
		acum[i] = acum[i-1] + up[i];
	}

	ll ans = 0;
	for(int i = 0; i < n; i++){
		int j = lower_bound(b, b+n, c[i]) - b;;
		if(j > 0){
			ans += acum[j-1];
		}
	}

	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 2944
#include <iostream>

using namespace std;

int main()
{
	int c[3][3];
	int dif1[3], dif2[3], dif3[3];
	int i, j;
	int num = 0;
	bool flag = true;

	for (i = 0; i < 3; i++) {
		for (j = 0; j < 3; j++) {
			cin >> c[i][j];
		}
	}

	for (j = 0; j < 3; j++) {
		dif1[j] = c[0][j] - c[1][j];
		dif2[j] = c[1][j] - c[2][j];
		dif3[j] = c[2][j] - c[0][j];
	}

	for (i = 0; i < 2; i++) {
		if (dif1[i] != dif1[i + 1]) flag = false;
		if (dif2[i] != dif2[i + 1]) flag = false;
		if (dif3[i] != dif3[i + 1]) flag = false;
	}

	if (flag == true) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}

    return 0;
}



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

const int N = 3005;

int dp[N][N][4];
int board[N][N];

signed main() {
  int R, C, K;
  cin >> R >> C >> K;

  memset(dp, 0, sizeof(dp));
  memset(board, 0, sizeof(board));

  rep(i,K) {
    int r, c, v;
    cin >> r >> c >> v;
    board[r][c] = v;
  }

  for (int row = 1; row <= R; row++) {
    for (int col = 1; col <= C; col++) {

      for (int i = 1; i <= 3; i++) {
        //列移動で取る
        chmax(dp[row][col][i], dp[row][col-1][i-1] + board[row][col]);
        //列移動で取らない
        chmax(dp[row][col][i], dp[row][col-1][i]);
      }

      //行移動で取る
      int max_prev = 0;
      rep(j, 4) chmax(max_prev, dp[row-1][col][j]);
      chmax(dp[row][col][1], max_prev + board[row][col]);

      //行移動で取らない
      chmax(dp[row][col][0], max_prev);

    }
  }

  int answer = 0;
  rep(i,4) chmax(answer, dp[R][C][i]);

  cout << answer << '\n';

  return 0;
}

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

void move(string area[], int i, int j, char ch, int h, int w){
	area[i][j] = '.';
	if(i - 1 >= 0 && area[i-1][j] == ch) move(area, i - 1, j, ch, h, w);
	if(i + 1 < h && area[i+1][j] == ch) move(area, i + 1, j, ch, h, w);
	if(j - 1 >= 0 && area[i][j-1] == ch) move(area, i, j - 1, ch, h, w);
	if(j + 1 < w && area[i][j+1] == ch) move(area, i, j + 1, ch, h, w);
}

int main(){
	const int hmax = 100;
	int h, w;
	string area[hmax];
	while(cin >> h >> w){
		getline(cin, area[0]);
		int count = 0;
		if(h == 0 && w == 0) break;
		for(int i = 0; i < h; i++){
			getline(cin, area[i]);
		}
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				if(area[i][j] != '.'){
					count++;
					move(area, i, j, area[i][j], h, w);
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 0