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

#define N 100000
#define Q
#define INF 1000000007
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define ABS(X) ((X)<0?-(X):(X))

int dp[N+1];


int main(void){
  int n, k;
  int h[N+1];
  
  cin >> n >> k;
  for (int i=1; i<=n; i++){
    cin >> h[i];
  }
  
  dp[1] = 0;
  for (int i=2; i<=n; i++){
    dp[i] = INF;
    for (int j=MAX(1,i-k); j<=i-1; j++){
      dp[i] = MIN(dp[i], dp[j]+ABS(h[i]-h[j]));
    }
    //cout << dp[i] << " ";
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main(void)
{
	double money = 100; //単位は千 10万=100,000
	int n,i;
	
	scanf("%d", &n);
	
	for (i=0; i<n; i++){
		money *= 1.05;
		money = ceil(money);
	}
	printf("%d\n", (int)money*1000);
	
	return 0;
}

Measured memory_bytes: 592
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = sum(b)
for i in range(1, n):
    if a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main (){
 unsigned short *A,*B;
 
 int C[VMAX+1];
 int n,i,j;
 scanf("%d",&n);
 
 A=malloc(sizeof(short)*n+1);
 B=malloc(sizeof(short)*n+1);
 
 for(i=0;i<=VMAX;i++) C[i]=0;
 
 for(i=0;i<n;i++){
  scanf("%hu",&A[i+1]);
  C[A[i+1]]++;
  }
  
 
 for(i=1;i<=VMAX;i++) C[i]=C[i]+C[i-1];
 
 for(j=1;j<=n;j++){
  B[C[A[j]]]=A[j];
  C[A[j]]--;
  }
 
 for(i=1;i<=n;i++){
  if(i>1)printf(" ");
  printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
  
  }

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

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

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

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

int main(){
 
  int n; cin >> n;
  vector<ll> a(n);
  ll mina = linf;

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

  bool flag = true;
  while(flag){
    int temp = mina;      
    flag = false;
    
    rep(i, n){
      a[i] %= mina;
      if(a[i] != 0){
        chmin(mina, a[i]);
        flag = true;
      }
      else
        a[i] = temp;
    }
  }

  pr(mina);

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MD 1000000007
#define INF 1ll<<60
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main(){
    int r;
    cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int x, y, temp;
	
	do{
		scanf("%d %d", &x, &y);

		if(x == 0 && y == 0){
			break;
		}else{
			if(x > y){
				temp = x;
				x = y;
				y = temp;
			}
		
			printf("%d %d\n", x, y);
		}

	}while(x != 0 || y != 0);
	
	return(0);
}

Measured memory_bytes: 600
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int l = sc.nextInt();
        int[] ar = new int[n];
        int sum = 0;
        int res = 114514;
        for (int i = 0; i < n; i++) {
            ar[i] = l+i;
            sum += ar[i];
            if(Math.abs(res) > Math.abs(ar[i])){
                res = ar[i];
            }
        }
        res = sum - res;
        System.out.println(res);
    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}



Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(b>=c)cout<<"delicious"<<endl;
	else if(a>=c-b)cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
}











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

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  for(ll i=1;i*i<n;i++){
    ll res=n/i-1;
    if(n%i==0&&n/res==n%res) ans+=res;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll euclid(ll x,ll y){
  if(x%y==0) return y;
  else return euclid(y,x%y);
}
int main(){
  ll a,b;
  cin>>a>>b;
  if(a<b) swap(a,b);
  cout<<a*b/euclid(a,b)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int x, y;
        cin >> x >> y;
        for (int i = 0; i <= x; ++i) {
            for (int j = 0; j <= x; ++j) {
                if (i * 2 + j * 4 == y && i + j == x) {
                    cout << "Yes";
                    return 0;
                }
            }
        }
        cout << "No";
        return 0;
    }


Measured memory_bytes: 3596
function main(input) {
  input=input.trim();
  const a = input.split(" ")[0];
  const b = input.split(" ")[1];
  const c = input.split(" ")[2];
  if(a.substr(a.length-1,1)==b.substr(0,1)&&b.substr(b.length-1,1)==c.substr(0,1)){
    console.log("YES");
  }else{
    console.log("NO");
  }

}



main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
const long long maxn=3000;
long long f[maxn+5][maxn+5];
int main()
{
    string s,s1="",ans="";
    long long i,j,m,n;
    cin>>s1>>s;
    if (s1.length()>s.length()) swap(s1,s);
    m=s.length();
    n=s1.length();
    s='l'+s;
    s1='l'+s1;
    for (i=1;i<=m;i++)
    {
        for (j=1;j<=n;j++)
        {
            if(s[i]==s1[j]) f[i][j]=f[i-1][j-1]+1;
            else f[i][j]=max(f[i-1][j],f[i][j-1]);
        }
    }
    while (f[m][n]>0)
    {
        if (s[m]==s1[n]) ans+=s[m],m--,n--;
        else if (f[m][n]==f[m][n-1]) n--;
        else m--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 74044
//#pragma warning(disable:4996)
//#pragma comment(linker, "/STACK:336777216")
//#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
const int N=200005;


void solve()
{
    int n,k,s;
    cin>>n>>k>>s;
    int a[n];
    for(int i=0;i<k;i++)
        a[i]=s;
    if((n-k)<s)
    {
        for(int i=k;i<n;i++)
            a[i]=1;
        for(int i=0;i<n;i++)
            cout<<a[i]<<" ";
        cout<<endl;
        return;
    }
    for(int i=k;i<n;i++)
        a[i]=s+i-k+1;
    for(int i=0;i<n;i++)
        cout<<a[i]<<" ";
    cout<<endl;
}
int32_t main()
{
    IOS;
    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

using namespace std;

#define int long long

const int N = 1055;
char mat[N][N];
int dp[N][N], n, m;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int MOD = 1e9 + 7;

int sol(int i, int j) {
    if (i == n - 1 && j == m - 1) return 1;
    int& ans = dp[i][j];
    if (ans != -1) return ans;
    ans = 0;
    for (int k = 0; k < 2; k++) {
        int x = i + dx[k];
        int y = j + dy[k];
        if (x >= 0 && y >= 0 && x < n && y < m && mat[x][y] == '.') {
            ans = (ans + sol(x, y)) % MOD;
        }
    }
    return ans;
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> mat[i][j];
        }
    }
    memset(dp, -1, sizeof(dp));
    cout << sol(0, 0) << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define pb push_back
#define ld long double
#define f first
#define s second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e18 + 5;
const int mod = 1e9 + 7;
const int  N = 2e5 + 314;
const long double pi = 3.1415926535897932384626433832795;
void solve(){
    string s;
    cin>>s;
    int cnt0=0, cnt1=0, cnt2=0;
    int i =0;
    while(s[i]=='R')cnt0++, i++;
    i=1;
    while(s[i]=='R')cnt1++, i++;
    i=2;
    while(s[i]=='R')cnt2++, i++;
    cout<<max({cnt0, cnt1, cnt2});
}
signed main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstdlib>

struct Node {
  struct Node *right;
  struct Node *left;
  struct Node *parent;
  int key;
};

struct Node *insertNode(struct Node *root, int k){
  struct Node *y = NULL;
  struct Node *x = root;
  struct Node *newNode;

  newNode = (struct Node *) std::malloc(sizeof(struct Node));
  
  newNode->right = NULL;
  newNode->left = NULL;
  newNode->parent = NULL;
  newNode->key = k;

  while (x != NULL) {
    y = x;
    
    if (newNode->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  newNode->parent = y;

  if (y == NULL) {
    root = newNode;
  } else if (newNode->key < y->key) {
    y->left = newNode;
  } else {
    y->right = newNode;
  }

  return root;
}

void printByInorder(struct Node *root) {
  if (root == NULL) {
    return;
  }

  if ((root->left == NULL) && (root->right == NULL)) {
    std::cout << " " << root->key;
    return;
  }

  printByInorder(root->left);
  std::cout << " " << root->key;
  printByInorder(root->right);
}

void printByPreorder(struct Node *root) {
  if (root == NULL) {
    return;
  }

  if ((root->left == NULL) && (root->right == NULL)) {
    std::cout << " " << root->key;
    return;
  }
  
  std::cout << " " << root->key;
  printByPreorder(root->left);
  printByPreorder(root->right);
}

int main(){
  int n = 0;
  struct Node *root = NULL;

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::string command;
    
    std::cin >> command;
    
    if (command.at(0) == 'p') {
      printByInorder(root);
      std::cout << std::endl;


      printByPreorder(root);
      std::cout << std::endl;
    } else if (command.at(0) == 'i') {
      int k = 0;

      std::cin >> k;
      
      root = insertNode(root, k);
    }
  }

  return 0;
}

Measured memory_bytes: 24644
#include<cstdio>
#include<iostream>
#include<string>
#include<list>
#include<algorithm>
using namespace std;

int main(){
    string S;
    cin >> S;
    list<char> answer;
    for(const auto c : S) answer.push_back(c);
    unsigned Q;
    scanf("%u", &Q);
    unsigned manipulation;
    bool is_reversed = false;
    for (size_t i = 0; i < Q; i++){
        scanf("%u", &manipulation);
        if(manipulation == 1) is_reversed ^= true;
        else{
            unsigned f;
            char c;
            scanf("%u %c", &f, &c);
            if((f == 1)^is_reversed) answer.push_front(c);
            else answer.push_back(c);
        }
    }
    if(is_reversed) reverse(answer.begin(), answer.end());
    for(auto c : answer) printf("%c", c);
    printf("\n");
	return 0;
}

Measured memory_bytes: 9984
/*

  "With age, comes wisdom. With travel, comes understanding.
   Remember that happiness is a way of travel – not a destination"

*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define ld             long double
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> Set;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 400005;
int a[N], n, m, k;
vpi v;

void solve()
{
	int i, j;
	cin >> n;
	mii mp;
	for (i = 0; i < n; i++)
	{
		int x, y; cin >> x >> y;
		v.pb({x + y, x - y});
	}
	sort(all(v));
	int ans = 1;
	int last = v[0].F;

	for (i = 1; i < n; i++)
	{
		if (v[i].S >= last)
		{
			ans++;
			last = v[i].F;
		}
	}
	cout << ans;


}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout << setprecision(9) << fixed;
	clock_t z = clock();
	solve();
	cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <map>

int main() {
    int n;
    std::cin >> n;
    std::vector<std::vector<std::pair<int, int>>> a(n, std::vector<std::pair<int, int>>(n - 1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - 1; j++) {
            int b = i, c;
            std::cin >> c;
            c--;
            if (b > c) {
                std::swap(b, c);
            }
            a[i][j] = {b, c};
        }
    }

    std::vector<int> pos(n);
    auto end = [&]() -> bool {
        bool res = true;
        for (int i = 0; i < n; i++) {
            if (pos[i] < n - 1) {
                res = false;
                break;
            }
        }
        return res;
    };

    int ans = 0;
    std::map<std::pair<int, int>, std::vector<int>> num;
    std::vector<int> upd(n);
    for (int i = 0; i < n; i++) {
        upd[i] = i;
    }
    while (!end()) {
        bool can = false;
        std::vector<int> tmp;

        for (int i: upd) {
            if (pos[i] < n - 1) {
                num[a[i][pos[i]]].push_back(i);
                auto p = a[i][pos[i]];
                if (num[a[i][pos[i]]].size() == 2) {
                    for (int j: num[a[i][pos[i]]]) {
                        pos[j]++;
                        tmp.push_back(j);
                    }
                    num[p].assign(0, 0);
                    can = true;
                }
            }  
        }
        if (can) {
            ans++;
        } else {
            ans = -1;
            break;
        }

        upd = tmp;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 62848
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":"\n");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<vi> a(N);
    REP(i, N) {
        int x, y, h;
        cin >> x >> y >> h;
        a[i] = {h, x, y};
    }
    sort(RALL(a));
    
    auto dist = [](int x1, int y1, int x2, int y2) {
        return abs(x1 - x2) + abs(y1 - y2);
    };

    REP(x, 101) {
        REP(y, 101) {
            int h = -1;
            bool ok = true;
            REP(k, N) {
                int d = dist(a[k][1], a[k][2], x, y);
                if (h == -1) {
                    h = d + a[k][0];
                }
                if (max(h - d, 0LL) != a[k][0]) {
                    ok = false;
                    continue;
                }
            }
            if (ok) {
                cout << x << " " << y << " " << h << endl;
                return 0;
            }
        }
    }
    return (0^_^0);
}



Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
query = [[] for _ in range(N)]
for _ in range(M):
    a, b = mapint()
    query[a-1].append(b-1)
    query[b-1].append(a-1)

dp = [[0]*N for _ in range(1<<N)]
dp[1][0] = 1
for i in range(1<<N):
    for j in range(N):
        # 今jにいて、いったことのない場所に行く
        for nx in query[j]:
            if not (i>>nx)&1:
                dp[i+(1<<nx)][nx] += dp[i][j]

print(sum(dp[-1]))

Measured memory_bytes: 67352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 2e9;

int main(){
    int n, a[100005], begin[100005], end[100005];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    begin[0] = a[0];
    end[0] = a[n-1];
    for(int i=1; i<n; i++){
        begin[i] = __gcd(a[i],begin[i-1]);
        end[i] = __gcd(a[n-1-i],end[i-1]);
    }
    int ans;
    ans = max(begin[n-2], end[n-2]);
    for(int i=0; i<n-2; i++){
        ans = max(ans, __gcd(begin[i],end[n-1-i-2]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 16/Feb/20 05:41:17 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int n;
	cin >> n;
	map< string, int > mp;
	fr (i, 0, n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	ve< pair< int, string > > v;
	for (auto& i : mp) {
		v.push_back ({i.ss, i.ff});
	}
	sort (all (v));
	reverse (all (v));
	int x = v[0].ff;
	ve< string > ans;
	for (auto& i : v) {
		if (i.ff < x) break;
		ans.pb (i.ss);
	}
	sort (all (ans));
	for (auto& i : ans)
		pr (i);
	return 0;
}

Measured memory_bytes: 30572
s = list(input())

offset_f = []
offset_c = []
for i in range(len(s)):
        if s[i] == 'F':
                offset_f += [i]

offset_f.sort()


for i in range(len(s)):
        if s[i] == 'C':
                offset_c += [i]

offset_c.sort()


if offset_f and offset_c:
        if offset_f[-1] > offset_c[0]:
                print('Yes')
        else:
                print('No')
else:
        print('No')

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

int main (void) {
  int K;
  cin >> K;
  int ans;
  int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  cout << a[K-1] << endl;
  return 0;
}

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

#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define all(v) (v.begin(),v.end())
#define ll long long

const int N=105;
const int inf=2e9;


int main(){
    ios::sync_with_stdio(0);
    //freopen("in.txt","r",stdin);
    int q;
    ll x,y,t,l,r,tmax;
    ll ans;
    cin>>q;
    while(q--){
        cin>>x>>y;
        t=sqrt(x*y);
        if(t*t==x*y) --t;
        ans=t*2-1;
        if(x==y){
            ++ans;
        }
        else{
            tmax=2*t+1;
            l=t;
            r=tmax-l;
            bool f1=0,f2=0;
            while(l<=r+2){
                if(!f1&&x<=l) {++l;f1=1;}
                if(!f2&&r<=y){--r;f2=1;}
                if(l*r>=x*y) {
                    --ans;
                    break;
                }
                ++l;
                --r;
            }
        }
        cout<<ans<<'\n';
    }

    return 0;
}


Measured memory_bytes: 256
sx, sy, tx, ty = input().split(" ")

start = (int(sx), int(sy))
end = (int(tx), int(ty))
l = list()

for _ in range(abs(int(sy)-int(ty))):
	l.append("U")

for _ in range(abs(int(sx)-int(tx))):
	l.append("R")

for _ in range(abs(int(sy)-int(ty))):
	l.append("D")

for _ in range(abs(int(sx)-int(tx))):
	l.append("L")

l.append("L")

for _ in range(abs(int(sy)-int(ty)) + 1):
	l.append("U")

for _ in range(abs(int(sx)-int(tx)) + 1):
	l.append("R")

l.append("DR")

for _ in range(abs(int(sy)-int(ty)) + 1):
	l.append("D")

for _ in range(abs(int(sx)-int(tx)) + 1):
	l.append("L")

l.append("U")

print("".join(l))

Measured memory_bytes: 3188
def selection_sort(a, n):
    cnt = 0
    for i in range(n):
        min_j = i
        for j in range(i, n):
            if a[j] < a[min_j]:
                min_j = j
        if i < min_j:
            a[i], a[min_j] = a[min_j], a[i]
            cnt += 1
    print(" ".join([str(x) for x in a]))
    print(cnt)


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    selection_sort(a, n)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    vector<bool> Prime(150000,1);
    Prime.at(0)=Prime.at(1)=false;
    int i=2;
    while(1){
        int next_i=i;
        for(int j=i+1;j<Prime.size();j++){
            if(Prime.at(j)){
                next_i=j;
                break;
            }
        }
        if(i==next_i) break;

        for(int j=2*i;j<Prime.size();j+=i){
            Prime.at(j)=false;
        }

        i=next_i;
    }

    rep(j,x,Prime.size()){
        if(Prime.at(j)){
            cout<<j<<endl;
            break;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define r(i,a,n) for(int i=a,i<(int)(n)i++)
typedef long long ll;
int main(){
    int N,K;
    cin>>N>>K;
    if(N%K==0){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,a[10000];
	cin>>n>>m;
	for(int i=0;i<m;i++)
        cin>>a[i];
    int s=0;
    for(int i=0;i<m;i++)
        s+=a[i];
    if(s>n){
        cout<<"-1"<<endl;
    }else{
        cout<<n-s<<endl;
    }


}


Measured memory_bytes: 3592
#include<stdio.h>
#define M 100000

int main(){
  int num,i;
  int d[M+1];
  scanf("%d",&num);

  for(i=1;i<=num;i++){
    scanf("%d",&d[i]);
  }

  for(i=1;i<=num;i++){
    printf("node %d: key = %d, ",i,d[i]);
    if(i/2 >= 1){
      printf("parent key = %d, ",d[i/2]);
    }
    if(i*2 <= num){
      printf("left key = %d, ",d[i*2]);
    }
    if(i*2+1 <= num){
      printf("right key = %d, ",d[i*2+1]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
const int INF = 1001001001;
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; }

int dp[1000005][2];

int main(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    s += '0';
    int n = int(s.size());
    rep(i,n+1) rep(j,2) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i,n) rep(j,2){
        int x = s[i] - '0';
        x += j;
        rep(a,10){
            int ni = i+1, nj = 0;
            int b = a - x;
            if(b<0){
                nj = 1;
                b += 10;
            }
            chmin(dp[ni][nj],dp[i][j]+a+b);
        }
    }
    cout << dp[n][0] << endl;
}

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

int main(){
	int N;
	cin >> N;
	
	string S, T, ST_Mixed;
	
	cin >> S >> T;
	for(int i=0;i<N;i++){
		// cout << S << ' ' << T << endl;
		ST_Mixed.append(S, i, 1);
		ST_Mixed.append(T, i, 1);
//		ST_Mixed.at(2*i) = S.at(i);
	//	ST_Mixed.at(2*i+1) = T.at(i);
	}
	cout << ST_Mixed << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int INF=1e8;

int N;
string S;
int main(){
	cin>>N;
	cin>>S;
	int c1=0,c2=0;
	int ans;
	REP(i,(int)S.size()-1){
		if (S[i+1]=='E'){
			c2++;
		}
	}
	ans=c2;
	REP(i,(int)S.size()-1){
		if (S[i+1]=='E'){
			c2--;
		}
		if (S[i]=='W'){
			c1++;
		}
		ans=min(ans,c1+c2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 900
N = int(input())

A = [int(i) for i in input().split()]

if N == 0 and A[0] != 1:
    print(-1)
    exit()

nodes = [0] * (N+1)
nodes[0] = 1
for i in range(1, N+1):
    node = (nodes[i-1]-A[i-1])*2
    if node < A[i]:
        print(-1)
        exit()
    nodes[i] = node

#print(nodes)

nodes[-1] = A[-1]
for i in range(N-1, -1, -1):
    nodes[i] = min(nodes[i], nodes[i+1]+A[i])

#print(nodes)

print(sum(nodes))

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

using namespace std;

const int INF = 100100100;

int dp[41][401][401];
int N, Ma, Mb;
int a[40], b[40], c[40];

int main()
{
    cin >> N >> Ma >> Mb;
    for (int i = 1; i <= N;i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }

    for (int i = 0; i <= N; i++)
    {
        for (int ag = 0; ag < 401; ag++)
        {
            for (int bg = 0; bg < 401; bg++)
            {
                dp[i][ag][bg] = INF;
            }
        }
    }

    dp[0][0][0] = 0;

    for (int i = 1; i <= N;i++)
    {
        for (int ag = 0; ag <= 400;ag++)
        {
            for (int bg = 0; bg <= 400;bg++)
            {
                dp[i][ag][bg] = min(dp[i][ag][bg], dp[i - 1][ag][bg]);
                if (ag - a[i] >= 0 && bg - b[i] >= 0)
                {
                    dp[i][ag][bg] = min(dp[i][ag][bg], dp[i - 1][ag - a[i]][bg - b[i]] + c[i]);
                }
            }
        }
    }

    int ans = INF;
    int g = max( Ma, Mb);
    int i = 1;
    while (i * g <= 400)
    {
        ans = min(ans, dp[N][i * Ma][i * Mb]);
        i++;
    }

    if(ans == INF)
    {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 25984
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
using namespace std;
int main(){
  long long n;
  long long a[1000001];

  cin >> n;
  for(long long i=0; i<n; i++){
    cin >> a[i];
  }
  long long sa[1000001];
  sa[0] = 0;
  for(long long i=0; i<n; i++){
    sa[i+1] = sa[i] + a[i];
  }

  sort(sa, sa+n+1);
  long long k = 1;
  long long ans=0;
  for(long long i = 1; i<=n; i++){
    if(sa[i]==sa[i-1]) k++;
    else{
      ans += k*(k-1)/2;
      k = 1;
    }
  }
  cout << ans+k*(k-1)/2 << endl;
}


Measured memory_bytes: 7552
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v) for (auto i : v)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)
#define mset(m, v) memset(m, v, sizeof(m))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//#define int ll

int main() { 
        ll x, y;
        cin >> x >> y;
        puts(abs(x - y) == 0 || abs(x - y) == 1 ? "Brown" : "Alice");
        return 0;
}


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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, s;
    cin >> n >> m >> s;
    f(m){
        cout << s << ' ';
    }
    if(s == 1000000000){
        f(n - m){
            cout << s - 1 << ' ';
        }
    }
    else{
        f(n - m){
            cout << s + 1 << ' ';
        }
    }
    cout << '\n';
}

Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>

#include <vector>

using namespace std;

int main()
{
    int x, n;

    while (cin >> n >> x) {

        if (n == 0 && x == 0) {
            break;
        }

        int ptn = 0;

        for (int i = 1; i <= x; i++) {
            int c = x - i;

            for (int j = i + 1; j < x - 1; j++) {
                
                if (c - j <= j) {
                    break;
                }
                if (c - j <= n) {
                    
                    ptn = ptn + 1;
                }
            }
        }

        cout << ptn << endl;
    }
    return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>
#include <math.h>

int main(void)
{
	int n, s[1001], i;
	double a, m;
	
	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		for(i = 0, a = 0; i < n; i++){
			scanf("%d", &s[i]);
			a += s[i];
		}
		m = a / n;
		for(i = 0, a = 0; i < n; i++){
			a += pow(s[i]-m, 2);
		}
		a /= n;
		printf("%f\n", sqrt(a));
	}
	
	return(0);
}



Measured memory_bytes: 1856
#include <stdio.h>
#include <iostream>

using namespace std;




int main(void) {

	int X;
	cin >> X;

	if (X < 600)
		cout << "8" << endl;
	else if (X < 800)
		cout << "7" << endl;
	else if (X < 1000)
		cout << "6" << endl;
	else if (X < 1200)
		cout << "5" << endl;
	else if (X < 1400)
		cout << "4" << endl;
	else if (X < 1600)
		cout << "3" << endl;
	else if (X < 1800)
		cout << "2" << endl;
	else
		cout << "1" << endl;

	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1e18;
int main(){
    int n; cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    long long ans = 1;
    for(int i = 0; i < n; i++){ 
        if(ans <= INF/a[i]){
            ans *= a[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}
//Saw the solution video

Measured memory_bytes: 4036
#include <stdio.h>
#define MAX 100000
int A[MAX],n;

int main(){
  int i,k;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  k=partition(0,n-1);

  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i==k) printf("[");
    printf("%d",A[i]);
    if(i==k) printf("]");
  }
  printf("\n");
  return 0;
}

int partition(int k,int m){
  int i,j;
  int t;
  int x=A[m];
  i=k-1;
  for(j=k;j<m;j++){
    if(A[j]<=x){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t=A[i+1];A[i+1]=A[m];A[m]=t;
  return i+1;
}



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

using namespace std;
typedef long long ll;
int main(){

    ll n;
    cin>>n;
    ll sum=0;

    for(ll i=1;i<=n;i++)
    {
        if( i%3==0 || i%5==0)
            continue;
        else
            sum+=i;
    }

 cout<<sum;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cctype>

using namespace std;

int main() {
    char ch;
    int count [26] = {0}, i;
    while(1){
        cin >> ch;

        if(cin.eof()) break;

        if(islower(ch)) {
            ch = ch - 'a';
            count[ch]++;
        }

        else if (isupper(ch)) {
            ch = ch - 'A';
            count[ch]++;
        }

    }
    for(i=0;i<26;i++)
        cout << (char)(i + 'a') << " : " << count[i] << endl;
    
}

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

int c[1500];
int d[1500];
int main() {
	int a, b;
	while (scanf("%d%d", &a, &b),a | b) {
		map<int, int>e;
		map<int, int>f;
		memset(c, 0, a * 4);
		memset(d, 0, b * 4);
		for (int g = 0; g < a; g++) {
			int h;
			scanf("%d", &h);
			for (int i = 0; i <= g; i++) {
				c[i] += h;
				e[c[i]]++;
			}
		}
		for (int g = 0; g < b; g++) {
			int h;
			scanf("%d", &h);
			for (int i = 0; i <= g; i++) {
				d[i] += h;
				f[d[i]]++;
			}
		}
		int s = 0;
		for (auto k = e.begin(); k != e.end(); k++) {
			s += f[k->first] * k->second;
		}
		printf("%d\n", s);
	}
}

Measured memory_bytes: 34464
s = input()

# s ="redcoder"

len = int(len(s)/2)

input = s[:len]
reverse_s =s[::-1]
reverse_s=reverse_s[:len]

cnt = 0

for i in range(len):
    if input[i] != reverse_s[i]:
        cnt +=1

# print(input)
# print(reverse_s)
print(cnt)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 100010;
const int MOD = (int) 1e9 + 7;

const int INF = (int) 1e9;

int a[Maxn];
int d[Maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    int minv = a[0], maxd = -INF;
    for (int i = 1; i < n; ++i) {
        d[i] = a[i] - minv;
        maxd = max(maxd, d[i]);
        minv = min(minv, a[i]);
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (d[i] == maxd) ++cnt;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
X = int(input())
LEN = int(1e6)
p = [True] * LEN

p[0] = False
p[1] = False

for i in range(LEN):
  if p[i]:
    if i >= X:
      print(i)
      exit()
      
    for j in range(i * 2, LEN, i):
      p[j] = False



Measured memory_bytes: 10868
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, C, A[410], B[410], s[410][410], dp[410][410];
const int mod = 1e9 + 7;
int add(int x,int y)
{
	return (x += y) < mod ? x : x - mod;
}
int mul(int x,int y)
{
	return (int)((ll)x * y % mod);
}
int sub(int x,int y)
{
	return add(x, mod - y);
}
int dfs(int i, int tot)
{
	if(i == n + 1)return tot == 0 ? 1 : 0;
	int&res = dp[i][tot];
	if(res != -1) return res;
	res = 0;
	rep(j, 0, tot)
		res = add(res, mul(dfs(i + 1, tot - j), sub(s[j][B[i]], s[j][A[i] - 1])));
	return res;
}
int main()
{
	scanf("%d%d", &n, &C);
	rep(i, 1, n) scanf("%d", &A[i]);
	rep(i, 1, n) scanf("%d", &B[i]);
	rep(x, 1, 400)
	{
		s[0][x] = 1;
		rep(i, 1, C) s[i][x] = mul(x, s[i - 1][x]);
	}
	rep(i, 0, C)
		rep(x, 1, 400)
			s[i][x] = add(s[i][x], s[i][x - 1]);
	memset(dp, -1, sizeof(dp));
	printf("%d\n",dfs(1, C));
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> x(n),y(m);
    for(int i=0;i<n;i++)cin>>x[i];
    for(int i=0;i<m;i++)cin>>y[i];
    ll sumx=0,sumy=0;
    for(int i=0;i<n;i++){
        (sumx+=x[i]*i-x[i]*(n-i-1))%=mod;
    }
    for(int i=0;i<m;i++){
        (sumy+=y[i]*i-y[i]*(m-i-1))%=mod;
    }
    cout<<sumx*sumy%mod<<endl;
}

Measured memory_bytes: 1792
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Face = Tuple!(char, "dir", long, "num", bool, "edge");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long n, q;
    scan(n, q);
    auto tree = new long[][](n, 0);
    auto node = new long[](n);
    foreach (_; iota(n - 1))
    {
        long a, b;
        scan(a, b);
        a--, b--;
        tree[a] ~= b;
        tree[b] ~= a;
    }
    foreach (_; iota(q))
    {
        long p, x;
        scan(p, x);
        p--;
        node[p] += x;
    }
    auto stack = DList!(long)(0);
    bool[long] visited;
    visited[0] = true;
    while (!stack.empty)
    {
        auto current = stack.back;
        stack.removeBack();
        foreach (e; tree[current])
        {
            if (!(e in visited))
            {
                visited[e] = true;
                node[e] += node[current];
                stack.insertBack(e);
            }
        }
    }
    foreach (e; node)
        writef("%s ", e);
    writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 61052
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	int ans=0;
	if(n==10||n==100||n==1000||n==10000||n==100000)ans=10;
	int a,b,c,d,e;
	e=n%10;
	n=n/10;
	d=n%10;
	n=n/10;
	c=n%10;
	n=n/10;
	b=n%10;
	n=n/10;
	a=n;
	if(ans==0)ans=a+b+c+d+e;
	printf("%d\n",ans);
	return 0;
}

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

int main() {
	int N;	// 整数.
	cin >> N;

	int x = N;
	int fx = 0;
	while (x != 0) {
		fx += x % 10;
		x /= 10;
	}
	if (N % fx == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
S = int(input())
  
X1, Y1 = 0, 0

X2, Y3 = int(S ** (1 / 2)), int(S ** (1 / 2))

if X2 < 10 ** 9:
  X2 += 1
if Y3 < 10 ** 9:
  Y3 += 1
if X2 * Y3 >= S:  
  X3, Y2 = X2 * Y3 - S, 1

print(X1, Y1, X2, Y2, X3, Y3)

Measured memory_bytes: 3064
#include<stdio.h>

int main(void){

    char S[5];
    int i,ans=0;

    scanf("%s",S);

    for(i = 0;i < 4;i++){
        if(S[i] == '+'){
            ans++;
        }else{
            ans--;
        }
    }

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  int a[n+1];
  int M=-10000000,m=10000000;
  int Mi=-1,mi=-1;
  REP(i,n){
    cin>>a[i+1];
    if(M<a[i+1]){
      M = a[i+1];
      Mi = i+1;
    }
    if(m>a[i+1]){
      m = a[i+1];
      mi = i+1;
    }
  }
  if(m>=0){
    cout<<n-1<<endl;
    REP(i,n-1){
      cout<<i+1<<' '<<i+2<<endl;
    }
    return 0;
  }else if(M<=0){
    cout<<n-1<<endl;
    for(int i=n;i>=2;i--){
      cout<<i<<' '<<i-1<<endl;
    }
    return 0;
  }else{
    if(abs(m)<=abs(M)){
      cout<<2*n-2<<endl;
      REP(i,n){
        if(i+1==Mi){
          continue;
        }else{
          cout<<Mi<<' '<<i+1<<endl;
        }
      }
      REP(i,n-1){
        cout<<i+1<<' '<<i+2<<endl;
      }
    }else{
      cout<<2*n-2<<endl;
      REP(i,n){
        if(i+1==mi){
          continue;
        }else{
          cout<<mi<<' '<<i+1<<endl;
        }
      }
      for(int i=n;i>=2;i--){
        cout<<i<<' '<<i-1<<endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256