akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
vector<int> P, invP;

int dp[510000];

int rec(int i) {
    if (dp[i] != -1) return dp[i];
    if (P[i] == N-1) return 1;
    int j = invP[P[i]+1];
    if (j < i) return 1;
    else return dp[i] = rec(j) + 1;
}

int main() {
    while (cin >> N) {
        P.resize(N); invP.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> P[i];
            --P[i];
            invP[P[i]] = i;
        }
        int res = 0;
        memset(dp, -1, sizeof(dp));
        for (int i = 0; i < N; ++i) {
            chmax(res, rec(i));
            //cout << i << ": " << P[i] << ", " << rec(i) << endl;
        }
        cout << N - res << endl;
    }
}











Measured memory_bytes: 6912
# coding: utf-8
# Your code here!
INF = 2000000000

def matrixChainMultiplication(m):
    global n
    for l in range(2, n+1):
        for i in range(1, n-l + 2):
            j = i + l - 1
            m[i][j] = INF
            for k in range(i, j):
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j]+p[i-1]*p[k]*p[j])
    return m
 
    
n = int(input())

m = [[0 for i in range(n + 1)] for j in range(n + 1)]
p = []


for i in range(n):
    input_command = input()
    num1,num2 = input_command.split()
    p.append(int(num1))
    if i == n-1:
        p.append(int(num2))
        
m = matrixChainMultiplication(m)
print(m[1][n])





Measured memory_bytes: 5684
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	ll ans=inf;
	for(ll i=0;i<=1e7;i+=2){
		ll now=i*c+max(0ll,x-i/2)*a+max(0ll,y-i/2)*b;
		chmin(ans,now);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


ll gcd(ll a, ll  b) {
	if (a < b)swap(a, b);
		if (a % b == 0) {
			return b;
		}
		else {
			gcd(b, a % b);
		}
}

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

int main() {
	
	int N;
	int k=-1;
	cin >> N;
	vector<int> p(N);
	unordered_map<ll,int> f;
	rep(i, N) {
		cin >> p[i];
		if (p[i] == 1) {
			k = 0;
		}
	}
	rep(i, 1 << N) {
		ll plcm = 1;
		rep(j, N) {
			if (i >> j & 1) {
				plcm = lcm(plcm, p[j]);
			}
		}
		f[plcm] = 1;
		
	}
	int ans = f.size();
	cout << ans + k << endl;

	return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N,K; cin >> N >> K;
    string S; cin >> S;
    int j = 0;
    rep(i,K) {
        int s = 0;
        char c = S[0];
        for(; j<N; j++) if (c != S[j]) break;
        if (j == N) break;
        s = j;
        c = S[j];
        for(; j<N; j++) if (c != S[j]) break;
        c = (c == 'L') ? 'R' : 'L';
        fill(S.begin()+s, S.begin()+j, c);
    }
    int cnt = 0, sum = 0;
    rep(i,N-1) {
        if (S[i] == S[i+1]) cnt++; else cnt = 0;
        sum += (cnt > 0);
    }
    cout << sum << endl;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int A;
int B;
int C;
int main(){
  rd(A);
  rd(B);
  rd(C);
  if(B-A==C-B){
    wt_L("YES");
    wt_L('\n');
  }
  else{
    wt_L("NO");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int A, B, C;
// {
//   rd(A,B,C);
//   wt( if[B-A==C-B, "YES", "NO"] );
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct Mint {
  using M = Mint;
  static unsigned P;
  unsigned v;
  Mint() : v(0) {}
  Mint(auto x) : v(x >= 0 ? x % P : (P - -x % P) % P) {}
  constexpr Mint(unsigned v, int) : v(v) {}
  M operator+() const { return *this; }
  M operator-() const { return {v ? P - v : 0, 0}; }
  explicit operator bool() const noexcept { return v; }
  bool operator!() const noexcept { return !(bool)*this; }
  M operator*(M r) const { return M(*this) *= r; }
  M operator/(M r) const { return M(*this) /= r; }
  M operator+(M r) const { return M(*this) += r; }
  M operator-(M r) const { return M(*this) -= r; }
  bool operator==(M r) const { return v == r.v; }
  bool operator!=(M r) const { return !(*this == r); }
  M& operator*=(M r) { v = (uint64_t)v * r.v % P; return *this; }
  M& operator/=(M r) { return *this *= r.inv(); }
  M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; }
  M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; }
  M inv() const {
    int a = v, b = P, x = 1, u = 0;
    while (b) {
      int q = a / b;
      swap(a -= q * b, b);
      swap(x -= q * u, u);
    }
    assert(a == 1);
    return x;
  }
  M pow(auto n) const {
    if (n < 0) return pow(-n).inv();
    M res = 1;
    for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a;
    return res;
  }
  friend M operator*(auto l, M r) { return M(l) *= r; }
  friend M operator/(auto l, M r) { return M(l) /= r; }
  friend M operator+(auto l, M r) { return M(l) += r; }
  friend M operator-(auto l, M r) { return M(l) -= r; }
  friend ostream& operator<<(ostream& os, M r) { return os << r.v; }
  friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; }
  friend bool operator==(auto l, M r) { return M(l) == r; }
  friend bool operator!=(auto l, M r) { return !(l == r); }
};
unsigned Mint::P;

map< V<>, Mint> dp[101][101];

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k >> Mint::P;
  dp[1][0][{0, 0, 0}] = 1;
  for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) {
    for (const auto& e : dp[i][j]) {
      auto v = e.first;
      if (v.size() >= 3 and i + j - min(v[0], v[2]) > k) continue;
      if (i + 1 <= n and i + j - v.back() <= k) {
        auto nv = v;
        nv.push_back(i + j);
        dp[i + 1][j][nv] += e.second;
      }
      if (j + 1 <= i and i + j - min(v[0], v[2]) <= k) {
        auto nv = v;
        nv.erase(begin(nv));
        nv[0] = i + j;
        dp[i][j + 1][nv] += e.second;
      }
    }
  }
  Mint res;
  for (const auto& e : dp[n][n]) res += e.second;
  cout << res << '\n';
}


Measured memory_bytes: 47884
<?php
    
    while ($line = fgets(STDIN)) {
        $inputs = array();
        $inputs[] = explode(' ', trim($line));
        
        $result = (int) $inputs[0][0] + (int) $inputs[0][1];
        
        $length = strlen($result);
        print_r("$length\n");
    }

Measured memory_bytes: 6572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14

int main(){
    ll n; cin >> n;
    vector<vector<ll>> dp(n+1,vector<ll>(30,0));
    REP(i,n){
        ll a; cin >> a;
        REP(j,30){
            if ((a>>j)%2) dp[i+1][j]=dp[i][j]+1;
            else dp[i+1][j]=dp[i][j];
        }
    }
    vector<vector<ll>> ansl(n+1,vector<ll>(30,0));
    REP(j,30){
        vector<ll> cnter(n+1);
        REP(i,n+1) cnter[i]=dp[i][j];
        REP(i,n+1){
            ll ind = upper_bound(cnter.begin(),cnter.end(),cnter[i]+1)-cnter.begin();
            ansl[i][j]=ind-i-1;
        }
    }
    ll ans = 0;
    REP(i,n+1){
        ll ansc = n;
        REP(j,30) ansc = min(ansc,ansl[i][j]);
        ans+=ansc;
        //cout << i << " " << ansc << endl;
    }
    cout << ans << endl;
}

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

int main() {
    long long int n, a, b, ans = 0;
    cin >> n >> a >> b;
    long long int x[n];
    for(int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    long long int push_sum = 0;
    for(int i = 1; i < n; ++i) {
        long long int d = x[i] - x[i-1];
        if(d*a <= b) ans += d*a;
        else ans += b;
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(){
  int i,j,v,N,k;
  int A[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  for(i=0;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    for(k=0;k<N;k++){
      printf("%d",A[k]);
      if(k<N-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}





Measured memory_bytes: 2052
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
c=0
for i in range(Y-X):
	if max(x)<i+X+1<=min(y):
		print("No War")
		exit()
else:
	print("War")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a == b) cout << "Draw" << endl;
  else if(a == 1) cout << "Alice" << endl;
  else if(b == 1) cout << "Bob" << endl;
  else if(a > b) cout << "Alice" << endl;
  else if(a < b) cout << "Bob" << endl;
  return 0;
}


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

#define NIL -1
#define MAX 100005

struct Node{int parent,	left,	right; };
Node T[MAX];

int n,D[MAX],H[MAX];

// ここからプロトタイプ宣言
void setDepth(int u, int d);
int setHeight(int u);
int getSibling(int u);
void Print(int u);
// ここまでプロトタイプ宣言

int main(){
	int id,l,r,root=0;
	cin>>n;

	for(int i=0;i<n;i++)T[i].parent=NIL;

	for(int i=0;i<n;i++){
		cin>>id>>l>>r;
		T[id].left = l;
		T[id].right = r;
		if(l != NIL) T[l].parent = id;
		if(r != NIL) T[r].parent = id;
	}

	for(int i=0;i<n;i++){
		if(T[i].parent==NIL) root=i;
	}

	setDepth(root,0);
	setHeight(root);

	for(int i=0;i<n;i++) Print(i);

	return 0;
}



// --------------------- //
// 関数
void setDepth(int u, int d){
	if(u==NIL) return;

	D[u]=d;

	setDepth(T[u].left, d+1);
	setDepth(T[u].right, d+1);
}

int setHeight(int u){
	int h1=0, h2=0;
	if(T[u].left != NIL)
		h1 = setHeight(T[u].left) +1;

	if(T[u].right != NIL)
		h2 = setHeight(T[u].right) +1;

	return H[u]=(h1>h2 ? h1 : h2);

}

int getSibling(int u){
	if(T[u].parent == NIL)return NIL;

	if(T[ T[u].parent ].left != u && T[ T[u].parent ].left != NIL)
		return T[ T[u].parent ].left;

	if(T[ T[u].parent ].right != u && T[ T[u].parent ].right != NIL)
		return T[ T[u].parent ].right;

	return NIL;

}

void Print(int u){
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].parent);
	printf("sibling = %d, ",getSibling(u) );

	int deg=0;
	if(T[u].left != NIL)deg++;
	if(T[u].right != NIL)deg++;

	printf("degree = %d, ",deg);
	printf("depth = %d, ",D[u]);
	printf("height = %d, ",H[u]);

	if(T[u].parent == NIL)						printf("root\n");
	else if(T[u].left==NIL && T[u].right==NIL)	printf("leaf\n");
	else										printf("internal node\n");
}



Measured memory_bytes: 3240
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var dictS = new Dictionary<string, int>();
            for (var i = 0; i < N; i++)
            {
                var s = Console.ReadLine();
                if (!dictS.ContainsKey(s)) dictS[s] = 0;
                dictS[s]++;
            }
            var M = int.Parse(Console.ReadLine());
            var dictT = new Dictionary<string, int>();
            for (var i = 0; i < M; i++)
            {
                var t = Console.ReadLine();
                if (!dictT.ContainsKey(t)) dictT[t] = 0;
                dictT[t]++;
            }
            var answer = 0;
            foreach (var s in dictS.Keys)
            {
                if (dictT.ContainsKey(s)) answer = Math.Max(answer, dictS[s] - dictT[s]);
                else answer = Math.Max(answer, dictS[s]);
            }
            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 13152
#include<stdio.h>
int n,a[50];
int solve(int i,int m){
	if(m==0)return 1;//該当パターンが発見されたとき
	if(i>=n) return 0;
	int res = solve(i+1,m)||solve(i+1,m-a[i]);//考えられるパターンをすべて列挙するためにsolve関数を繰り返している、１が生成された瞬間or分のため成功
	return res;
}
int main(){
	int q,m,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&m);
		if(solve(0,m))printf("yes\n");
		else printf("no\n");
	}
	return 0;
	
	
	
}



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

ll solve() {
    ll N, a;
    cin >> N;
    vector<pair<int,int>> p;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        p.push_back(make_pair(a,i));
    }
    sort(p.begin(), p.end());
    for ( int i = 0; i < N; i++ ) {
        cout << (i != 0 ? " " : "") << p[i].second + 1;
    }
    cout << "\n";
    return 0;
}

int main() {
    auto ans = solve();
    return 0;
}

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

int main(){
    long long int N,D,cnt=0;
    cin >> N >> D;
    long long int X,Y;
    for(int i=0;i<N;i++){
        cin >> X >> Y;
        if(D*D>=X*X+Y*Y)cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main()
{
    char character;



    scanf("%c", &character);


    if(character >= 'A' && character <= 'Z')
    {
        printf("A");
    }
    else if(character >= 'a' && character <= 'z')
    {
        printf("a");
    }


    return 0;
}

Measured memory_bytes: 1596
#include <iostream>
#include <list>
#include <string>

using namespace std;

int main()
{
	list<int> l;
	string i;

	while (cin >> i) {
		if (i == "insert") {
			int k;
			cin >> k;

			l.push_front(k);
		} else if (i == "delete") {
			int k;
			cin >> k;

			for (auto i = l.begin(); i != l.end(); i++) {
				if (*i == k) {
					l.erase(i);
					break;
				}
			}
		} else if (i == "deleteFirst") {
			l.pop_front();
		} else if (i == "deleteLast") {
			l.pop_back();
		}
	}

	for (auto i = l.begin(); i != --l.end(); i++) {
		cout << *i << ' ';
	}
	cout << *(--l.end()) << endl;
}

Measured memory_bytes: 34316
Module Module1
    Sub Main()
        'let'
        Dim tmp() As Integer =
            Array.ConvertAll(Of String, Integer)(
                Split(Console.ReadLine()), AddressOf Integer.Parse)
        Dim N As Integer = tmp(0)
        Dim Y As Integer = tmp(1)

        'var'
        Dim ans() As Integer = New Integer() {-1, -1, -1}
        Dim flg As Boolean

        For i As Integer = 0 To N
            For j As Integer = 0 To N - i
                Dim k As Integer = N - i - j
                If 10 * i + 5 * j + k = Y \ 10 ^ 3 Then
                    ans(0) = i
                    ans(1) = j
                    ans(2) = k
                    flg = True
                    Exit For
                End If
            Next
            If flg Then Exit For
        Next

        For i As Integer = 0 To UBound(ans)
            Console.Write(ans(i))
            If i <> UBound(ans) Then
                Console.Write(" ")
            Else
                Console.WriteLine()
            End If
        Next

    End Sub
End Module


Measured memory_bytes: 13536
import java.io.*;

import java.util.*;



public class Main {



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

		Scanner sc = new Scanner(System.in);

		PrintWriter pw = new PrintWriter(System.out);
        int n=sc.nextInt();
        int w=sc.nextInt();
        int[] w1=new int[n];
        int[] v=new int[n];
        for(int i=0;i<n;i++){
            w1[i]=sc.nextInt();
            v[i]=sc.nextInt();
        }
        long[][] arr=new long[2][w+1];
        for(int i=0;i<w+1;i++){
            arr[1][i]=0;
        }
        arr[0][0]=0;
        for(int i=n-1;i>=0;i--){
            for(int j=1;j<w+1;j++){
                long leave=arr[1][j];
                long take=(j-w1[i]>=0)?(v[i]+arr[1][j-w1[i]]):-1*Long.MAX_VALUE;
                arr[0][j]=Math.max(take,leave);
            }
            arr[1]=arr[0];
            arr[0]=new long[w+1];
        }
        pw.println(arr[1][w]);
		pw.close();

	}
public static boolean prime(int x){
	    int[] arr=new int[10000000];
	    int index=0;
	    int num=3;
	    int i=0;
	    arr[0]=2;
	    while(num<=x){
	      for(i=0;i<=index;i++){
	          if(num%arr[i]==0){
	              break;
	          }
	      }
	      if(i==index+1){
	          arr[++index]=num;
	      }
	      num++;
	    }
	    if(arr[index]==x)return true;
	    return false;
	      
	}
public static void conquer(int[] arr,int b,int m,int e){
	    int len1=m-b+1;
	    int len2=e-m;
	    int[] l=new int[len1];
	    int[] r=new int[len2];
	    for(int i=0;i<len1;i++){
	        l[i]=arr[b+i];
	    }
	   for(int j=0;j<len2;j++){
	            r[j]=arr[m+1+j];
	   }
	    int i=0,j=0,k=b;
	    while((i<len1)&&(j<len2)){
	        if(r[j]>=l[i]){
	            arr[k]=l[i];
	            k++;
	            i++;
	        }
	        else{
	           arr[k]=r[j];
	           k++;
	           j++;
	        }
	    }
	    while(i<len1){
	        arr[k++]=l[i++];
	    }
	    while(j<len2){
	        arr[k++]=r[j++];
	    }
	}
	static int mid;
	public static void sort(int[] arr,int b,int e){
	    if(b<e){
	        int mid =(e+b)/2;
	        sort(arr,b,mid);
	        sort(arr,mid+1,e);
	        conquer(arr,b,mid,e);
	    }
	}
    public static void Sort(int[] arr){
        sort(arr,0,arr.length-1);
    }

	static class Scanner {

		StringTokenizer st;

		BufferedReader br;



		public Scanner(InputStream s) {

			br = new BufferedReader(new InputStreamReader(s));

		}



		public Scanner(String file) throws FileNotFoundException {

			br = new BufferedReader(new FileReader(file));

		}



		public String next() throws IOException {

			while (st == null || !st.hasMoreTokens())

				st = new StringTokenizer(br.readLine());

			return st.nextToken();

		}



		public int nextInt() throws IOException {

			return Integer.parseInt(next());

		}



		public long nextLong() throws IOException {

			return Long.parseLong(next());

		}



		public String nextLine() throws IOException {

			return br.readLine();

		}



		public double nextDouble() throws IOException {

			return Double.parseDouble(next());

		}



		public boolean ready() throws IOException {

			return br.ready();

		}



	}

}



Measured memory_bytes: 44460
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

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

  string s;
  int ans = 0;

  cin >> s;

  for(int i=0;i<s.size();i++){
    if(s[i] == '-'){
      ans--;
    } else {
      ans++;
    }
  }
  
  cout << ans << endl; 

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
  char a[11],b[11],c[11];
  scanf("%s %s %s",a,b,c);
  if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0]){
    printf("YES");
  }else printf("NO");
   return 0;
}
  

Measured memory_bytes: 128
# coding: utf-8
import sys
import math
import fractions
input = sys.stdin.readline


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


a, b = map(int, input().split())
x = fractions.gcd(a, b)
check_list = []
i = 2

while x % 2 == 0:
    check_list.append(2)
    x //= 2
i = 3
while i * i <= x:
    if x % i == 0:
        check_list.append(i)
        x //= i
    else:
        i += 2
if x != 1:
    check_list.append(x)

print(len(set(check_list))+1)


Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    int cnt = 0, ans = s.size();
    rep(i, s.size())
    {
        if (s[i] == 'S')
            cnt++;
        else if (s[i] == 'T')
        {
            if (cnt > 0)
            {
                cnt--;
                ans -= 2;
            }
        }
        else
            cnt = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
//#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
ll test[12345678], res[12345678];
signed main() {
	vector<ll> v; map<ll, ll> cost;
	ll n, m, a, b, c, x, cnt = 0, ans = 0; string s, t;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;


int main(){

  int x, t;
  cin >> x >> t;
  cout << max(0, x-t) << endl;

  return 0;
}





//


Measured memory_bytes: 256
from math import gcd
n = int(input())
a = [int(i) for i in input().split()]

g = a[0]
for i in range(n):
    g = gcd(g,a[i])
if g != 1:
    print("not coprime")
    exit()

m = max(a)
fac = [1]*(m+1)
for i in range(2,m+1):
    if fac[i] != 1: continue
    for j in range(i,m+1,i): fac[j] = i
s = set()
for i in range(n):
    x = fac[a[i]]
    if x == 1: continue
    if x in s:
        print("setwise coprime")
        exit()
    s.add(x)
print("pairwise coprime")

Measured memory_bytes: 134416
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#define ll long long
#define inf  999999999
#define pa pair<int,int>
#define int long long

using namespace std;


struct seg_addsum_getsum{
	//       1
	//   2        3
	// 4   5   6    7
	
	
	private:
	public:
	
	// (1<<15)=32768
	// 1<<16 = 65536
	// 1<<17 = 131072
	// 1<<18 = 262144
	
	int cor=(1<<17);
	
	vector<int> vec;
	vector<int> lazy;
	void shoki1(){
		vec.resize(2*cor+3, 0);
		lazy.resize(2*cor+3, 0);
	}
	void shoki2(){
			for(int i=cor-1;i>0;i--) vec[i]=vec[2*i]+vec[2*i+1];
	}
		
	void chien(int k,int l,int r){
		if(lazy[k]==0) return;
		if(l+1<r){
			lazy[k*2]+=lazy[k]/2;
			lazy[k*2+1]+=lazy[k]/2;
		}
		vec[k]+=lazy[k];
		lazy[k]=0;
	}
	
	void rangeadd(int a,int b,int w, int k=1,int l=0,int r=-3){
		//[a,b)に w加算
		if(r<0) r=cor;
		chien(k,l,r);
		if(a<=l && r<=b){
			lazy[k]+=w*(r-l);
			
			chien(k,l,r);
			return ;
		}
		if(r<=a || b<=l){
			return ;
		}
		
		rangeadd(a,b,w,k*2,l,(l+r)/2);
		rangeadd(a,b,w,k*2+1,(l+r)/2,r);
		vec[k]=vec[2*k]+vec[2*k+1];
		return ;
	}
	
	// [a,b)
	// k-th node
	// k no kukanha [l,r)
	int getsum(int a,int b,int k=1,int l=0,int  r=-3){
		if(r<0) r=cor;
		chien(k,l,r);
		if(a<=l && r<=b){
			return vec[k];
		}
		if(r<=a || b<=l){
			return 0;
		}
		return getsum(a,b,k*2,l,(l+r)/2)+getsum(a,b,k*2+1,(l+r)/2,r);
		
	}
	
	void pre(){
		for(int i=1;i<2*cor;i++){
			cout<<vec[i]<<"/"<<lazy[i]<<" ";
			if(((i+1)&(-(i+1)))==i+1) cout<<endl;
		}
	}
	
};


signed main(){
seg_addsum_getsum SE;
	
	SE.shoki1();
//	for(int i=0;i<SE.cor;i++){
//		SE.vec[i+SE.cor]=i;
//	}
	SE.shoki2();
	
	
	int n,q;
	cin>>n>>q;
	
	for(int i=0;i<q;i++){
	int d,a,b,c;
		cin>>a;
		
		if(a==0){
			cin>>b>>c>>d;
			
			SE.rangeadd(b,c+1,d);
		}
		else{
			cin>>b>>c;
			
			cout<<SE.getsum(b,c+1)<<endl;
		}
	}
	return 0;
}





Measured memory_bytes: 7004
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000009LL
#define EPS 1e-8

int main()
{
	int A, B;
	cin >> A >> B;
	cout << ( A - 1 ) * ( B - 1 ) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>

int leader(char *s, int n, int E, int W){
    int c=n;
    int e=0;
    int w=0;
    int tmp;

    for(int i=0;i<n;i++){
        if(s[i]=='E'){
            tmp = w+E-e-1;
            e++;
        }else{
            tmp = w+E-e;
            w++;
        }
        if(tmp<c)c=tmp;

    }

    return c;
}

int main(){
    int i,n;
    char *s;
    scanf("%d",&n);
    s = (char *)malloc(sizeof(char)*(n+1));
    scanf("%s",s);
    int E=0;
    int W=0;
    for(i=0;i<n;i++){
        if(s[i]=='E')E++;
        else W++;
    }
    printf("%d\n",leader(s,n,E,W));
    return 0;
}


Measured memory_bytes: 512
A, B = map(int, input().split())
if A == 0:
    print(0^B)
elif A == 1:
    print(1^B)
elif A == B:
    print(A)
else:
    A = A-1
    Ab = format(A, 'b')
    Bb = format(B, 'b')
    an = len(Ab)
    #print(an)
    bn = len(Bb)
    #print(bn)
    sa = ''
    sb = ''
    for i in range(1,bn+1):
        if i == 1:
            if (B+1) // 2 % 2 == 1:
                sb = '0' + sb
            else:
                sb = '1' + sb
            continue
        if B % (2**i) >= 2**(i-1) and (B % (2**i)) % 2 == 0:
            sb = '1' + sb
        else:
            sb = '0' + sb

    for j in range(1,an+1):
        if j == 1:
            if (A+1) // 2 % 2 == 1:
                sa = '0' + sa
            else:
                sa = '1' + sa
            continue
        if A % (2**j) >= 2**(j-1) and (A % (2**j)) % 2 == 0:
            sa = '1' + sa
        else:
            sa = '0' + sa
    #print(sa)
    sa = int(sa,2)
    sb = int(sb,2)
    #print(sa,sb)
    ans = sa^sb

    print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string st;
    cin >> n;
    cin >> st;
    if(n < 3200)
    {
        cout << "red" << endl;
    }
    else
    {
        cout << st << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long LL;

const int N=1e5+10;

struct Edge{ int to,next;} way[N<<1];

int n,A[N],num[N],tot,d[N];
LL val[N];

void Build(int a,int b) { way[++tot]=(Edge){b,num[a]}; num[a]=tot; }

void Init()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&A[i]);
	int a,b;
	for (int i=2;i<=n;++i)
	{
		scanf("%d%d",&a,&b);
		Build(a,b); Build(b,a);
		d[a]++; d[b]++;
	}
}

bool Dfs(int x,int fa)
{
	if (d[x]==1) { val[x]=A[x]; return 1; }
	LL sum=0,Mx=0;
	for (int i=num[x];i;i=way[i].next)
	{
		int v=way[i].to;
		if (v==fa) continue;
		if (!Dfs(v,x)) return 0; 
		sum+=val[v]; Mx=max(Mx,val[v]);
	}
	if (A[x]>sum) return 0;
	LL need=sum-A[x],now=0;
	if (Mx>sum-Mx) now=sum-Mx;else now=sum/2;
	if (now>=need) val[x]=A[x]-need;
	else return 0;
	return 1;
}

void Solve()
{
	if (n==2) 
	{ 
		if (A[1]==A[2]) printf("YES\n");
		else printf("NO\n");
		return ; 
	}
	int root=0;
	for (int i=1;i<=n;++i) if (d[i]>1) { root=i; break; }
	bool fl=Dfs(root,0);
	if (val[root]) fl=0;
	if (fl) printf("YES\n");
	else printf("NO\n");
}

int main()
{
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 10368
#include <iostream>

#include <vector>
#include <string>

using namespace std;

int main()
{
   uint64_t x;

   cin >> x;

    uint64_t now = 100;
   for(uint64_t i = 0;; ++i)
   {
       if(now >= x)
       {
           cout << i << "\n";
           return 0;
       }
        now += now * 0.01;
   }

    return 0;
}

Measured memory_bytes: 3632
N=int(input())
a=input()
num=[]
n=a.split()
for i in(n):
  num.append(int(i))

num.sort()
b=0
for i in range(len(num)-1):
  b+=num[i]
if(num[len(num)-1]<b): print('Yes')
else: print('No')

Measured memory_bytes: 3064
N, X, Y = map(int, input().split())
A = [0 for i in range(N - 1)]
for i in range(1, N):
  for j in range(i+1, N+1):
    if j <= X:
      A[j-i-1] += 1
    elif i >= Y:
      A[j-i-1] += 1
    elif i <= X:
      if j >= Y:
        A[j-Y+X-i] += 1
      elif X < j < Y:
        m = min(X-i+1+Y-j, j-i)
        A[m-1] += 1
    elif j >= Y:
      if i <= X:
        A[j-Y+X-i] += 1
      elif X < i < Y:
        m = min(i-X+1+j-Y, j-i)
        A[m-1] += 1
    elif X <= i and j <= Y:
      m = min(i-X+1+Y-j, j-i)
      A[m-1] += 1
for i in range(N-1):
  print(A[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define pb push_back

int n, a[100100], ans;
pair <int, int> mx;
map <int, int> c;

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	mx.second = 0;
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i) {
		c[a[i]]++;
		c[a[i]-1]++;
		c[a[i]+1]++;
	}
	for(auto it : c) {
		if (it.second > mx.second) {
			mx.second = it.second;
			mx.first = it.first;
		}
	}
	cout << mx.second;
}


Measured memory_bytes: 10212
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, H, val[1005], cst[1005], memo[10005][1005];

int util(int h, int idx){
  if(h <= 0) return 0;
  if(idx < 0) return INF;

  int &cost = memo[h][idx];
  if(cost != -1) return cost;

  cost = util(h, idx - 1);
  min_self(cost, util(h - val[idx], idx) + cst[idx]);

  return cost;
}

int main(){
  FAST_IO
  cin >> H >> N;
  for(int rep = 0; rep < N; ++rep) cin >> val[rep] >> cst[rep];
  memset(memo, -1, sizeof memo);

  cout << util(H, N - 1) << '\n';
  return 0;
}


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

using namespace std;

int x[111111];
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
		scanf("%d", x + i);
	if (n >= m) {
		cout << 0 << endl;
		return 0;
	}
	sort(x, x + m);
	int r = x[m - 1] - *x;
	for (int i = 1; i < m; i++)
		x[i - 1] -= x[i];
	sort(x, x + m - 1);
	for (int i = 0; i < n - 1; i++)
		r += x[i];
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct node{
	struct node *parent;
	struct node *right;
	struct node *left;
	int key;
}node;

typedef struct{
	struct node *root;
}tree;

node *createNode(int n){
	node *node;
	mymalloc(node,1);
	node->parent=NULL;
	node->right=NULL;
	node->left=NULL;
	node->key=n;
	return node;
}

void insert(tree *T, node *z){
	node *x,*y;
	y=NULL;
	x=T->root;
	while(x!=NULL){
		y=x;
		if(z->key<x->key){
			x=x->left;
		}else{
			x=x->right;
		}
	}
	z->parent=y;
	if(y==NULL){
		T->root=z;
	}else{
	if(z->key<y->key){
		y->left=z;
	}else{
		y->right=z;
	}}
}

void preorder(node *root){
	printf(" %d",root->key);
	if(root->left!=NULL){
		preorder(root->left);
	}
	if(root->right!=NULL){
		preorder(root->right);
	}
}

void inorder(node *root){
	if(root->left!=NULL){
		inorder(root->left);
	}
	printf(" %d",root->key);
	if(root->right!=NULL){
		inorder(root->right);
	}
}


void freeNode(node *root){
	if(root->left!=NULL){
		freeNode(root->left);
	}
	if(root->right!=NULL){
		freeNode(root->right);
	}
	free(root);
}

void printTree(node *root){
	inorder(root);
	printf("\n");
	preorder(root);
	printf("\n");
}

main(){
	int i,n,m;
	tree *T;
	node *obj;
	char s[10];
	mymalloc(T,1);
	T->root=NULL;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf(" %s",s);
		if(strcmp(s,"insert")==0){
			scanf(" %d",&m);
			obj=createNode(m);
			insert(T,obj);
		}else{
		if(strcmp(s,"print")==0){
			printTree(T->root);
		}}
	}
	freeNode(T->root);
	free(T);
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, K;
    cin >> A >> B >> K;
    for(ll i = A; i < A + K; i++){
        if(i > B) break;
        cout << i << endl;
    }

    for(ll i = max(A + K, B - K + 1); i <= B; i++){
        cout << i << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

        int SUM[4];
        int K;
        int i,j;
        int ANS;
        int TMP;

        cin >> SUM[0] >> SUM[1] >> SUM[2];
        cin >> K;

        SUM[4] = 0;

        for(i=0; i < K ; i++){

                if(SUM[0] >= SUM[1]){

                        if(SUM[0] >= SUM[2]){

                                SUM[0]=SUM[0]*2;

                        }

                }


                if(SUM[1] >= SUM[0]){

                        if(SUM[1] >= SUM[2]){

                                SUM[1]=SUM[1]*2;

                        }

                }

                if(SUM[2] >= SUM[0]){

                        if(SUM[2] >= SUM[1]){

                                SUM[2]=SUM[2]*2;

                        }

                }

        }

        ANS=0;

        for(i=0; i < 3; i++){

                ANS+=SUM[i];

        }


        cout << ANS << endl;

        return 0;

}

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

#define N 100000

using namespace std;

int main(void){
long int debt = 0;

  int n;
  cin >> n;
  int money = N;
  
  for(int i = 0;i < n;i++){
  	
  	if(((money *= 1.05) % 1000) != 0){
  		money += 1000 - (money % 1000);
  	}
  	
  }
  cout << money << endl;


  return 0;
}

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

int main(){
    int N,x=0,y=0;
    scanf("%d",&N);
    if(N % 1000 != 0){
    x = N / 1000;
    x+=1;
    y = (x*1000) - N;}
    else{
        y = 0;
    }
    printf("%d",y);
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[5];
for(int i=0;i<5;i++) cin>>a[i];
sort(a,a+5); reverse(a,a+5);
for(int i=0;i<5;i++){
if(i) cout<<" ";
cout<<a[i];
}
cout<<endl;
}


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

using namespace std;

int main(){
  int n, m;
  map <string, int> blue;

  cin >> n;
  for(int i=0;i<n;i++){
    string s;
    cin >> s;
    if(blue.count(s)==0)blue[s]=1;
    else blue[s]+=1;
  }
  
  cin >> m;
  for(int i=0;i<m;i++){
    string s;
    cin >> s;
    if(blue.count(s)==0)blue[s]=-1;
    else blue[s]-=1;
  }
  
  int ans = 0;
  for(point : blue){
    if(ans<point.second)ans=point.second;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int H,W; scanf("%d%d",&H,&W);
	char a[H][W];
	for(int i=0;i<H;i++) scanf("%s",a[i]);
	long long int dp[H][W];
	for(int i=0;i<H;i++) for(int j=0;j<W;j++) dp[i][j] = 0;
	dp[0][0] = 1;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			if(a[i][j]=='.'){
			if(i<H-1&&a[i+1][j]=='.') dp[i+1][j] += (dp[i][j])%1000000007;
			if(j<W-1&&a[i][j+1]=='.') dp[i][j+1] += (dp[i][j])%1000000007;
			
			}
		}
	}
	
	printf("%d",dp[H-1][W-1]%1000000007);
	
	//for(int i=0;i<H;i++) for(int j=0;j<W;j++) printf("%d ",dp[i][j]);
	
	
	
	return 0;
}

Measured memory_bytes: 8960
import collections
N, M = map(int, input().split())
A = collections.Counter(map(int, input().split()))
A = sorted(A.items(), reverse=True)
_N = len(A)

syukei = collections.Counter()
for i in range(M):
  B, C = map(int, input().split())
  syukei[C] += B 

rest = N
goukei = 0

head_idx = 0
max_value, max_value_num = A[head_idx]

for value, card_num in sorted(syukei.items(), reverse=True):
  while max_value >= value and rest > 0 and head_idx < _N:
    if max_value_num <= rest:
      goukei += max_value_num * max_value
    else:
      goukei += rest * max_value

    rest -= max_value_num
    head_idx += 1
    max_value, max_value_num = (A[head_idx] if head_idx < _N else (0, 0))
  if rest <= 0:
    break

  if card_num <= rest:
    goukei += card_num * value
  else:
    goukei += rest * value
  rest -= card_num
  if rest <= 0:
    break
else:
  for value, card_num in A[head_idx:]:
    if card_num <= rest:
      goukei += card_num * value
    else:
      goukei += rest * value
    rest -= card_num
    if rest <= 0:
      break
print(goukei)



Measured memory_bytes: 38684
S=input()
mod=10**9+7
lst=[[0 for e in range(13)] for f in range(len(S)+1)]
lst[0][0]=1
for i in range(len(S)):
 if S[i]=="?":
  for j in range(13):
   for k in range(10):
    lst[i+1][(j*10+k)%13]+=lst[i][j]
    lst[i+1][(j*10+k)%13]%=mod
 else:
  for j in range(13):
   lst[i+1][(j*10+int(S[i]))%13]+=lst[i][j]
   lst[i+1][(j*10+int(S[i]))%13]%=mod
print(lst[len(S)][5])


Measured memory_bytes: 66268
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>
#define PI 3.14159265359

using namespace std;
#define INF 100100100100100100

#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    double a, b, x;

    cin >> a >> b >> x;

    if(((a*a*b)/2.0 - x) < 0) { 
        double m = (a*a*b - x)/(0.5*a*a*a);
        double ans = atan(m) * (180/PI);

        printf("%.9f\n", ans);
    } else {
        double m = x/(0.5*a*b*b);
        double ans = atan(m) * (180/PI);

        printf("%.9f\n", 90-ans);
    }
    return 0;
}




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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

string board[10];
li h, w;
li k;

int main() {
    cin >> h >> w >> k;
    rep(i, h) {
        cin >> board[i];
    }
    li cnt = 0;
    rep(i, bit(h)) {
        bitset<10> ii(i);
        rep(j, bit(w)) {
            bitset<10> jj(j);
            li tmp = 0;
            rep(hh, h) {
                rep(ww, w) {
                    if (ii[hh] || jj[ww]) {
                        continue;
                    }
                    if (board[hh][ww] == '#') {
                        tmp++;
                    }
                }
            }
            if (tmp == k) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
// typedef pair<int, int> P;
typedef pair<ll, ll> P;

const ll INF = 1LL << 60;

ll N;
ll g[20][20];
int main() {
    cin >> N;

    rep(i, 20)rep(j, 20) g[i][j] = -1;

    rep(i, N) {
        int m;
        cin >> m;

        rep(j, m) {
            ll x, y;
            cin >> x >> y;
            x--;

            g[i][x] = y;
        }
    }

    ll ans = 0;
    for (int i = 0; i < 1 << N; i++) {
    // for (int i = 1; i <= 1; i++) {
        set<ll> honest;
        for (int j = 0; j < N; j++) {
            if (i >> j & 1) {
                honest.insert(j);
            }
        }
        bool judge = true;

        // 矛盾があるか調べる
        for (int j = 0; j < N; j++) {
            if (!honest.count(j)) continue;

            // j は正直者 証言が正しいかどうか
            for (int k = 0; k < N; k++) {
                if (g[j][k] == -1) continue;

                if (g[j][k] == 1) {
                    if (honest.count(k)) continue;
                    judge = false;
                } else {
                    if (!honest.count(k)) continue;
                    judge = false;
                }
            }
        }

        if (!judge) continue; 

        ans = max(ans, (ll)__builtin_popcount(i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  string S1 = S;
  string S2 = S;
  int ans   = 1e6;
  int l     = S.length();
  int c1    = 0;
  int c2    = 1;
  for (int i = 1; i < l; i++) {
	  if (S1[i] == S1[i - 1]) {
		  c1++;
		  if (S1[i] == '0') {
			  S1[i] = '1';
			}
		  else {
			  S1[i] = '0';
			}
		}
	}
  if (S2[0] == '0') {
	  S2[0] = '1';
	}
  else {
	  S2[0] = '0';
	}
  for (int i = 1; i < l; i++) {
	  if (S2[i] == S2[i - 1]) {
		  c2++;
		  if (S2[i] == '0') {
			  S2[i] = '1';
			}
		  else {
			  S2[i] = '0';
			}
		}
	}
  cout << min(c1, c2) << endl;
  return 0;
}


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


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

	vector<int> arr(n+1);

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

	int cnt = 0;

	for(int i = 1;i <= n;i++){
		if(arr[i] != i){
			cnt++;
		}
	}

	if(cnt <= 2) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
int N,M,Q;


int main() {
	cin >> N;
	vector<int>A(N);
	rep(i, N) {
		A[i] = i + 1;
	}
	sort(A.begin(), A.end());
	do
	{
		rep(i, N - 1)cout << A[i] << " ";
		cout << A[N - 1] << endl;
	} while (next_permutation(A.begin(),A.end()));
	return 0;
}





Measured memory_bytes: 3100