akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{	
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	if (a + b > (n * m) / 2)
	{
		cout << "NO\n";
		return 0;
	}
	bool f1 = 0, f2 = 0;
	vector<vector<char> > ans(n, vector<char>(m, '.'));
	if (n % 2)
	{
		f1 = 1;
		--n;
		for (int i = 0; i + 1 < m; i += 2)
			if (a)
			{
				--a;
				ans[n][i] = '<';
				ans[n][i + 1] = '>';
			}
	}
	if (m % 2)
	{
		f2 = 1;
		--m;
		for (int i = 0; i + 1 < n; i += 2)
			if (b)
			{
				--b;
				ans[i][m] = '^';
				ans[i + 1][m] = 'v';
			}
	}
	if (a + b > (n * m) / 2)
	{
		cout << "NO";
		return 0;
	}
	if (a + (a % 2) + b + (b % 2) > (n * m) / 2)
	{
		if (f1 && f2)
		{
			n++, m++;
			ans[n - 3][m - 3] = ans[n - 1][m - 2] = '<';
			ans[n - 3][m - 2] = ans[n - 1][m - 1] = '>';
			ans[n - 2][m - 3] = ans[n - 3][m - 1] = '^';
			ans[n - 1][m - 3] = ans[n - 2][m - 1] = 'v';
			--n, --m;
			--a, --b;
		}
		else
		{
			cout << "NO";
			return 0;
		}
	}
	for (int i = 0; i < n; i+= 2)
		for (int j = 0; j < m; j += 2)
		{
			if (a > 0)
			{
				ans[i][j] = '<';
				ans[i][j + 1] = '>';
				if (a > 1)
				{
					ans[i + 1][j] = '<';
					ans[i + 1][j + 1] = '>';
				}
				a -= 2;
				continue;
			}
			if (b > 0)
			{
				ans[i][j] = '^';
				ans[i + 1][j] = 'v';
				if (b > 1)
				{
					ans[i][j + 1] = '^';
					ans[i + 1][j + 1] = 'v';
				}
				b -= 2;
				continue;
			}
		}
	cout << "YES\n";
	for (auto &a : ans)
	{
		for (auto i : a)
			cout << i;
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
	int w, d;
	while( scanf("%d%d", &w, &d), w != 0 ){
		vector<int> v1(w), v2(d);

		for(int i = 0; i < w; ++i ){
			scanf("%d", &v1[i] );
		}
		for(int i = 0; i < d; ++i ){
			scanf("%d", &v2[i] );
		}
		
		sort( v1.begin(), v1.end(), greater<int>() );
		sort( v2.begin(), v2.end(), greater<int>() );

		if( v1[0] < v2[0] ){
			v1.swap(v2);
		}

		int j = 0, k = 0;
		int ans = 0;
		while( j < v1.size() && k < v2.size() ){
			if( v1[j] == v2[k] ){
				ans += v1[j];
				++j;
				++k;
			}
			else if( v1[j] > v2[k] ){
				ans += v1[j];
				++j;
			}
			else{
				ans += v2[k];
				++k;
			}
		}
		
		while( j < v1.size() ){
			ans += v1[j];
			++j;
		}
		while( k < v2.size() ){
			ans += v2[k];
			++k;
		}
		
		printf("%d\n", ans);
	}
}

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

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

  int a, b;
  cin >> a >> b;
  if (a == 1) a += 20;
  if (b == 1) b += 20;
  cout << (a < b ? "Bob" : (a == b ? "Draw" : "Alice")) << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final String s = scanner.next();
        final long count = IntStream.range(0, 3)
                .mapToObj(s::charAt)
                .distinct()
                .count();

        if(count == 1){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 28108
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
ans=0
c=Counter(A).most_common()
c.sort(reverse=True)
l=[0]*2
four=[0]*2
for t in c:
    if t[1]>=2:
        l.append(t[0])
        if t[1]>=4:
            four.append(t[0])

l.sort(reverse=True)
four.sort(reverse=True)
    
ans=max(l[0]*l[1],four[0]*four[0])
print(ans)

Measured memory_bytes: 21540
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#include <bitset>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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 n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    ll money=1000,kabu=0;
    for(int i=0;i<n-1;i++){
        if(A[i]<A[i+1]){
            kabu=money/A[i];
            money-=kabu*A[i];
            money+=kabu*A[i+1];
            kabu=0;
        }
    }
    cout << money << endl;
}

Measured memory_bytes: 3608
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ac = Counter(a).most_common()
all_sum = sum([x * (x-1) // 2 for _, x in ac])
dic = {i: x for i, x in ac}
for i in range(n):
    print(all_sum - dic[a[i]] + 1)

Measured memory_bytes: 33976
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 w = 100;
		int h = 42;
		int countA = 1;
		int countB = 1;
		char[][] blacks = new char[21][100];
		char[][] whites = new char[21][100];
		for (int i = 0; i < 21; i++){
			Arrays.fill(blacks[i], '#');
			Arrays.fill(whites[i], '.');
		}
		for (int i = 0; i < 21; i += 2) {
			for (int j = 0; j < 100; j += 2) {
				if (countA < a) {
					blacks[i][j] = '.';
					countA++;
				}
				if (countB < b) {
					whites[i + 1][j] = '#';
					countB++;
				}
			}
		}
		StringBuilder sbA = new StringBuilder();
		StringBuilder sbB = new StringBuilder();
		for (int i = 0; i < 21; i++) {
			sbA.append(blacks[i]).append("\n");
			sbB.append(whites[i]).append("\n");
		}
		System.out.println(h + " " + w);
		System.out.print(sbA);
		System.out.print(sbB);
	}
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    cin>>N>>K;
    set<int> no;
    rep(i,K){
        cin>>A;
        no.insert(A);
    }
    reps(i, N, 1e+6 + 1){
        int temp = i;
        while(temp > 0){
            if(no.find(temp%10) != no.end()) break;
            temp /= 10;
        }
        if(temp == 0){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<tgmath.h>
#include<stdbool.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
int cmp(const void *a, const void *b){return *(int *)a - *(int *)b;}

ll n;
int main(){
    scanf("%lld", &n);
    ll t = 26, x = 1;
    while(t < n){
        n -= t;
        t *= 26;
        x++;
    }
    n--;
    char s[1001001];
    for(int i=0; i<x; i++){
        s[i] = 97 + n%26;
        n /= 26;
    }
    while(x--)putchar(s[x]);putchar(10);
    //printf("%lld\n", n);
}

Measured memory_bytes: 1668
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> num = {A, B, C};
  sort(num.begin(), num.end());
  cout << num.at(0) + num.at(1) + num.at(2) * 10 << endl;
}

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

void solve(long long N, std::vector<long long> h){
    auto dp = vector<long long>(N, 0);
    for (ll i = 1; i < N; i++) {
	ll first = dp[i-1] + abs(h[i] - h[i-1]);
	ll second = i - 2 >= 0 ? dp[i-2] + abs(h[i] - h[i-2]) : 100000;
	dp[i] = min(first, second);
    }
    cout << dp.back() << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, std::move(h));
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,T,K=0;
  cin >> N >> T;
  vector<int> A(T);
  for(int i=0;i<T;i++){
    cin >> A[i];
    K+=A[i];
  }
  sort(A.begin(),A.end());
  K-=(2*A[T-1]-1);
  if(K>=0) cout << 0 << endl;
  else cout << K*-1 << endl;
}

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

int main(){

 
  while(1){
    int score = 0, n, max = INT_MIN, min = INT_MAX, ava = 0, cnt = 0;

    cin >> n;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> score;
      ava += score;
      if(score > max) max = score;
      if(score < min) min = score;
  }
    cout << (ava - max - min) / (n - 2) << endl;
  }

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	const int m = 3;
	int a[3][3];
	rep(i,m)rep(j,m) cin >> a[i][j];
	int n; cin >> n;
	while(n--) {
		int b; cin >> b;
		rep(i,m)rep(j,m) {
			if(a[i][j] == b) {
				a[i][j] = -1;
			}
		}
	}
	rep(i,m) {
		bool ok = true;
		rep(j,m) {
			if(a[i][j] != -1) {
				ok = false;
			}
		}
		if(ok) {
			cout << "Yes" << '\n';
			return 0;
		}
	}
	rep(i,m) {
		bool ok = true;
		rep(j,m) {
			if(a[j][i] != -1) {
				ok = false;
			}
		}
		if(ok) {
			cout << "Yes" << '\n';
			return 0;
		}
	}
	{
		bool ok = true;
		rep(i,m) {
			if(a[i][i] != -1) {
				ok = false;
			}
		}
		if(ok) {
			cout << "Yes" << '\n';
			return 0;
		}
	}
	{
		bool ok = true;
		rep(i,m) {
			if(a[i][(m - 1) - i] != -1) {
				ok = false;
			}
		}
		if(ok) {
			cout << "Yes" << '\n';
			return 0;
		}
	}
	cout << "No" << '\n';
	return 0;
}

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

int main(){
    int N, x;
    cin >> N >> x;
    if (x == 1 || x == 2*N-1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    if (N == 2) {
        cout << "1\n2\n3" << endl;
        return 0;
    }
    if (x > 2) {
        int now = 3;
        for (int i = 1; i <= N-2; i++) {
            while (now == 2 || now == x || now == 2*N-1) now++;
            cout << now << endl;
            now++;
        }
        cout << 1 << endl << x << endl << 2*N-1 << endl << 2 << endl;
        for (int i = N+3; i <= 2*N-1; i++) {
            while (now == 2 || now == x || now == 2*N-1) now++;
            cout << now << endl;
            now++;
        }
    }else if (x == 2) {
        int now = 3;
        for (int i = 1; i <= N-2; i++) {
            while (now == 2 || now == 2*N-2 || now == 2*N-1) now++;
            cout << now << endl;
            now++;
        }
        cout << 2*N-1 << endl << 2 << endl << 1 << endl << 2*N-2 << endl;
        for (int i = N+3; i <= 2*N-1; i++) {
            while (now == 2 || now == 2*N-2 || now == 2*N-1) now++;
            cout << now << endl;
            now++;
        }
    }
    return 0;
}

Measured memory_bytes: 1536
line1 = gets.strip
num=line1.to_i
num_sum=num*(num+1)/2
num5=(num/5).to_i
num3=(num/3).to_i
num15=(num/15).to_i
num_sum3=num3*(num3+1)/2
num_sum5=num5*(num5+1)/2
num_sum15=num15*(num15+1)/2
puts num_sum-num_sum3*3-num_sum5*5+num_sum15*15

Measured memory_bytes: 14360
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[210000];
int t[210000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d",p+i);
		t[p[i]]++;
	}
	long long ret=0;
	for(int i=1;i<=a;i++)ret+=(long long)t[i]*(t[i]-1)/2;
	for(int i=0;i<a;i++){
		int I=p[i];
		ret-=(long long)t[I]*(t[I]-1)/2;
		t[I]--;
		ret+=(long long)t[I]*(t[I]-1)/2;
		printf("%lld\n",ret);
		ret-=(long long)t[I]*(t[I]-1)/2;
		t[I]++;
		ret+=(long long)t[I]*(t[I]-1)/2;
	}
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int s = a*100+b*10+c;
    if(s%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main() {
  ll n,k; cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vector<int> m(n+1);
  rep(i,n) m[i+1] = (m[i]+a[i])%k;
  rep(i,n+1){ m[i] -= i; m[i] %= k; if(m[i] < 0) m[i] += k;}

  ll ans = 0;
  map<int,int> mp;
  int l = 0;
  rep(r,n+1){
    if(r-l+1>k){
      mp[m[l]]--;
      ++l;
    }
    ans += mp[m[r]];
    mp[m[r]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

map<int, int> mp;

int main() {
	int n, q, m, d, res, mx;
	IL {
		cin >> n >> q;
		if (n == 0 && q == 0) break;
		mp.clear();
		rep (i, n) {
			cin >> m;
			rep (j, m) {
				cin >> d;
				++mp[d];
			}
		}
		res = mx = 0;
		for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
			if (mx < it->second) {
				res = it -> first;
				mx = it -> second;
			}
		}
		if (mx < q) cout << 0 << endl;
		else cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 908
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T[] Reads(T)() { return readln.split.to!(T[]); }
alias reads = Reads!int;
void scan(Args...)(ref Args args) {
    string[] ss = readln.split;
    foreach (i, ref arg ; args) arg = ss[i].parse!int;
}

void main() {
    int x,y,z; scan(x,y,z);
    writeln(z, " ", x, " ",y);
}



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

//#define int long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
typedef vector<int>vint;
typedef pair<int,int>pint;

const int mod=10000;

int N,K;
int lis[100];

int dp[101][3][3];

signed main(){
    cin>>N>>K;
    memset(lis,-1,sizeof(lis));
    rep(i,K){
        int a,b;
        cin>>a>>b;
        lis[--a]=--b;
    }

    rep(i,3)rep(j,3){
        if(lis[0]!=-1&&lis[0]!=i)continue;
        if(lis[1]!=-1&&lis[1]!=j)continue;
        dp[2][i][j]=1;
    }

    reps(i,2,N)rep(j,3)rep(k,3)rep(l,3){
        if(j==k&&k==l)continue;
        if(lis[i]!=-1&&lis[i]!=l)continue;
        dp[i+1][k][l]=(dp[i+1][k][l]+dp[i][j][k])%mod;
    }

    int ans=0;
    rep(i,3)rep(j,3)ans=(ans+dp[N][i][j])%mod;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1164
#include <stdio.h>
int main(){
  int i,j,n,data[11];
  double res,a;

  while(1){
    for(i=0;i<11;i++){
      data[i]=0;
    }
    scanf("%d",&n);
    if(n==-1)break;

    for(i=10;i>=0;i--){
      data[i]=n%4;
      n/=4;
    }
    a=1; 
    res=0;

    for(i=10;i>=0;i--){
      res+=data[i]*a;
      a*=10;
    }

    printf("%.0f\n",res);

  }
  return 0;
}

Measured memory_bytes: 628
#include<bits/stdc++.h>
using namespace std;
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
/*template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    ll k, a, b;
    cin>>k>>a>>b;
    if(a >= b){
        cout<<k + 1;
        return 0;
    }
    else{
        if(b == a + 1 || b == a + 2){
            cout<<k + 1;
            return 0;
        }
        if(k > a - 1){
            k -= (a - 1);
            ll bis = a;
            ll inc = b - a;
            bis += (k/2) * inc * 1L;
            k %= 2;
            if(k) bis++;
            cout<<bis;
        }
        else{
            cout<<k + 1;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    char a;
    cin>>a;
    printf("%c",a+1);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	string s;
	cin>>s;
	int ans=INF;
	rep(i,0,s.size()-2)
	{
		int x=(s[i]-'0')*100+(s[i+1]-'0')*10+s[i+2]-'0';
		ans=min(ans,abs(753-x));
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
set<int> s;

main(){
  cin>>n;
  rep(i,n){
    int a;
    cin>>a;
    s.insert(a);
  }

  cout<<s.size()<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int K = 38; int N = K*K-K+1;
    cout << N << " " << K << "\n";
    vector<vi> ans;
    for (int i = 2; i < N; i += K-1) {
        vi v = {1}; 
        FOR(j,i,i+K-1) v.pb(j);
        ans.pb(v);
    }
    FOR(i,2,39) {
        int dif = i-2;
        F0R(j,37) {
            vi v = {i};
            F0R(k,37) v.pb(2+37*(k+1)+(j+k*dif)%37);
            ans.pb(v);
        }
    }
    for (auto a: ans) {
        for (int i: a) cout << i << " ";
        cout << "\n";
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 768
#include <stdio.h>

int main(void) {
  int a, b;
  char op;
  scanf ("%d %c %d", &a, &op, &b );
  while(op != '?'){
    if ( op == '+' ) printf("%d\n", a + b);
    else if ( op == '-' ) printf("%d\n", a - b);
    else if ( op == '*' ) printf("%d\n", a * b);
    else if ( op == '/' ) printf("%d\n", a / b);
    else printf("Unexpexted syntax!! ERROR!!!\n");
    scanf ("%d %c %d", &a, &op, &b );
  }
  return 0;
}



Measured memory_bytes: 2064
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    int M=gi();
	    int K=gi();

	    for (int i=0; i<=N;i++) {
	    	for (int j=0; j<=M;j++) {
		    	int c=i*M+j*N-2*i*j;
		    	if(c==K) {
		    		System.out.println("Yes");
		    		return;
		    	}
		    }
	    }
	    

        System.out.println("No");
//	    if(max>s-max) {
//	    	System.out.println(s-max-1);
//	    }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35540
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    k = kwargs["k"]
    P = kwargs["P"]
    P = sorted(P)
    res = sum(P[:k])
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"], kwargs["k"] = [int(i) for i in cin]
    cin = input().split()
    kwargs["P"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31224
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        List<Integer> num = new ArrayList<Integer>();
        int total = 0;
        for(int i = 1; i < N+1; i++){
            num.add(i);
        }
        for(int v:num){
            total += result(v,A,B);
        }
        System.out.println(total);
    }

    static int result(int x,int A,int B) {
        int ans = 0,max = 0,xx = x;
        while (x >= 1) {
            ans = x % 10;
            max += ans;
            x /= 10;
        }
        if (A <= max && B >= max) {
            return xx;
        }else{
            return 0;
        }
    }
}


Measured memory_bytes: 21716
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {
	static int[] x, y;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		x = new int[n];
		y = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		sc.close();

		double ans = permutation(new int[n], new LinkedHashSet<>());
		for (int i = 1; i <= n; i++) {
			ans /= i;
		}
		System.out.println(ans);
	}

	static double permutation(int[] target, LinkedHashSet<Integer> set) {
		if (set.size() == target.length) {
			double d = 0;
			Integer[] arr = set.toArray(new Integer[0]);
			for (int i = 1; i < arr.length; i++) {
				d += Math.hypot(x[arr[i]] - x[arr[i - 1]], y[arr[i]] - y[arr[i - 1]]);
			}
			return d;
		}

		double ret = 0;
		for (int i = 0; i < target.length; i++) {
			if (!set.contains(i)) {
				set.add(i);
				ret += permutation(target, set);
				set.remove(i);
			}
		}
		return ret;
	}
}


Measured memory_bytes: 34924
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

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



Measured memory_bytes: 256
nums = input().split()
N = int(nums[0])
K = int(nums[1])
totalProb = 0

for i in range(N):
    x = i + 1
    tempProb = 1/N

    while x < K:
        tempProb = tempProb / 2
        x = x * 2

    totalProb += tempProb

print(totalProb)




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

long pow2[50];

int main(){
  pow2[0]=1;
  for(int i=1; i<50; i++)pow2[i]=2*pow2[i-1];
  long n, k;
  cin >> n >> k;
  int ketac[50]={};
  for(int i=0; i<n; i++){
    long a;
    int cnt=0;
    cin >> a;
    while(a>0){
      ketac[cnt]+=(a%2);
      a/=2;
      cnt++;
    }
  }
  long x=0, ret=0;
  for(int i=49; i>=0; i--){
    if(ketac[i]>n/2 || x+pow2[i]>k)ret+=pow2[i]*ketac[i];
    else {
      x+=pow2[i];
      ret+=pow2[i]*(n-ketac[i]);
    }
  }
  cout << ret;
  return 0;
}

Measured memory_bytes: 256
import sys
N = int(input())
A = [0]*N
for i in range(N):
	A[i] = int(input())

cmax = -1
for i in range(N):
	if A[i] > cmax + 1:
		print(-1)
		sys.exit(0)
	elif A[i] == cmax + 1:
		cmax += 1
	else:
		cmax = A[i]
		
res = 0
for i in range(N-1):
	if A[i] + 1 != A[i+1]:
		res += A[i]

res += A[N-1]

print(res)


Measured memory_bytes: 10996
def main(n, s):
    if n % 2 == 0:
        half = int(n / 2)
        if s[:half] == s[half:]:
            return 'Yes'

    return 'No'


if __name__ == "__main__":
    n = int(input())
    s = input()
    print(main(n, s))


Measured memory_bytes: 2940
$<.each_line do |line|
  src = line.split(",").map(&:to_i)

  lens   = src[0...10]
  v1, v2 = src[10, 11]

  total_len = lens.inject(:+).to_f
  meet_time = total_len / (v1+v2)
  meet_spot = meet_time * v1

  advanced     = 0
  meet_section = lens.index{|l| advanced += l; advanced >= meet_spot}+1

  puts meet_section
end

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

const int MOD = 1e9 + 7;


int main(){
    int N;
    cin >> N;
    vector<long long> A(N);

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


    vector<long long> cumsum(N);
    cumsum[0] = A[0];

    for(int i=1; i<N; ++i){
        cumsum[i] = cumsum[i-1] + A[i];
        cumsum[i] %= MOD;
    }

    long long res= 0;
    for(int i=0; i<N-1; ++i){
        res += cumsum[i] * A[i+1];
        res %= MOD;
    }

    cout << res << endl;

}

Measured memory_bytes: 6308
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

const int MAX_N = 100;
const int MAX_W = 10000;

int VS[MAX_N+1];
int WS[MAX_N+1];
int X[MAX_N+1][MAX_W+1];

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

  for (int i = 1; i <= n; i++)
    cin >> VS[i] >> WS[i];

  memset(X, 0, sizeof(X));

  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= w; j++) {
      if (WS[i] <= j)
        X[i][j] = max(X[i-1][j], X[i-1][j-WS[i]] + VS[i]);
      else
        X[i][j] = X[i-1][j];
    }
  }

  cout << X[n][w] << endl;
}

Measured memory_bytes: 5116
program line_plus_plus
  implicit none
  integer :: n, x, y, i, j
  integer :: d(2000,2000) = 1e8, c(0:2000) = 0
  read(*,*) n, x, y
  do i = 1, n
    call dfs(i,-1,0,i)
  end do
  do i = 1, n
    do j = 1, n
      c(d(i,j)) = c(d(i,j))+1
    end do
  end do
  do i = 1, n-1
    write(*,'(i0)') c(i)/2
  end do
contains
  recursive subroutine dfs(v,p,s,k)
    integer, intent(in) :: v, p, s, k
    if (s >= d(k,v)) return
    d(k,v) = s
    if (v > 1 .and. p /= v-1) call dfs(v-1,v,s+1,k)
    if (v < n .and. p /= v+1) call dfs(v+1,v,s+1,k)
    if (v == x .and. p /= y) call dfs(y,x,s+1,k)
    if (v == y .and. p /= x) call dfs(x,y,s+1,k)
  end
end program line_plus_plus

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

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

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

using namespace std;

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

	vector<ll>a(n);
	rep(i, n)cin >> a[i];

	//マイナスの数をカウント
	ll cnt = 0;
	rep(i, n) {
		if (a[i] < 0) {
			cnt++;
		}
	}

	ll res = 0;

	rep(i, n) {
		res += abs(a[i]);
	}

	ll mini = INF;

	for (int i = 0; i < n; i++) {
		mini = min(abs(a[i]), mini);
	}

	if (cnt % 2 == 0) {
		cout << res << endl;
	}
	else {
		cout << res - mini * 2 << endl;
	}
}



Measured memory_bytes: 1024
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (replicateM)
import           Data.Array.Unboxed    ((!))
import qualified Data.Array.Unboxed    as A
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)


main :: IO ()
main = do
  [n, c] <- getInts
  dss <- replicateM c getInts
  css <- replicateM n getInts
  print $ solve n c dss css

solve :: Int -> Int -> [[Int]] -> [[Int]] -> Int
solve n c dss css = minimum [f i j k | i <- [1 .. c]
                                     , j <- [1 .. c]
                                     , i /= j
                                     , k <- [1 .. c]
                                     , i /= k
                                     , j /= k] where
  f i j k = sum $ [dss' ! (l, i) * css' ! (0, l)
                  | l <- [1 .. c]]
            ++ [dss' ! (l, j) * css' ! (1, l)
               | l <- [1 .. c]]
            ++ [dss' ! (l, k) * css' ! (2, l)
               | l <- [1 .. c]]
  dss' = A.array ((1, 1), (c, c)) [((i, j), d)
                                   | (ds, i) <- zip dss [1 .. c]
                                   , (d, j) <- zip ds [1 .. c]] :: A.UArray (Int, Int) Int
  css' = A.accumArray (+) 0 ((0, 1), (2, c))
    [(((i + j) `mod` 3, c), 1) | (cs, i) <- zip css [1 .. ]
                               , (c, j) <- zip cs [1 .. ]]
         :: A.UArray (Int, Int) Int

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt

getInts :: IO [Int]
getInts = map readInt . BC.words <$> BC.getLine


Measured memory_bytes: 3452
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> A(N),B(N),C(N-1);
  for (int i=0;i<N;++i){
    cin>>A[i];
  }
  for (int i=0;i<N;++i){
    cin>>B[i];
  }
  for (int i=0;i<N-1;++i){
    cin>>C[i];
  }
  int ans=0;
  for (int i=0;i<N;++i){
    ans+=B[A[i]-1];
    if (A[i]+1==A[i+1]){
      ans+=C[A[i]-1];
    }
  }  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
long DIV = 1000000007;
int main() {

    int n;
    long p = 1;
    string s;
    cin >> n >> s;
    vector<int> a(30, 1);
    for(size_t i = 0; i < n; i++)
    {
        a[s[i]-'a'] += 1;
    }
    for(size_t i = 0; i < 30; i++)
    {
        if(a[i] != 1) {
            p *= a[i];
            p %= DIV;
        }
    }
    cout << p-1 << endl;
}


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

int func ( string s, string t ) {
  int ans= 0;
  for ( char c = 'a'; c <= 'z'; c++ ) {
    bool founds = false,foundt = false;
    for ( int i = 0; i < s.length(); i++ ) {
      if ( s[i] == c) founds = true;
    }
    for ( int i = 0; i < t.length(); i++ ) {
      if ( t[i] == c) foundt = true;
    }
    if ( founds ==true && foundt == true ) ans++;
  }
  // cout << "ans" << ans << endl;
  return ans;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for ( int i = 0; i <= N; i++ ) {
    int tmp = func(S.substr(0,i),S.substr(i));
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  bool dp[100005]={false};
  cin>>n;
  ll l,r;
  rep(i,n){
    cin>>l>>r;
    repl(j,l,r+1){
      dp[j] = true;
    }
  }
  ll ans = 0;
  rep(i,100005){
    if(dp[i]) ans++;
  }

  cout<<ans<<endl;
  
}

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


Measured memory_bytes: 384
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

module Util =
    let strRev s =
        s
        |> Seq.rev
        |> Seq.map string
        |> String.concat ""

[<EntryPoint>]
let main _ =
    let s = read string

    seq {
        for i in 0 .. s.Length - 2 do
            if s.[i] = 'A' && s.[i + 1] = 'C' then yield ()
    }
    |> fun x ->
        if Seq.isEmpty x then "No"
        else "Yes"
    |> printfn "%s"
    0 // return an integer exit code


Measured memory_bytes: 14160
#include <bits/stdc++.h>
using namespace std;
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int a[16];
int x[16][16];
int y[16][16];

int main(){
  int n;cin>>n;
  REP(i,n){
    cin>>a[i];
    REP(j,a[i]){
      cin>>x[i][j]>>y[i][j];
      x[i][j]--;
    }
  }

  int result=0;
  for(int comb=0;comb<(1<<n);comb++){
    bool valid=true;
    REP(i,n){
      if((comb&(1<<i))==0) continue;
      REP(j,a[i]){
	int obj=x[i][j];
	if((comb&(1<<obj))!=0&&y[i][j]==0){
	  valid=false;
	}else if((comb&(1<<obj))==0&&y[i][j]==1){
	  valid=false;
	}
	if(!valid)break;
      }
      if(!valid)break;
    }
    if(valid){
      result=max(result,__builtin_popcount(comb));
    }
  }
  cout<<result<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin>>n;
  int ans=1;
  for(int i=1;i<=n;i++)
  {
     if(i*i>n)
      break;
    ans=i*i;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int p,q,r;
  cin >> p >> q >> r;

  int ans;
  ans = min({p+q, q+r, r+p});
  cout << ans << endl;

  return 0;
}

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

int main() {
    int r, D, X_1;
    
    cin >> r >> D >> X_1;

    for (int i = 0; i < 10; i++){
        X_1 = r * X_1 - D;
        cout << X_1 << endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int i,n;
    scanf("%d",&n);
    int a[n+1],b[n+1],c[n+1];
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int count=0;
    for(i=n;i>0;i--){
        int sum=a[i];
        for(int j=i*2;j<=n;j+=i)
            sum+=b[j];
        if(b[i]=sum%2)
            c[count++]=i;
    }
    printf("%d\n",count);
    while(count--)
        printf("%d ",c[count]);
    return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
static const int MAX_N = 100000;

int N;
int a[MAX_N];

int odd, mul_4;

bool def(){
	if(N % 2 == 0){
		if(mul_4 >= odd) return true;
	}else if(N % 2 == 1){
		if(mul_4 >= odd) return true;
		else if(odd == (N + 1) / 2 && mul_4 >= odd - 1) return true;
	}
	return false;
}

void solve(){
	odd = 0, mul_4 = 0;
	for(int i = 0; i < N; i++){
		if(a[i] % 4 == 0) mul_4++;
		if(a[i] % 2 != 0) odd++;
	}
	if(def()) printf("Yes\n");
	else printf("No\n");
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &a[i]);
	solve();
	return 0;
}


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

//macro-----------------------------------------------------------------------------------------
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i=a;i>b;i--)
#define int long long

//constant--------------------------------------------------------------------------------------
const int inf = 100100100100000;
const int mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//general_method--------------------------------------------------------------------------------
vector<int> cs(vector<int> arr){vector<int> ret = arr;rep(i,1,arr.size()){ret[i] += ret[i-1];}return ret;}
int ceil(int a, int b){if(a%b == 0) return a/b;else return a/b + 1;}
int digitlen(int i){int t = i;int count = 0;while(t){count += 1;t /= 10;}return count;}
int gcd(int m, int n){if((0== m)||(0 == n))return 0;while(m != n){if(m > n)m = m - n;else n = n - m;}return m;}
int lcm(int n, int m){return n*m/gcd(n,m);}

//io_method-------------------------------------------------------------------------------------
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
void print(int n){cout << n << endl;}
void print(vector<int> arr){cout << arr[0];rep(i,1,arr.size()) cout << " " << arr[i];cout << endl;}
void print(string s){cout << s << endl;}
void print(pair<int, int> p){cout << p.first << " " << p.second;}
void print(vector<vector<int>> arr){rep(i,0,arr.size()){print(arr[i]);}}
void print(double n){cout << n << endl;}

//main------------------------------------------------------------------------------------------


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

    int a,b,c,d; cin >>a >> b >> c >> d;

    int t = min(b,d) - max(a,c);
    print( t > 0 ? t : 0);
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main() {
  int K;
   cin >> K;
  int q = 0;
  int w = 0;
  for(int a = 1; a < K + 1; a++) {
    for(int b = 1; b < K + 1; b++) {
      for(int c = 1; c < K + 1; c++) {
        q -= q;
        q += gcd(a, b);
        w += gcd(q, c);
      }
    }
  }
  cout << w << endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	vector<ll> P;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

vector<ll> prime_factor(ll n){
	ll sn = sqrt(n)+1;
	auto prime_list = enum_prime(sn);
	vector<ll> res;
	for(int i=0,ei=prime_list.size();i<ei;i++){
		ll v = prime_list[i];
		if(v*v>n) break;
		while(!(n%v)){
			n /= v;
			res.push_back(v);
		}
	}
	if(n>1){
		res.push_back(n);
	}

	return res;
}

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

	int N=in();
	if(N==1){
		out(1);
		return 0;
	}

	auto PL = enum_prime(1000);
	sort(ALL(PL));
	vector<ll> C(PL.size(),0);
	map<ll,ll> T;
	for(int i=0,ei=PL.size();i<ei;i++){
		T[PL[i]] = i;
	}
	
	for(int i=2;i<=N;i++){
		auto P = prime_factor(i);
		for(auto& x:P) C[T[x]]++;
	}
	ll sum=1;
	for(auto& x:C){
		sum *= (x+1LL)%atcoder_mod;
		sum %= atcoder_mod;
	}
	out(sum);
	return 0;
}


Measured memory_bytes: 256