akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N), cum(N+1);
    map<ll, ll> mp;
    REP(i,N){
        cin >> A[i];
        --A[i];
    }
    REP(i,N) cum[i+1] = (cum[i] + A[i]) % K;
    ll ans = 0;
    REP(i,N+1){
        ans += mp[cum[i]];
        mp[cum[i]]++;
        if(i - K + 1 >= 0) mp[cum[i-K+1]]--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var kx = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var k = kx[0];
            var x = kx[1];
            var result = new List<int> { x };
            const int max = 1000000;
            for (var i = 1; i < k; i++)
            {
                if (x + i <= max) result.Add(x + i);
                if (x - i >= -max) result.Add(x - i);
            }

            Console.WriteLine(string.Join(" ", result.OrderBy(x => x)));
        }
    }
}

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

template<typename T,typename F>
T KnuthYao(int n,T INF,F cost){
  vector<vector<T> > dp(n+1,vector<T>(n+1,INF));
  vector<vector<int> > nx(n,vector<int>(n));
  for(int i=0;i<n;i++) dp[i][i]=0,nx[i][i]=i;
  for(int w=1;w<n;w++){
    for(int i=0;i+w<n;i++){
      int j=i+w;
      for(int r=nx[i][j-1];r<=nx[i+1][j];r++){
	T c=dp[i][r]+dp[r+1][j]+cost(i,r,j);
	if(dp[i][j]>c) dp[i][j]=c,nx[i][j]=r;
      }
    }
  }
  return dp[0][n-1];
}

signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n),y(n);
  for(Int i=0;i<n;i++) cin>>x[i]>>y[i];
  const Int INF = 1e18;
  auto calc=[&](int i,int r,int j){	      
	      return r+1<n?x[r+1]-x[i]+y[r]-y[j]:INF;
	    };
  cout<<KnuthYao(n,INF,calc)<<endl;
  return 0;
}




Measured memory_bytes: 14680
#include <bits/stdc++.h>
using namespace std;
#define fo(i, x, y) for (int i = x; i <= y; ++i)
#define fd(i, x, y) for (int i = x; i >= y; --i)
const int maxn = 1e6 + 5;
int n, lim;
int a[maxn], pri[maxn];
bool f[maxn];
int getint()
{
	char ch;
	int res = 0, p;
	while (!isdigit(ch = getchar()) && (ch ^ '-'));
	p = ch == '-'? ch = getchar(), -1 : 1;
	while (isdigit(ch))
		res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
	return res * p;
}
int gcd(int a, int b)
{
	return b? gcd(b, a % b) : a;
}
int main()
{
	n = getint();
	fo(i, 1, n) a[i] = getint(), lim = max(lim, a[i]);
	fo(i, 2, lim)
		if (!pri[i])
		{
			pri[i] = i;
			fo(j, i, lim / i)
				if (!pri[i * j]) pri[i * j] = i;
		}
	bool flag = true;
	fd(i, n, 1)
	{
		int x = a[i];
		while (x > 1)
		{
			if (f[pri[x]]) {flag = false; goto sig;}
			x /= pri[x];
		}
		x = a[i];
		while (x > 1)
		{
			f[pri[x]] = true;
			x /= pri[x];
		}
	}
	sig:
	if (flag) {printf("pairwise coprime\n"); return 0;}
	int x = a[1];
	fo(i, 2, n) x = gcd(x, a[i]);
	printf(x == 1? "setwise coprime\n" : "not coprime\n");
	return 0;
}

Measured memory_bytes: 11364
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    int ans=0;
    for (int i = 0; i < n; i+=2)
    {
        if (a[i]%2==1)
        {
            ans++;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
using namespace std;
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long 
#define FF first
#define SS second
#define MOD 1000000007

typedef vector<ll> vll;


int main()
{
	ios_base::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll minsum = (n-1)*(a) + b; 
	ll maxsum = (n-1)*(b) + a;
	ll ans = maxsum-minsum+1;
	cout<<max(ans,0LL);
	return 0;
}


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

#define ll long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()

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

    int a, b, d;
    cin >> a >> b >> d;
    cout << (a % d == 0 || b % d == 0) + (b - a) / d << '\n';
}

Measured memory_bytes: 3620
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = 100000000000;
const long long int Mod = 1000000007;
using ll = long long int; //long long int は64bit
using vi = vector<int>; using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(long long int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
typedef pair<ll,ll> Pair;
bool p_compare(const Pair& firstP, const Pair& secondP){ 
    return firstP.second < secondP.second; 
}//sort(all(v),p_compare)で昇順ソート
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////
//Snipet -> Caps Lock

ll n,m,c;
int b[100];
int a[100][100];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>m>>c;ll aaa;
    rep(i,m)cin>>b[i];
    rep(i,n){
        rep(j,m){
            cin>>a[j][i];
        }
    }
    ll tmp = 0;
    ll ans = 0;
    rep(i,n){
        tmp =0;
        rep(j,m){
            tmp += b[j]*a[j][i];
        }
        if(tmp+c>0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> P;

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

	int MAX = 0;
	for (int i = 1; i <= 1000; i++) {
		for (int j = 2; j <= 10; j++) {
			if (MAX <= pow(i, j) && pow(i, j) <= n) {
				MAX = pow(i, j);
			}
		}
	}
	cout << MAX << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <set>
#include <climits>
#define INF 1000000000000000
#define ll long long
using namespace std;
double h(double a){
    if(a<0) return -a;
    return a;
}
int main(){
    int N;
    cin >> N;
    ll A[N];
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A,A+N);
    ll mx = A[N-1];
    double d = (double)mx/2;
    double count = 1000000000000;
    ll ans;
    for(int i=0;i<N;i++){
        if(h(A[i]-d)<count){
            count = h(A[i]-d);
            ans = A[i];
        }
    }
    cout << mx << " " << ans << endl;
}

Measured memory_bytes: 1024
S = list(input())
N = len(S)
res = [0] * N

def calc(pivot_r, pivot_l, r_count, l_count):
  # print(pivot_r, pivot_l, r_count, l_count)
  common = (r_count+l_count)//2
  res[pivot_r], res[pivot_l] = 1+common, 1+common
  if (r_count+l_count)%2 == 1:
    if r_count > l_count:
      res[pivot_r] += 1
    else:
      res[pivot_l] += 1

  if max(r_count,l_count) % 2 == 1:
    res[pivot_r], res[pivot_l] = res[pivot_l], res[pivot_r]


cur = "R"
r_count = 0
l_count = 0
pivot_r = 0
pivot_l = 0
for i in range(N):
  if S[i] == cur:
    if cur=="R": r_count += 1
    if cur=="L": l_count += 1
  else:
    if cur=="R": 
      cur = "L"
      pivot_r = i-1
      pivot_l = i
    elif cur=="L":
      calc(pivot_r,pivot_l,r_count-1,l_count)
      cur ="R"
      r_count,l_count = 1,0
      pivot_r,pivot_l = 0,0
calc(pivot_r,pivot_l,r_count-1,l_count)

print(" ".join(map(str, res)))

Measured memory_bytes: 56716
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
/*---------------------------------------*/

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

  int a, b; cin >> a >> b;
  cout << (a - 1) * (b - 1) << "\n";
  return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  string s;
  ll cnt=0,n;
  cin >> s;
  n = s.size();
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n-1-i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
void init(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int main()
{
    int q;
    int n[6];
    int i,j;
    char t[110];
    int ts;
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init(n);
    scanf("%s",&t);
    ts=strlen(t);
    for(i=0;i<ts;i++){
        throwdice(t[i]);    
    }
    printf("%d\n",dice1.d[0]);
    return 0;
}




Measured memory_bytes: 2112
#include <bits/stdc++.h>
 
using namespace std;
int main(void)
{
  int n;
  cin >> n;
 
  int min_count = n;
  
  for(int i95=0; i95*9*9*9*9*9 <= n; i95++){
    int p95=i95*pow(9,5);
    if(p95 > n) break;
      
    for(int i94=0; i94 < 9; i94++){
      int p94=i94*pow(9,4);
      if(p95+p94 > n) break;
 
      for(int i93=0; i93 < 9; i93++){
        int p93=i93*pow(9,3);
        if(p95+p94+p93 > n) break;
 
        for(int i92=0; i92 < 9; i92++){
          int p92=i92*pow(9,2);
          if(p95+p94+p93+p92 > n) break;
 
          for(int i91=0; i91 < 9; i91++){
            int p91=i91*pow(9,1);
            if(p95+p94+p93+p92+p91 > n) break;
        
            for(int i61=0; i61 < 6; i61++){
              int p61=i61*pow(6,1);
              if(p95+p94+p93+p92+p91+p61 > n) break;
            
              for(int i62=0; i62 < 6; i62++){
                int p62=i62*pow(6,2);
                if(p95+p94+p93+p92+p91+p61+p62 > n) break;
                
                for(int i63=0; i63 < 6; i63++){
                  int p63=i63*pow(6,3);
                  if(p95+p94+p93+p92+p91+p61+p62+p63 > n) break;
                  
                  for(int i64=0; i64 < 6; i64++){
                    int p64=i64*pow(6,4);
                    if(p95+p94+p93+p92+p91+p61+p62+p63+p64 > n) break;
                  
                    for(int i65=0; i65 < 6; i65++){
                      int p65=i65*pow(6,5);
                      if(p95+p94+p93+p92+p91+p61+p62+p63+p64+p65 > n) break;
 
                      for(int i66=0; i66*6*6*6*6*6*6 <= n; i66++){
                          int p66=i66*pow(6,6);
                          int p= p95+p94+p93+p92+p91+p61+p62+p63+p64+p65+p66 ;
                          
                            
                          if(p<=n){
                            int i1 = n-p;
                            int count = i91 +i92 +i93 +i94 +i95 +i61 +i62 +i63 +i64 +i65 +i66 + i1;
                            //printf("%dx%d %dx%d %dx%d %dx%d %dx%d ", i91, (int)pow(9,1), i92, (int)pow(9,2),i93, (int)pow(9,3),i94, (int)pow(9,4),i95, (int)pow(9,5));
                            //printf("%dx%d %dx%d %dx%d %dx%d %dx%d %dx%d \n", i61, (int)pow(6,1), i62, (int)pow(6,2),i63, (int)pow(6,3),i64, (int)pow(6,4),i65, (int)pow(6,5), i66, (int)pow(6,6));
                            //printf("p %d  i1 %d  count %d  min %d\n", (int)p, i1, count, min_count);
                            min_count = min(min_count, count);
                          }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  cout << min_count << endl;
  return 0;
}


Measured memory_bytes: 256
import math
a,b,c= input().split()
x,y,z=(int(a),int(b),int(c))
num_one_gr = y + z
num_gr = math.floor(x/num_one_gr)
amari = x - num_one_gr*num_gr
if amari <= y:
    total = y * num_gr + amari
else:
    total = y*(num_gr + 1)
print(total)

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var n int
	var c []byte
	fmt.Scan(&n, &c)

	ans := 0
	l, r := 0, n-1
	for l < r {
		for l < r && c[l] == 'R' {
			l++
		}
		for l < r && c[r] == 'W' {
			r--
		}

		if c[l] == 'W' && c[r] == 'R' {
			ans++
			c[l], c[r] = c[r], c[l]
			r--
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3396
#include<cstdio>
#include<iostream>
#include<algorithm>
long long a,b,k;
using namespace std;
int main()
	{
	cin>>a>>b>>k;
	if(a+k>=b&&b-k<=a) 
		{
		for(int i=a;i<=b;i++)
			{
			cout<<i<<endl; 
			}
		}
	else 
	{
	for(int i=a;i<=a+k-1;i++)
		{
		if(i<=b+1-k) cout<<i<<endl;
		else continue;
		}
	for(int i=b+1-k;i<=b;i++)
		{
		if(i>a+k-1)	cout<<i<<endl;
		else continue;
		}
	}
	return 0;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int x;
char c;
inline int read()
{
	x=0; c=getchar();
	while(c<'0'||c>'9') c=getchar();
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return x;
}
main()
{
	long n = read(), ans = n;
	for (int i = 1; i < n; ++i)
	{
        int u = read(), v = read();
		if (u > v) swap(u, v);
        ans += i * (n - i + 1) - u * (n - v + 1);
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3724
//#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>
#include "bits/stdc++.h"

#define rep(i,n) for(long long (i)=0;(i)<(long long)(n);(i)++)
#define all(x) (x).begin(),(x).end()
//#define int long long

#define PI (3.14159265358979323)
#define MOD (1000000007LL)
#define INF (1LL<<60LL)
#define MAX_N (100001)

using namespace std;

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

Measured memory_bytes: 3568
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

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 main(void){

    int a,b;
    cin>>a>>b;

    if(a==1){
        if(b==2){
            cout<<"3"<<endl;
            return 0;
        }else{
            cout<<"2"<<endl;
            return 0;
        }
    }else if(a==2){
        if(b==1){
            cout<<"3"<<endl;
            return 0;
        }else{
            cout<<"1"<<endl;
            return 0;
        }
    }else{
        if(b==2){
            cout<<"1"<<endl;
            return 0;
        }else{
            cout<<"2"<<endl;
            return 0;
        }
    }

  // cout<< <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int MOD = 1e9 + 7;
void add(int &a, int b)
{
    a = (a + b) % MOD;
}
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<vector<int>> dp(n+1, vector<int>(k+1, 0));
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++)
    {
        int num = 0;
        for(int j = 0; j <= k; j++)
        {
            add(num, dp[i-1][j]);
            dp[i][j] = num;
            if(j-a[i-1] >= 0) add(num, -dp[i-1][j-a[i-1]]);
        }
    }
    cout << (dp[n][k]+MOD)%MOD << endl;
}


Measured memory_bytes: 43384
#include<iostream>
#include<vector>

int n, m, count, ans;
std::vector<std::vector<int>>v;
std::vector<bool>used(8, 0);

void dfs(int num) {
	used[num] = true;
	count++;
	if (count == n)ans++;
	for (auto i : v[num]) {
		if (used[i])continue;
		dfs(i);
	}
	count--;
	used[num] = false;
}

int main() {

	std::cin >> n >> m;
	v.resize(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		std::cin >> a >> b;
		a--;
		b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}

	dfs(0);

	printf("%d\n", ans);
}

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

int main(){
    char a, b;
    cin >> a;
    for(int i = 0; i < 3; i++){
        cin >> b;
        if(a == b){
            cout << "Bad" << endl;
            return 0;
        }
        a = b;
    }
    cout << "Good" << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for(auto& i: A) cin >> i;

  multiset<int> S;
  S.emplace(-1);
  for(auto a: A) {
    auto i = S.lower_bound(a);
    --i;
    if(i != begin(S)) S.erase(i);
    S.emplace(a);
  }
  cout << S.size() - 1 << endl;
}


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

#define INF 2e9
#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;

int a[5000];
int b[5000];
ll c[5000];
ll dist[2500];
bool negative[2500];

int main() {
    int n, m, p;
    cin >> n >> m >> p;

    rep(i, m) { 
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        c[i] = -(c[i]-p);
    }

    rep(i, n) dist[i] = INF;
    dist[0] = 0;

    rep(i, n-1) rep(j, m) {
        if (dist[a[j]] == INF) continue;
        dist[b[j]] = min(dist[b[j]], dist[a[j]]+c[j]);
    }

    ll ans = dist[n-1];
    rep(i, n) negative[i] = false;

    rep(i, n) rep(j, m) {
        if (dist[a[j]] == INF) continue;

        if (dist[b[j]] > dist[a[j]]+c[j]){
            dist[b[j]] = dist[a[j]]+c[j];
            negative[b[j]] = true;
        }
        if (negative[a[j]]) negative[b[j]] = true;
    }

    if (negative[n-1]) cout << -1 << endl;
    else if (ans > 0) cout << 0 << endl;
    else cout << -ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b))?(b):(a))
#define chmin(a, b) a = (((a)<(b))?(a):(b))

const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};

#define lengthof(x) (sizeof(x) / sizeof(*(x)))


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}

signed main(){
  int n; cin>>n;
  VL x(n); rep(i,n) cin>>x[i];
  ll a = 0;
  ll ans = 0;
  reps(i,n-1){
    a += mpow(i,MOD-2);
    a %= MOD;
    ll d = x[i]-x[i-1];
    ans += (a*d)%MOD;
    ans %= MOD;
  }

  reps(i,n-1){
    ans *= i; ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
dhw = [(1,0),(0,-1),(0,1),(-1,0),
( 2,-2),( 2,-1),( 2, 0),( 2, 1),( 2, 2),
( 1,-2),( 1,-1),        ( 1, 1),( 1, 2),
( 0,-2),                        ( 0, 2),
(-1,-2),(-1,-1),        (-1, 1),(-1, 2),
(-2,-2),(-2,-1),(-2, 0),(-2, 1),(-2, 2)]

H, W = map(int, input().split())
sh, sw = map(lambda x:int(x)-1, input().split())
eh, ew = map(lambda x:int(x)-1, input().split())
S = [input() for _ in range(H)]

dst = [[-1]*W for _ in range(H)]

from collections import deque
dq = deque([(sh, sw, 0)])
while dq:
    h, w, d = dq.popleft()
    if h < 0 or H <= h or w < 0 or W <= w or dst[h][w] >= 0 or S[h][w] == '#': continue
    dst[h][w] = d
    for i in range(4): dq.appendleft((h + dhw[i][0], w + dhw[i][1], d))
    for i in range(4, 24): dq.append((h + dhw[i][0], w + dhw[i][1], d+1))

print(dst[eh][ew])


Measured memory_bytes: 265084
while True:
    M, F, R = map(int, input().split())
    if M == -1 and F == -1 and R == -1:
        break
    if M == -1 or F == -1:
        print('F')
    elif M + F >= 80:
        print('A')
    elif M + F >= 65:
        print('B')
    elif M + F >= 50:
        print('C')
    elif M + F >= 30:
        if R >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}

int main(){
    ll n;
    cin >>n;
    n%=10;
    if (n==2 or n==4 or n==5 or n==7 or n==9){
        cout << "hon" << endl;
    }else if (n==0 or n==1 or n==6 or n==8){
        cout << "pon" << endl;
    }else{
        cout << "bon" << endl;
    }
    return 0;
}
 
 

Measured memory_bytes: 3132
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    int W, a, b;
    cin >> W >> a >> b;

    if (b > a + W) { cout << b - (a + W) << endl; }
    else if (a > b + W) { cout << a - (b + W) << endl; }
    else { cout << 0 << endl; }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
 
	Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
   
	int gohyaku = X/500;
	int goen =(X-(gohyaku*500))/5;

      System.out.println(1000*gohyaku + 5*goen);

    }
}

Measured memory_bytes: 20948
#include<iostream>
#define int long long
using namespace std;int m[114514];signed main(){int n,k;cin>>n>>k;for(int i=0;i<n;i++){int a,b;cin>>a>>b;m[a]+=b;}int r=0;for(int i=0;i<100001;i++){r+=m[i];if(r>=k){cout<<i<<endl;break;}}}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll mod = 998244353;

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

vector<ll> inv, fact, invfact;
void Mod_build(int n = 101010) {
    fact.resize(n + 1);
    inv.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = inv[0] = invfact[0] = 1;
    inv[1] = 1;
    for (ll i = 0; i < n; i++) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        if (i > 0) inv[i + 1] = mod - inv[mod % (i + 1)] * (mod / (i + 1)) % mod;
        invfact[i + 1] = invfact[i] * inv[i + 1] % mod;
    }
}
ll perm(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return fact[n] * invfact[n - k] % mod;
}
ll comb(int n, int k) {
    if (n < 0 || k < 0 || k > n) return 0;
    return (fact[n] * invfact[n - k] % mod) * invfact[k] % mod;
}
ll powmod(ll n, ll k) {
    k %= mod - 1;
    if (k < 0) k += mod - 1;
    ll ret = 1;
    while (k) {
        if (k & 1) ret = ret * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return ret;
}

int main() {
    Mod_build();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    int n, s;
    cin >> n >> s;
    int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    VI c(3030, 0);
    c[0] = 1;
    for (i = 0; i < n; i++) {
        for (j = 3029; j >= a[i]; j--) {
            c[j] += inv[2] * c[j - a[i]];
            c[j] %= mod;
        }
    }
    cout << (c[s] * powmod(2, n)) % mod << endl;
}

Measured memory_bytes: 5456
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;



int main(){
    int M,K;
    cin >> M >> K;
    long long ans = K;
    for(int i = 1;i<M;i++){
        ans = ans * (K-1);
    }
    cout << ans << endl;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

	int A, B;

	cin >> A >> B;

	if((A < 10) && (B < 10)){
		cout << A*B << "\n";
	}
	else{
		cout << "-1" << "\n";
	}

return 0;
}

Measured memory_bytes: 256
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{

    //freopen("input.txt","r", stdin);
    lli n,t,i,j,k,ans=0,flag=0,a,b,m,w;
    cin>>n>>w;
    vector<vector<lli>> v(n,vector<lli>(2));
    for(i=0;i<n;i++)
    {
        cin>>v[i][0]>>v[i][1];
        ans+=v[i][1];
    }
    //minimize weight for each price
    vector<lli> dp(ans+1,INT_MAX);
    dp[0]=0;
    for(i=0;i<n;i++)
    {
        for(j=ans-v[i][1];j>=0;j--)
        {
            dp[j+v[i][1]]
            =min(dp[j+v[i][1]],
                 dp[j]+v[i][0]);
        }
        //for(auto j:dp)
         //   cout<<j<<" ";cout<<"\n";
    }
    for(j=ans;j>=0;j--)
        if(dp[j]!=INT_MAX && dp[j]<=w)
    {
        cout<<j;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdlib>
#include<iomanip>
#include<queue>
#include<set>


using namespace std;

void Solution()
{
    map<string, set<int>> saveData;  //set の中には、各要素がソートされて格納されます。
    string str;
    int n;
    
    while (cin>>str>>n)
    {
        saveData[str].insert(n); // insert int type data to STL
    }
    
    for (map<string, set<int>>::iterator i = saveData.begin(); i != saveData.end(); i++)
    {
        cout<<(i -> first)<<endl;
        
        for (set<int>::iterator j = (i ->second).begin(); j != (i -> second).end(); j++)
        {
            if(j != (i -> second).begin()) // after output the first data, then can be divided by space keey.
            {
                cout<<" ";
            }
            
            cout<< *j;
        }
        
        cout<<endl;
    }
    
}

int main()
{
    Solution();
    return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX
using namespace std;

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
#define FORR(i,s,e) for(ll (i)=(s);(i)>(e);(i)--)
#define MOD 1000000007
#define llong long long
#define debug(x) cout<<#x<<": "<<x<<endl
typedef long long ll;
llong N;

/* 2010/00/00 問題 -----  Name/Link ----- */
/* -----解説等-----
問題:


*/

int K, S;

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

    ll ans = 0;
    cin >> K >> S;
        FOR(x, 0, K + 1) {
            FOR(y, 0, K + 1) {
                if ((S - (x + y) >= 0) && (S - (x+y)<=K))ans++;
            }
        }


        cout << ans<< endl;

    return 0;
}

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

using namespace std;
#define ll long long int
int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans=0;
    if(k<=a)
        ans=k;
    else
    {
        if(k>a)
        {
            ans+=a;
            k-=a;
        }
        k=max(0,int(k-b));
        ans-=k;
    }
    cout<<ans;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

char decodeChar(char c,int n)
{
  rep(i,n)
    {
      if(c == 'a')
	{
	  c = 'Z';
	  continue;
	}
      if(c == 'A')
	{
	  c = 'z';
	  continue;
	}
      c = (char)(c-1);
    }
  return c;
}

int main()
{
  int n;
  while(cin >> n,n)
    {
      vector<int> vec(n);
      rep(i,n) cin >> vec[i];
      string message;
      cin >> message;
      for(int i=0,index=0;i<message.size();i++,index=(index+1)%n)
	cout << decodeChar(message[i],vec[index]);
      cout << endl;
    }
  return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <atcoder/all>

using ll = long long int;
const int INF = (1<<25);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int n,m,i,a,b;
	std::cin >> n >> m;
	atcoder::scc_graph g(n);
	for(i=0; i<m; ++i){
		std::cin >> a >> b;
		g.add_edge(a,b);
	}
	auto ans = g.scc();
	std::cout << ans.l_ength() << std::endl;
	for(auto v: ans){
		std::cout << v.l_ength();
		for(auto e: v){
			std::cout << " " << e;
		}
		std::cout << std::endl;
	}
	return 0;
}


Measured memory_bytes: 40080
#入力
N, A, B = map(int, input().split())

#Nの範囲内の数値をリストに格納
N_list = list(range(1, N+1))

#条件に合うNの値を格納するリストを作成
N_match = []


#以下の処理をNの範囲で繰り返す
for n in N_list:
    
    #最後の処理（※）のためにnを別の値に代入しておく
    i = n

    #各桁の数値を求める
    #余りを格納するリストを作成
    R_list = []

    while True:
    
        #1の位の数値を算出しリストに順に格納
        R = n%10   
        R_list.append(R)    
    
        #10で割ることで、1の位を削る
        n = int(n/10)
    
        #1の位を削った時、N==0となった場合処理終了
        if n==0:
            break
    
    
    #あるnにおける各桁の和を算出
    R_sum = sum(R_list)
    
    #（※）条件に合致した時、その時のnをリストに格納
    if A<=R_sum<=B:
        N_match.append(i)
               
print(sum(N_match))

Measured memory_bytes: 3444
#include<bits/stdc++.h>
typedef long long LL;
using namespace std;
const int maxn=2e5+10;
const LL mod=1e4+7;
const double pi=acos(-1.0);
inline LL read()
{
	LL X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}
LL a[maxn];
LL n;
int main()
{
    LL sum=0;
    scanf("%lld",&n);
    for(LL i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum^=a[i];
    }
    for(LL i=1;i<=n;i++){
        printf("%lld ",sum^a[i]);
    }
    return 0;
}


Measured memory_bytes: 5248
#include<string>
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin >> s;
  if(s[0]=='S' && s[1]=='S' && s[2]=='S')
    cout << 0;
  else if(s[0]=='R' && s[1]=='R' && s[2]=='R')
    cout << 3;
  else if((s[0]=='R' && s[1]=='R' && s[2]=='S') || (s[0]!='R' && s[1]=='R' && s[2]=='R'))
    cout << 2;
  else
    cout << 1;
  return(0);
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)    \
    vl v;               \
    rep(i, n)           \
    {                   \
        ll x;           \
        cin >> x;       \
        v.push_back(x); \
    }
const ll INF = 999999999999999;
const ll MOD = 998244353;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
int main()
{
    cin>>n;
    inputv(A,n);
    inputv(B,n);

    vl v(n);
rep(i,n){
  v[i]=i+1;
}

    k=0;
    do
    {
        k++;
        if(A==v)a=k;
        if(B==v)b=k;                            // v の要素を表示
    } while (next_permutation(v.begin(), v.end())); // 次の順列を生成
    
    cout<<labs(a-b)<<endl;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)
ll N,M,S[2020],T[2020];

ll i, j, k,ans;
ll dp[2020][2020];
int main(){
    scanf("%lld%lld", &N, &M);
    fornum(i,0,N){
        scanf("%lld", S+i);
    }
    fornum(i,0,M){
        scanf("%lld", T+i+1);
    }
    dp[0][0] = 1;
    fornum (i,0,N){
        k = 0;
        fornum(j,0,M+1){
            
            dp[i + 1][j] = dp[i][j];
            if(S[i]==T[j]){
                dp[i + 1][j] += k;
                dp[i + 1][j] % MOD;
            }
            k = (k+dp[i][j])%MOD;
        }
    }
    fornum(i,0,M+1){
        ans = (ans + dp[N][i]) % MOD;
    }
    printf("%lld", ans);

    return 0;
}

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

int main() {
  int mod=1000000007;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n){
    cin>>a.at(i);
  }
  rep(i,n){
    cin>>b.at(i);
  }
  bool ch=true;
  rep(i,n-1){
    if(a.at(i+1)!=a.at(i)&&a.at(i+1)>b.at(i+1)){
      ch=false;
    }
    if(b.at(i+1)!=b.at(i)&&a.at(i)<b.at(i)){
      ch=false;
    }
  }
  if(a.at(n-1)!=b.at(0)){
    ch=false;
  }
  if(ch){
    long ans=1;
    rep(i,n-2){
      if(a.at(i)==a.at(i+1)&&b.at(i+2)==b.at(i+1)){
        ans*=min(a.at(i+1),b.at(i+1));
        ans%=mod;
      }
    }
    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }
  
}

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

using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
int n,pri[3005],vis[3005],tot,res=0;
ll x[MAXN],y[MAXN],t;
map<ll,int> mp,avl;

ll cube(int a){return 1ll*a*a*a;}
ll sqr(int a){return 1ll*a*a;}
int main()
{
	for(int i=2;i<=3000;i++)
	{
		if(!vis[i]) pri[++tot]=i;
		for(int j=1;j<=tot&&i*pri[j]<=3000;j++)
		{
			vis[i*pri[j]]=1;
			if(i%pri[j]==0) break;
		}
	}
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&t);x[i]=y[i]=1;
		for(int j=1;cube(pri[j])<=t;j++)
		{
			int cnt=0;
			while(t%pri[j]==0) t/=pri[j],cnt++;
			if(cnt%3==1) x[i]*=pri[j],y[i]*=sqr(pri[j]);
			else if(cnt%3==2) x[i]*=sqr(pri[j]),y[i]*=pri[j];
		}
		x[i]*=t;mp[x[i]]++;
		y[i]*=sqr(sqrt(t))==t?sqrt(t):sqr(t);
	}
	
	for(int i=1;i<=n;i++)
		if(!avl[x[i]])
		{
			avl[x[i]]=avl[y[i]]=1;
			if(x[i]==1) res++;
			else res+=max(mp[x[i]],mp[y[i]]);
		}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 22400
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int M;
int A[1000010];

signed main(){
	cin>>N>>M;
	int sum=0;
	REP(i,M){
		cin>>A[i];
		sum+=A[i];
	}
	if(N-sum<0){
		cout<<-1<<endl;
	}
	else{
		cout<<N-sum<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3672
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int n, x;
    cin >> n >> x;
    int m[n+1];
    FOR(i,0,n)
        cin >> m[i];
    sort(m, m + n);
    int y = x;
    int ans = 0;
    FOR(i,0,n) {
        y -= m[i];
        ans ++;
    }
    while (y >= 0) {
        y -= m[0];
        ans++;
    }
    cout << ans - 1 << endl;
}


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

// AtCoder Beginner Contest 141
int main(){

    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> ans(N, K);
    rep(i, Q){
        int a;
        cin >> a;
        ans[a - 1]++;
    }

    rep(i, N){
        if(ans[i] - Q <= 0){
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }

}

Measured memory_bytes: 1024
<?php
	$n = trim(fgets(STDIN));
	$a = array();
	while ($n--) {
		$a[] = trim(fgets(STDIN));
	}
	echo sosu($a) . "\n";

	function sosu($a) {
		$cnt = 0;
		foreach ($a as $v) {
			if ($v == 2) {
				$cnt++;
				continue;
			}
			if ($v < 2 || $v % 2 == 0) {
				continue;
			}

			$flg = false;
			$p = ceil(sqrt($v));
			for ($i = 2; $i <= $p; $i++) {
				if ($v % $i == 0) {
					$flg = true;
					break;
				}
			}
			if (!$flg) $cnt++;
		}
		return $cnt;
	}

Measured memory_bytes: 9380
/*input
4
3 4 2 1
*/
#include "bits/stdc++.h"
using namespace std;
const long long md=1e9+7;
long long a[1000005],n;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i=1;i<=n;++i)
		cin >> a[i];
	sort(a+1,a+n+1);

	long long ans = 0;
	for(int i=1;i<=n;++i) for(int j=i+1;j<=n;++j){
		int req = a[j] - a[i] + 1;
		if(a[i-1] < req) continue;
		ans += i - (lower_bound(a+1,a+i,req) - a);
		// cout << a[i] << ' ' << a[j] << ' ' << req << ' ' << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256