akhauriyash/Code-Regression huggingface dataset:
/* This code is written by Nemlit */
#include<bits/stdc++.h>

using namespace std;

#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 10234567890000000
#define mod 1000000007
#define lb(x) (x)&(-(x))
inline int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
inline int Mul(int a, int b) { return 1ll * a * b % mod; }
inline int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
inline int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
inline int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define ls k * 2
#define rs k * 2 + 1
#define maxn 55
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next, a, b; }e[maxn << 2];
	inline void add(int u, int v, int a, int b) { e[++ cnt] = (edge){v, head[u], a, b}, head[u] = cnt; }
}
using namespace Graph;
int n, m, dp[maxn][5005], s, c[maxn], d[maxn], vis[maxn][5005];
struct node {
	int u, v;
};
queue<node>q;
signed main() {
	n = read(), m = read(), s = min(read(), 5000ll);
	rep(i, 1, m) {
		int u = read(), v = read(), a = read(), b = read();
		add(u, v, a, b), add(v, u, a, b);
	}
	mem(dp, 63), dp[1][s] = 0;
	rep(i, 1, n) c[i] = min(2500ll, read()), d[i] = read();
	q.push((node){1, s});
	while(!q.empty()) {
		int u = q.front().u, l = q.front().v; q.pop(), vis[u][l] = 0;
		Next(i, u) {
			int v = e[i].v;
			if(l >= e[i].a && dp[u][l] + e[i].b < dp[v][l - e[i].a]) {
				dp[v][l - e[i].a] = dp[u][l] + e[i].b;
				if(vis[v][l - e[i].a] == 0) q.push((node){v, l - e[i].a}), vis[v][l - e[i].a] = 1;
			}
		}
		int tim = dp[u][l];
		l += c[u], tim += d[u];
		while(l <= 5000) {
			if(tim < dp[u][l]) {
				dp[u][l] = tim;
				if(vis[u][l] == 0) q.push((node){u, l}), vis[u][l] = 1;
			}
			l += c[u], tim += d[u];
		}
	}
	rep(i, 2, n) {
		int ans = inf;
		rep(j, 0, 5000) ans = min(ans, dp[i][j]);
		printf("%lld\n", ans);
	} 
	return 0;
}


Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	string str1,str2;
	cin>>str1>>str2;
	bool flag=false;
	for(ll i=0;i<str1.length();i++)
	{
		if(str1[i]==str2[i])
		{flag=true;}
		else
		{flag=false;
		break;}
	}
	if(flag and (str2.length()==str1.length()+1))
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}
	


Measured memory_bytes: 3596
n,m,c =map(int,input().split())

b =list(map(int,input().split()))

ans=0
for _ in range(n):
    total =c

    a = list(map(int,input().split()))

    for i in range(m):
        total += a[i]*b[i]

    if total>0:
        ans+=1
    
print(ans)


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

int main() {
    int n, a[3]; cin >> n >> a[0] >> a[1] >> a[2];
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int dp[4][1 << n];
    int d[1 << n];
    for (int bit = 0; bit < (1 << n); bit++) {
        d[bit] = 0;
        for (int j = 0; j < n; j++) {
            if (bit & (1 << j)) d[bit] += v[j];
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < (1 << n); j++) {
            dp[i][j] = 1e9;
        }
    }
    dp[0][(1 << n)-1] = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 1; j < (1 << n); j++) {
            for (int k = j; k >= 0; k = (k-1) & j) {
                if (k == j) continue;
                dp[i+1][k] = min(dp[i+1][k], dp[i][j] + abs(a[i]-d[j^k]));
                if (k == 0) break;
            }
        }
    }
    int ans = 1e9;
    for (int i = 0; i < (1 << n); i++) {
        bitset<8> bit = i;
    }
    for (int i = 0; i < (1 << n); i++) {
        bitset<8> bit = i;
        ans = min(ans, (int) (n-bit.count()-3) * 10 + dp[3][i]);
    }
    cout << ans << endl;
    return 0;
}

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

struct MillerRabin {
    using lint = unsigned long long int;
private : 
    const lint v1[3] = {2, 7, 61};
    const lint v2[7] = {2, 3, 5, 7, 11, 13, 17};
    const lint v3[7] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022};
public : 
    inline lint modpow(lint x, lint k, lint m){
        lint a = 1, p = x;
        while(k > 0) {
            if (k % 2 == 0) { p = p * p % m; k /= 2; }
            else { a = a * p % m; k--; }
        }
        return a;
    }

    inline bool sub (lint a, lint n, lint d, lint s) {
        bool flag = true;
        for (lint r = 0; r < s; r++) {
            if (modpow(a, d, n) == n - 1) {
                flag = false; break;
            }
            d <<= 1LL;
        }
        return flag;
    }

    bool isprime (lint n) {
        if (n < 2) return false;
        lint d = n - 1, s = 0;
        while (d % 2 == 0) { d /= 2; s++; }
        if (n < 4759123141LL) {
            for (const lint &a : v1) {
                if (a == n) return true;
                if (n < a) break;
                if (modpow(a, d, n) == 1) continue;
                if (sub(a, n, d, s)) return false;
            }
        } else if (n < 341550071728321LL) {
            for (const lint &a : v2) {
                if (a == n) return true;
                if (n < a) break;
                if (modpow(a, d, n) == 1) continue;
                if (sub(a, n, d, s)) return false;
            }
        } else {
            for (const lint &a : v3) {
                if (a == n) return true;
                if (n < a) break;
                if (modpow(a, d, n) == 1) continue;
                if (sub(a, n, d, s)) return false;
            }
        }
        return true;
    }

};


int main() {
    MillerRabin miller;
    int q, ans = 0;
    cin >> q;
    
    while (q--) {
        long long n;
        cin >> n;
        ans += (miller.isprime(n));
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
#include<queue>
#include<stdio.h>
int main()
{
	while(1)
	{
		int a,b,x,y,i,c[18][18]={0},n,v=0;
		pair<int,int> s,m;
		queue<pair<int,int> > u;
		cin>>a>>b;
		if(a==0&&b==0)
		break;
		cin>>n;
		for(i=0;i<=a;i++)
		{
			c[i][0]=1;
			c[i][b+1]=1;
		}
		for(i=0;i<=b;i++)
		{
			c[0][i]=1;
			c[a+1][i]=1;
		}
		for(i=0;i<n;i++)
		{
			cin>>x>>y;
			c[x][y]=1;
		}
		s.first=1;
		s.second=1;
		m.first=a;
		m.second=b;
		u.push(s);
		while(!u.empty())
		{
			s=u.front();
			u.pop();
			if(c[s.first+1][s.second]!=1)
			{
				s.first++;
				u.push(s);
				s.first--;
			}
			if(c[s.first][s.second+1]!=1)
			{
				s.second++;
				u.push(s);
				s.second--;
			}
			if(s==m)
			{
				v++;
			}
		}
		cout<<v<<endl;
	}
	return 0;
}

Measured memory_bytes: 9232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
     vector<int> p(N);
   for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  
   sort(p.begin(), p.end());
  int S =0;
  for (int i = 0; i < N-1; i++) {
 S +=p[i];
}
S += + p[N-1]/2;
cout << S <<endl;
}

Measured memory_bytes: 256
// AOJ Volume 0 Problem 0003

#include <stdio.h>

int main(void)
{
    int i;
    int n, num1, num2, num3;
    int flag;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
        scanf("%d%d%d", &num1, &num2, &num3);
        
        flag = 0;
        if (num1 * num1 == num2 * num2 + num3 * num3){
            flag = 1;
        }
        if (num2 * num2 == num1 * num1 + num3 * num3){
            flag = 1;
        }
        if (num3 * num3 == num2 * num2 + num1 * num1){
            flag = 1;
        }

        if (flag == 1){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N, a[105];
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N) cin>>a[i];

    sort(a, a+N);

    int al=0, bo=0;

    int cnt = 0;
    RREP(i,0,N){
        if(cnt % 2 == 0){
            al += a[i];
        }else{
            bo += a[i];
        }
        cnt++;
    }

    cout<<al - bo<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.security.SecureRandom;
import java.sql.Array;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x=sc.nextInt();

            int n=sc.nextInt();
            int a[]= new int[n];
            Set<Integer> s= new HashSet<>();
            for (int i=0;i<n;i++){
                a[i]=sc.nextInt();
                s.add(a[i]);
            }
            int min=Integer.MAX_VALUE;
            int index=0;
            for (int i=x;i>=-1000;i--){
                if (!s.contains(i)){
                    if (min>Math.abs(x-i)){
                        min=Math.abs(x-i);
                        index=i;
                        break;
                    }

                }
            }
        for (int i=x;i<=1000;i++){
            if (!s.contains(i)){
                if (min>Math.abs(x-i)){
                    min=Math.abs(x-i);
                    index=i;
                    break;
                }

            }
        }
        System.out.println(index);


        }
    }






Measured memory_bytes: 36132
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <map>

const long long INF = 1LL << 60;
typedef long long LL;

using namespace std;

LL A, B, C, D;
std::map<LL, LL> number;

LL solve(LL N)
{

    if (N == 0)
    {
        return 0;
    }

    if (N == 1)
    {
        return D;
    }

    if (number.count(N))
    {
        return number[N];
    }
    LL minimum = INF;
    LL f2 = (N / 2) * 2;
    LL r2 = ((N + 1) / 2) * 2;
    LL f3 = (N / 3) * 3;
    LL r3 = ((N + 2) / 3) * 3;
    LL f5 = (N / 5) * 5;
    LL r5 = ((N + 4) / 5) * 5;

    if (N < minimum / D)
    {
        minimum = N * D;
    }

    minimum = min(minimum, A + llabs(N - f2) * D + solve(f2 / 2));
    minimum = min(minimum, A + llabs(N - r2) * D + solve(r2 / 2));
    minimum = min(minimum, B + llabs(N - f3) * D + solve(f3 / 3));
    minimum = min(minimum, B + llabs(N - r3) * D + solve(r3 / 3));
    minimum = min(minimum, C + llabs(N - f5) * D + solve(f5 / 5));
    minimum = min(minimum, C + llabs(N - r5) * D + solve(r5 / 5));

    number[N] = minimum;

    return minimum;
}

int main()
{
    int T;
    cin >> T;
    //T = 1;
    LL N;
    for (int i = 0; i < T; i++)
    {
        cin >> N >> A >> B >> C >> D;
        number.clear();
        /*
        N = 11;
        A = 1;
        B = 2;
        C = 4;
        D = 8;
        */
        cout << solve(N) << endl;
    }

    return 0;
}

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

using namespace std;

const int N = 2e5 + 5;
char s[N];
int sum[N];

int main() {
  int n;
  scanf("%d %s", &n, s);
  sum[0] = 0;
  for (int i = 0; i < n; ++i) {
    sum[i+1] = sum[i] + (s[i] == '#');
  }
  int ans = n;
  for (int i = 0; i <= n; ++i) {
    int black = sum[i];
    int white = (n-i) - (sum[n]-sum[i]);
    ans = min(ans, black + white);
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define mm(arr) memset(arr, 0, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
#define pb push_back
#define PI 3.141592653589793
#define MOD 1000000007

using namespace std;
int main(){
    FAST
    ll n,k; cin >> n >> k;
    ll a[n];
    scanArray(a,n);
    sort(a,a+n);
    ll mndf = 1e10;
    for(ll i=0;i+k-1<n;i++){
            if(i==n-1){
                break;
            }
            mndf=min(mndf,abs(a[i]-a[i+k-1]));
    }
    cout << mndf << endl;

    return 0;
}


Measured memory_bytes: 4324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        string s = sc.Next();

        long answer = s.Where(c => c == 'R').Count();

        if (s == "RSR")
        {
            answer = 1;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

using namespace std;

bool double_rock(uint64_t N, const string &S, uint64_t src, uint64_t dst)
{
  for (uint64_t n = src; (n + 1) <= dst; ++n) {
    if ((S[n] == '#') && (S[n + 1] == '#')) {
      return true;
    }
  }
  return false;
}

bool swapable(uint64_t N, uint64_t A, uint64_t B, uint64_t C, uint64_t D, const string &S)
{
  for (uint64_t n = B; n <= D; ++n) {
    if ((A <= (n - 1)) && ((n + 1) <= C)) {
      if ((S[n - 1] == '.') && (S[n] == '.') && (S[n + 1] == '.')) {
        return true;
      }
    }
  }
  return false;
}

int main()
{
  uint64_t N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  
  string S;
  cin >> S;
  
  S.insert(S.begin(), '?');
  S.insert(S.end(),   '?');
  
  if (C < B) {
    if (double_rock(N, S, A, C) || double_rock(N, S, B, D)) {
      cout << "No" << endl;
      return 0;
    } else {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  if (double_rock(N, S, A, max(C, D))) {
    cout << "No" << endl;
    return 0;
  }
  
  if ((C < B) || (C < D)) {
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << (swapable(N, A, B, C, D, S) ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 640
l = [0]

def format_input(filename = None):
	global l
	if filename == None:
		l = int(input())

	elif filename == '__random__':
		from random import randint as rng
		l = rng(1, 10**3)

def get_answer():
	answer = (l/3)**3
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 2940
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int n;
    bool is_prime[260000];
    rep(i, 260000) is_prime[i] = 1;
    is_prime[0] = is_prime[1] = 0;
    for(int i = 2; i < 260000; ++ i) {
        if(is_prime[i]) {
            for(int j = 2 * i; j < 260000; j += i) {
                is_prime[j] = 0;
            }
        }
    }
    int cnt[270000];
    cnt[0] = 0;
    rep(i, 260000) {
        cnt[i + 1] = cnt[i] + (is_prime[i] ? 1 : 0);
    }
    while(cin >> n) {
        if(n == 0) break;
        cout << cnt[2 * n + 1] - cnt[n + 1] << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}


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

namespace abc152_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var a = CIn.ReadInt();
      var b = CIn.ReadInt();

      var max = Math.Max(a, b);
      var min = Math.Min(a, b);

      var ans = "";

      for (int i = 0; i < max; i++)
      {
        ans += min;
      }

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(long h, long w)
    {
      var array = new char[h, w];
      for (var i = 0L; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0L; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(tokens[i]);
		int h = a[0];
		long ans = 0;
		for (int i = 1; i < n; i++) {
			if (a[i] <= h)
				ans += h-a[i];
			else
				h = a[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 55536
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <bitset>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
using ppp = pair<pair<int, int>, pair<int, int>>;
#define MOD 1000000007
#define INF 1LL << 59
const int MAX = 510000;
const long long mod = 917120411LL;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int sieve[1000010];
void make_sieve()
{
    for (int i = 0; i < 1000010; ++i)
        sieve[i] = true;
    sieve[0] = sieve[1] = false;
    for (int i = 0; i * i < 1000010; ++i)
    {
        if (sieve[i])
        {
            for (int j = 2; j * i < 1000010; ++j)
            {
                sieve[i * j] = false;
            }
        }
    }
}

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

ll dp[100010][13];
int main()
{
    string s;
    cin >> s;

    int n = s.size();

    dp[0][0] = 1;
    for (int i = 0; i < n; ++i)
    {
        int c;
        if (s[i] == '?')
            c = -1;
        else
            c = s[i] - '0';

        for (int j = 0; j < 10; ++j)
        {
            if (c != -1 && c != j)
                continue;

            for (int k = 0; k < 13; ++k)
            {
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
            }
        }
        for (int j = 0; j < 13; ++j)
            dp[i + 1][j] %= MOD;
    }

    cout << dp[n][5] << endl;
    return 0;
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while(A>0 && B>0){
        if(C-B <= 0 ){
            cout << "Yes" << endl;
            break;
        }
        C = C - B;
        if(A-D <= 0){
            cout << "No" << endl;
            break;
        }
        A = A-D;

    }
    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
using namespace boost::multiprecision;

int main(){

    int h,n;
    cin >> h >> n;

    vector<pair<int,int>> magic;

    rep(i,n){
        int a,b;
        cin >> a >> b;

        magic.pback(mpair(a,b));
    }

    vector<vector<int>> dp(n + 1, vector<int>(10001, INT_MAX));

    for(int i = 1; i <= n; i++){
        int tmp_a = magic[i - 1].first;
        int tmp_b = magic[i - 1].second;

        for(int j = 10000; j >= 0; j--){
            dp[i][j] = min(dp[i - 1][j], (j + tmp_a - 1) / tmp_a * tmp_b);
        }
    }

    dp[n][0] = 0;

    for(int i = 2; i <= 10000; i++){
        for(int j = 0; j <= i; j++){
            dp[n][i] = min(dp[n][i], dp[n][j] + dp[n][i - j]);
        }
    }

    cout << dp[n][h] << endl;
    
    return 0;
}

Measured memory_bytes: 41472
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

ans=0
jibun=""
for i in range(n):
  if i<k:
    if t[i]=="s":
      ans+=r
      jibun+="r"
    elif t[i]=="p":
      ans+=s
      jibun+="s"
    else:
      ans+=p
      jibun+="p"
  else:
    if t[i]==t[i-k]:
      if (t[i]=="s" and jibun[i-k]=="r") or (t[i]=="p" and jibun[i-k]=="s") or (t[i]=="r" and jibun[i-k]=="p"):
        jibun+="n"
      else:
        if t[i]=="s":
          ans+=r
          jibun+="r"
        elif t[i]=="p":
          ans+=s
          jibun+="s"
        else:
          ans+=p
          jibun+="p"
    else:
        if t[i]=="s":
          ans+=r
          jibun+="r"
        elif t[i]=="p":
          ans+=s
          jibun+="s"
        else:
          ans+=p
          jibun+="p"
print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); if (n == 0) cout << endl; REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    map<int, ll> m;
    ll a, b;
    REP(i, n) {
        cin >> a >> b;
        m[a] += b;
    }
    for (auto v : m) {
        k -= v.second;
        if (k <= 0) {
            cout << v.first << endl;
            return;
        }
    }
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Already 2018
            string s = Console.ReadLine();

            Console.WriteLine(s.Replace("2017", "2018"));
        }
    }
}

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

long long n, k;

long long solve();

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

  cout << solve() << endl;
  return 0;
}

long long solve() {
  if(k == 0) return n * n;
  long long ans = 0;
  for(long long i = k + 1; i <= n; ++i) {
    ans += n / i * (i - k);
    ans += max(0LL, n % i - k + 1);
  }
  return ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

const int MAXN=1e6+10;

vector<vector<int> >lista_susjedstva;
int najduzi[MAXN];

int dfs(int node)
{
    int maxi=0;

    for (int i=0; i<lista_susjedstva[node].size(); ++i)
    {
        if (najduzi[node]!=-1)
            maxi=max(maxi, najduzi[lista_susjedstva[node][i]]+1);
        else
            maxi=max(maxi, dfs(lista_susjedstva[node][i])+1);
    }

    najduzi[node]=maxi;

    return maxi;
}

int main()
{
    int n, m;

    cin >>n>>m;

    lista_susjedstva.resize(n);
    memset(najduzi, -1, sizeof(najduzi));


    for (int i=0; i<m; ++i)
    {
        int x, y;

        cin >>x>>y;

        --x;
        --y;

        lista_susjedstva[y].push_back(x);
    }

    int maxi=0;

    for (int i=0; i<n; ++i)
    {
        if (najduzi[i]==-1)
            dfs(i);

        maxi=max(maxi, najduzi[i]);
    }

    cout <<maxi;

    return 0;
}


Measured memory_bytes: 14080
import collections

n = int(input())
k = [int(a) for a in input().split()]
k_set = set(k)
all = 0
count_dic = collections.Counter(k)

for b in k_set:
    tmp = count_dic[b]
    all += tmp * (tmp - 1) // 2

for c in k:
    tmp = count_dic[c]
    print(all - (tmp - 1))

Measured memory_bytes: 28680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(x,y,z) for(int x = y; x < z; x++)
#define INF 9999999;
#define VEC vector<int>
#define in push_back
#define ans(x) cout<<x<<endl
#define ll long long int 

using namespace std;


int main()
{
	string s;
	while (cin >> s)
	{
		int IOI = 0, JOI = 0;
		for (int i = 0; i < s.length() - 2; i++)
		{
			if (s[i] == 'J'&&s[i + 1] == 'O'&&s[i + 2] == 'I')JOI++;
			if (s[i] == 'I' &&s[i + 1] == 'O'&&s[i + 2] == 'I')IOI++;
		}
		ans(JOI);
		ans(IOI);
	}
}

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

ll fastpower (ll b , ll p){
    ll k= p%2 ? b : 1 ;
    return p==0 ? 1 : k*(fastpower(b*b,p/2));
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll sum=0;
        ll n=s.length();
        for(int i=0;i<n;i++){
            sum+=s[i]-'0';
            sum%=9;
        }
        cout<<(sum?"No\n":"Yes\n");
    }
}

Measured memory_bytes: 3780
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int n = in.next().length();
            String s = "";
            for (int i = 0; i < n; i++)
            {
                s += 'x';
            }
            out.print(s);
        }

    }
}



Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+100;
#define ll long long

void solve(){
    string s;
    cin>>s;
    if(s[4]==s[5]&&s[2]==s[3])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main(){
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    sort(all(h));
    ll ans = LONG_LONG_MAX;
    rep(i, n - k + 1) {
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<typename T = lint>inline T in() { T x; cin >> x; return x; }
#define INF           1e9
#define INFL          static_cast<lint>(INF)
#define REP(i,n)      for(lint i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)     for(lint i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)     for(lint i=n-1;i>=0;--i)
#define REPR1(i,n)    for(lint i=n;i>0;--i)
#define REPI(i,ini,n) for(lint i=(ini),i##_len=(n);i<i##_len;++i)
#define REPC(i,obj)   for(auto i:obj)
#define R_UP(a,b)     (((a)+(b)-1)/(b))
#define ALL(obj)      (obj).begin(),(obj).end()
int main()
{
	int n = in();
	vector<int>a(n);
	REP(i, n)a[i] = i + 1;
	REP(i, a.size())
	{
		if (i != 0)cout << ' ';
		cout << a[i];
	}
	cout << endl;
	while (true)
	{
		int index = -1;
		REPR(i, n - 1)
		{
			if (a[i] < a[i + 1])
			{
				index = i;
				break;
			}
		}
		if (index != -1)
		{
			REP(i, index)cout << a[i] << ' ';
			vector<int>a_copy(a.begin() + index, a.end());
			vector<int>::iterator itr;
			for (int i = 1;; ++i)if ((itr = find(ALL(a_copy), a[index] + i)) != a_copy.end())break;
			cout << *itr << ' ';
			a[index] = *itr;
			a_copy.erase(itr);
			sort(ALL(a_copy));
			REP(i, a_copy.size())
			{
				if (i != 0)cout << ' ';
				cout << a_copy[i];
				a[index + 1 + i] = a_copy[i];
			}
			cout << endl;
		}
		else break;
	}
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

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

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

const int limit = 50;
int n, m;
int a[limit], b[limit];
bool grapgh[limit][limit];
bool visited[limit];

signed main() {
  std::cin >> n >> m;
  REP(i, m) {
    std::cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    grapgh[a[i]][b[i]] = grapgh[b[i]][a[i]] = true;
  }
  int ans = 0;
  REP(i, m) {
    grapgh[a[i]][b[i]] = grapgh[b[i]][a[i]] = false;
    REP(j, n) visited[j] = false;
    {
      vi que;
      que.PB(0);
      for (int b = 0; b < (int)que.size(); b++) {
        visited[que[b]] = true;
        for (int v2 = 0; v2 < n; v2++) {
          if (grapgh[que[b]][v2] == false)
            continue;
          if (visited[v2] == true)
            continue;
          que.PB(v2);
        }
      }
    }
    bool isBridge = false;
    REP(j, n) {
      if (!visited[j]) {
        isBridge = true;
        break;
      }
    }
    if (isBridge)
      ans++;
    grapgh[a[i]][b[i]] = grapgh[b[i]][a[i]] = true;
  }
  print(ans);
}


Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
a, b, c = 0, 0, 0

tmp = min(X, Y)
if tmp * A + tmp * B < tmp * C * 2:
    a += tmp
    b += tmp
else:
    c += tmp * 2
X -= tmp
Y -= tmp
if X:
    if C * 2 < A:
        c += X * 2
    else:
        a += X
if Y:
    if C * 2 < B:
        c += Y * 2
    else:
        b += Y
print(a * A + b * B + c * C)




Measured memory_bytes: 3064
using System;
        using System.Linq;
        using static System.Math;

        public class Program
        {
            public static void Main(string[] args)
            {
            long[] input = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            Console.WriteLine(Abs(input[0] - 2) * Abs(input[1] - 2));
            }
        }

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
   int n;
   cin >> n;
   map<int,int> a;
   rep(i,n-1) {
       int b;
       cin >> b;
       b--;
       a[b]++;
   }
   vector<int> ans;
   rep(i,n-1) {
       ans.push_back(a[i]);
   }
   ans.push_back(0);
   rep(i,n) cout << ans[i] << endl;
}


Measured memory_bytes: 13696
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

int h, w, k;
vector<string>brd;
int dist[890][890];
int dxy[] = { 1,0,-1,0,1 };
auto ceil_m = [](int a, int b) {return (a - 1) / b + 1; };

int main(void)
{
	cin >> h >> w >> k;
	for (int i = 0; i < h; ++i)
	{
		string s;
		cin >> s;
		brd.push_back(s);
	}
	int sx, sy;
	for (int i = 0; i < h; ++i)for (int j = 0; j < w; ++j)
	{
		if (brd[i][j] == 'S')
		{
			brd[i][j] = '.';
			sx = i;
			sy = j;
		}
	}
	memset(dist, 0xff, sizeof(dist));
	int ans = INT_MAX;
	queue<pair<pair<int, int>, int>>que;
	dist[sx][sy] = 0;
	que.push({ {sx,sy},0 });
	while (!que.empty())
	{
		auto par = que.front();
		que.pop();
		int i = par.first.first;
		int j = par.first.second;
		int dis = par.second;
		if (i < 0 || j < 0 || i >= h || j >= w)
		{
			//距離0の#と扱う
			int can = max(1, ceil_m(dis, k));
			ans = min(ans, can);
			continue;
		}
		if (brd[i][j] == '#')
		{
			int P = min({ h - i,i + 1 ,w - j ,j + 1 });
			int can = max(ceil_m(P, k) + 1, ceil_m(dis + P - 1, k));
			ans = min(ans, can);
			continue;
		}
		for (int dir = 0; dir < 4; ++dir)
		{
			int ii = i + dxy[dir];
			int jj = j + dxy[dir + 1];
			if (ii < 0 || jj < 0 || ii >= h || jj >= w)
			{
				que.push({ { ii,jj },dis + 1 });
			}
			else
			{
				if (dist[ii][jj] < 0)
				{
					dist[ii][jj] = dis + 1;
					que.push({ {ii,jj},dis + 1 });
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    if(a > b) cout << 0 << endl;
    else if(n == 1) {
        if(a == b) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else cout << a + (n - 1) * b - (n - 1) * a - b + 1<< endl;
    return 0;
}

Measured memory_bytes: 3592
import sys
def I(): return int(sys.stdin.readline())
def LI(): return [int(x) for x in sys.stdin.readline().split()]

N,M,V,P = LI()
A = LI()
A.sort()

def check(x):
    if (N-x)<=P:
        return True

    x_score = A[x]+M
    total_v = (V-x-P)*M

    if(A[N-P]>x_score):
        return False

    for i in range(x+1,N-P+1):
        total_v -= min(M,(x_score - A[i]))
    if total_v <= 0:
        return True
    else:
        return False

def main():
    if(check(0)):
        print(N)
        return

    isOK = N-1
    isNG = 0
    while(isOK-isNG>1):
        mid = (isOK+isNG)//2
        if(check(mid)):
            isOK = mid
        else:
            isNG = mid
    print(N-isOK)
    return


if __name__ == "__main__":
    main()



Measured memory_bytes: 58736
import java.io.*;

class Main{
    public static void main(String[]args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String str;
        int sum = 0;

        while(true){
            str = br.readLine();

            if(str.equals("0"))break;
            
            for(int i=0; i<str.length(); i++){
                sum += Integer.parseInt(str.substring(i,i+1));
            }
            System.out.println(sum);
            sum = 0;
        }
    }
}

Measured memory_bytes: 24804
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect
import numpy as np

def ln():
    return map(int, input().split())

N, K = ln()

tmp = 0
tmp2 = 0
for a in range(1,N+1):
    if a%K == 0:
        tmp += 1
if K%2 == 0:
    for a in range(1,N+1):
        if a%K == K//2:
            tmp2 += 1
ans = tmp**3 + tmp2**3
print(ans)


Measured memory_bytes: 13636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pii pair<int,int>
#define pb push_back
#define eb emplace_back

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int ull;
int MOD=1000000007;
int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
inline int rund() {int x576363482791fuweh=rng();return abs(x576363482791fuweh)%RAND_MAX;}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	if (w.size()) cout<<w[w.size()-1]<<endl;
}

void M998()
{
	swap(MOD,MOD2);
}

ll raand()
{
	ll a=rund();
	a*=RAND_MAX;
	a+=rund();
    return a;
}

#define rand raand

ll raaand()
{
	return raand()*(MOD-7)+raand();
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

ll min(ll a,int b)
{
	if (a<b) return a;
	return b;
}

ll min(int a,ll b)
{
	if (a<b) return a;
	return b;
}

ll max(ll a,int b)
{
	if (a>b) return a;
	return b;
}

ll max(int a,ll b)
{
	if (a>b) return a;
	return b;
}

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

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

inline int mult(ll a,ll b)
{
	return (a*b)%MOD;
}

inline int pot(int n,int k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

int divide(int a,int b)
{
	return mult(a,pot(b,MOD-2));
}

inline int sub(int a,int b)
{
	if (a-b>=0) return a-b;
	return a-b+MOD;
}

inline int add(int a,int b)
{
	if (a+b>=MOD) return a+b-MOD;
	return a+b;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

ll has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=bases[3];
		h2*=bases[1];
		h2+=a-'a';
		h2%=bases[4];
	}
	return h1*(MOD+13893829)+h2;
}

const int N=3010;
int n,m,dp[N][N],a[N],b[N];
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	for (int i=0;i<10;++i) bases.push_back(rand()%(MOD-13893829)+13893829);
	cin>>n>>m;
	for (int i=0;i<=n;++i) dp[i][0]=1;
	for (int i=0;i<=m;++i) dp[0][i]=1;
	for (int i=1;i<=n;++i) cin>>a[i];
	for (int i=1;i<=m;++i) cin>>b[i];
	for (int i=1;i<=n;++i) for (int j=1;j<=m;++j) dp[i][j]=sub(add(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]*(a[i]!=b[j]));
	//for (int i=0;i<=n;++i,cout<<en) for (int j=0;j<=m;++j) cout<<dp[i][j]<<' ';
	cout<<dp[n][m];
}




Measured memory_bytes: 24960
// Package main provides
//
// File:  a.go
// Author: ymiyamoto
//
// Created on Sat Aug  4 04:27:17 2018
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	arr := make([]int, 3)
	fmt.Scan(&arr[0], &arr[1], &arr[2])
	sort.Ints(arr)

	ans := 0
	for i := range arr {
		if i+1 < len(arr) {
			ans += arr[i+1] - arr[i]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.*;
class Main
{
		public static void main(String[] args) 
		{
			Scanner sc = new Scanner(System.in);
			
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			int c = a*b;
			
			if(c%2==0){
				System.out.println("Even");
			}else{
				System.out.println("Odd");
			}
		}
}

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

const int mod = 1e9 + 7, N = 1e5 + 10;

ll pw(ll a, ll b) {
    ll r = 1;
    for( ; b ; b >>= 1, a = a * a % mod) {
        if(b & 1) {
            r = r * a % mod;
        }
    }
    return r;
}
#define double long double
ll getinv(ll n) {
    return pw(n, mod - 2);
}

ll x[N], y[N], dir[N];
int n;
// const ll inf = 0x3f3f3f3f3f3f3f3fll;
const double inf = 1e60;

double get_ran_x(double T) {
	double mn = inf, mx = -inf;
	for(int i = 1 ; i <= n ; ++ i) {
		if(dir[i] == 'L') {
			mn = min(mn, x[i] - T);
			mx = max(mx, x[i] - T);
		} else if(dir[i] == 'R') {
			mn = min(mn, x[i] + T);
			mx = max(mx, x[i] + T);
		} else {
			mn = min(mn, (double) x[i]);
			mx = max(mx, (double) x[i]);
		}
	}
	return (mx - mn);
}

double get_ran_y(double T) {
	double mn = inf, mx = -inf;
	for(int i = 1 ; i <= n ; ++ i) {
		if(dir[i] == 'U') {
			mn = min(mn, y[i] + T);
			mx = max(mx, y[i] + T);
		} else if(dir[i] == 'D') {
			mn = min(mn, y[i] - T);
			mx = max(mx, y[i] - T);
		} else {
			mn = min(mn, (double) y[i]);
			mx = max(mx, (double) y[i]);
		}
	}
	return (mx - mn);
}
double get(double T) {
	return get_ran_x(T) * get_ran_y(T);
}

int main() {
	scanf("%d", &n);
	for(int i = 1 ; i <= n ; ++ i) {
		char s[10];
		scanf("%lld%lld%s", &x[i], &y[i], s);
		dir[i] = s[0];
	}

	// n = 1e5;
	// for(int i = 1 ; i <= n ; ++ i) {
	// 	// char s[10];
	// 	// scanf("%lld%lld%s", &x[i], &y[i], s);
	// 	// dir[i] = s[0];
	// 	x[i] = rand() % int(2e8) - int(1e8);
	// 	y[i] = rand() % int(2e8) - int(1e8);
	// 	dir[i] = "LRUD"[rand() % 4];
	// }

	// for(int T = 0 ; T <= 100 ; ++ T) {
	// 	double ranx = get_ran_x(T);
	// 	double rany = get_ran_y(T);
	// 	printf("%lf %lf: %lf\n", ranx, rany, ranx * rany);
	// }
	double l = 0, r = 1e10;
	for(int i = 1 ; i <= 1000 ; ++ i) {
		double len = (r - l) / 3;
        double ml = l + len, mr = l + len * 2;
        if(get(ml) < get(mr)) {
            r = mr;
        } else {
            l = ml;
        }
	}
	// cout << l << ' ' << r << endl;
	double ans = get(l);
	cout << fixed << setprecision(10) << ans << endl;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,m,ans1,ans2,wa[100000];
bool f[100000];

signed main() {
    cin >> n >> m;
    rep(i,m) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if (!f[p]) {
            if (s == "AC") {
                ans1++;
                f[p] = true;
            }
            if (s == "WA") wa[p]++;
        }
    }
    rep(i,n) if (f[i]) ans2 += wa[i];
    cout << ans1 << " " << ans2 << endl;
}



Measured memory_bytes: 1152