akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
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; }


using namespace std;

int main(){
    ll N, M;
    cin >> N >> M;
    ll A[N];
    ll S[N+1];
    S[0] = 0;
    rep(i, N) {
        cin >> A[i];
        S[i+1] = A[i] + S[i];
        S[i+1] %= M;
    }

    map<ll, ll> m;
    REP(i,1, N+1) {
        if (!m.count(S[i])) {
            m.insert(make_pair(S[i], 1));
        } else {
            m[S[i]]++;
//            cout << S[i] << " " << m[S[i]] << endl;
        }
    }
    ll ans = 0;
    for (auto i = m.begin(); i != m.end(); ++i) {
//        cout << i->second << endl;
        if (i->first != 0) {
            ans += (i->second * (i->second - 1))/2;
        } else {
            ans += (i->second * (i->second - 1))/2 + i->second;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 5760
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

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

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);

  int x; cin >> x;
  if (x<1200){cout << "ABC";}
  else {cout <<"ARC";}

  return 0;
}


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

#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<ll>
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)

using namespace std;
void OJ();

#define ld long double
void solve(){
    int n ,k; cin >> n >> k;
    cout << (bool)(n%k);
}

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

    int t = 1;
    //cin >> t;
    while ( t-- ){
        solve();
    }
    return  0;
}

void OJ(){
#ifndef ONLINE_JUDGE
    freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\in.txt" , "r" , stdin  );
   // freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\out.txt", "w" , stdout );
#endif // ONLINE_JUDGE
}



Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r;

string s;
int main() {
	vector<LL> a;
	cin >> N>>M;
	for (int i = 0; i < N; i++) {
		cin >> r;
		a.push_back(r);
	}
	ans = 0;
	for (int i = 0; i < N-1; i++) {
		if(a[i]+a[i+1]>M){
			ans += (a[i] + a[i + 1]) - M;
			if ((a[i] + a[i + 1])-M > a[i + 1]) {
				a[i + 1] = 0;
			}
			else {
				a[i + 1] = a[i + 1] - ((a[i] + a[i + 1]) - M);
			}
		}
	}
	cout << ans<<endl;

	return 0;

}


Measured memory_bytes: 1400
abk = gets.chomp.split(' ').map { |s| s.to_i }
a = abk[0]
b = abk[1]
k = abk[2]

a_ans = [0, a - k].max
diff = [0, k - a].max
b_ans = [0, b - diff].max

puts "#{a_ans} #{b_ans}"


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

typedef pair<ll, ll> p_ll;

int main() {
  ll N; cin >> N;
  ll A[N], B[N]; rep(i,N) cin >> A[i] >> B[i];
  p_ll dish[N]; rep(i,N) dish[i] = make_pair(A[i],B[i]);
  sort(dish,dish+N,[](const p_ll &x, const p_ll &y){return x.first+x.second>y.first+y.second;});

  ll result = 0; rep(i,N) result += A[i];
  rep(i,N/2) result -= dish[i*2+1].first + dish[i*2+1].second;
  cout << result << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n,k,d,a[10000],i,f[100000]= {0},k1=0,p[100000]= {0};
    map<int,int>m;
    cin>>n>>k;
    int j=0;
    while(k--)
    {
        cin>>d;
        for(i=0; i<d; i++)
        {
            cin>>a[i];
            p[j]=a[i];
            j++;
        }
    }
     for(i=0;i<j;i++)
     {
            // cout<<p[i]<<endl;
             f[p[i]]++;
     }
    for(i=0; i<j; i++)
    {
        if(f[p[i]]!=0)
        {
          //  cout<<p[i]<<" "<<f[p[i]]<<endl;
            k1++;
            f[p[i]]=0;
        }
    }
    cout<<n-k1<<endl;

}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>

using namespace std;
typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;

template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    std::reverse(ret.begin(), ret.end());

    return ret;
}

int upf(double num){
    if(num-(int)num>0)return (int)num+1;
    else return num;
}

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

struct Chara{
    int hp;
    int sp;
};

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int num;
    string buf;
    set<string> kind;
    std::cin>>num;
    rep(i,num){std::cin>>buf;kind.insert(buf);}
    std::cout<<kind.size();
    return 0;
}


Measured memory_bytes: 19248
//
#include <bits/stdc++.h>
using namespace std;
template<size_t SIZE, class T> inline size_t array_size(T (&arr)[SIZE]) {
    return SIZE;
}
int main() {
#if 1
    int n=5, k=1;
    string str="00010";
    cin >> n >> k;
    cin >> str;

    std::vector<int64_t> tbl;
    tbl.reserve(str.size());
    char nowc=1; //1-0-1-0-の数を格納していく
    int cnt=0;
    for (int i=0;i<str.size();++i) {
        if (str[i]==('0'+nowc)) ++cnt;
        else {
            tbl.push_back(cnt);
            cnt = 1;
            nowc = 1 - nowc; //0 or 1
        }
    }
    tbl.push_back(cnt);
    //1-0-1 ,1で終わってほしい
    if (tbl.size()%2==0)tbl.push_back(0);

    //累積和
    vector<int> sumtbl(tbl.size()+1,0);
    for(int i=0;i < tbl.size();++i){
        sumtbl[i+1] = sumtbl[i]+tbl[i];
    }
    int pick_num=2*k+1;
    int ans = 0;
    for (int i = 0; i < tbl.size(); i+=2)
    {
        int left = i;
        int right = min(left + pick_num, (int)tbl.size());
        ans = max(ans, sumtbl[right] - sumtbl[left]);
    }
    cout<<ans<<endl;
    return 0;
#else
#endif
}

Measured memory_bytes: 1664
#include<string>
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<ios>
#include<algorithm>
#include<stack>
#include<queue>
#include<cmath>
#include<type_traits>
#include<random>
#include<vector>
#include<map>

using namespace std;


int main()
{
	string s;
	cin >> s;
	int a,b,c,d;
	a = s[5] - '0';
	b = s[6] - '0';
	c = s[8] - '0';
	d = s[9] - '0';
	if(10*a+b>4)
	{
		cout << "TBD" << endl;
	}
	else if(4>10*a+b)
	{
		cout << "Heisei" << endl;
	}
	else if(10*c+d<=30)
	{
		cout << "Heisei" << endl;
	}
	else if(10*c+d>30)
	{
		cout << "TBD" << endl;
	}
}



Measured memory_bytes: 256
a = list(map(int,input().split()))

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

print(len(set(prime_factorize(a[0])) & set(prime_factorize(a[1])))+1)
  

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
int a, b ;
cin >> a >> b ;
if(a<10 && b<10){
cout << a*b <<endl ;
}
else{
cout << -1 <<endl ;
}


  return 0 ;
}



Measured memory_bytes: 256
#include<stdio.h>

typedef long long int int64;

void run(void){
  int n,a,b,c,d;
  scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
  for(int64 i=0;i<=n-1;i++){
    int64 max=a+i*d-(n-1-i)*c;
    int64 min=a+i*c-(n-1-i)*d;
    if(min<=b && b<=max){
      puts("YES");
      return;
    }
  }
  puts("NO");
}

int main(void){
  run();
  return 0;
}


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

using namespace std;
#define ll long long

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

signed main()
{
	string s1, s2;
	cin >> s1 >> s2;
	int l1 = s1.length();
	int l2 = s2.length();
	if (l1 < l2) {
		cout << "LESS" << endl;
		return 0;
	} else if (l1 > l2) {
		cout << "GREATER" << endl;
		return 0;
	}
	rep(i, l1) {
		if (s1[i] < s2[i]) {
			cout << "LESS" << endl;
			return 0;
		} else if (s1[i] > s2[i]) {
			cout << "GREATER" << endl;
			return 0;
		}
	}
	cout << "EQUAL" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n,k,r,s,p;cin>>n>>k>>r>>s>>p;
    string t;cin>>t;
    int score=0;
    vch hand(n);
    rep(i,k){
        if(t[i]=='r'){
            score+=p;
            hand[i]='p';
        }
        else if(t[i]=='s'){
            score+=r;
            hand[i]='r';
        }
        else{
            score+=s;
            hand[i]='s';
        }
    }
    rep2(i,k,n){
        if(t[i]=='r'&&hand[i-k]!='p'){
            score+=p;
            hand[i]='p';
        }
        else if(t[i]=='s'&&hand[i-k]!='r'){
            score+=r;
            hand[i]='r';
        }
        else if(t[i]=='p'&&hand[i-k]!='s'){
            score+=s;
            hand[i]='s';
        }
        else hand[i]='z';
    }
    cout<<score<<endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
using namespace std;
vector<int> f(vector<int> v) {
	int cnt[110] = {};
	for (int i = 0; i < v.size(); i++) 
		cnt[v[i]]++;
	vector<int> r;
	for (int i = 0; i < v.size(); i++)
		r.push_back(cnt[v[i]]);
	return r;
}
int main() {
	int n;
	while (cin >> n, n) {
		vector<int>b, a;
		for (int i = 0; i < n; i++) {
			int k; cin >> k;
			b.push_back(k);
		}
		int cnt = 0;
		while (true) {
			cnt++;
			a = f(b);
			if (a == b)break;
			b = a;
		}
		cout << --cnt << endl;
		for (int i = 0; i < a.size(); i++) {
			if (i)cout << ' '; cout << b[i];
		}cout << endl;
	}
}

Measured memory_bytes: 3116
#include <stdio.h>
#include <string.h>
int main(void){
    char s[100];
    scanf("%s",s);
    int x,len;
    x=0;
    len=strlen(s);
    for(int i=0; i<len/4; i++){
        if(s[i]!=s[len-1-i] || s[i]!=s[(len-1)/2-1-i] ||s[i]!=s[(len+3)/2-1+i])
            x=1;
    }
    if(s[len/4]!=s[len-len/4-1] || x==1)
        printf("No");
    else
        printf("Yes");
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        String[] values = line.split(" ");
        String a = values[0];
        if (a.equals("AAA") || a.equals("BBB")) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
using P=pair<int,int>;

vector<int> pa;
vector<int> seen;
vector<pair<int,int>> sta;//順番保持

int main(){
    int n,i;cin>>n;
    
    Graph G(n);
    
    for(i=0;i<n-1;i++){//Graphの作成
        int a,b;cin>>a>>b;a--;b--;
        G[a].push_back({b});
        G[b].push_back({a});
        P q=make_pair(a,b);
        sta.push_back(q);
    }

    queue<int> que;//BFS
    
    seen.assign(n,0);
    pa.assign(n,0);
    map<P,int> num;
    
    que.emplace(0);//0からstart
    seen[0]=1;

    while(que.size()!=0){
        int state=que.front();
        que.pop();

        int color=0;
        for(auto next:G[state]){//ある根のまわりについて色をつける
            if(seen[next]==0){//まだ訪れていないとき
                seen[next]=1;//訪れる
                color++;//同じ根周りなので色を変えていく
                if(color==pa[state]){color++;}//親と一致したらずらす
                P p=make_pair(state,next);//辺
                num[p]=color;//辺の色

                pa[next]=color;//nextが親の時もあるのでpaに色をつけておく

                que.emplace(next);//次へ

            }
        }
    }
    
    int max=0;
    for(auto next:sta){
        if(max<num[next]){max=num[next];}
    }

    cout<<max<<endl;
    for(auto next:sta){
        cout<<num[next]<<endl;//色を入力された辺順に出す
    }
    return 0;
}

Measured memory_bytes: 13940
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  n %= 10;
  if(n==3)
    cout << "bon";
  else if(n==0 or n==1 or n ==6 or n ==8)
    cout << "pon";
  else
    cout << "hon";
  return 0;
}


Measured memory_bytes: 3604
using System;

namespace ABC167
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var s = Console.ReadLine().ToCharArray();
            var r = Console.ReadLine().ToCharArray();

            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] == r[i]) continue;
                Console.WriteLine("No");
                return;
            }
            Console.WriteLine("Yes");
        }
    }
}


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

int main () {
	int A;
	int B;
	scanf("%d %d", &A, &B);

	if (A == 1 && B != 1) {
		cout << "Alice" << endl;
	} else if (B == 1 && A != 1) {
		cout << "Bob" << endl;
	} else if (A > B) {
		cout << "Alice" << endl;
	} else if (B > A) {
		cout << "Bob" << endl;
	} else {
		cout << "Draw" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); ++i)
 
int main(void) {
    string s;
    long long int K;
    cin >> s >> K;
    rep(i, s.size()) {
        if(s[i] != 'a') {
            int p = 'z'+1 - s[i];
            if(K >= p) {
                K -= p;
                s[i] = 'a';
            }
        }
        if(K==0) break;
    }
    if(K > 0) {
        int i = s.size()-1;
        s[i] += K%26;
        if(s[i] > 'z') s[i] = 'a' + (s[i]-'z'-1);
    }
    cout << s << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(b-(a-c), 0) << endl;
}

Measured memory_bytes: 256
import copy
import heapq
H, W = map(int, input().split())
S = [['.'] * (W+1)]
for _ in range(H):
    s = list(input())
    s.insert(0,'.')
    S.append(s)

inf = float('inf')

dp = []
for _ in range(H+1):
    dp.append([inf] * (W+1))

if S[1][1] == '.':
    dp[1][1] = 0
else:
    dp[1][1] = 1

for i in range(1,H+1):
    for j in range(1,W+1):
        right = dp[i][j-1]
        down = dp[i-1][j]
        if S[i][j] == '#':
            if S[i-1][j] == '.':
                down += 1
            if S[i][j-1] == '.':
                right += 1

        dp[i][j] = min(dp[i][j],right,down)

print(dp[H][W])

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

int main(int argc,char** argv){
  int topping = 0;
  char str[3];
  cin >> str;

  for(int i = 0; i < 3 ; i++){
    if(str[i] == 'o'){
      topping++;
    }
  }

  cout << 700 + topping * 100 << endl;
  return 0;
}


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

#define int long long

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0, cur_r = -1e15;
    cin >> n;
    pair <int, int> X[n];
    for(int i = 0; i < n; i++){
        int x, d;
        cin >> x >> d;
        X[i] = {x + d, x - d};
    }
    sort(X, X + n);
    for(int i = 0; i < n; i++){
        if(X[i].second >= cur_r){
            cur_r = X[i].first;
            ans++;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1792
#if 0

#endif

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int N, W;
int v[110]; int w[110];
int V[110][10010];

int main() {
  cin >> N >> W;
  for (int i = 1; i <= N; i++)
    cin >> v[i] >> w[i];
  for (int i = 0; i <= N; i++) {
    for (int c = 0; c <= W; c++) {
      if (i == 0 || c == 0)
        V[i][c] = 0;
      else if (c-w[i] < 0)
        V[i][c] = V[i-1][c];
      else
        V[i][c] = max(v[i] + V[i-1][c-w[i]], V[i-1][c]);
    }
  }
  cout << V[N][W] << endl;
}



Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n,cnt=0,i;
	cin>>n;
	while(1){
    bool ans=true;
    for(i=2;i*i<=n;i++){
      if(n%i==0)ans=false;
    }
    if(ans)break;
    n++;
  }
  cout<<n<<endl;
}


Measured memory_bytes: 3560
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
public class Main {

  public static class P {
    double x;
    double y;

    P(double _x, double _y) {
      x = _x;
      y = _y;
    }
  }

  public static void koch(int d, P pl, P pr) {
    //pl__s//u\\t__pr 

    if (d==0) return;

    P ps = new P((pl.x * 2 + pr.x)/3, (pl.y * 2 + pr.y)/3);
    P pt = new P((pl.x + pr.x * 2)/3, (pl.y + pr.y * 2)/3);
    P pu = new P(ps.x + (pt.x-ps.x)*0.5 - (pt.y-ps.y)*sqrt(3.0)*0.5, 
         ps.y + (pt.x-ps.x)*sqrt(3.0)*0.5 + (pt.y-ps.y)*0.5);

    koch(d-1, pl, ps); System.out.println(String.valueOf(ps.x) + ' ' + String.valueOf(ps.y));
    koch(d-1, ps, pu); System.out.println(String.valueOf(pu.x) + ' ' + String.valueOf(pu.y));
    koch(d-1, pu, pt); System.out.println(String.valueOf(pt.x) + ' ' + String.valueOf(pt.y));
    koch(d-1, pt, pr);
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    P pl = new P(0.0, 0.0);
    P pr = new P(100.0, 0.0);
    System.out.println(String.valueOf(pl.x) + ' ' + String.valueOf(pl.y));
    koch(n, pl, pr);
    System.out.println(String.valueOf(pr.x) + ' ' + String.valueOf(pr.y));
  }
}

Measured memory_bytes: 29308
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long Y = sc.nextLong();
        int ans = 0;
        while (X <= Y){
            ans++;
            Y/=2;
        }
        System.out.println(ans);
	}
}

Measured memory_bytes: 26916
#include <stdio.h>
int main ()
{
  int a, b, c;
  char op;
  
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if( op == '?' )break;
    
    if( op == '+' ){
      c=a+b;
      printf("%d\n",c);
    }
    else if( op == '-'){
	c=a-b;
	printf("%d\n",c);
      }
    else if( op == '*'){
	c=a*b;
	printf("%d\n",c);
      }
    else if( op == '/' ){
	c=a/b;
	printf("%d\n",c);
      }
  } 
  return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

void write(int, int);

int main() {
    int H, W, i, j;
    
    while(1) {
        
        scanf("%d%d", &H, &W);
        
        if (H == 0 && W == 0) break;
        
        write(H, W);
    }
    return 0;
}

void write(int H, int W) {
    int i, j;
    
    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            if (i == 0 || j == 0 || i == H-1 || j == W-1) {
                printf("#");
            }
            else printf(".");
        }
        printf("\n");
    }
    printf("\n");
}


Measured memory_bytes: 2088
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vll(a)	  vector<ll>a
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "



int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		double a,b;
		cin >> a >> b;
		printf("%.10lf",a/b);
		return 0;
}



Measured memory_bytes: 3788
#include <algorithm>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n;
long long c;
vector<long long> h;
long long dp[202020] = {0};

template <typename T> class ConvecHullTrick {
private:
  // 直線群(配列)
  std::vector<std::pair<T, T>> lines;
  // 最小値(最大値)を求めるxが単調であるか
  bool isMonotonicX;
  // 最小/最大を判断する関数
  std::function<bool(T l, T r)> comp;

public:
  // コンストラクタ ( クエリが単調であった場合はflag = trueとする )
  ConvecHullTrick(bool flagX = false, std::function<bool(T l, T r)> compFunc =
                                          [](T l, T r) { return l >= r; })
      : isMonotonicX(flagX), comp(compFunc) {
    lines.emplace_back(0, 0);
  };

  // 直線l1, l2, l3のうちl2が不必要であるかどうか
  bool check(std::pair<T, T> l1, std::pair<T, T> l2, std::pair<T, T> l3) {
    if (l1 < l3)
      std::swap(l1, l3);
    return (l3.second - l2.second) * (l2.first - l1.first) >=
           (l2.second - l1.second) * (l3.first - l2.first);
  }

  // 直線y=ax+bを追加する
  void add(T a, T b) {
    std::pair<T, T> line(a, b);
    while (lines.size() >= 2 && check(*(lines.end() - 2), lines.back(), line))
      lines.pop_back();
    lines.emplace_back(line);
  }

  // i番目の直線f_i(x)に対するxの時の値を返す
  T f(int i, T x) { return lines[i].first * x + lines[i].second; }

  // i番目の直線f_i(x)に対するxの時の値を返す
  T f(std::pair<T, T> line, T x) { return line.first * x + line.second; }

  // 直線群の中でxの時に最小(最大)となる値を返す
  T get(T x) {
    // 最小値(最大値)クエリにおけるxが単調
    if (isMonotonicX) {
      static int head = 0;
      while (lines.size() - head >= 2 && comp(f(head, x), f(head + 1, x)))
        ++head;
      return f(head, x);
    } else {
      int low = -1, high = lines.size() - 1;
      while (high - low > 1) {
        int mid = (high + low) / 2;
        (comp(f(mid, x), f(mid + 1, x)) ? low : high) = mid;
      }
      return f(high, x);
    }
  }
};
// ref: http://satanic0258.hatenablog.com/entry/2016/08/16/181331

int main() {
  cin >> n >> c;
  h.resize(n);
  for (int i = 0; i < n; i++)
    cin >> h[i];
  ConvecHullTrick<long long> q(true);
  dp[0] = 0;
  q.add(-2 * h[0], h[0] * h[0] + dp[0]);
  for (int i = 1; i < n; i++) {
    dp[i] = q.get(h[i]) + h[i] * h[i] + c;
    q.add(-2 * h[i], h[i] * h[i] + dp[i]);
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 9072
main = do
  s <- getLine
  let toInt x = read x :: Int
  let puts a b = putStrLn $ a ++ " " ++ b
  let [a,b] = map toInt . words $ s
  if a == 0 && b == 0 then return ()
  else do
    if a < b then puts (show a) (show b) else puts (show b) (show a)
    main

Measured memory_bytes: 4184
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef struct Point {
    float x;
    float y;
} point;

point newP(float x, float y) {
    point p;
    p.x = x;
    p.y = y;
    return p;
}

point calc1(point p1, point p2) {
    point p;
    p.x = (p2.x + 2 * p1.x) / 3.0;
    p.y = (p2.y + 2 * p1.y) / 3.0;        
    return p;
}

point calc2(point p1, point p2) {
    point p;
    p.x = (3.0 * p2.x + 3.0 * p1.x - sqrt(3) * (p2.y - p1.y)) / 6.0;
    p.y = (3.0 * p2.y + 3.0 * p1.y + sqrt(3) * (p2.x - p1.x)) / 6.0;
    return p;
}

point calc3(point p1, point p2) {
    point p;
    p.x = (2 * p2.x + p1.x) / 3.0;
    p.y = (2 * p2.y + p1.y) / 3.0;
    return p;
}

void printP(point p) {
    cout << fixed;
    cout << setprecision(8) << p.x << " " << p.y << endl;
}

int n;

void rec(point head, point tail, int i) {
    if (i >= n) {
        return;
    }

    point p1 = calc1(head, tail);
    point p2 = calc2(head, tail);
    point p3 = calc3(head, tail);

    rec(head, p1, i + 1);
    printP(p1);
    rec(p1, p2, i + 1);
    printP(p2);
    rec(p2, p3, i + 1);
    printP(p3);
    rec(p3, tail, i + 1);
}

int main(){
    cin >> n;
    point head = newP(0.0, 0.0);
    point tail = newP(100.0, 0.0);

    printP(head);
    rec(head, tail, 0);
    printP(tail);
    
    return 0;
}



Measured memory_bytes: 3284
import sys
input = sys.stdin.readline
from collections import deque

def bfs(s):
    dist = [-1]*N
    dist[s] = 0
    q = deque([s])
    
    while q:
        v = q.popleft()
        
        for nv in adj_list[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
                
    return dist

N, u, v = map(int, input().split())
adj_list = [[] for _ in range(N)]

for _ in range(N-1):
    Ai, Bi = map(int, input().split())
    adj_list[Ai-1].append(Bi-1)
    adj_list[Bi-1].append(Ai-1)

d1 = bfs(u-1)
d2 = bfs(v-1)
ans = 0

for i in range(N):
    if d1[i]<d2[i]:
        ans = max(ans, d2[i]-1)

print(ans)

Measured memory_bytes: 61344
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <string>
#include <map>
#include <set>
#include <stdlib.h>
#include <cmath>
#include <math.h>
#include <fstream>
#include <bitset>
#include <time.h>
#include <queue>
#define int long long
using namespace std;
int n, ai;
vector<int> data;
signed main()
{
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> ai;
        data.push_back(ai);
    }
    if (n % 2 == 0){
        for (int i=n-1;i>=0;i-=2){
            cout << data[i] << " ";
        }
        for (int i=0;i<n;i+=2){
            cout << data[i] << " ";
        }
    }
    else{
        for (int i=n-1;i>=0;i-=2){
            cout << data[i] << " ";
        }
        for (int i=1;i<n;i+=2){
            cout << data[i] << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int n,Lp[2010],Rp[2010],Mis[2010],buc[2010],tmpMis[2010],mn=0x3f3f3f3f,Suf[2010];
char tms[2010];
bool a[2010],b[2010],s1,s2;
void Sort(){//use a bucket sort to let the complexity of sorting become O(n)
	for(int i=0;i<=n;i++)buc[i]=0;
	for(int i=1;i<=Mis[0];i++)buc[Rp[Mis[i]]+1]++;
	for(int i=1;i<=n;i++)buc[i]+=buc[i-1];
	for(int i=1;i<=Mis[0];i++)tmpMis[++buc[Rp[Mis[i]]]]=Mis[i];
	for(int i=1;i<=Mis[0];i++)Mis[i]=tmpMis[i];
}
int main(){
	scanf("%s",tms),n=strlen(tms);
	for(int i=0;i<n;i++)a[i]=tms[i]-'0';
	scanf("%s",tms);
	for(int i=0;i<n;i++)b[i]=tms[i]-'0';
	memset(Lp,0x3f3f3f3f,sizeof(Lp)),memset(Rp,0x3f3f3f3f,sizeof(Rp));
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(b[j])Lp[i]=min(Lp[i],(i-j+n)%n),Rp[i]=min(Rp[i],(j-i+n)%n);
	for(int i=0;i<n;i++)s1|=a[i],s2|=b[i];//check if there's no '1' in array b. If so, only if there's no '1' in array a, it is unable to get a proper answer.
	if(!s2){
		if(!s1)puts("0");
		else puts("-1");
		return 0;
	}
	for(int i=0;i<n;i++){
		Mis[0]=0;
		for(int j=0,k=i;j<n;j++,k++,k%=n)if(a[k]!=b[j])Mis[++Mis[0]]=k;
		Sort();
		Suf[Mis[0]+1]=0;
		for(int j=Mis[0];j;j--)Suf[j]=max(Suf[j+1],Lp[Mis[j]]);
		mn=min(mn,max(i,Suf[1])*2-i+Mis[0]);
		mn=min(mn,(Suf[1]+(n-i)%n)*2-(n-i)%n+Mis[0]);
		for(int j=1;j<=Mis[0];j++){
			mn=min(mn,(Rp[Mis[j]]+max(i,Suf[j+1]))*2-i+Mis[0]);
			mn=min(mn,(Suf[j+1]+max((n-i)%n,Rp[Mis[j]]))*2-(n-i)%n+Mis[0]);
		}
	}
	printf("%d\n",mn);
	return 0;
}

Measured memory_bytes: 256
using System;

namespace Multi3_or_Division2
{
    class Program
    {
        public static string Solve()
        {
            Console.ReadLine();
            string inputCON = Console.ReadLine();

            int count = 0;

            foreach (var item in inputCON.Split(' '))
            {
                for (int a = int.Parse(item); a % 2 == 0; a /= 2)
                {
                    count++;
                }
            }

            return count.ToString();
        }

        static void Main(string[] args)
        {
            Console.WriteLine(Solve());
        }
    }
}


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

#define int long long

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int K, N; cin >> K >> N;
    vi A(N); REP(i, N) cin >> A[i];
    int ans = INF;
    REP(i, N)
    {
        int t = A[(i+N-1)%N];
        if(t < A[i]) t += K;
        chmin(ans, t-A[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();

        int T = (int) Math.round(sc.nextInt() + 0.5);

        int b = 0;
        for (int t = 1; t < T; t++) {
            if (t % A == 0) {
                b += B;
            }
        }

        System.out.println(b);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int i,a[100009],d[100008],n,k;
int dp(int i){
    if(i>=n-1) return (i!=n-1)*1e6;
    if(d[i]!=-1) return d[i];
    d[i]=1e9;
    for(int j=1;j<=k&&i+j<=n;j++)
      d[i]=min(d[i],abs(a[i+j]-a[i])+dp(i+j));
    return d[i];
}
int main()
{
    cin>>n>>k;
    for(i=0;i<n;i++) {cin>>a[i];
d[i]=-1;}
    cout<<dp(0);
    return 0;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }
// -------------------------------------------------------------------

using P = pair<int, int>;
using vec = vector<int>;

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

    map<int, int> mp;
    int a, b;
    rep (i, 3) {
        cin >> a >> b;
        mp[a]++;
        mp[b]++;
    }
    int c = 0;
    repall (i, mp)
        c += i.second % 2;

    YN(c == 2);
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a,b,c,d] <- getIntList
    let x | a < 0 && 0 < b = [0,a,b]
          | otherwise = [a,b]
        y | c < 0 && 0 < d = [0,c,d]
          | otherwise = [c,d]
    let ans = maximum [s*t| s <- x, t <- y]
    print ans

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

int main() {
    // your code goes here
    ll h,i,j,k=1,sum=0;
    cin >> h;
    while(h>0){
        sum+=k;
        k*=2;
        h=floor(h/2);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  if (s.length() < t.length()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = s.length() - t.length(); i >= 0; i--) {
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        break;
      }
      if (j == t.length() - 1) {
        s.replace(i, t.length(), t);
        for (int k = 0; k < s.length(); k++) {
          if (s[k] == '?') {
            s[k] = 'a';
          }
        }
        cout << s << endl;
        return 0;
      }
    }
  }
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll int
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

void solve(){
    ll a,p; cin>>a>>p;

    ll x = a*3 + p;

    ll ans = x/2;
    cout<<ans<<endl;
}   

signed main(){

   FastRead;    


    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}




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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "cycle"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 405;

ll ppow[MAXN][MAXN];

ll sum_pow[MAXN][MAXN];

ll dp[MAXN][MAXN];

int a[MAXN], b[MAXN];

void solve(){
	int n, c;
	scanf("%d%d", &n, &c);
	REPN(i, 1, n){
		scanf("%d", &a[i]);
	}
	REPN(i, 1, n){
		scanf("%d", &b[i]);
	}
	REP(i, 1, MAXN){
		ppow[i][0] = 1;
		REPN(j, 1, c){
			ppow[i][j] = (ppow[i][j - 1] * i) % MOD;
		}
	}
	REPN(j, 0, c){
		REP(i, 1, MAXN){
			sum_pow[i][j] = (sum_pow[i - 1][j] + ppow[i][j]) % MOD;
		}
	}
	dp[0][0] = 1;
	REP(i, 0, n){
		REPN(j, 0, c){
			REPN(k, j, c){
				ll mul = sum_pow[b[i + 1]][k - j] - sum_pow[a[i + 1] - 1][k - j];
				if (mul < 0){
					mul += MOD;
				}
				dp[i + 1][k] = (dp[i + 1][k] + dp[i][j] * mul) % MOD;
			}
		}
	}
	/*REPN(i, 0, n){
		REPN(j, 0, c){
			printf("%d %d %lld\n", i, j, dp[i][j]);
		}
	}*/
	printf("%lld\n", dp[n][c]);
}	

int main(){

	//freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 4096
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
#include<cmath>
using namespace std;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
const int maxn = 333333, mod = 1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read() { char ch = getchar(); int x = 0, f = 0; while (ch < '0' || ch>'9')f |= ch == '-', ch = getchar(); while (ch >= '0' && ch <= '9')x = x * 10 + ch - '0', ch = getchar(); return f ? -x : x; }


int main()
{
    
    unordered_map<int, int > umap;
    int n; cin >> n;
    ll cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        int t; cin >> t;
        int y = i - t;
        cnt += umap[y];
        umap[t + i] += 1;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 17272
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

from collections import defaultdict

N = ni()
s = nsn(N)
M = ni()
t = nsn(M)

d = defaultdict(int)
b = defaultdict(int)
for i in range(N):
    d[s[i]] += 1

for i in range(M):
    b[t[i]] += 1

ans = -inf
for k, v in d.items():
    ans = max(ans, v - b[k])

if ans < 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 3316
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    n, m = map(int, input().split())
    ans = []
    for i in range(1, (m+1)//2+1):
        ans.append([i, m+2-i])

    for i in range(1, (m+1)//2+1):
        if len(ans) == m:
            break
        ans.append([m+1+i, 2*m+2-i])

    for x in ans:
        print(x[0], x[1])

main()


Measured memory_bytes: 22948
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    map <int , int> mp;
    for(int i = 0; i<n; ++i){
        int tmp; cin >> tmp;
        if(mp.count(tmp)){
            cout << "NO" << endl; return 0;
        }else{
            mp[tmp] = 1;
        }
    }
    cout << "YES" << endl; return 0;
}

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

typedef long long ll;

#define REP(i,m,n) for(int i=(int)m; i < (int) n; ++i)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()


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

    int a, b; cin >> a >> b;
    cout << a-b+1 << '\n';
    return 0;
}

Measured memory_bytes: 256
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.5**i-1)/1.5)for i in range(19,1,-1)]+[1]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print(*A,sep='\n')


Measured memory_bytes: 53324
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        
        int a[] = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }

        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += a[i] - 1;
        }

        System.out.println(sum);
        
        sc.close();
    }
}

Measured memory_bytes: 25428
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX_N = 100005;

int n;
string s[MAX_N];

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

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s, s + n);

	ll result = 0;
	ll currCnt = 0;
	for (int i = 0; i < n; i++)
	{
		if (i != 0 && s[i] != s[i - 1])
		{
			result += currCnt * (currCnt - 1) / 2LL;
			currCnt = 1;
		}
		else
			currCnt++;
	}
	result += currCnt * (currCnt - 1) / 2LL;
	cout << result << endl;
}

Measured memory_bytes: 5760
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
q = int(input())
d = defaultdict(int)

for i in a:
  d[i] += 1
s = sum(a)

for i in range(q):
  b, c = map(int, input().split())
  if b < c:
    x = (c-b)*d[b]
    s += x
  else:
    x = (b-c)*d[b]
    s -= x
  d[c] += d[b]
  d[b] = 0
  print (s)

Measured memory_bytes: 24008
#include <iostream>
#include <string>

int main()
{
	std::string s;
	std::cin >> s;

	int sum = 0;
	for( int i = 0; i < s.size(); i++ ) {
		sum += s[ i ] - '0';
	}

	std::cout << sum << std::endl;
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
int main(){
  int X,Y;
  cin>>X>>Y;
  int judge=0;
  for(int i=0;i<=X;i++){
    if(2*i+4*(X-i)==Y){
     judge=1;
      break;
    }
  }
  if(judge==0) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  
  return 0;
}

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

int n,m;
vector<int> e[600];
double dp[600];

double solve(int v){
    for(int i=0;i<n;i++){
        dp[i]=0;
    }
    for(int i=n-2;i>=0;i--){
        int sz=(int)e[i].size();
        double mx=0;
        bool flag=false;
        if(i==v&&sz!=1){
            sz--;
            flag=true;
        }
        for(int u:e[i]){
            dp[i]+=(dp[u]+1)/sz;
            mx=max(mx,(dp[u]+1)/sz);
        }
        if(flag)dp[i]-=mx;
    }
    return dp[0];
}

int main(){
    cin>>n>>m;
    double ans=1e10;
    for(int i=0;i<m;i++){
        int s,t;
        cin>>s>>t;
        --s,--t;
        e[s].push_back(t);
    }
    for(int i=0;i<n-1;i++){
        ans=min(ans,solve(i));
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 1408