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

int main(){
  long long l, r;
  cin >> l >> r;
  long long lmod = l % 2019;
  long long rmod = r % 2019;
  long long min = 1000000000;
  if(r < 2019){
    for(long long i=l; i<=r-1; i++){
      for(long long j=l+1; j<=r; j++){
        long long imod = i % 2019;
        long long jmod = j % 2019;
        long long res = (imod * jmod) % 2019;
        if(res < min) min = res;
        if(min == 0){
          cout << 0 << endl;
          return 0;
        }
      }
    }
  }else{
    for(long long i=l; i<=r-1; i++){
      for(long long j=i+1; j<=r; j++){
        long long imod = i % 2019;
        long long jmod = j % 2019;
        long long res = (imod * jmod) % 2019;
        if(res < min) min = res;
        if(min == 0){
          cout << 0 << endl;
          return 0;
        }
      }
    }
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long int dp[101][21];
int n;

int main(){

  int a[101] = {0};
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    cin >> a[i];
  }
  dp[1][a[0]] = 1;
  for(int i = 0 ; i < n ; i++ ){
    for(int j = 0 ; j <= 20 ; j++ ){
      if(j+a[i] <= 20 ){
	dp[i+1][j+a[i]] += dp[i][j];
      }
      if(j-a[i] >= 0 ){
	dp[i+1][j-a[i]] += dp[i][j];
      }
    }
  }

  cout << dp[n-1][a[n-1]] << endl;
}

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

int main(){
    int n; cin >> n;
    float x[n];
    string u[n];

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

    float sum = 0;

    for (int i=0;i<n;i++){
        if (u[i] == "JPY") {
            sum += x[i];
        } else {
            sum += x[i] * 380000.0;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
def q2():
    n = int(input())
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(1, n-1):
        if (P[i] >= P[i-1] and P[i] <= P[i+1] or
            P[i] <= P[i-1] and P[i] >= P[i+1]):
            ans += 1
    print(ans)

    
if __name__ == '__main__':
    q2()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    } 

    if(a[0] > 0) {
        out(-1);
        re0;
    }

    rep(i, n-1) {
        if(a[i] + 2 <= a[i+1]) {
            out(-1);
            re0;
        }
    }

    if(n == 1) {
        out(0);
        re0;
    }

    ll ans = 0;
    rep(i, n-1) {
        if(a[i] + 1 == a[i+1]) {
            ans++;
        }
        else {
            ans += a[i+1];
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  string a;cin>>a;
  if(a[0]==a[1]||a[1]==a[2]||a[2]==a[0]){
    cout<<"No"<<endl;
  }else{
    cout<<"Yes"<<endl;
  }

}

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

long long N;
int main() {
    cin >> N;
    vector<int> a(N), b(N, 0);
    int count = 0;
    for(int i = 0; i < N; ++i) {
        cin >> a.at(i);
    }
    for(int i = N; i > 0; --i) {
        int t = a.at(i-1);      
        for(int j = 2; i * j <= N; ++j) {
            t ^= b.at(j * i - 1);
        }
        b.at(i-1) = t;
        count += b.at(i-1);
    }

    cout << count << endl;
    for(int i = 0; i < N; ++i) {
        if(b.at(i)) {
            cout << i+1 << " ";
        }
    }
}

Measured memory_bytes: 2432
n = int(input())

def basen(n):
    a = []
    while n!= 0:
        r = n % 2
        if (r < 0):
            r += 2

        n = (n - r)//(-2)
        a.append(r)
    if a == []:
        a.append(0)
    a.reverse()
    return "".join(map(str,a))
print(basen(n))

            

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] ary = sc.next().toCharArray();
		boolean beau = true;
		for (char c1 : ary) {
			int count = 0;
			for (char c2 : ary) {
				if(c1 == c2) {
					count++;
				}
			}
			if(count%2 != 0) {
				beau = false;
				break;
			}
		}
		if(beau) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

#define int long long
const int sqrtN = 512;
struct SqrtDecomposition {
  int N, K;
  vector<int> data;
  vector<int> bucketAdd;
  SqrtDecomposition(int n) : N(n) {
    K = (N + sqrtN - 1) / sqrtN;
    data.assign(K * sqrtN, 0);
    bucketAdd.assign(K, 0);
  }
  void add(int s, int t, int x) {
    for (int k = 0; k < K; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if (r <= s || t <= l)
        continue;
      if (s <= l && r <= t) {
        bucketAdd[k] += x;
      } else {
        for (int i = max(s, l); i < min(t, r); ++i) {
          data[i] += x;
        }
      }
    }
  }
  // [x, y)
  int get(int s) {
    int k = s / sqrtN;
    return data[s] + bucketAdd[k];
  }
};

signed main() {
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  SqrtDecomposition decomp(N);
  while (Q--) {
    int c;
    cin >> c;
    if (c == 0) {
      int s, t, x; cin >> s >> t >> x;
      decomp.add(s, t + 1, x);
    } else {
      int i; cin >> i;
      cout << decomp.get(i) << endl;
    }
  }
}

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

int main(){
    int n,k;
    while(cin>>n>>k,n||k){
        bool series[100001]={},flag,ansflag;
        int ans,input,lastedge,lastlen,edge,len,mxlen;
        for(int i=0;i<k;i++){
            cin>>input;
            series[input]=true;
        }
        ans=0;lastedge=-1;
        for(int i=1;i<=n;i++){
            if(series[i]){
                edge=i;
                for(len=0;i<=n && series[i];i++){
                    len++;
                }
                if(series[0] && lastedge+2==edge){
                    mxlen=len+lastlen+1;
                    flag=true;
                }
                else{
                    mxlen=len;
                    flag=false;
                }
                if(mxlen>ans){
                    ans=mxlen;
                    ansflag=flag;
                }
                lastlen=len;
                lastedge=i-1;
            }
        }
        if(series[0] && !ansflag) ans++;
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1248
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split;
	auto A = data[0].to!long, B = data[1].to!long;
	
	long f(long n) { switch(n%4) {
		case 0: return n;
		case 1: return 1;
		case 2: return 1+n;
		case 3: return 0;
		default: return 0;
	} }
	if (A == 1) writeln(f(B));
	else { writeln(f(A-1) ^ f(B)); }
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int k, string s) {
    // 0, 1 でグループ化して個数を記録する
    int[] g;
    // 先頭要素が 0 なら、先頭に 0 個の 1 があると見なす
    if (s.front == '0') g ~= 0;

    int lo = 0;
    while (lo < s.length) {
        int hi = lo;
        while (hi < s.length && s[lo] == s[hi]) hi++;
        g ~= hi - lo;
        lo = hi;
    }

    // 累積和
    auto sum = new int[g.length];
    sum[0] = g[0];
    for (int i = 1; i < g.length; i++) {
        sum[i] = g[i] + sum[i - 1];
    }

    int ans = 0;
    // 1 の個数, 0 の個数... のパターンで並んでいるので
    // 各 1 の位置から、2 * k + 1 個取り出す
    for (int i = 0; i < sum.length; i += 2) {
        int hi = min(i + 2 * k, cast(int)sum.length - 1);

        int a = sum[hi] - (i-1 >= 0 ? sum[i-1] : 0);
        ans = max(ans, a);
    }
    return ans;
}

void main() {
    auto nk = readints;
    int k = nk[1];
    string s = read!string;

    writeln(calc(k, s));
}


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

int main(void) {
        double r;
        double round, surface;
        
        cin >> r;
        round = 2 * M_PI * r;
        surface = M_PI * pow(r,2);

        cout << fixed << setprecision(5) << surface << " " << round << endl;
        
        
        return 0;
}

Measured memory_bytes: 1292
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,x;
int32_t A[200];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>x;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i];
	}

	std::sort(A, A + N);
	int32_t res = 0;
	for (size_t i = 0; i < N; i++)
	{
		if (x <= 0) { break; }
		x -= A[i];
		++res;
	}
	if (x != 0) { --res; }

	out << res << endl;

	return 0;
}
#endif


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n;
    cin >> n;
    int num[n];
    int in = 10000000,ax = -10000000;
    long long sum = 0;
    rep(i,n) cin >> num[i], in = min(in,num[i]), ax = max(ax,num[i]), sum += num[i];
    cout << in << ' ' << ax << ' ' << sum << endl;
}


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

using namespace std;

int n,a[100005],b[100005];
bool bl=0;

int main () {
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	reverse(a, a + n);
	for(int i = 0; i < n - 1; i++) {
		if(a[i + 1] > a[i]) {
			if(a[i + 1] - 1 <= a[i]) {
				a[i+1]--;
			}
			else {
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}

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

int main(){
  int K;
  string S;
  int s,i;
  string sc;
  
  cin >> K >> S;

  s = S.size();

  if(s <= K){
    cout << S << endl;
  }else{
    for(i=0;i<K;i++){
      sc += S.at(i);
    }
    cout << sc << "..." << endl;
  }
}


Measured memory_bytes: 3628
N = int(input())
K = int(input())

X = str(N)

dp = [[[0] * (K+1) for _ in range(2)] for _ in range(len(X)+1)]
dp[0][0][0] = 1

for i in range(len(X)):
    digit = int(X[i])
    for j in range(2):
        for k in range(K+1):
            for d in range(10 if j == 1 else digit+1):
                if k + int(d != 0) <= K:
                    dp[i+1][j | (d < digit)][k + (d!=0)] += dp[i][j][k]
print(dp[-1][0][-1]+dp[-1][1][-1])

Measured memory_bytes: 40944
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険                                   // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍

#define INF ((1LL<<62)-(1LL<<31))
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p) pom(a,p-2,p)

////////////////////////////////////////////////////////////////////////////////////////
ll lcm(ll a, ll b){
    if(b == 0) return a;
    return lcm(b, a%b);
}

int main(){
    ll a, b; cin >> a >> b;
    cout << a*b/lcm(a,b) << endl;
}


Measured memory_bytes: 256
N, W = map(int, input().split())
dp = [[0] * (W + 1)] * (N + 1)
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W - w, -1, -1):
        dp[i+1][j + w] = max(dp[i][j + w], dp[i][j] + v)
print(dp[N][W])

Measured memory_bytes: 41836
#include <iostream>

int L[int(5e5 / 2)+10];
int R[int(5e5 / 2)+10];
const int INT_MAX_ = static_cast<int>(2e9);
int count = 0;

void merge(int* A, const int left, const int mid, const int right) {
    int n1 = mid - left;
    int n2 = right - mid;

    for(int i=0; i<n1; ++i) {
        L[i] = A[left + i];
    }

    for(int i=0; i<n2; i++) {
        R[i] = A[mid + i];
    }

    L[n1] = INT_MAX_;
    R[n2] = INT_MAX_;

    int i = 0;
    int j = 0;

    for(int k=left; k < right; ++k) {
        if(L[i] < R[j]) {
            count++;
            A[k] = L[i];
            ++i;
        } else {
            count++;
            A[k] = R[j];
            ++j;
        }
    }
}

void mergeSort(int* A, const int left, const int right) {
    if(left+1 < right) {
        const int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}


int main() {
    int n;
    std::cin >> n;
    int A[int(5e5)+10];

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

    mergeSort(A, 0, n);

    for(int i=0; i<n; ++i) {
        if(i != n-1){
            std::cout << A[i] << " ";
        } else {
            std::cout << A[i];
        }
    }

    std::cout << std::endl;
    std::cout << count << std::endl;

}


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

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

	int N, D;
	cin >> N >> D;

	int t = D * 2 + 1;
	int o = N / t;
	if (N % t != 0)
		o++;

	cout << o;

	return 0;
}


Measured memory_bytes: 256
/*イヅア公園には、夕方になると柴犬と散歩する人たちがたくさん来ます。
   柴犬には毛の色によって赤柴、黒柴、白柴、胡麻柴という種類があります。
   柴犬がたくさんいるとうれしいトモエちゃんは、
   それぞれの毛色の柴犬が何頭いるかがんばって数えましたが、
   まだ足し算ができないので柴犬が全部で何頭いるかわかりません。
   それぞれの毛色の柴犬の数が与えられたときに、
   柴犬の総数を計算するプログラムを作成せよ。*/

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
        int R, /*赤柴の数*/
            B, /*黒柴の数*/
            W, /*白柴の数*/
            G, /*胡麻柴の数*/
            sum; /*柴犬の総数*/
        cin >> R >> B >> W >> G;
        sum = R + B + W + G;
        cout << sum <<endl;
        return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <cstring>
#define rep(i,o,u) for(int i = o;i < u; i++)
using namespace std;
struct no{
	int value;
	char name;
}a[101],b[101];
int main(){
	int n;
	cin >> n;
	rep(i,0,n){ cin >> a[i].name; cin >> a[i].value;b[i] = a[i];}
	rep(i,0,n-1){
		rep(j,0,n-1-i){
			if(a[j].value > a[j+1].value){ swap(a[j],a[j+1]); }
		}
	}
	rep(i,0,n){ cout << a[i].name << a[i].value;if(i != n-1) cout << " ";}
	cout << endl;
	cout << "Stable" << endl;
	rep(i,0,n){
		int mn = i;
		rep(j,i+1,n){
			if(b[mn].value > b[j].value){
				mn = j;
			}
		}
		swap(b[i],b[mn]);
	}
	rep(i,0,n) { cout << b[i].name << a[i].value;if(i != n-1) cout << " ";}
	cout << endl;
	int flag = 0;
	rep(i,0,n){ if(a[i].name == b[i].name&&a[i].value == b[i].value){ flag++;} }
	if(flag == n){ cout << "Stable" << endl;}
	else cout << "Not stable" << endl;
	return 0;
}

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

const int INF = 1000000000;

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> to[100005];
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q;
    vector<int> dist(n,INF);
    vector<int> pre(n, -1);
    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int u : to[v]){
            if(dist[u] != INF) continue;
            dist[u] = dist[v]+ 1;
            pre[u] = v;
            q.push(u);
        }
    }

    cout << "Yes" << endl;
    rep(i,n){
        if(i == 0)continue;
        int ans = pre[i];
        ans++;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 10680
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int nax=1e7;
const ll inf=1e10+17;
vector<int> prime(nax,-1);
ll pow1(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b%2) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;

}
ll mul(ll a,ll b)
{
    return (a*1LL*b)%mod;
}
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 42120
<?php
list($N, $W) = array_map("intval", explode(" ", trim(fgets(STDIN))));
for($i = 0; $i < $N; $i++){
    $map[] = array_map("intval", explode(" ", trim(fgets(STDIN))));
}
array_unshift($map,[]);

for($j = 0; $j <= $W; $j++){
    $dp[0][$j] = 0;
}
for($i = 1; $i <= $N; $i++){
    list($w, $p) = $map[$i];
    $dpn = &$dp[$i];
    $dpp = &$dp[$i-1];
    for($j = 0; $j <= $W; $j++){
        $dpn[$j] = $dpp[$j];
    }
    for($j = $map[$i][0]; $j <= $W; $j++){
        $dpn[$j] = max($dpn[$j], $dpp[$j - $w] + $p);
    }
}
echo $dp[$N][$W];


Measured memory_bytes: 420328
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {
	int h, w;
	int c[10][10] = {};
	int a[201][201] = {};
	int total = 0;

	cin >> h >> w;

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

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}

	for (int k = 0; k <= 9; k++) {
		for (int i = 0; i <= 9; i++) {
			for (int j = 0; j <= 9; j++) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}

	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (a[i][j] != -1) {
				total += c[a[i][j]][1];
			}
		}
	}

	cout << total << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
//using namespace atcoder;

#define REP(i, n) for (int i=0; i<(n); ++i)
#define RREP(i, n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i, a, n) for (int i=(a); i<(n); ++i)
#define RFOR(i, a, n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld eps = 1e-9;


// edit

void solve() {
    int N;
    cin >> N;
    int ans = 0;
    for (int a = 1; a <= N; ++a) {
        for (int b = 1; a * b <= N; ++b) {
            int c = N - a * b;
            if (c > 0) {
                ans++;
            } else {
                break;
            }
        }
    }
    cout << ans << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define clr(n, r) memset(n,r,sizeof(n))
#define endl "\n"
typedef bitset<11> MASK;
typedef pair<int, int> ii;
typedef vector<int> vii;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<vector<int>> vvi;
#define all(v) v.begin(),v.end()
int n, m, k;
vector<vector<char>> arr(6, vector<char>(6));

int valid(int i, int j) {
    return i < n && j < m && i >= 0 && j >= 0;
}

map<vector<vector<char>>, bool> viss;
bool vis[10][10][40][40];
vector<vector<int>> rows;
vector<vector<int>> cols;
vi t;

void gen(int i, int n) {
    rows.push_back(t);
    for (int j = i; j < n; ++j) {
        t.push_back(j);
        gen(j + 1, n);
        t.pop_back();
    }
}

void gen1(int i, int n) {
    cols.push_back(t);
    for (int j = i; j < n; ++j) {
        t.push_back(j);
        gen1(j + 1, n);
        t.pop_back();
    }
}


int main() {
    std::ios_base::sync_with_stdio(false);
//        freopen("scratch.txt", "r", stdin);
    cin >> n >> m >> k;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> arr[i][j];
        }
    }
    gen(0, n);
    t.clear();
    gen1(0, m);
    int ans = 0;
    for (int l = 0; l < rows.size(); ++l) {
        for (int i = 0; i < cols.size(); ++i) {
            int cnt = 0;
            vector<vector<char>> tmp = arr;
            vi r = rows[l];
            vi c = cols[i];
            for (int j = 0; j < r.size(); ++j) {
                for (int w = 0; w < m; ++w) {
                    tmp[r[j]][w] = 'r';
                }
            }
            for (int j = 0; j < c.size(); ++j) {
                for (int w = 0; w < n; ++w) {
                    tmp[w][c[j]] = 'r';
                }
            }
            for (int i1 = 0; i1 < n; ++i1) {
                for (int j = 0; j < m; ++j) {
                    cnt += (tmp[i1][j] == '#');
                }
            }
            ans += (cnt == k);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n,a[100];
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);

	int ans=0;
	for(int i=0;i<n;i++){
		int mini=i;
		for(int j=i;j<n;j++){
			if(a[j]<a[mini]){
				mini=j;
			}
		}
		if(a[i]!=a[mini]){
			    swap(a[i],a[mini]);
			    ans++;
			}
	}
	for(int i=0;i<n;i++){
		if(i==n-1)printf("%d\n",a[i]);
		else printf("%d ",a[i]);
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1188
def solve(n):
    c = 0
    for a in range(1, n+1):
        if n % a == 0:
            c += 1
    return c == 8


def main():
    n = int(input())

    c = 0
    for a in range(1, n + 1, 2):
        if solve(a):
            c += 1
    print(c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007


int main() {
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	vector<ll>p,q,r;
	for(ll i=0;i<a;i++){
		ll now;
		cin>>now;
		p.push_back(now);
	}
	sort(p.begin(),p.end());
	for(ll i=0;i<x;i++){
		ll now=p[a-i-1];
		r.push_back(now);
	}
	for(ll i=0;i<b;i++){
		ll now;
		cin>>now;
		q.push_back(now);
	}
	sort(q.begin(),q.end());
	for(ll i=0;i<y;i++){
		ll now=q[b-i-1];
		r.push_back(now);
	}	
	for(ll i=0;i<c;i++){
		ll now;
		cin>>now;
		r.push_back(now);
	}
	sort(r.begin(),r.end());
	reverse(r.begin(),r.end());
	ll ans=0;
	for(ll i=0;i<x+y;i++){
		ans+=r[i];
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 9024
r, c = map(int, input().split())

mat = [[0 for i in range(c+1)] for j in range(r+1)]
for i in range(r):
    mat[i] = list(map(int, input().split()))

for i in range(r):
    s = sum(mat[i])
    mat[i].append(s)

for j in range(c):
    s = 0
    for i in range(r):
        s += mat[i][j]
    mat[r][j] = s

mat[r][c] = (sum(mat[r]))

for i in range(r+1):
    for j in range(c+1):
        if j == c:
            print(str(mat[i][j]))
        else:
            print(str(mat[i][j]) + " ", end="")


Measured memory_bytes: 6212
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long ll;

int dfs(int h,int n, int sum,int s){
    
    if(h==10){
        if(sum == s && n == 0) return 1;
        return 0;
    }
    
    return dfs(h+1,n-1,sum+h,s)+dfs(h+1,n,sum,s);
    
}

int main(){
    int n,s;
    
    while(1){
        
        scanf("%d%d",&n,&s);
        
        if(n==0) break;
        
        printf("%d\n",dfs(0,n,0,s));
    }
    
    return 0;
}

Measured memory_bytes: 1188
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

S = s()

left = 8
for c in S:
    if c == 'o':
        left -= 1

if 15 - len(S) < left:
    print('NO')
else:
    print('YES')


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;
int main()
{
    long long S,c,ans=0;
    
    cin >> S >> c;
    
    ans = min(S,c/2);
    
    c-=ans*2;
    
    if(c > 0)
    {
    ans += c/4;
    }
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<string>
#include<vector>
#include<list>
#include<cmath>
//#include <bits/stdc++.h>
using namespace std;

int main(){
    long long int n;cin>>n;
    long long int a[n+1];

    int count=0;
    for(int i=0;i<n;i++)cin>>a[i];
    long long int min=200001;
    for(int i=0;i<n;i++){
        if(min>a[i]){
            min=a[i];
            count++;
        }
    }
    cout<<count<<endl;
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        
        if(n == 0)  break;
        
        vector<int> person(n, 0);
        int turn = 0, ba = 0;
        
        char c;
        for(int i = 0; i < 100; i++){
            cin >> c;
            if(c == 'M')        person[turn]++;
            else if(c == 'S')   ba += person[turn]+1, person[turn] = 0;
            else if(c == 'L')   person[turn] += ba+1, ba = 0;
            turn = (turn+1)%n;
        }
        
        sort(person.begin(), person.end());
        for(int i = 0; i < n; i++){
            cout << person[i] << " ";
        }
        
        cout << ba << endl;
    }
    return 0;
}



Measured memory_bytes: 3120
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			String r = stdIn.next();
			String a = stdIn.next();
			
			if(r.equals("0") && a.equals("0")) {
				break;
			}
			int hit = 0;
			int blow = 0;
			for(int i = 0; i < 4; i++) {
				for(int j = 0; j < 4; j++) {
					if(i == j) {
						if(r.charAt(i) == a.charAt(j)) {
							hit++;
							break;
						}
					}
					else {
						if(r.charAt(i) == a.charAt(j)) {
							blow++;
							break;
						}
					}
				}
			}
			System.out.println(hit + " " + blow);
			
			
		}
	}
}

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

const int N = 110;

int a[N];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	long long cur = 1, now = 1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cur *= 3;
		if (a[i] % 2 == 0) now *= 2;
	}
	cout << cur - now << "\n";
	
	return 0;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#define fi first
#define se second
#define Mp make_pair
#define pb push_back
#define rep(i, j, k) for (int i = (j); i <= (k); i++)
#define per(i, j, k) for (int i = (j); i >= (k); i--)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int, int> PII;
typedef vector<int> VI;

const db PI = 3.1415926535898;
db a,b,x,tot;

int main(){
    cin>>a>>b>>x; tot=a*a*b;
    if(x==tot/2) printf("%.10f\n",atan(a/b)*180/PI);
    else if(x<tot/2){
        db t=2*x/a/b;
        printf("%.10f\n",90-atan(t/b)*180/PI);
    }
    else {
        db rx=tot-x;
        db t=2*rx/a/a;
        printf("%.10f\n",90-atan(a/t)*180/PI);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
  string s;
  string ans;
  cin >> s;
  if (s == "Sunny") ans = "Cloudy";
  if (s == "Cloudy") ans = "Rainy";
  if (s == "Rainy") ans = "Sunny";

  cout << ans << endl;
}


Measured memory_bytes: 888
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
 
using namespace __gnu_pbds;
using namespace std;

#define double      	long double
#define int         	long long
#define pb          	push_back
#define pii         	pair<int,int>
#define vi          	vector<int>
#define vii         	vector<pii>
#define mi          	map<int,int>
#define mii         	map<pii,int>
#define all(a)      	(a).begin(),(a).end()
#define sz(x)       	(int)x.size()
#define endl        	"\n"
#define repp(i,a,b) 	for(int i=a;i<b;i++)
#define rep(i,a,b) 		for(int i=a;i<=b;i++)
#define brep(i,a,b)     for(int i=a;i>=b;i--)
#define deb1(x)      	cout << #x << "=" << x << endl
#define deb2(x, y)  	cout << #x << "=" << x << "," << #y << "=" << y << endl
#define deb3(x, y, z)  	cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define trace(v) 		for(auto it=v.begin();it!=v.end();it++)cout<<*it<<" ";cout<<endl;
#define tracearr(a,l,r) for(int iii=l;iii<=r;iii++)cout << a[iii] << " ";cout << endl;
#define PI          	3.1415926535897932384626
#define F 				first
#define S 				second
#define clr(x,y) 		memset(x, y, sizeof(x))
#define IOS         	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
// *s.find_by_order(1) - gives the 2nd samllest element in set
// s.order_of_key(x)   - gives the number of elements in the set which are strictly smaller than x


const int N=1e5 + 5;
const int MOD=1e9 + 7;

int32_t main()
{
	IOS;
	int T=1;
	//cin >> T;
	// int numOfSetBits = __builtin_popcountll(n);
	std::cout << std::fixed << std::setprecision(12);
	while(T--)
	{
		int n;
		cin >> n;
		mi mp;
		int sum = 0;
		rep(i,1,n)
		{
			int x;
			cin >> x;
			mp[x]++;
			sum += x;
		}
		int q;
		cin >> q;
		while(q--)
		{
			int x,y;
			cin >> x >> y;
			sum -= x*(mp[x]);
			sum += y*(mp[x]);
			int t = mp[x];
			mp[x] = 0;
			mp.erase(x);
			mp[y] = mp[y] + t;
			cout << sum << endl;
		}
	}
}



Measured memory_bytes: 7568
N = int(input())
Hs = [int(h) for h in input().split()]

for i in range(N - 2, -1, -1): 
    if Hs[i] > Hs[i + 1]:
        Hs[i] -= 1
    
    if Hs[i] > Hs[i + 1]:
        break
else:
    print('Yes')
    exit()
    
print('No')

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

using namespace std;
typedef long long ll;

#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define out(ans) cout << ans << endl
#define in(n) cin >> n

void solve();
ll m, d;

int main()
{
    solve();
}

void solve()
{
    in(m);
    in(d);
    ll ans;
    floop1(i, m)
    {
        floop1(j, d)
        {
            int da[2] = {j / 10, j % 10};
            if (i == da[0] * da[1] && da[0] >= 2 && da[1] >= 2)
            {
                ans++;
            }
        }
    }
    out(ans);
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program{
    static void Main(){
        int[] hw = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int c = 0;
        for (int i = 0 ;i < hw[0] ;i++){
            char[] a = Console.ReadLine().ToCharArray();
            c += a.Count(s => s == '#');
        }
        string ans = (c == hw[0] + hw[1] - 1) ? "Possible" : "Impossible";
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13396
k = int(input())

if k % 2 == 0 or k % 5 == 0:
    print(-1)
else:
    n = 7
    cnt = 1
    for i in range(k):
        if n % k == 0:
            break
        cnt += 1
        n = (n * 10 + 7) % k
    print(cnt)


Measured memory_bytes: 8980
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int n = sc.nextInt();
        System.out.println(n / 3);
    }
}

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

#define endl '\n'
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define add push_back
#define MAXN 200005

int n, t;

int main(){ios_base::sync_with_stdio(false);
    
    double r;
    cin >> r;
    cout <<setprecision(9)<< 2*M_PI*r << endl;

    return 0;
}



Measured memory_bytes: 3784
#include <iostream>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);

#if DEBUG_ON
    freopen("input", "r", stdin);
#endif

    long long a, b, c;
    std::cin >> a >> b >> c;
    long long d = c - a - b;
    if (d > 0 && 4 * a * b < d * d) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }
    return 0;
}

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

#define db(x) cout << "> " << #x << ": " << x << endl;

const int N = 100100;
using namespace std;

long long p[N];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, m;
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++)
	{
		int a;
		cin >> a;
		p[i] = (p[i -1] +a) % m;
	}
	
	map <int, int> cnt;
	for(int i = 1; i <= n; i++)
		cnt[p[i]]++;
	
	long long res = 0;
	for(int i = 1; i <= n; i++)
	{
		res += cnt[p[i -1]];
		cnt[p[i]]--;
	}
	
	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 3968
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll x;
//ld ;
//string s;

bool isPrime(ll n){
    if(n > 3){
        for(ll i = 2; i*i <= n; i++){
            if(n % i == 0){
                return false;
           }
        }
    }
    return true;
}

int main() {
    cin >> x;
    ll result = x;
    for(ll i=x; ;i++){
        if(isPrime(i)){
            result = i;
            break;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 888;
int p[MAXN], d[MAXN];

struct Edge {
	int to;
	int cost;
	Edge() {}
	Edge(int to, int cost) : to(to), cost(cost) {}
};

vector<Edge> G[MAXN];

ll dp[MAXN][2];

// flag = 0: ??°??£?????????????????????
// flag = 1: ?????? v ????????£?????????????????°????????????
ll dfs(int v, int p, int flag) {
	ll& ret = dp[v][flag];
	if (ret >= 0) return ret;
	ret = 0;
	ll sum = 0;
	for (Edge e : G[v]) {
		if (e.to == p) continue;
		dfs(e.to, v, 0);
		dfs(e.to, v, 1);
		if (G[e.to].size()==1) {
			sum += e.cost;
		} else {
			sum += e.cost + dp[e.to][1] + e.cost + e.cost;
		}
	}
	ret = sum;
	if (!flag) {
		for (Edge e : G[v]) {
			if (e.to == p) continue;
			if (G[e.to].size() == 1) continue;
			ll tmp = sum-dp[e.to][1]-e.cost + dp[e.to][0];
			ret = min(ret, tmp);
		}
	}
	return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
    	if (n==0) break;
    	for (int i = 0; i < n-1; i++) 
    		cin >> p[i];
    	for (int i = 0; i < n-1; i++) 
    		cin >> d[i];
    	for (int i = 0; i < n; i++)
    		G[i].clear();
    	for (int i = 0; i < n-1; i++) {
    		p[i]--;
    		G[i+1].emplace_back(p[i], d[i]);
    		G[p[i]].emplace_back(i+1, d[i]);
    	}
    	ll ans = 1ll<<55;
    	for (int i = 0; i < n; i++) {
    		memset(dp, -1, sizeof(dp));
    		ans = min(ans, dfs(i, -1, 0));
    	}
    	cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3328
import sys,math
sys.setrecursionlimit(10**9)
import itertools
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())


n=int(input())


def dfs(s,lim):

    
    if len(s)==n:
        print(s)
    else:
        for i in range(ord('a'),ord(lim)+1):
            
            if i==ord(lim):
                dfs(s+chr(i),chr(ord(lim)+1))
            else:
                dfs(s+chr(i),lim)

dfs('','a')


Measured memory_bytes: 4720
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 2000 + 5;

/***************************************************************************/

pii A[2*N];
int DP[N][N];
int W[N], B[N];
int BC[N][N], WC[N][N];

int main() {

	boost;

	int n; cin>>n;
	for(int i=1; i<=2*n; i++) {
		char ch; int a; cin>>ch>>a;
		if(ch == 'B') {
			B[a] = i;
		}
		else {
			W[a] = i;
		}
		A[i] = pii(a, (ch == 'B'));
	}

	for(int i=1; i<=2*n; i++) {
		if(A[i].se == 0) continue;
		for(int j=1; j<i; j++) {
			if(A[j].se == 0) continue;
			if(A[j].fi > A[i].fi) BC[A[i].fi][n] += 1;
		}
	}

	for(int i=1; i<=2*n; i++) {
		if(A[i].se == 1) continue;
		for(int j=1; j<i; j++) {
			if(A[j].se == 1) continue;
			if(A[j].fi > A[i].fi) WC[n][A[i].fi] += 1;
		}
	}

	for(int j=0; j<n; j++) {
		int cnt = 0;
		for(int i=1; i<=2*n; i++) {
			if(A[i].se == 0) {
				if(A[i].fi > j) cnt++;
			}
			else {
				BC[A[i].fi][j] = BC[A[i].fi][n] + cnt;
			}
		}
	}

	for(int j=0; j<n; j++) {
		int cnt = 0;
		for(int i=1; i<=2*n; i++) {
			if(A[i].se == 1) {
				if(A[i].fi > j) cnt++;
			}
			else {
				WC[j][A[i].fi] = WC[n][A[i].fi] + cnt;
			}
		}
	}

	for(int i=n; i>=0; i--) {

		for(int j=n; j>=0; j--) {

            if(i == n and j == n) continue;
            else if(i == n) DP[i][j] = WC[i][j+1] + DP[i][j+1];
            else if(j == n) DP[i][j] = BC[i+1][j] + DP[i+1][j];
            else DP[i][j] = min(BC[i+1][j]+ DP[i+1][j], 
                                WC[i][j+1] + DP[i][j+1]);
		}
	}

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

Measured memory_bytes: 47360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b)
{
    int t;
    if(a<b)
    {
        t=a;a=b;b=t;
    }
    while(b!=0)
    {
        t=a%b;
        a=b;b=t;
    }
    return a;
}
int main()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        for(int k=1;k<=n;k++)
        ans+=gcd(gcd(i,j),k);
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main(){
	
	int a,b,c,ans;
	ans=0;
	cin>>a>>b>>c;
	
	for(int n=a;n<=b;n++){
		
		if(c%n==0){ans=ans+1;
		}
		
	}
	cout<<ans<<endl;
	
	
}


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

template <class operator_monoid> class dual_segment_tree{
public:
	typedef typename operator_monoid::underlying_type underlying_type;
	typedef typename operator_monoid::value_type value_type;
	size_t n;
	vector<underlying_type> v;
	vector<value_type> w;
	underlying_type e = operator_monoid::unit();
	dual_segment_tree(size_t size){
		n = 1;
		while(n < size) n <<= 1;
		v.resize(2*n, e);
		w.resize(size, operator_monoid::default_value());
	}
	dual_segment_tree(vector<value_type> _w){
		size_t size = w.size();
		n = 1;
		while(n < size) n <<= 1;
		v.resize(2*n, e);
		w(_w);
	}
	void range_operate(underlying_type f, size_t a, size_t b, size_t k, size_t l, size_t r){
		if(r <= a || b <= l) return;
		if(a <= l && r <= b) v[k] = operator_monoid::compose(f, v[k]);
		else{
			if(2*k < v.size())
				v[2*k] = operator_monoid::compose(v[k], v[2*k]);
			if(2*k+1 < v.size())
				v[2*k+1] = operator_monoid::compose(v[k], v[2*k+1]);
			v[k] = operator_monoid::unit();
			range_operate(f, a, b, 2*k, l, (l+r+1)/2);
			range_operate(f, a, b, 2*k+1, (l+r+1)/2, r);
		}
	}
	void range_operate(underlying_type f, size_t a, size_t b){
		range_operate(f, a, b, 1, 0, n);
	}
	value_type point_get(size_t i){
		range_operate(e, i, i+1, 1, 0, n);
		return operator_monoid::operate(v[i+n], w[i]);
	}
};
struct assign_operator_monoid{
	using underlying_type = pair<bool, Int>;
	using value_type = Int;
	static underlying_type unit(){
		return pair<bool, int>(true, 0);
	}
	static underlying_type compose(underlying_type l, underlying_type r){
		if(l == unit()) return r;
		return l;
	}
	static value_type default_value(){
		return (1ll<<31)-1;
	}
	static value_type operate(underlying_type f, value_type x){
		return f.first ? x : f.second;
	}
};

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	Int n, q; cin >> n >> q;
	dual_segment_tree<assign_operator_monoid> dst(n);
	while(q--){
		Int p; cin >> p;
		if(p == 0){
			Int s, t, x; cin >> s >> t >> x;
			dst.range_operate(pair<bool, Int>(false, x), s, t+1);
		}else{
			Int i; cin >> i;
			cout << dst.point_get(i) << "\n";
//			if(i == 5)
//				for(Int j=0; j<64; ++j)
//					cout << j << " " << (dst.v[j].first ? "id" : "no") << " " << dst.v[j].second << "\n";
		}
	}
}


Measured memory_bytes: 7504
#include "bits/stdc++.h"
using namespace std;
#define forn(i, x, n) for (int i = x; i < n; i++)
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long double ld;
typedef long long ll;
template <typename... Args>
void dbg(Args&&... args) {
  using expander = int[];
  (void)expander {0,(static_cast<void>(void(cout << std::forward<Args>(args) << " ")), 0)...};
  cout << endl;
}
void gen() {exit(0);}

const int N = 1e5 + 5;
const int M = 1e9 + 5;
int n, m;
int a[N];

void input() {
  scanf("%d %d", &n, &m);
  forn(i, 0, n) {
    scanf(" %d", &a[i]);
  }
}

ll ans = 0;
map<int, int> counts;

void solve() {
  int cur = 0;
  
  forn(i, 0, n) {
    cur = (cur + a[i]) % m;
    ans += counts[cur] + (cur == 0);
    counts[cur]++;
  }
 
  printf("%lld\n", ans);
}

int main() {
#ifdef DEBUG
  freopen("input", "r", stdin);
  //  freopen("output", "w", stdout);
  //  gen();
#endif
  input();
  solve();
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  bool flag = true;
  for(int i=0;i<n;i++){
    int a = 0;  
    cin >> a;
    if(a%2==0){
      if(a%3==0||a%5==0) continue;
      else{
        flag = false;
        break;
      }
    } 
  }
  if (flag == true) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

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

int main() {
	int n, ans;
	cin >> n;
	ans = n;

	for (int i = 0; i <= n; i++) {
		int x = 0;
		int k = i;

		while (k > 0) {
			x += k % 6;
			k /= 6;
		}
		k = n - i;
		while (k > 0) {
			x += k % 9;
			k /= 9;
		}
		if (ans > x) {
			ans = x;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		long a=sc.nextLong();		//高橋
		long b=sc.nextLong();		//青木
		long k=sc.nextLong();		//繰り返し
		
		if(k<=a){
	          System.out.println(a-k+" "+ b);
	        }else if(k<=a+b){
	          System.out.println(0+" "+(b-(k-a)));
	        }else{
	          System.out.println(0+" "+0);
	        } 
		sc.close();
	}

}

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

int main(){
    vector< vector<char> > C(3, vector<char>(3));
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> C.at(i).at(j);
        }
    }

    cout << C.at(0).at(0) << C.at(1).at(1) << C.at(2).at(2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 200000

int main(void){
  int data[N],len,i,j,max,min;

  scanf("%d",&len);
  for(i=0;i<len;i++) scanf("%d",&data[i]);

  min=data[0];
  max=data[1]-data[0];

  for(j=1;j<len;j++){
    if(max<data[j]-min) max=data[j]-min;
    if(min>data[j]) min=data[j];
  }

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

Measured memory_bytes: 1376
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pb push_back
#define speed_up ios_base::sync_with_stdio(false);cin.tie(NULL);
#define f(i,n) for(i=0;i<n;i++)
#define test  lli t;cin>>t;while(t--)
typedef long long int lli;
int main()
{
    speed_up
    lli o,w,i,j;
    cin>>o>>w;
 lli ar[o+1][3]={0};


 for(i=1;i<=o;i++)
 {
   cin>>ar[i][1];
   cin>>ar[i][2];
 }
lli  dp[o+1][w+1]={0};
 for(i=0;i<=o;i++)
 {
     for(j=0;j<=w;j++)
     {
         if(i==0||j==0)
         dp[i][j]=0;
         else
         {if(j<ar[i][1])
         {
             dp[i][j]=dp[i-1][j];
         }
         else
         {
             dp[i][j]=max(dp[i-1][j],dp[i-1][j-ar[i][1]]+ar[i][2]);
         }
         }
     }
 }
 cout<<dp[o][w];
}

Measured memory_bytes: 79232