akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    ll n = in(), a = in(), b = in();
    ll ans = LINF;
    if ((b - a) % 2 == 0)
    {
        ans = (b - a) / 2;
    }
    else
    {
        ans = min(ans, a + ((b - a) - 1) / 2);
        ans = min(ans, n - b + 1 + (n - (a + (n - b + 1))) / 2);
    }
    cout << ans << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
//Reminder Reminder
#include <iostream>
using namespace std;
int main(){
  long long N,K;cin>>N>>K;
  long long ans = 0;
  if(K==0){
    cout << N*N << endl;
    return 0;
  }
  for(long long i = K+1; N >= i; i++){
    //?%i >= K
    ans += (N/i)*(i-1-(K-1));
    ans += max(0LL,(N%i)-K+1);
  }
  cout << ans << endl;
}

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

int main() {
  int w, h, x, y, r;
  scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
  if(r <= x && x+r <= w && r <= y && y+r <= h) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 3152
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。

ll ans(ll a){
	ll ret=0;
	for(int i=57;i>=0;i--){
		ll pos=(1ll<<i);
		if(i==0){
			if(a%4<=2&&a%4>=1) ret++; 
		}
		else if(a/pos&&((a&1)==0)){
			ret^=pos;
		}
		if(i>1)a%=pos;
		//cout<<a<<endl;
	}
	return ret;
}

int main(){
	ll H,W,h,w;
	cin>>H>>W>>h>>w;
	cout<<(H-h)*(W-w)<<endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int count = 0;
  for (int i = a; i <= b; i++){
    int w, x, y, z;
    
    w = i / 10000;
    x = i / 1000 % 10;
    y = i % 100 / 10;
    z = i % 10;
    
    if (w == z && x == y) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

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

	int n, m;
	cin >>n >> m;
	vi attempts(n);
	vi solved(n);
	int solvedCount = 0;
	int penaltyCount = 0;
	REP(i, m) {
		int p;
		string ver;
		cin >> p >> ver;
		--p;
		if (solved[p]) {
			continue;
		}
		if (ver[0] == 'A') {
			solved[p] = true;
			++solvedCount;
			penaltyCount += attempts[p];
		} else {
			++attempts[p];
		}
	}
	cout << solvedCount << ' ' << penaltyCount << endl;
	
}

Measured memory_bytes: 1024
import java.util.Scanner;

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

    public Main() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            int element = Integer.parseInt(sc.next());
            nums[i] = element;
        }
        int min = 1;
        for (int i = 0; i < n; i++) {
            int element = nums[i];
            if (element == min) {
                min++;
            }
        }
        int diff = min == 1 ? -1 : n + 1 - min;
        System.out.println(diff);
    }
}


Measured memory_bytes: 62740
#import <Foundation/Foundation.h>

int main(void){
    
    NSData   *allData = [[NSFileHandle fileHandleWithStandardInput] readDataToEndOfFile];
    NSString *allText = [[NSString alloc]
                         initWithBytes:[allData bytes]
                         length:[allData length]
                         encoding:NSUTF8StringEncoding];
    NSArray *allLines = [allText componentsSeparatedByString:@"\n"];
    NSArray *inputs = [[allLines objectAtIndex:0] componentsSeparatedByString:@" "];
    
    NSInteger month = [[inputs objectAtIndex:0] intValue];
    NSInteger day = [[inputs objectAtIndex:1] intValue];
    
    NSString *s = @"";
    
    if (month <= day) {
        s = [NSString stringWithFormat:@"%ld", month];
    } else {
        s = [NSString stringWithFormat:@"%ld", month - 1];
    }
    
    [[NSFileHandle fileHandleWithStandardOutput] writeData: [s dataUsingEncoding:NSUTF8StringEncoding]];
    
    return 0;
}

Measured memory_bytes: 11224
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
struct edge {int from,to,cost;};

signed main(){
    int n;
    int a,b;
    cin >> n >> a >> b;
    if((a-b)%2) puts("Borys");
    else puts("Alice");
    return 0;
}



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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


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

	vector<int> v;

	for (int i = a; i < a+k && i <= b; ++i) {
		v.push_back(i);
	}
	for (int i = b; i > b-k && i >= a; --i) {
		v.push_back(i);
	}
	sort(v.begin(), v.end());


	int prev = 0;
	for (int i = 0; i < v.size(); ++i) {
		if (prev == v[i]) {
			continue;
		} else {
			prev = v[i];
			cout << v[i] << "\n";
		}
	}
}


Measured memory_bytes: 256
#include <stdio.h>
// a b c a b c
// 0 1 2 3 4 5
int main () {
	int n;
	scanf("%d", &n);
	
	char str[n + 1];
	scanf("%s", str);
	
	int count = 0;
	for (int i = 0; i < n / 2; i++) {
		if (str[i] == str[i + (n / 2)]) {
			count++;
		}
	}
	
	if (n % 2 == 1) {
		puts("No");
	}
	else if (count == n / 2) {
		puts("Yes");
	}
	else {
		puts("No");
	}
	
	return 0;
}

Measured memory_bytes: 1608
#include<stdio.h>
#include <sstream>
#include <iostream>
#include <cstdlib>
using namespace std;

#define BUF_SIZE 1024
#define ARRAY_SIZE 100


void selectionSort(int array[],int n,int& change_count)
{
	int min;
	for(int i = 0; i < n-1; i++){
		min = i;	//?????????
		for(int j = i+1; j < n; j++){
			if(array[j] < array[min]){
				min = j;
			}
		}
		if(i != min){
			swap(array[i],array[min]);
			change_count++;
		}
	}

}

int main(){
	char buf[BUF_SIZE];
	int n = atoi(fgets(buf,BUF_SIZE,stdin));
	int array[ARRAY_SIZE];
	int change_count = 0;

	for(int i = 0; i < n; i++){
		cin >> array[i];
	}

	selectionSort(array,n,change_count);

	for(int i = 0; i < n; i++){
		if(i != n-1){
			printf("%d ",array[i]);
		}else{
			printf("%d\n",array[i]);
		}
	}
	printf("%d\n",change_count);
}



Measured memory_bytes: 3212
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  private static final long MOD = 1000000007L;

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    long k = sc.nextLong();

    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    long result = 0;
    for (int i = 0; i < n; i++) {
      long l = 0;
      long r = 0;

      for (int j = 0; j < i; j++) {
        if (a[i] > a[j]) {
          l++;
        }
      }
      long addL = ((k - 1) * k / 2) % MOD * l % MOD;
      if (addL < 0) throw new IllegalStateException();
      result += addL;
      result %= MOD;

      for (int j = i + 1; j < n; j++) {
        if (a[i] > a[j]) {
          r++;
        }
      }
      long addR = (k * (k + 1) / 2) % MOD * r % MOD;
      if (addR < 0) throw new IllegalStateException();

      result += addR;
      result %= MOD;

    }

    os.println(result);
  }

  private static long calc(long a, long n, long d) {
    long result = 0;
    result += (n * a) % MOD;
    result += (n * (n - 1)) % MOD / 2 * d % MOD;
    return result % MOD;
//    return ((n * (2 * a + (n - 1) * d)) / 2) % MOD;
  }
}

Measured memory_bytes: 25968
#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-i; j++) {
			if ((i + j) == x && 2 * i + 4 * j == y) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3616
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,b; cin >> a >> b;
    cout << a * b << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <math.h>

using namespace std;

long long candles[100010];

int main()
{

    long long res = 1e18;
    int n, k, p, q;
    cin >> n >> k;

    for (int i = 1; i <= n; i++)
    {
        cin >> candles[i];
    }

    for (int i = 1; i + k - 1 <= n; i++)
    {
        p = i;
        q = i + k - 1;
        res = min(res, candles[q] - candles[p] + min(abs(candles[p]), abs(candles[q])));
    }
    cout << res << endl;
    return 0;
}


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

int main() {
	long long N = 0;
	cin >> N;
    if(N % 2 == 0){
		cout << N << endl;
	}
	else if(N % 2 == 1){
		cout << N * 2 << endl;
	}
	getchar();
	getchar();
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    bool t = false;
    for (int i = 0; 4 * i <= N; i++) {
        for (int j = 0; 4 * i + 7 * j <= N; j++) {
            if (N == 4 * i + 7 * j) t = true;
        }
    }

    cout << ((t) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B)
    {
        cout << C << endl;
    }
    else if (A == C)
    {
        cout << B << endl;
    }
    else
    {
        cout << A << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 2e5;
const char newl = '\n';

vl parent(MAX), depth(MAX);
 
ll find(ll x) {if(parent[x]==x) return x; return parent[x] = find(parent[x]);}
 
void unite(ll x, ll y) {
  x = find(x);
  y = find(y);
  if (x==y) return;
  
  if(depth[x] < depth[y]) {
    parent[x] = y;
  }else {
    parent[y] = x;
    if(depth[x] == depth[y]) depth[x]++;
  }
}

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

  ll n, m;
  cin >> n >> m;
  
  rep(i, MAX) {
    if(i < n) parent[i] = i;
    else parent[i] = INF;
  }
  
  ll a, b;
  rep(_, m) {
    cin >> a >> b;
    a--; b--;
    unite(a, b);
  }
  
  vl cnt(n);
  rep(i, n) cnt[find(i)]++;
  ll ans=0;
  rep(i, n) chmax(ans, cnt[i]);
  cout << ans << newl;
}

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

int main() {
	int n;
	cin>>n;
	vector<int> L(n);
	rep(i,n)cin>>L[i];
	
	sort(L.begin(),L.end());
	
	//i,j,k順にa,b,cと対応
	
	ll count=0;
	
	for(int i=0;i<n-2;i++){
		for(int j=i+1;j<n-1;j++){
			for(int k=j+1;k<n;k++){
				if(L[k]>=L[i]+L[j])break;
				count++;
				
			}
		}
	}
	
	cout<<count<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX = 500010;
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;
    }
}

ll com(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    vector<ll> v;
    for (int i = 2; i <= sqrt(m); i++) {
        ll a = 0;
        while (m % i == 0) {
            m /= i;
            a++;
        }
        if (a) v.push_back(a);
    }
    if (m != 1) v.push_back(1);

    ComInit();
    ll ans = 1;
    for (auto a: v) {
        ans *= com(a+n-1, a);
        ans %= MOD;
        if (ans < 0) ans += MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n-1);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n){
    cin >> b.at(i);
  }
  rep(i,n-1){
    cin >> c.at(i);
  }
  long answer = 0;
  rep(i,n){
    answer += b.at(i);
    if(i==0) continue;
    if(a.at(i) == a.at(i-1) + 1){
      int tmp = a.at(i-1);
      answer += c.at(tmp-1);
    }
  }
  cout << answer << endl;
}

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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int mod = (int) 1e9 + 7;

int n;
int x, y, z;

map <vector<int>, int> mp;
vector<int> seq[205000];
int len[205000];
int seqSum[205000];
bool haiku[205000];
int cnt;
int mxSum = 0;
int mxNum = 0;

bool check(vector<int>& v) {
    int p = 0;
    int xx = x, yy = y, zz = z;
    while (p < sz(v) && xx > 0) {
        xx -= v[p];
        p++;
    }
    while (p < sz(v) && yy > 0) {
        yy -= v[p];
        p++;
    }
    while (p < sz(v) && zz > 0) {
        zz -= v[p];
        p++;
    }
    return xx == 0 && yy == 0 && zz == 0 && p == sz(v);
}

void go(vector<int>& v, int sum) {
    mp[v] = cnt;
    len[cnt] = sz(v);
    seq[cnt] = v;
    seqSum[cnt] = sum;
    haiku[cnt] = check(v);
    cnt++;

    for (int i = 1; i <= min(mxNum, mxSum - sum); i++) {
        v.push_back(i);
        go(v, sum + i);
        v.pop_back();
    }
}

long long dp[45][2][130500];
int mv[130500][12];

int main() {

    cin >> n >> x >> y >> z;
    mxSum = x + y + z;
    mxNum = max(max(x, y), z);

    vector<int> v;
    go(v, 0);

    // cerr << cnt << endl;

    for (int i = 0; i < cnt; i++) {
        for (int num = 1; num <= mxNum; num++) {
            int sum = seqSum[i] + num;
            int p = 0;
            while (p < sz(seq[i]) && sum > mxSum) {
                sum -= seq[i][p];
                p++;
            }
            vector<int> go;
            while (p < sz(seq[i])) {
                go.push_back(seq[i][p]);
                p++;
            }
            go.push_back(num);
            mv[i][num] = mp[go];
        }
    }

    dp[0][0][0] = true;
    for (int i = 0; i < n; i++) 
        for (int j = 0; j <= 1; j++) 
            for (int k = 0; k < cnt; k++) {
                if (dp[i][j][k] == 0) continue;
                if (haiku[k] && j == 0) continue;
                if (len[k] > i) continue;

                for (int num = 1; num <= mxNum; num++) {
                    int goK = mv[k][num];
                    dp[i + 1][j | haiku[goK]][goK] = (dp[i + 1][j | haiku[goK]][goK] + dp[i][j][k]) % mod;
                }
                dp[i + 1][j][0] = (dp[i + 1][j][0] + dp[i][j][k] * (10 - mxNum)) % mod;
            }

    long long ans = 0;
    for (int i = 0; i < cnt; i++)
        ans = (ans + dp[n][1][i]) % mod;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 120320
k = int(input())
li = [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]
print(li[k - 1])

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

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

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n), x(n), y(n);
  rep(i, n) cin >> t[i] >> x[i] >> y[i];
  
  rep(i, n) {
    if (x[i] + y[i] > t[i] || (x[i]+y[i])%2 != t[i]%2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 2560
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var strs = str.Split(' ');
            var a = int.Parse(strs[0]);
            var b = int.Parse(strs[1]);
            var c = int.Parse(strs[2]);

            var max = b / a;

            var ans = (max > c) ? c : max;

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){

			List<Integer> lst = new ArrayList<Integer>();
			int input;
			int cnt=0;
			while((input = sc.nextInt())!=0 && cnt < 10000) {
				if(input>=0 && input <=10000){
					lst.add(input);
					cnt++;
				}
			}
			Integer[] aaa = lst.toArray(new Integer[0]);
			int[] ary = new int[lst.size()];
			for(int i = 0; i<lst.size(); i++) {
				ary[i] = aaa[i];
			}
			
			for(int i=0; i< ary.length ; i++) {
				System.out.println(String.format("Case %d: %d",i+1,ary[i]));
			}
		}
	}
}

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

int main() {
  int N, A , C , D;
  cin >> N >> A >> C >> D;

  if (N+A==C+D) {
    cout << "Balanced" << endl;
  }
  else if  (N+A>C+D){
    cout <<"Left" << endl;
  }
  else {
   cout <<"Right" << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
s = sum(w)
s1 = 0
for wi in w :
    if s1+wi < s/2 :
        s1 += wi
    else :
        print(min(abs(s-2*s1), abs(s-2*(s1+wi))))
        break

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

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

typedef long long ll;
const int N = 100005;

int dst[N];
int vstd[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int n;
	cin>>n;
	
	deque<pair<int,int> > dq;
	
	memset(dst,0x7f,sizeof dst);
	
	dq.push_front({1,1});
	dst[1] = 1;
	
	while(!dq.empty()){
		int x = dq.front().second;
		dq.pop_front();
		int y = (x+1)%n, v = dst[x]+1;
		if( v < dst[y] ){
			dst[y] = v;
			dq.push_back({v,y});
		}
		y = (x*10)%n;
		v = dst[x];
		if( v < dst[y] ){
			dst[y] = v;
			dq.push_front({v,y});
		}
	}
	
	cout<<dst[0];
	
	return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int, vector<int>, greater<int>> A;
    rep(i, N) {
        int A_i;
        cin >> A_i;
        A.push(A_i);
    }
    vector<pair<int, int>> BC(M);
    rep(i, M) {
        int B, C;
        cin >> B >> C;
        BC[i] = make_pair(B, C);
    }

    sort(BC.begin(), BC.end(), [](pair<int, int> x, pair<int, int> y) -> int {
        return x.second > y.second;
    });
    for (pair<int, int> &p: BC) {
        for (int i = 0; i < p.first; i ++) {
            if (A.top() < p.second) {
                A.pop();
                A.push(p.second);
            } else{
                break;
            }
        }
    }

    long long sum = 0;
    while (!A.empty()) {
        sum += A.top();
        A.pop();
    }
    cout << sum << endl;
}


Measured memory_bytes: 1528
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);	
		
		int n = scan.nextInt();
		
		long sum = 0;
		
		long cnt = 2;
		
		
		long a = scan.nextLong();
		
		if(a >= 2){
			sum += a - 1;
		}
		
		for(int i = 1 ; i < n ; i++){
			
			a = scan.nextLong();
			
			long b = a / cnt;
			
			
			if(cnt == a){
				cnt++;
				b = 0;
			} else if(a % cnt == 0){
				b--;
			}
			
			sum += b;
		}
		
		System.out.println(sum);
	}
}


Measured memory_bytes: 32816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main() {
    int a_index,z_index; string s; cin>>s;
    rep(i,s.size()){
        if(s[s.size()-1-i]=='A'){
            a_index = s.size()-1-i;
        }
        if(s[i]=='Z'){
            z_index = i;
        }
    }
    cout<< z_index - a_index + 1 <<endl;
}

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

long long mask[11];

int main() {
	mask[0] = 1;
	for(int i = 1; i < 11; ++i) {
		mask[i] = mask[i - 1] * 10;
	}

	std::string str;

	std::cin >> str;

	long long ans = 0;
	for(int i = 0; i < str.size(); ++i) {
		int idx = str.size() - i - 1;
		auto n = static_cast<long long>(str[str.size() - i - 1] - '0');

		for(int j = 0; j <= i; ++j) {
 			int cnt = str.size() - (idx + j) - 2;
			if(idx + j == str.size() - 1) {
				++cnt;
			}

			ans += (1ll << (idx + cnt)) * n * mask[j];
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pMAX 1000000
bool is_prim[pMAX];

bool isPrim(int a){
  for(int i=2; i < sqrt(a); i++){
    if(a % i == 0) return false;
  }
  return true;
}

void eratosthenes(){
  for(int i=0; i < pMAX; i++){
    is_prim[i] = true;
  }
  is_prim[0] = false;
  is_prim[1] = false;
  for(int i=2; i < pMAX; i++){
    if(isPrim(i)){
      for(int j=i+i; j < pMAX; j+=i){
        is_prim[j] = false;
      }
    }
  }
}

int main(void){
  int a, d, n;
  eratosthenes();
  while(cin >> a >> d >> n, a | d | n){
    int cnt = 0;
    while(1){
      if(is_prim[a]){
        cnt++;
      }
      if(cnt == n){
        cout << a << endl;
        break;
      }
      a += d;
    }
  }
  return 0;
}

Measured memory_bytes: 2136
def Input():
    N = int(input())
    nums = [int(input()) for _ in range(N)]
    return nums, N

def FindPrimeNums(nums, N):
    not_prime = 0
    
    for i in range(len(nums)):
        if nums[i] % 2 == 0:
            if nums[i] != 2:
                not_prime += 1
        else:
            for j in range(3, len(nums), 2):
                if j**2 > nums[i]:
                    break
                if nums[i] % j ==0:
                    not_prime += 1
                    break
   
    return N - not_prime
nums, N = Input()
print(FindPrimeNums(nums, N))




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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;

    ll res;
    if(K == 1){
    	res = 0;
    }else if(N == K){
    	res = 0;
    }else if(N < K){
    	res = 1;
    }else{
    	res = N-K;
    }
    cout << res <<endl;
    return 0;
}

Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define endl '\n'


class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
		string a;
        in >> a;
        int x = 10*(a[0] - '0') + (a[1] - '0');
        int y = 10*(a[2] - '0') + (a[3] - '0');
        if (1 <= x and x <= 12 and 1 <= y and y <= 12) out << "AMBIGUOUS" << endl;
        else if (1 <= x and x <= 12) out << "MMYY" << endl;
        else if (1 <= y and y <= 12) out << "YYMM" << endl;
        else out << "NA" << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

int main() {
  int ball, robotB, distance = 0;
  cin >> ball >> robotB;
  for (int i = 0; i < ball; i++){
    int position, distanceA, distanceB;
    cin >> position;
    distanceA = position;
    distanceB = position - robotB;
      if (distanceB < 0){
        distanceB = -1 * distanceB;
      }
    /*else{
      distanceB = distanceB
    }*/
    if (distanceB < distanceA){
      distance = distance + 2 * distanceB;
    }
    else {
      distance = distance + 2 * distanceA;
    }
  }
  cout << distance << endl;
}


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

typedef long long int LLI;

int N;
int K;
int as[114514];
bool ldp[5002][5002];
int rdp[5002][5002];

int main() {
  scanf("%d%d", &N, &K);
  for (int i=1; i<=N; i++) {
    scanf("%d", &as[i]);
  }

  for (int i=1; i<=N; i++) {
    ldp[i-1][0] = true;
    for (int j=as[i]; j<=K; j++) {
      ldp[i][j] |= ldp[i-1][j-as[i]];
    }
    for (int j=0; j<=K; j++) ldp[i][j] |= ldp[i-1][j];
  }
  
  for (int i=N; i>=1; i--) {
    rdp[i+1][0] = 1;
    for (int j=as[i]; j<=K; j++) {
      rdp[i][j] |= rdp[i+1][j-as[i]];
    }
    for (int j=0; j<=K; j++) rdp[i][j] |= rdp[i+1][j];
  }

  for (int i=0; i<=N+1; i++) {
    for (int j=1; j<=K; j++) {
      rdp[i][j] += rdp[i][j-1];
    }
  }

  int ans = 0;
  for (int i=1; i<=N; i++) {
    for (int j=0; j<K; j++) {
      if (ldp[i-1][j]) {
        int l = max(K-j-as[i], 0);
        int cnt = rdp[i+1][K-j-1];
        if (l > 0) cnt -= rdp[i+1][l-1];
        if (cnt > 0) {
          ans++;
          break;
        }
      }
    }
  }
  printf("%d\n", N-ans);
}


Measured memory_bytes: 122368
using System;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var name = new [,,] { {{"black", "blue"},{"lime", "aqua"}}, {{"red","fuchsia"},{"yellow","white"}} };
            string input;
            while((input = Console.ReadLine()) != "0") {
                int code = Convert.ToInt32(input.TrimStart('#'), 16);
                var color = new [] { (code >> 16) > 0x7F ? 1 : 0, (code >> 8 & 0xFF) > 0x7F ? 1 : 0, (code & 0xFF) > 0x7F ? 1 : 0 };
                Console.WriteLine(name[color[0], color[1], color[2]]);
            }
        }
    }
}

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

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> A(N);
	int sum = 0, Ol[2] = {0, 0};
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
		A[i] %= 2;
		sum += A[i];
		Ol[A[i]]++;
	}
	if(Ol[0] == N || Ol[1] == N){
		printf("0\n");
	}
	else if(sum % 2 == 1){
		printf("%d\n", N - 1);
	}
	else{
		printf("%d\n", N - 2);
	}
	return 0;
}


Measured memory_bytes: 3656
#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>;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int h, w;
    vector<P> data;

    while(true) {
        cin >> h >> w;
        if(h == 0 && w == 0) break;
        data.push_back(P(h, w));

    }
    for(auto d : data){
        for(int i = 0; i < d.first; i++){
            for(int k = 0; k < d.second; k++){
                if(i == 0 || i % 2 == 0){
                    if(k == 0 || k % 2 == 0) cout << '#';
                    else cout << '.';

                }else{
                    if(k == 0 || k % 2 == 0) cout << '.';
                    else cout << '#';

                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] inputString = br.readLine().split(" ");
            int firstRectangleHeight = Integer.parseInt(inputString[0]);
            int firstRectangleWidth = Integer.parseInt(inputString[1]);
            int secondRectangleHeight = Integer.parseInt(inputString[2]);
            int secondRectangleWidth = Integer.parseInt(inputString[3]);

            int areaOfAFirstRectangle = firstRectangleHeight * firstRectangleWidth;
            int areaOfASecondRectangle = secondRectangleHeight * secondRectangleWidth;

            if (areaOfAFirstRectangle >= areaOfASecondRectangle) {
                System.out.println(areaOfAFirstRectangle);
            } else {
                System.out.println(areaOfASecondRectangle);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21460
//list index out of rangeエラー表示用
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep1(i, n) for (int i = 0; i < (int)(n); i++)


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

Measured memory_bytes: 3592
N = int(input())
H = list(map(int, input().split()))
prev = 0
l = 0
maxl = 0
for h in H:
    if prev >= h:
        l += 1
        prev = h
        if maxl < l:
            maxl = l
    else:
        l = 0
        prev = h
print(maxl)
        


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<int, int>;
using PL = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {cout << (expr ? "Yes" : "No") << "\n";}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  lint K;
  cin >> K;
  lint rem = 0;
  REP(i, K+1) {
    rem = (rem + 7) % K;
    if(rem == 0) {
      cout << (i+1) << endl;
      return 0;
    }
    rem = rem * 10 % K;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	int ans = 0;
	int tmp = 0;
	int l = -1;
	for(int i=0; i<N; i++){
		int a;
		cin >> a;
		if(l != a){
			ans += tmp/2;
			l = a;
			tmp = 1;
		}
		else tmp++;
	}
	ans += tmp/2;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const ull B = 1777771;
ull S[100010],PB[100010]={1};
int n;
string str;

ull get(int l,int r){return S[r]-S[l]*PB[r-l];}
ull get(int l,int r,int x,char ch){
  ull res=get(l,r);
  if(x<l||r<=x) return res;
  return res+ch*PB[r-x-1]-str[x]*PB[r-x-1];
}

int search(int a,int b,int x,int ch){
  int L=0,M,R=1e5+1;
  while(L<R){
    M = (L+R)/2;
    if(max(a,b)+M>n||get(a,a+M,x,ch)!=get(b,b+M,x,ch)) R = M;
    else L = M+1;
  }
  return L-1;
}

bool check(int l,int r,int t){
  int p = l+t+search(l,l+t,-1,0);
  int q = l+(p-l-t)%t;
  return get(l,r-t,p,str[q])==get(l+t,r,p,str[q])||
    get(l,r-t,q,str[p])==get(l+t,r,q,str[p]);
}

int main(){
  cin>>str;
  n = str.size();
  for(int i=0;i<n;i++) S[i+1]=S[i]*B+str[i];
  for(int i=1;i<n;i++) PB[i]=PB[i-1]*B;
  
  int q;
  cin>>q;
  while(q--){
    int l,r,t;
    scanf("%d%d%d",&l,&r,&t);
    cout<<(check(l-1,r,t)? "Yes":"No")<<endl;
  }
  return 0;
}

Measured memory_bytes: 4972
#include<stdio.h>

int main()
{
  int k, s;
  int i, j;
  int count = 0;
  

  scanf("%d %d", &k, &s);
  
  for (i = 0; i <= k; i++) {
    for (j = 0; j <= k; j++) {
      if( (s - i - j) <= k && (s - i - j) >= 0) {
	  count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n;
  	int x=0;
  	int i;
  	cin >> n;
  	
  	for(i=0;i<3;i++){
      if( (n % 10) == 1){
        x++;
      }
      n = n / 10;
    }
  	cout << x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int b[25];
int main(){
	int n, m, c;
	scanf("%d%d%d", &n, &m, &c);
	for(int i = 0 ; i < m ; ++i)
		scanf("%d", &b[i]);
	
	int a, res = 0;
	for(int i = 0 ; i < n ; ++i){
		int sum = 0;
		for(int j = 0 ; j < m ; ++j){
			scanf("%d", &a);
			sum += b[j] * a;
		}	
		if(sum + c > 0 )
			res++;
	}
	printf("%d\n", res);
	return 0;
}
 

Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int X = in.nextInt();
		int A = in.nextInt();
		int B = in.nextInt();
		
		if(B - A > X) System.out.println("dangerous");
		else System.out.println((B <= A) ? "delicious" : "safe");
	}
}


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

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static int Calc(int[] xs) {
        var dp = new bool[xs.Length * 100 + 1];

        foreach (var x in xs) {
            int n = dp.Length;
            for (int i = n - 1; i > 0; i--) {
                if (dp[i] && i + x < n)
                    dp[i + x] = true;
            }
            dp[x] = true;
        }

        for (int i = dp.Length-1; i > 0; i--) {
            if (dp[i] && i % 10 != 0)
                return i;
        }
        return 0;
    }

    static void Main() {
        int n = ReadInt();
        var xs = new int[n];
        for (int i = 0; i < n; i++) {
            xs[i] = ReadInt();
        }

        Console.WriteLine(Calc(xs));
    }
}

Measured memory_bytes: 11092
N, M = map(int, input().split())
Ls = []
Rs = []
for _ in range(M):
    l, r = map(int, input().split())
    Ls.append(l)
    Rs.append(r)

s = 1
e = N

for l,r in zip(Ls, Rs):
    s = max(s, l)
    e = min(e, r)
    if s > e:
        break
print(max(0, (e+1)-s))





Measured memory_bytes: 10996
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;

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


/////////////////////////////////////////////////////////////////////////////////////////
int par[100000],rank_[100000];


void init(int N){
    for (int i = 0;i < N;i++){
        par[i] = i;
        rank_[i] = 0;
    }
}

int find(int x){
    if (par[x] == x){
        return x;
    }

    return par[x] = find(par[x]);
}


void unite(int x,int y){ 
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (rank_[x] < rank_[y]){
        par[x] = y;
    }
    else {
        par[y] = x;
        if (rank_[x] == rank_[y]){
            rank_[x]++;
        }
    }
}


bool same(int x,int y){ 
    return (find(x) == find(y));
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m),b(m);

    for (int i = 0;i < m;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    int ans = 0;

    for (int i = 0;i < m;i++){
        init(n);
        for (int j = 0;j < m;j++){
            if (i != j){
                unite(a[j],b[j]);
            }
        }
        int cnt = 0;
        for (int j = 0;j < n;j++){
            if (find(j) == j) cnt++;
        }
        if (cnt > 1) ans++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<"Draw"<<endl;
    }else if((a==1&&b!=1)||(a>b&&b!=1)){
        cout<<"Alice"<<endl;
    }else if((a!=1&&b==1)||(a<b&&a!=1)){
        cout<<"Bob"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int x, ans;

int main() {
	scanf("%d", &x);
	for(int i = x; i <= x * 2; i++) {
		bool flg = 1;
		for(int j = 2; j <= sqrt(i); j++) {
			if(i % j == 0) {
				flg = 0;
				break;
			}
		}
		if(flg) {
			ans = i;
			break;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string s;
  ll res=0,MOD=1000000007,wild[100001],A[100001],C[100001],power[100001],ls,rs;
  power[0] = 1;
  REP(i,100000){
    power[i+1] = (3*power[i]) % MOD;
  }
  cin >> s;
  wild[0] = 0;
  A[0] = 0;
  C[0] = 0;
  if(s[0] == '?')
    wild[0] = 1;
  else if(s[0] == 'C')
    C[0] = 1;
  else if(s[0] == 'A')
    A[0] = 1;
  REP(i,s.size()-1){
    if(s[i+1] == 'C')
      C[i+1] = C[i] + 1;
    else
      C[i+1] = C[i];
    if(s[i+1] == 'A')
      A[i+1] = A[i] + 1;
    else
      A[i+1] = A[i];
    if(s[i+1] == '?')
      wild[i+1] = wild[i] + 1;
    else
      wild[i+1] = wild[i];
 
  }
  for(int i=1;i<s.size()-1;i++){
    if(s[i] == '?' || s[i] == 'B'){
      if(wild[i-1] -1 < 0)
        ls = (A[i]*power[wild[i-1]]) % MOD;
      else
        ls = (power[wild[i-1]]*A[i]+power[wild[i-1]-1]*wild[i-1]) % MOD;
      if(wild[s.size()-1]-wild[i] - 1 < 0)
        rs =(power[wild[s.size()-1]-wild[i]]*(C[s.size()-1]-C[i])) % MOD;
      else
        rs =(power[wild[s.size()-1]-wild[i]]*(C[s.size()-1]-C[i])+(wild[s.size()-1]-wild[i])*power[wild[s.size()-1]-wild[i] - 1])% MOD;
      
      res = (res +ls*rs) % MOD;
    }
  }
  
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 3584