akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

const double  PI = 3.14159265;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    double R;cin >> R;
    cout << 2 * R * PI << endl;

}


Measured memory_bytes: 3804
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EMP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
int m,n,c[21],dp[50010];

int main()
{
	cin>>n>>m;
	FOR(i,1,m+1)cin>>c[i];
	sort(c,c+m);
	FOR(i,0,n+1)dp[i]=i;
	FOR(i,2,m+1)
	{
		FOR(j,c[i],n+1)
		{
			dp[j]=min(dp[j],dp[j-c[i]]+1);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 3356
#include <bits/stdc++.h>
#define deb(x)     cerr << (#x) << " : " << (x) << "\n"
#define ll long long int
#define ld long double
#pragma warn +rvl
const ll MOD = 998244353;
const ll INF = 1e9;
using namespace std;
 
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint& operator/=(const mint& a){ (x*=a.ex(MOD-2).x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  mint operator/(const mint& a)const{ return mint(*this) /= a;}
  mint ex(ll t) const {
    if(!t) return 1;
    mint res = ex(t/2);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
 
mint ex(mint x, ll t) { return x.ex(t);}
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x % MOD;return o;}
 
ll powmod(ll a, ll b, ll MOD = MOD){
	if(!a and !b)	return 1ll;
	if(!a)	return a;
	ll res = 1ll;
	b %= (MOD - 1ll), a %= MOD;
	while(b){
		if(b%2 == 1)	res = (res * a) % MOD;
		a = (a * a) % MOD;
		b /= 2;
	}
	return res;
}
  
int main(){

 
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++)  cin >> arr[i];
    for(int i = 1; i < n; i++){
        if(arr[i] <= arr[0]){
            cout << 0;
            return 0;
        }
        arr[i] -= arr[0];
    }

    sort(arr, arr + n);
    
    ll ans = 1;
    if((n > 1 and arr[0] == arr[1]) or arr[0] != 0)    {
        cout << 0;
        return 0;
    }

    map<int, ll> mp;    
    mp[0]++;
    for(int i = 1; i < n; i++){
        ans = (ans * mp[arr[i] - 1]) % MOD;
        mp[arr[i]]++;
    }

    cout << ans;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
inline bool Valid(int a){
	string b;
	while(a!=0){
		b+=a%10+'0';
		a/=10;
	}
	for(int i=0;i<b.length()/2;i++){
		if(b[i]!=b[b.length()-i-1])return 0;
	}
	return 1;
}
int main(){
	int a,b,ans=0;cin>>a>>b;
	for(int i=a;i<=b;i++){
		ans+=Valid(i);
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
osatsu, okane = map(int, input().split())

#1万円の枚数 : x
#5千円の枚数 : y
#千円の枚数  : z

x_max = okane // 10000

for x in range(x_max + 1):
    z_max = (okane // 1000)
    tmp = z_max - osatsu - 9 * x
    if tmp % 4 != 0 or tmp < 0:
        continue
    y = tmp // 4
    z = osatsu - x - y
    if z < 0:
        continue

    print(x,y,z)
    break
else:
    print(-1, -1, -1)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a < b && b < c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");

        }

    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> pn(N), orig(N);
  for (int i=0; i<N; ++i) {
    cin >> orig[i];
    pn[i] = orig[i];
  }

  sort(pn.begin(), pn.end());
  int c = 0;
  for (int i=0; i<N; ++i) {
    if (pn[i] != orig[i]) ++c;
    if (2 < c) {
      cout << "NO\n";
      return 0;
    }
  }
  cout << "YES\n";
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def lcm(a, b): return a * b // math.gcd(a, b)

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]


sys.setrecursionlimit(1000000)
dire, dire8 = [[1, 0], [0, 1], [-1, 0], [0, -1]], [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets, ALPHABETS = "abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD, INF = 1000000007, float("inf")

def main():
    A, B, C, D = LI()

    print(B - A + 1 - ((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // lcm(C, D) - (A - 1) // lcm(C, D))))

if __name__ == '__main__':
    main()

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

using namespace std;

using mask_t = int;

int solve(const std::vector<int>& ls, int a, int b, int c) {
  int const n = ls.size();
  mask_t const endMask = 1 << n;
  std::pair<int, int> valueAndMpTbl[256];
  for (mask_t mask = 1; mask < endMask; ++mask) {
    int value = 0;
    int mp = 0;
    std::bitset<8> bits{static_cast<uint64_t>(mask)};
    for (int i = 0; i < 8; ++i) {
      if (!bits.test(i)) {
        continue;
      }
      if (value != 0) {
        mp += 10;
      }
      value += ls[i];
    }
    valueAndMpTbl[mask] = std::make_pair(value, mp);
  }
  int ret = INT_MAX;
  for (mask_t aMask = 1; aMask < endMask; ++aMask) {
    auto const aValueAndMp = valueAndMpTbl[aMask];
    int const aCandidate = aValueAndMp.second + abs(a - aValueAndMp.first);
    if (aCandidate >= ret) {
      continue;
    }
    for (mask_t bMask = 1; bMask < endMask; ++bMask) {
      if ((aMask & bMask) != 0) {
        continue;
      }
      auto const bValueAndMp = valueAndMpTbl[bMask];
      int const bCandidate =
          aCandidate + bValueAndMp.second + abs(b - bValueAndMp.first);
      if (bCandidate >= ret) {
        continue;
      }
      for (mask_t cMask = 1; cMask < endMask; ++cMask) {
        if ((aMask & cMask) != 0) {
          continue;
        }
        if ((bMask & cMask) != 0) {
          continue;
        }
        auto const cValueAndMp = valueAndMpTbl[cMask];
        int const cCandidate =
            bCandidate + cValueAndMp.second + abs(c - cValueAndMp.first);
        ret = std::min(cCandidate, ret);
      }
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, a, b, c;
  std::cin >> n >> a >> b >> c;
  std::vector<int> ls(n);
  bool aExists = false;
  bool bExists = false;
  bool cExists = false;
  for (auto& l : ls) {
    std::cin >> l;
    if (!aExists && l == a) {
      aExists = true;
    } else if (!bExists && l == b) {
      bExists = true;
    } else if (!cExists && l == c) {
      cExists = true;
    }
  }

  if (aExists && bExists && cExists) {
    std::cout << 0 << std::endl;
    return 0;
  }

  std::vector<int> needs;
  std::cout << solve(ls, a, b, c) << std::endl;
  return 0;
}


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

#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
} node;


void print(node *, int);
int preParse(node *, int);
int inParse(node *, int);
int postParse(node *, int);


int n;

int main(){
  node u[26];
  int id, c, l, r = 0;
  int i, j;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    u[i].p = NIL;
    u[i].l = NIL;
    u[i].r = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d", &id);

    for(j = 0; j < 2; j++){
      scanf("%d", &c);
      if(j == 0) u[id].l = c;

      else u[id].r = c;

      l = c;
      if(l >= 0) u[c].p = id; 
    }
  }

  for(i = 0; i < n; i++){
    if(u[i].p == NIL) r = i;
  }

  print(u, r);
  
  return 0;
}


void print(node *u, int r){
  printf("Preorder\n");
  preParse(u, r);
  printf("\n");
  
  printf("Inorder\n");
  inParse(u, r);
  printf("\n");
  
  printf("Postorder\n");
  postParse(u, r);  
  printf("\n");
}


int preParse(node *u, int r){
  if(r == NIL) return NIL;
  
  printf(" %d", r);
  preParse(u, u[r].l);
  preParse(u, u[r].r);
}


int inParse(node *u, int r){
  if(r == NIL) return NIL;
  
  inParse(u, u[r].l);

  printf(" %d", r);
  
  inParse(u, u[r].r);
}


int postParse(node *u, int r){
  if(r == NIL) return NIL;
  
  postParse(u, u[r].l);
  postParse(u, u[r].r);

  printf(" %d", r);
}






Measured memory_bytes: 2132
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
 
#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))
 
// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
 
// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;
 
int v[5];
int k;
 
int main(){
  REP(i,5)cin>>v[i];
  cin>>k;
  bool ok = true;
  REP(i,5)REP(j,i){
    int d = v[i]-v[j];
    if(d>k)ok=false;
  }
  puts(ok ? "Yay!" : ":(");
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

//
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int ed = 0;
        int ans=0;
        if(M==0){
            ans = (int) Math.pow(10, N-1);
            if(ans==1){ans=0;}
            System.out.println(ans);
        }
        else
        {

            int[][]cond=new int[M+1][3];
            for (int i=1;i<=M;i++){
                cond[i][1]=sc.nextInt();
                cond[i][2]=sc.nextInt();
            }
        //二桁以上で尚且一桁目０であるといっている場合
            for(int i=1;i<=M;i++){
                if ((N>=2)&&(cond[i][1]==1)&&(cond[i][2]==0)){
                    ans=-1;
                    ed = 1;
                    System.out.println(ans);
                    break;
                }
            }

        //cond間で矛盾する言及を行っている場合
            for (int i=1;i<=M-1;i++) {
                for (int j=i+1;j<=M;j++) {
                    if((cond[i][1]==cond[j][1])&&(cond[i][2]!=cond[j][2])){
                        ans=-1;
                        ed = 1;
                        System.out.println(ans);
                        break;
                    }
                }
            }
        //最小値を出力出来る場合はここで出力することとする
            int endflg=0;
            if(ed==0){
                loop:for (int i=(int) Math.pow(10, N-1)-1;i<=(((int)Math.pow(10, N))-1);i++) {
                    endflg=0;
                    for (int j=1;j<=M;j++) {
                        if(((i/(int)Math.pow(10,N-cond[j][1])*(int)Math.pow(10,N-cond[j][1]))-
                        (i/(int)Math.pow(10,N+1-cond[j][1])*(int)Math.pow(10,N+1-cond[j][1])))==(cond[j][2])*(int)Math.pow(10,N-cond[j][1])){
                            endflg=endflg+1;
                        }
                    if(endflg==M){
                        System.out.println(i);
                        break loop;
                        }
                    }
                }
            }
        }
    }
}



Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        if (v[i].second >= k) {
            cout << v[i].first << endl;
            return 0;
        } else {
            k -= v[i].second;
        }
    }
}


Measured memory_bytes: 1400
N = int(input())
W = [int(i) for i in input().split()]
s = sum(W)
a = 0

for i in range(N):
	_ = a + W[i]
	if abs(a - (s - a)) <= abs(_ - (s - _)):
		break
	else:
		a = _

print(abs(a-(s - a)))

Measured memory_bytes: 3060
#include<cstdio>

int main(){
	int r,c;
	while(1){
		scanf("%d %d\n", &r,&c);
		if(r==0&&c==0) break;
		for(int i=0;i<r;i++) {
			for(int j=0;j<c;j++) {
				if(i%2==0&&j%2==0) printf("#");
				else if(i%2==0&&j%2==1) printf(".");
				else if(i%2==1&&j%2==0) printf(".");
				else printf("#");
			}
		printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2596
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, M, Q;
P trains[200000];
P queries[100000];
int a[500][500];
int s[500][500];

void init()
{
}

void solve()
{
    REP(i, M){
        a[trains[i].fi][trains[i].se]++;
    }
    REP(i, N){
        REP(j, N){
            s[i][j] = a[i][j] + (j > 0 ? s[i][j-1] : 0);
        }
    }
    REP(i, Q){
        int ret = 0;
        P &q = queries[i];
        FOR(j, q.fi, q.se+1) ret += s[j][q.se];
        cout << ret << endl;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    REP(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        trains[i] = mp(a, b);
    }
    REP(i, Q){
        int a, b;
        cin >> a >> b;
        a--; b--;
        queries[i] = mp(a, b);
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 5248
#include <stdio.h>
int main(void){
    int N;
    int SUM=0;
    int H[20];
    scanf("%d",&N);
    for (int i=0; i<N; i++) {
        scanf("%d",&H[i]);
    }
    for (int i=0; i<N; i++) {
        for (int j=i-1; j>=-1; j--) {
            if(j==-1){
                SUM++;
            }
            else if(H[j]>H[i]){
                break;
            }
        }
    }
    printf("%d\n",SUM);
    
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static long Mod = (long)1e9 + 7;
        static long[] dirw = new long[] { -1, 0, 1, 0 };
        static long[] dirh = new long[] { 0, 1, 0, -1 };
        static string[] Sij;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var S = ReadLine();
            // 黒確定以降は全部黒になる。iで黒を確定させるときの値と全部白で行く場合を考える
            // dp[0]:黒確定
            // dp[1]:白のまま
            var dp = new long[2];
            for (var i = 0; i < S.Length; ++i)
            {
                if (S[i] == '#')//黒
                {
                    dp[0] = Min(dp[0],dp[1]);// 黒を確定させる
                    dp[1] = dp[1] + 1;
                }
                else// 白
                {
                    dp[0] = dp[0] + 1;
                    dp[1] = dp[1];
                }
            }
            WriteLine(Min(dp[0], dp[1]));
            //Out.Flush();
        }
    }
}


Measured memory_bytes: 13920
require 'prime'

n, m = gets.chomp.split(' ').map(&:to_i)
fs = Prime.prime_division(m)

def comb(n, r)
  raise ArgumentError if n < 0 || r < 0 || r > n

  # NOTE: rを小さい方に入れ替え
  r = n - r if n - r < r
  return 1 if r == 0
  return n if r == 1

  num = Array.new(r)
  deno = Array.new(r)

  0.upto(r - 1).each do |k|
    num[k] = n - r + k + 1
    deno[k] = k + 1
  end

  2.upto(r).each do |pi|
    pivot = deno[pi - 1];
    if pivot > 1
      offset = (n - r) % pi
      (pi - 1).step(r - 1, pi).each do |k|
        num[k - offset] /= pivot
        deno[k] /= pivot
      end
    end
  end

  num.select { |x| x > 1 }.inject(:*)
end

N = 1_000_000_000 + 7

ans = fs.inject(1) do |s, pair|
  b = pair[1]
  (s * comb(b + n - 1, b)) % N
end
puts ans


Measured memory_bytes: 3964
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = replicateM_ 9 solve

solve :: IO ()
solve = do
  xs <- words <$> getLine
  let m  = toInt (xs !! 1)
      af = toInt (xs !! 2)
  putStrLn $ (xs !! 0) ++ " " ++ show (m + af) ++ " " ++ show (m * 200 + af * 300)

toInt :: String -> Int
toInt s = read s

Measured memory_bytes: 3744
#include<iostream>
using namespace std;
int main()
{
	long long a,b,c,d,s,ss,k=0;
	cin>>a>>b>>c>>d;
	if ((a<=0 && 0<=b) || (c<=0 && 0<=d))k=1;
	s=max(a*c,a*d);
	ss=max(b*c,b*d);
	s=max(s,ss);
	if (k==1)s=max(0ll,s);
	cout<<s;
}
	
	


Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>

int main(void)
{
	char str[21];
	char rev[21];
	int len;
	int i;
	
	scanf("%s", str);
	
	len = strlen(str) - 1;
	
	for (i = 0; i <= len; i++){
		rev[i] = str[len - i];
	}
	rev[i] = '\0';
	
	printf("%s\n", rev);
	
	return (0);
}

Measured memory_bytes: 944
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int a, b; cin >> a >> b;
    cout << (a + b - 1) / b << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;

    int res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int32_t main()
{
        
     mlbb;   
     int n;
     cin>>n;
     int a[n+1];
     int maxx=1e9;
     int ans=0;
     for(int i=0;i<n;i++)   
     {
         cin>>a[i];
         maxx = min(a[i],maxx);
         
             if(a[i]<=maxx) ans++;
         
     }
     cout<<ans<<endl;
}


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

int main(){
  int n;
  while(cin>>n,n){
    int state=0,cnt=0;
    for(string step;n>0;--n){
      cin>>step;
      if(step=="lu"||step=="ru"){
        if(state==1) cnt++;
        state=1;
      }else{
        if(state==0) cnt++;
        state=0;
      }
    }
    cout<<cnt<<endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll N; cin >> N;
    vector<ll> v(N);
    rep(i, N) cin >> v[i];

    // variable
    ll ans = INTINF;
    // solve
    rep(i, 100){
        ll num = i + 1;
        ll sum = 0;
        rep(j, N){
            sum += abs(num - v[j]) * abs(num - v[j]);
        }
        ans = min(ans, sum);
    }

    print(ans);
    
    return 0;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.p = [-1]*n
        # union by rank
        self.r = [1]*n
 
    def find(self, x):
        if self.p[x] < 0:
            return x
        else:
            self.p[x] = self.find(self.p[x])
            return self.p[x]
 
    def union(self, x, y):
        rx, ry = self.find(x), self.find(y)
 
        if rx != ry:
            if self.r[rx] > self.r[ry]:
                rx, ry = ry, rx
            if self.r[rx] == self.r[ry]:
                self.r[ry] += 1
            self.p[ry] += self.p[rx]
            self.p[rx] = ry
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def count_member(self, x):
        return -self.p[self.find(x)]

n,m,k=map(int,input().split())
uf=UnionFind(n)
ab,cd=[],[]
for i in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  uf.union(a,b)
  ab.append((a,b))
for i in range(k):
  c,d=map(int,input().split())
  c-=1
  d-=1
  cd.append((c,d))
ans=[]
for i in range(n):
  t=uf.count_member(i)-1
  ans.append(t)
for a,b in ab:
  if uf.same(a,b):
    ans[a]-=1
    ans[b]-=1
for c,d in cd:
  if uf.same(c,d):
    ans[c]-=1
    ans[d]-=1
print(*ans)




 

Measured memory_bytes: 37948
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int m;
	HashMap<String, Integer> lbMap, ubMap;
	int n;
	String[] es;

	void run(){
		m=sc.nextInt();
		lbMap=new HashMap<String, Integer>();
		ubMap=new HashMap<String, Integer>();
		for(int i=0; i<m; i++){
			String name=sc.next();
			int lb=sc.nextInt();
			int ub=sc.nextInt();
			lbMap.put(name, lb);
			ubMap.put(name, ub);
		}
		n=sc.nextInt();
		es=new String[n];
		for(int i=0; i<n; i++){
			es[i]=sc.next();
		}
		solve();
	}

	void solve(){
		int M=256;
		LinkedList<int[]> stack=new LinkedList<int[]>();
		boolean correct=true;
		for(int k=0; k<n; k++){
//			debug(k);
			char c=es[k].charAt(0);
			if(Character.isDigit(c)){
				int[] a=new int[M];
				a[Integer.parseInt(es[k])]=1;
				stack.push(a);
			}else if(Character.isLetter(c)){
				int[] a=new int[M];
				int lb=lbMap.get(es[k]);
				int ub=ubMap.get(es[k]);
				for(int i=lb; i<=ub; i++){
					a[i]=1;
				}
				stack.push(a);
			}else{
				int[] b=stack.pop();
				int[] a=stack.pop();
				int[] r=new int[M];
				for(int j=0; j<M; j++){
					for(int i=0; i<M; i++){
						if(a[i]==0||b[j]==0){
							continue;
						}
						int res;
						if(c=='+'){
							res=(i+j)%256;
						}else if(c=='-'){
							res=(i-j+256)%256;
						}else if(c=='*'){
							res=(i*j)%256;
						}else{
							if(j==0){
								res=0;
								correct=false;
							}else{
								res=(i/j)%256;
							}
						}
						r[res]=1;
					}
				}
				stack.push(r);
			}
		}

		println(correct?"correct":"error");
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

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

int main(){
  int n,i,k;
  unsigned short *A;
  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(k<=A[i]){
      k=A[i];
    }
  }
  int x=A[n-1];
  int j=0,temp;
  for(i=0;i<n-1;i++){
    if(x>=A[i]){
      temp=A[j];
      A[j]=A[i];
      A[i]=temp;
      j++;
    }
  }
  temp=A[j];
  A[j]=A[n-1];
  A[n-1]=temp;

  for(i=0;i<j;i++){
    printf("%d ",A[i]);
  }
  printf("[%d] ",A[j]);
  for(i=j+1;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);

  return 0;
}



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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

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


  vector<int> left(N+1, 0), right(N+1, 0);
  for (int i = 0; i < N; i++) left[i+1] = GCD(left[i], A[i]);
  for (int i = N-1; i >= 0; i--) right[i] = GCD(right[i+1], A[i]);

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int l = left[i];
    int r = right[i+1];

    ans = max(ans, GCD(l, r));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


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

    ll val[n];
    ll cost[n];

    for(ll i=0;i<n;i++)
        cin>>val[i];

    for(ll j=0;j<n;j++)
        cin>>cost[j];

    ll maxval=0;
    for(ll i=0;i<n;i++)
    {
        if(val[i]>cost[i])
            maxval=maxval+val[i]-cost[i];
    }

    cout<<maxval;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define dbg(x) cerr<<#x": "<<(x)<<endl
#define dbg_p(x) cerr<<#x": "<<(x).first<<' '<<(x).second<<endl
#define dbg_v(x, n) {cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<(x)[_]<<' ';cerr<<endl;}
#define all(v) v.begin(), v.end()
#define fi first
#define se second

template<typename T1, typename T2>
ostream& operator <<(ostream &out, const pair<T1, T2> &item) {
	out << '(' << item.first << ", " << item.second << ')';
	return out;
}

template <typename T>
ostream& operator <<(ostream &out, const vector<T>& v) {
	for(const auto &item : v) out << item << ' ';
	return out;
}

const int N = 100010;

int a[N];

int main()
{
	ios_base::sync_with_stdio(false);
	int n, k, q, x;
  cin >> n >> k >> q;
  for(int i = 1; i <= q; ++i) cin >> x, ++a[x];
  for(int i = 1; i <= n; ++i)
    if(k - (q - a[i]) <= 0) cout << "No\n";
  	else cout << "Yes\n";
	return 0;
}


Measured memory_bytes: 1024
s = gets.chomp.split("")

def get_steps(s, r)
  cnt = 0
  max_step = 0
  s.each do |w|
    if w.eql? r
      max_step = cnt if max_step < cnt
      cnt = 0
    else
      cnt += 1
    end
  end
  max_step = cnt if max_step < cnt
  max_step
end

min_step = 10000
s.each do |w|
  step = get_steps(s, w)
  min_step = step if step < min_step
end

puts min_step


Measured memory_bytes: 1788
//Volume5-0500
import java.util.Scanner;

class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int n,a,b,i,j;
		while((n=sc.nextInt())!=0){
			a=0; b=0;
			while(n-- > 0){
				i = sc.nextInt();
				j = sc.nextInt();
				if(i==j){
					a+=i; b+=j;
				} else if(i>j) {
					a+=(i+j);
				} else {
					b+=(i+j);
				}
			}
			System.out.println(a+" "+b);
		}
	}
}

Measured memory_bytes: 51604
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int t; cin >> t;
	while(t--){
		int n; cin >> n;
		vector<P> ls(0), rs(0);
		int k, l, r; ll ans=0;
		REP(i,n){
			cin >> k >> l >> r;
			ans+=max(l,r);
			if(l>r)
				ls.push_back({k,abs(l-r)});
			else
				rs.push_back({n-k,abs(l-r)});
		}
		sort(ALL(ls));
		sort(ALL(rs));
		multiset<int> sel;
		REP(i,ls.size()){
			if(ls[i].first<=sel.size()){
				if(*sel.begin()<ls[i].second){
					ans-=*sel.begin();
					sel.erase(sel.begin());
					sel.insert(ls[i].second);
				}
				else{
					ans-=ls[i].second;
				}
			}
			else{
				sel.insert(ls[i].second);
			}
		}
		multiset<int> ser;
		REP(i,rs.size()){
			if(rs[i].first<=ser.size()){
				if(rs[i].first==0){
					ans-=rs[i].second;
					continue;
				}
				if(*ser.begin()<rs[i].second){
					ans-=*ser.begin();
					ser.erase(ser.begin());
					ser.insert(rs[i].second);
				}
				else{
					ans-=rs[i].second;
				}
			}
			else{
				ser.insert(rs[i].second);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 15720
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,C;
ll d[33][33];
ll c[505][505];
int main(){
    cin>>N>>C;
    for(ll i=1;i<=C;i++){
        for(ll j=1;j<=C;j++){
            cin>>d[i][j];
        }
    }
    for(ll i=0;i<N;i++){
        for(ll j=0;j<N;j++){
            cin>>c[i][j];
        }
    }
    set<P> st[3];
    for(ll col=1;col<=C;col++){
        ll sum[3]={};
        for(ll j=0;j<N;j++){
            for(ll k=0;k<N;k++){
                sum[(j+k)%3]+=d[c[j][k]][ col ] ;
            }
        }
        for(ll i=0;i<3;i++){
            st[i].insert(P(sum[i],col));
        }
    }
    ll ans=INF;
    auto it=st[0].begin();
    for(ll i=0;i<3;i++){//ひとつめのsetで何番目にするか
        set<ll> used;
        ll sum = it->first;
        used.insert(it->second);
        auto it2=st[1].begin();
        for(ll j=0;j<3;j++){//２つめのsetで何番目にするか
            if(used.find(it2->second)==used.end()){
                sum+=it2->first;
                used.insert(it2->second);
                auto it3=st[2].begin();
                for(ll k=0;k<3;k++){
                    if(used.find(it3->second)==used.end()){
                        ans=min(ans,sum+it3->first);
                    }
                    it3++;
                }
                sum-=it2->first;
                used.erase(it2->second);
            }
            it2++;
        }
        it++;
    }
    cout<<ans;
    return 0;
}

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


int main() {
  int A=0;
  int B=0;
  int C=0;
  int K=0;
  int magic_count=0;
  cin >> A >> B >> C >> K;
  while(A>=B){
    B=2*B;
    magic_count++;
  }
  while(B>=C){
    C=2*C;
    magic_count++;
  }

  if(magic_count<=K){
  cout << "Yes";
  }
  else{
    cout << "No";
  }
  
}

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

int main(){
  int H,W;
  cin>>H>>W;
  char c[H][W];
  int ans[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>c[i][j];
      if(c[i][j]=='#') ans[i][j]=-1;
      else ans[i][j]=0;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(c[i][j]=='.'){
        int cnt=0;
        for(int dx=-1;dx<=1;dx++){
          for(int dy=-1;dy<=1;dy++){
            int nx=i+dx,ny=j+dy;
            if(0<=nx&&nx<H&&0<=ny&&ny<W&&c[nx][ny]=='#') cnt++;
          }
        }
        ans[i][j]=cnt;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(ans[i][j]>=0)cout<<ans[i][j];
      else cout<<"#";
    }
    cout<<endl;
  }
}


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

#define S 3005
#define T 3005
ll dp_3[S][T] = {0};

ll dp_sumCommonPartString(vector<int> s, vector<int> t){
    for (int i = 0; i < s.size(); i++)
    {
        for (int j = 0; j < t.size(); j++)
        {
            if(s[i] == t[j]){
                dp_3[i + 1][j + 1] = (dp_3[i][j + 1] + dp_3[i + 1][j] + 1);
            } else {
                dp_3[i + 1][j + 1] = (dp_3[i][j + 1] + dp_3[i + 1][j] - dp_3[i][j]);
            }
            dp_3[i + 1][j + 1] %= MOD;
            if (dp_3[i + 1][j + 1] < 0) dp_3[i + 1][j + 1] += MOD;
            //printf("[%d][%d]:%d ", i, j, dp_3[i + 1][j + 1]);
        }
        //printf("\n");
    }
    return dp_3[s.size()][t.size()];
}


int main(){
    vector<int> s, t;
    int n, m;
    cin >> n >> m;
    rep(i, n){ int tmp; cin >> tmp; s.push_back(tmp);}
    rep(i, m){ int tmp; cin >> tmp; t.push_back(tmp);}
    cout << (dp_sumCommonPartString(s, t) + 1) % MOD << endl;  
}

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

using namespace std;

int main()
{
    int a, b, N, M; cin >> N >> M; map< int, int > request; vector< int > removed;

    for( int i = 0; i < M; i++ )
        cin >> a >> b, b--, request[ b ] = max( request[ b ], a );

    for( auto p: request )
        if ( removed.empty() or removed.back() < p.second )
            removed.push_back( p.first );

    cout << removed.size();
}


Measured memory_bytes: 3328
s=input()
kind=[]
kind.append([s[0],1]) #１つ目は確実に新種類
for i in range(1,4): #残りの３つを既存の種類と比べる。
    l=len(kind)
    a=0
    for j in range(l):
        if s[i] == kind[j][0]:
            a=1
            match=j
            break
    if a==0: #新種類
        kind.append([s[i],1])
    else:
        kind[match][1]+=1
        
    
if kind[0][1]==2 and kind[1][1]==2:
    print("Yes")
else:
    print("No")
#print(kind)

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

int main(){
  int n; cin>>n;
  string s; cin>>s;
  
  long long ans=1;
  ans*=count(s.begin(),s.end(),'R');
  ans*=count(s.begin(),s.end(),'G');
  ans*=count(s.begin(),s.end(),'B');
  
  for (int i=1; i<=n; i++){
    for (int j=0; j<=n; j++){
      if (j+2*i<n && s[j]!=s[j+i] && s[j+i]!=s[j+2*i] && s[j+2*i]!=s[j]){
        ans-=1;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3624
//#define _XCODE_DEBUG

#include <iostream>
#include <vector>

#ifdef _XCODE_DEBUG
    #include <fstream>
#endif

int main(int argc, const char * argv[]) {
    #ifdef _XCODE_DEBUG
        std::ifstream in("input.txt");
        std::cin.rdbuf(in.rdbuf());
    #endif
    
    int K, N;
    int a;
    std::cin >> K >> N;
    std::vector<int> vec_a;
    
    for(int i=0; i<N; ++i) {
        std::cin >> a;
        vec_a.push_back(a);
    }
    
    int ans = vec_a[N-1] - vec_a[0];
    for (int i=1; i<N; ++i) {
        int dist1 = vec_a[N-1] - vec_a[i];
        int dist2 = (K-vec_a[N-1]) + vec_a[i];
        int dist = dist1 + dist2;
        if (ans > dist) ans = dist;
    }
    for (int i=N-2; i>0; --i) {
        int dist1 = vec_a[i];
        int dist2 = std::abs(K-vec_a[i+1]);
        int dist = dist1 + dist2;
        if (ans > dist) ans = dist;
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int cnt[100009];

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int a;
      cin>>a;
      cnt[a]++;
    }
  }
  int ans=0;
  for(int i=1;i<=m;i++){
    if(cnt[i]==n)ans++;
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int,input().split()))
counter = 0
for i in range(1,n-1):
    if p[i-1] < p[i] and p[i] < p[i+1]:
        counter += 1
    elif p[i-1] > p[i] and p[i] > p[i+1]:
        counter += 1
print(counter)



Measured memory_bytes: 3316
n = gets.to_i
t,a = gets.split.map(&:to_f)
arr = gets.split.map(&:to_f)

sum = 100000
ans = 0
arr.each_with_index do |x,i|
  tmp = t - (x * 0.006)
  if (a - sum).abs > (a - tmp).abs
    sum = tmp
    ans = i + 1
  end
end

p ans

Measured memory_bytes: 1788
import java.util.*;

public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	// public static class Triple implements Comparable<Triple> {
	// 	public int A, B, C;
	// 	Triple(int A, int B, int C) {
	// 		this.A = A;
	// 		this.B = B;
	// 		this.C = C;
	// 	}

	// 	@Override
	// 	public String toString() {
	// 		return String.format("(%d, %d, %d)", A, B, C);
	// 	}

	// 	@Override
	// 	public int compareTo(Triple o) {
	// 		int a = this.A - o.A;
	// 		if (a != 0) return a;
	// 		int b = this.B - o.B;
	// 		if (b != 0) return b;
	// 		return this.C - o.C;
	// 	}
	// }

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] SS = new String[N];
		for (int i = 0; i < N; i++) {
			char[] cs = sc.next().toCharArray();
			Arrays.sort(cs);
			SS[i] = new String(cs);
		}
		HashMap<String, Long> h = new HashMap<>();
		long cnt = 0;
		for (int i = 0; i < N; i++) {
			String s = SS[i];
			if (h.containsKey(s)) {
				long v = h.get(s);
				cnt += v;
				h.put(s, v + 1);
			} else {
				h.put(s, 1L);
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 53560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
using namespace std;
const int INF = 1e9;
typedef long long ll;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
// const lint MOD = 998244353;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
char upper(char c){
	return c-0x20;
}
char lower(char c){
	return c+0x20;
}

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}
vector<int> L;
int N, A, B, C;
#define inf 1000000000
int dfs(int n, int a, int b, int c) {
	if (n == N) {
		if (min(a, min(b, c)) == 0) {
			return inf;
		}
		else {
			return abs(a - A) + abs(b - B) + abs(c - C) - 30;
		}
	}
	int cost0, cost1, cost2, cost3;
	cost0= dfs(n + 1, a, b, c);
	cost1=dfs(n + 1, a + L[n], b, c)+10;
	cost2=dfs(n + 1, a, b + L[n], c)+10;
	cost3=dfs(n + 1, a, b, c + L[n])+10;
	return min(cost0, min(cost1, min(cost2, cost3)));
}
 
int main()
{
	
	cin >> N >> A >> B >> C;
 
	int l;
	for (int i = 0; i < N; i++) {
		cin >> l;
		L.push_back(l);
	}
	cout << dfs(0, 0, 0, 0);
 
 
	return 0;
}

Measured memory_bytes: 256
N = int(input())
rests = []

for i in range(N):
    a = input().split()
    rests.append((a[0], int(a[1]), i+1))

def sort(A):
    for i in range(0, len(A) - 1):
        modify_order(A, i)

def modify_order(A,i):
    for j in range(len(A) - 1, i, -1):
        if A[j-1][0] == A[j][0] and A[j-1][1] < A[j][1]:
            A[j-1], A[j] = A[j], A[j - 1]
        elif A[j-1][0] > A[j][0]:
            A[j-1], A[j] = A[j], A[j - 1]

sort(rests)

for i in range(N):
    print(rests[i][2])


Measured memory_bytes: 3064
use proconio::*;
use itertools::Itertools;
use std::process::exit;

fn main() {
    input! {
    a:String,
    b:String,
    }
    let c=a+ &*b;
    let c=c.chars().map(|a|a.to_digit(10).unwrap() as i32).collect_vec();
    let mut d:i32=0;
    for i in 0..c.len() {
        d+=(c[i]*10_i32.pow((c.len() - i as usize-1) as u32));
    }
    for i in 0..1000 {
        if d==i*i {println!("Yes");exit(0)}
    }
    println!("No")
}

Measured memory_bytes: 2136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 1;
  for (int i = 1; i < N; i++) {
    if (S[i - 1] != S[i]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512