akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <sstream>
#include <random>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <iostream>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <set>
#include <iomanip>

#define ll long long
#define mod 1000000007
#define max_limit 1000005
using namespace std;

ll h;
ll w;
char S[25][25];
bool vis[25][25];
ll max_dist = 1;

struct V {
    pair<int, int> p;
    int dist;
};

ll bfs(int startI, int startJ) {
    int temp_max = 0;

    queue<V> q;
    q.push(V{make_pair(startI, startJ), 0});
    vis[startI][startJ] = true;

    while(!q.empty()) {
        V c = q.front();

        q.pop();
        int i = c.p.first;
        int j = c.p.second;
        int dist = c.dist;
        temp_max = max(temp_max, dist);

        if(i - 1 >= 0 && S[i - 1][j] == '.' && !vis[i - 1][j]) {
            vis[i - 1][j] = true;
            q.push(V{make_pair(i - 1, j), dist + 1});
        }

        if(i + 1 < h && S[i + 1][j] == '.' && !vis[i + 1][j]) {
            vis[i + 1][j] = true;
            q.push(V{make_pair(i + 1, j), dist + 1});

        }

        if(j - 1 >= 0 && S[i][j - 1] == '.' && !vis[i][j - 1]) {
            vis[i][j - 1] = true;
            q.push(V{make_pair(i, j - 1), dist + 1});

        }

        if(j + 1 < w && S[i][j + 1] == '.' && !vis[i][j + 1]) {
            vis[i][j + 1] = true;
            q.push(V{make_pair(i, j + 1), dist + 1});

        }

    }
    return temp_max;
}

void clear() {
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            vis[i][j] = false;
        }
    }
}

int main() {

    cin>>h>>w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin>>S[i][j];
        }
    }



    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {



            if(S[i][j] != '.') {
                continue;
            }

            clear();
            ll temp_max = bfs(i, j);
            if(temp_max > max_dist) {
                max_dist = temp_max;
            }
        }
    }


    cout<<max_dist<<'\n';
    return 0;
}


Measured memory_bytes: 256
import collections
n=int(input())
a=list(map(int,input().split()))
b=collections.deque()
for i in range(n):
  if i%2==0:
    b.append(a[i])
  else:
    b.appendleft(a[i])
if n%2!=0:
  b.reverse()
print(*b)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

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

  vector<int> pr(n);
  vector<vector<int>> v(n, vector<int>(m));

  rep(i, n) {
    cin >> pr[i];
    vector<int> a(m);
    rep(j, m) { cin >> a[j]; }
    v[i] = a;
  }

  // bit全探索
  int ans = INT_MAX;
  for (int tmp = 0; tmp < (1 << n); tmp++) {
    vector<int> p(m, 0);
    int price = 0;
    for (int i = 0; i < n; i++) {
      if (tmp & (1 << i)) {
        // 購入する
        price += pr[i];
        rep(j, m) { p[j] += v[i][j]; }
      }
    }

    int elig = true;
    rep(i, m) {
      if (p[i] < x) {
        elig = false;
      }
    }

    if (elig) {
      ans = min(ans, price);
    }
  }

  if (ans == INT_MAX) {
    cout << "-1";
  } else {
    cout << ans;
  }
}

Measured memory_bytes: 3632
T = input()
# pt = ''
# cnt = 0
# for t in T:
#     if t == 'D':
#         cnt += 1 + (pt == 'P')
#     elif t == '?':
#         cnt += 1 + (pt == 'P')
#     pt = t

# print(cnt)
ans = []
for t in T:
    if t == '?':
        ans.append('D')
    else:
        ans.append(t)
print(''.join(ans))


Measured memory_bytes: 10932
package main

import "fmt"

func main() {
	var n string
	fmt.Scan(&n)
	for i := 0; i < 3; i++ {
		if string(n[i]) == "9" {
			fmt.Print("1")
		} else {
			fmt.Print("9")
		}
	}
	fmt.Println()
}


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

#define FOR(i, l, r) for(size_t i = (l); i < (r); i = i + 1)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << C << " " << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
const int alpha=26;
int main(){
	string S,T;
	cin>>S>>T;
	vint A[26],B[26];
	for(int i=0;i<S.length();i++)
		A[S[i]-'a'].pb(i);
	for(int i=0;i<T.length();i++)
		B[T[i]-'a'].pb(i);
	vector<vint> C,D;
	for(int i=0;i<26;i++)
		C.pb(A[i]);
	for(int i=0;i<26;i++)
		D.pb(B[i]);
	sort(C.begin(),C.end());
	sort(D.begin(),D.end());
	if(C==D)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 4360
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var A = array[0];
            var B = array[1];

            if (A <= 9 && B <= 9)
            {
                Console.WriteLine(A * B);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int a = s[5] - '0';
  int b = s[6] - '0';
  if (a || b > 4) {
    cout << "TBD" << '\n';
  } else {
    cout << "Heisei" << '\n';
  }
  return 0;
}

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

int main(){
  string s,t;
  cin>>s>>t;
  int count=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){
      count++;
      break;
    }
  }
  if(count==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
	string s;
	cin >> s;
	string now = "";
	for (int i = 0; i < s.size(); i++){
		if (s[i] == '0'){
			now += "0";
		}
		else if (s[i] == '1'){
			now += "1";
		}
		else{
			if (now.size() > 0){
				now.erase(now.begin() + now.size() - 1);
			}
		}
	}
	cout << now << endl;
}

Measured memory_bytes: 256
s = input()
N = int(s)
l = len(s)
first = int(s[0])
last = int(s[-1])
if last == 0:
    N -= 1
    s = str(N)
    l = len(s)
    first = int(s[0])
    last = int(s[-1])
if N < 10:
    print(N)
else:
    if l > 2:
        middle = int(s[1:-1])
    else:
        middle = 0
    k1 = 0
    for i in range(l - 2):
        k1 += 10 ** i
    k2 = k1
    k1 += 10 ** (l - 2)

    li = [[0 for j in range(9)] for i in range(9)]
    for i in range(9):
        for j in range(9):
            if i + 1 < first:
                li[i][j] = k1
            elif i + 1 == first:
                li[i][j] = middle + k2
                if j + 1 <= last:
                    li[i][j] += 1
            else:
                li[i][j] = k2
            if i == j:
                li[i][j] += 1
    ans = 0
    for i in range(9):
        for j in range(9):
            ans += li[i][j] * li[j][i]
    print(ans)


Measured memory_bytes: 3064
program Rainy_Season
    implicit none
    character(len=3) s
    integer a

    read *,s

    a=len_trim(s)
    if(a<=3)then
        if(s(1:3)=="RRR")then
            print *,3
        elseif(s(1:2)=="RR" .or. s(2:3)=="RR")then
            print *,2
        elseif(s(1:1)=="R" .or. s(2:2)=="R" .or. s(3:3)=="R")then
            print *,1
        else
            print *,0
        end if
    endif
end program Rainy_Season

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

int n, x;
int ans[500005];
int q[500005];
int main() {
	ios::sync_with_stdio(false);

	cin >> n >> x;
	n = 2 * n - 1;
	if (x == 1 || n == x) {
		puts("No");
		return 0;
	}
	if (x > n / 2) {
		ans[n / 2] = x;
		int ind = 0;
		for (int i = 1; i <= n; i++)
			if (i != x)
				q[ind++] = i;

		int ind1 = ind / 2 - 1, ind2 = ind - 1;
		int L = n / 2 - 1, R = n / 2 + 1;
		while (L >= 0)
			ans[L--] = q[ind1--], ans[R++] = q[ind2--];
		puts("Yes");
		for (int i = 0; i < n; i++)
			printf("%d%c", ans[i], '\n');
	}
	else if (x <= n / 2) {
		ans[n / 2] = x;
		int ind = 0;
		for (int i = 1; i <= n; i++)
			if (i != x)
				q[ind++] = i;
		int ind1 = 0, ind2 = ind / 2;
		int L = n / 2 - 1, R = n / 2 + 1;
		while (L >= 0)
			ans[L--] = q[ind1++], ans[R++] = q[ind2++];
		puts("Yes");
		for (int i = 0; i < n; i++)
			printf("%d%c", ans[i], '\n');
	}


	return 0;
}


Measured memory_bytes: 3072
/*
 * N 人の人がいて、i 番目の人の名前は Si です。
 * 
 * この中から、以下の条件を満たすように 3 人を選びたいです。
 * 
 *     全ての人の名前が M,A,R,C,H のどれかから始まっている
 *     同じ文字から始まる名前を持つ人が複数いない
 * 
 * これらの条件を満たすように 3 人を選ぶ方法が何通りあるか、求めてください。ただし、選ぶ順番は考えません。
 * 
 * 答えが 32 bit整数型に収まらない場合に注意してください。
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            // 入力
            int n = Integer.parseInt(sc.next());
            long[] counter = new long[5];
            for(int i=0; i<5; i++){
            	counter[i] = 0;
            }
            
            for(int i=0; i<n; i++){
            	// 文字列の入力
                String a = sc.next();
                if(a.substring(0,1).equals("M")){
                	counter[0]++;
                }
                else if(a.substring(0,1).equals("A")){
                	counter[1]++;
                }
                else if(a.substring(0,1).equals("R")){
                	counter[2]++;
                }
                else if(a.substring(0,1).equals("C")){
                	counter[3]++;
                }
                else if(a.substring(0,1).equals("H")){
                	counter[4]++;
                }
            }
            long ret = counter[0] * counter[1] * counter[2]
            			+ counter[0] * counter[1] * counter[3]
            					+ counter[0] * counter[1] * counter[4]
            							+ counter[0] * counter[2] * counter[3]
            									+ counter[0] * counter[2] * counter[4]
            											+ counter[0] * counter[3] * counter[4]
            													+ counter[1] * counter[2] * counter[3]
            															+ counter[1] * counter[2] * counter[4]
            																	+ counter[1] * counter[3] * counter[4]
            																			+ counter[2] * counter[3] * counter[4];
            // 出力
            System.out.println(ret);
            
            sc.close();
        }
    }


Measured memory_bytes: 45336
import java.util.*;

class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int n = Integer.parseInt(sc.next());
      	char[] s = sc.next().toCharArray();
      	char[] t = sc.next().toCharArray();
      
      	StringBuilder sb = new StringBuilder();
      	for (int i = 0; i < n; i++) {
        	sb.append(s[i]);
        	sb.append(t[i]);
        }
      	System.out.println(sb);
    }
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main(){
  int n;
  int w[100];
  cin >> n;
  for(int i = 0;i < n;i ++) {
    cin >> w[i];
  }
  long long s1 = 0,s2 = 0,ans = 0;
  for(int i = 0; i < n; i++){
    s2+= w[i];
  }
  ans = s2;
  for(int i = 0; i < n; i++){
    s1 += w[i];
    s2 -= w[i];
    if(ans > abs(s2-s1) )
      ans = abs(s2-s1);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


int memo[200005];//最大値の添え字を覚える
int maxNum[200005];//memoに含まれる添え字のビットを立てる

int main() {
	int N;
	int A[200005];
	int max = 0;
	int next = 0;
	int count = 0;

	scanf("%d", &N);

	for (int i = 0; i < N; i++) {
		memo[i] = -1;
		maxNum[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
		if (A[i] == max) {
			max = A[i];
			next = A[i];
			memo[count] = A[i];
			count++;
		}
		else if (A[i] > max) {
			for (int j = 0; j <= count; j++)memo[j] = -1;
			count = 0;
			memo[count] = i;
			next = max;
			max = A[i];
		}
		else if (A[i] > next)next = A[i];
	}
	
	for (int i = 0; i <= count; i++) maxNum[memo[i]] = 1;

	
	for (int i = 0; i < N; i++) {
		if (memo[1] != -1)printf("%d\n", max);
		else if (maxNum[i]==1)printf("%d\n", next);
		else printf("%d\n", max);
	}


	
}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=(n)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b);
#define mins(a,b) a=min(a,b);
#define max3(a,b,c) max(a,max(b,c)) 
#define mix3(a,b,c) mix(a,mix(b,c))
#define pairi pair<int,int>

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

void set_frame(vector<string>& vstr,string s){
    vector<string> t(vstr.size()+2,"");
    rep(i,vstr[0].size()+2){
        t[0] += s;
    }
    t[vstr.size()+1] = t[0];
    rep(i,vstr.size()){
        t[i+1] = vstr[i];
        t[i+1] = s + t[i+1] + s; 
    }
    vstr = t;
}

int main(){
   
    int h,w;cin>>h>>w;
    vector<string> m(h+1,"");
    rep(i,h){
        cin>>m[i];
        m[i]+="#";
    }
    rep(i,w)m[h]+="#";

    vvi ptn(h,vi(w,0));
    ptn[0][0]=1;

    rep(i,h){
        rep(j,w){
            if(m[i][j]=='#')continue;
            if(m[i+1][j]=='.')ptn[i+1][j] = (ptn[i+1][j]+ptn[i][j])%MOD;
            if(m[i][j+1]=='.')ptn[i][j+1] = (ptn[i][j+1]+ptn[i][j])%MOD;
            // cerr<<"ptn["<<i<<"]["<<j<<"] = "<<ptn[i][j]<<endl;
        }
    }

    cout << ptn[h-1][w-1] << endl;
    
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> s(1<<n);
    REP(i,(1<<n))cin >> s[i];
    sort(ALL(s));
    vector<int32> t;
    t.push_back(s.back());
    s.back() = INF;
    REP(i,n){
        vector<int32> p = t;
        sort(ALL(p));
        int32 pi = p.size()-1;
        FORR(j,(1<<n)-1,0){
            if(s[j] < p[pi]){
                t.push_back(s[j]);
                pi--;
                s[j] = INF;
            }
            if(pi == -1)break;
        }
        if(pi != -1){
            Yes(false);
            return 0;
        }
    }
    Yes(true);
    return 0;
}

Measured memory_bytes: 5484
time=[]
for i in range(5):
    a=int(input())
    time.append(a)

sum_time=sum(time)
divide_time=[]
for i in range(5):
    amari=time[i]%10
    divide=10-amari
    if divide==10:
        divide=0
    divide_time.append(divide)
result=sum_time+sum(divide_time)-max(divide_time)
print(result)


Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;

int n, x, sum;

int hantei(int p) {
	int v = max((int)sqrt(p), p);
	for (int i = 1; i <= sqrt(p); i++) {
		int a = p - i;
		if (a % (2 * i + 1) == 0 && a >= 1) {
			return 0;
		}
	}
	return 1;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		sum += hantei(x);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
	public static void main(String[] args) {
		// practice contest

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		int add = 0;
		add = a + b;
		int sub = 0;
		sub = a - b;
		int product = 0;
		product = a * b;
		int x = 0;
		x = Math.max(add, sub);
		int y = 0;
		y = Math.max(x, product);
		System.out.println(y);
	}

}


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

void solve(){


    return;
}

int main()
{
    string s;
    deque<char> d;
    int q;
    cin >> s >> q;
    for(char c: s) d.push_back(c);
    vector<vector<char>> vec(q, vector<char>(3));
    rep(i,q)rep(j,3){
        cin >> vec[i][j];
        if(vec[i][0] == '1'){
            vec[i][1] = '0';
            vec[i][2] = '0';
            break;
        }
    }

    bool rev = false;
    string tmp;
    rep(i,q){
        if(vec[i][0]=='1' && i != 0) rev = !rev;
        else if(vec[i][0]=='2'){
            if(!rev){
                if(vec[i][1]=='1') d.push_front(vec[i][2]);
                else if(vec[i][1]=='2') d.push_back(vec[i][2]); 
            }
            else{
                if(vec[i][1]=='1') d.push_back(vec[i][2]); 
                else if(vec[i][1]=='2') d.push_front(vec[i][2]);              
            }

        }
    }

    if(rev) reverse(d.begin(), d.end());
    
    string ans;
    for(char c : d) ans += c;
    cout << ans << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 12292
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

// ll get_pow(ll x, ll y){
//   ll ret=0;
//   ll temp = y;
//   while(true){
//     if(x<=temp) break;
//     ret++;
//     temp *= 2;
//   }
//   return ret;
// }



int main() {
  cout<<fixed<<setprecision(10);

  ll N,M;
  cin>>N>>M;
  vint L(M),R(M);
  rep(i,M)cin>>L[i]>>R[i];

  ll ans = 0;
  ll left = 1;
  ll right = N;

  rep(i,M){
    left = max(left, L[i]);
    right = min(right, R[i]);
  }

  ans = max(right-left+1, 0ll);

  cout << ans << endl;

}

















//


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>

using namespace std;

long Inf = 1000000000000;

double grad(pair<double, double> &l, pair<double, double> &r){
    if(l.first == r.first){
        return Inf;
    }else{
        return (l.second - r.second) / (l.first - r.first);
    }
}

int main(){
    int n;
    cin >> n;
    vector<pair<double, double> > p;
    vector<pair<double, double> > ans;
    vector<pair<double, double> > ans_;
    double x, y;
    for(int i = 0; i < n; i++){
        cin >> x >> y;
        p.push_back(make_pair(x, y));
    }
    sort(p.begin(), p.end());
    ans.push_back(p[0]);
    ans.push_back(p[1]);
    double g, g_;
    g = grad(p[0], p[1]);
    pair<double, double> last = p[1]; 
    for(int i = 2; i < n; i++){
        g_ = grad(last, p[i]);
        while(g_ < g && ans.size() > 1){
            ans.pop_back();
            pair<double, double> a = ans[ans.size()-1];
            pair<double, double> b = ans[ans.size()-2];
            g = grad(b,a);
            g_ = grad(a, p[i]);
        }
        g = g_;
        ans.push_back(p[i]);
        last = p[i];
    }

    reverse(p.begin(), p.end());
    ans_.push_back(p[0]);
    ans_.push_back(p[1]);
    g = grad(p[0], p[1]);
    last = p[1]; 
    for(int i = 2; i < n; i++){
        g_ = grad(last, p[i]);
        while(g_ < g && ans_.size() > 1){
            ans_.pop_back();
            pair<double, double> a = ans_[ans_.size()-1];
            pair<double, double> b = ans_[ans_.size()-2];
            g = grad(b,a);
            g_ = grad(a, p[i]);
        }
        g = g_;
        ans_.push_back(p[i]);
        last = p[i];
    }
    cout << ans.size()+ans_.size() - 2 << endl;
    /*for(int i = 0; i < ans.size(); i++){
        //cout << ans[i].first << " " << ans[i].second << endl;
        push_back(ans[i]);
    }*/
    for(int i = 1; i < ans_.size()-1; i++){
        //cout << ans_[i].first << " " << ans_[i].second << endl;
        ans.push_back(ans_[i]);
    }
    int i = 0;
    while(ans[i].second > ans[i+1].second){
        ans.push_back(ans[i]);
        i++;
    }
    //cout << i << endl;
    for(int j = i; j < ans.size(); j++){
        cout << ans[j].first << " " << ans[j].second << endl;
    }
}

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

int main(int argc, char** argv){
  /*
  int N;
  cin >> N;
  priority_queue<int> d;
  
  int tmp = 0;
  int dmax = 0;
  for(int cnt0=0; cnt0<N; cnt0++){
    cin >> tmp;
    dmax = max(dmax, tmp);
    d.push(tmp);
  }
  cout << dmax;
  return 0;
  
  int ans = 0;
  for(int cnt0=1; cnt0<=dmax; cnt0++){
    int tmpnum = 0;
    priority_queue<int> dtmp = d;
    for(int cnt1=0; cnt1 < N/2 + 1; cnt1++){
      if(dtmp.top() < cnt0) tmpnum++;
      dtmp.pop();
    }
    if(tmpnum == N/2) ans++;
  }
  
  printf("%d\n", ans);
  */

  int N;
  cin >> N;
  int d[N];
  
  for(int cnt0=0; cnt0<N; cnt0++){
    cin >> d[cnt0];
  }
  sort(d, d+N);
  int* ptr_half;
//  ptr_half = (d, d+N, d[N/2 -1]);
//  int idx = (d, d+N, d[N/2 -1]);
//  printf("%d\n", *ptr_half);
  printf("%d\n", d[N/2] - d[N/2-1]);
}

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

int main(){
  	
	string s;
  	cin >> s;
  	int n = s.size();
  	vector<bool> a(26);
	for(int i = 0; i<n;i++)
      a[s[i] - 'a']=true;
	for(int i = 0; i<26;i++)
      if(a[i] == false) {
        	cout << (char)('a'+i) << endl;
  			return 0;
      }
	cout << "None" << endl;
	
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int H, W; cin >> H >> W;
	vector<string>v(H); rep(i, 0, H) { cin >> v[i]; }
	int ans = 0;
	rep(i, 0, H)rep(j, 0, W) {
		rep(a, 0, H)rep(b, 0, W) {
			if (i == a and j == b)continue;
			if (v[i][j] == 'B' and v[a][b] == 'B') {
				int d = abs(i - a) + abs(j - b);
				chmax(ans, d);
			}
		}
	}
	cout << ans << endl;

	return 0;
}



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

#define int long long
using namespace std;
const int MAXN = 4010;
int R[MAXN], G[MAXN], B[MAXN];

signed main(){
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    int n, sum = 0; string s;
    cin >> n >> s; s = ' ' + s;
    for (int i = n;i > 0; i--){
        if (s[i] == 'R') R[i]++;
        if (s[i] == 'G') G[i]++;
        if (s[i] == 'B') B[i]++;
        R[i] += R[i + 1];
        G[i] += G[i + 1];
        B[i] += B[i + 1];
    }
    for (int i = 1;i < n; i++){
        for (int j = i + 1;j < n; j++){
            if (s[i] != s[j]){
                bool flagR = false, flagG = false, flagB = false;
                if (s[i] == 'R' || s[j] == 'R') flagR = true;
                if (s[i] == 'G' || s[j] == 'G') flagG = true;
                if (s[i] == 'B' || s[j] == 'B') flagB = true;
                if (!flagR){
                    sum += R[j + 1];
                    if (s[j + (j - i)] == 'R') sum--;
                }
                if (!flagG){
                    sum += G[j + 1];
                    if (s[j + (j - i)] == 'G') sum--;
                }
                if (!flagB){
                    sum += B[j + 1];
                    if (s[j + (j - i)] == 'B') sum--;
                }
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int parent[200005];
int find(int i){
    if(parent[i]==i)return i;
    else{
        //Recurse until main parent os found.
        int j=find(parent[i]);
        //Path compression
        parent[i]=j;
        return j;
    }
}
void set_union(int x,int y){
    //Find both of their (main) parents
    int x1=find(x);
    int y1=find(y);
    //Then check which one has fewer children and make 
    // it the child of the larger family.
        parent[x1]=y1;
}
int32_t main(){
   int n,m; cin>>n>>m;
   rep(i,1,n+1)parent[i]=i;
   rep(i,0,m){
       int a,b; cin>>a>>b;
       if(find(a)!=find(b))set_union(a,b);
   }
   map<int,int> mp;
   rep(i,1,n+1){
    mp[find(i)]++;
    }
    int ans=0;
    rr(mp)ans=max(ans,val.se);
    cout<<ans<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll ans;
int n,k;
vvl G;
vb visited;
void dfs(int node,int dist,ll &ans){
    if(dist > k/2)ans++;
    visited[node] = true;
    for(auto nv:G[node]){
        if(visited[nv] == false)dfs(nv,dist+1,ans);
    }
}
signed main()
{   
    gearup;
    cin >> n >> k;
    G.resize(n);
    visited.resize(n);
    vpii edge;
    rep(i,n-1){
        int a,b; cin >> a >> b;
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        edge.emplace_back(a,b);
    }
    ll res = L_INF;
    if(k % 2 == 0){
        rep(i,n){
            ans = 0;
            rep(i,n)visited[i]=false;
            dfs(i,0,ans);
            res = min(res,ans);
        }
    }
    else{
        k--;
        rep(i,n-1){
            int a = edge[i].first;
            int b = edge[i].second;
            rep(i,n)visited[i] = false;
            visited[a] = true;
            visited[b] = true;
            ans = 0;
            dfs(a,0,ans);
            dfs(b,0,ans);
            res = min(res,ans);
        }
    }
    out(res);
}


Measured memory_bytes: 512
#include <stdio.h>
int main()
{
	int S,h,m,s;
	scanf("%d",&S);
	h = S / 3600;
	m = S%3600 / 60;
	s = (S%3600)%60;
	printf("%d:%d:%d\n" ,h,m,s);
	
	return 0;
}

Measured memory_bytes: 2756
#include <stdio.h>
#include <string.h>

int main(){
  int Adj[101][101],n,v,i,j,u,k;
  memset(Adj, 0, 101*101*sizeof(int));
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      Adj[u][v]=1;
    }
  }
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=1)printf(" ");
      printf("%d",Adj[i][j]);
    }
    printf("\n");
  }
  
  return 0;
}



Measured memory_bytes: 2112
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]

for i in range(n-m+1): #縦
    for j in range(n-m+1): #横
        for k in range(m): #テンプレートの縦
            #print(i,j,k)
            #print(a[i+k][j:m+j],b[k])
            if a[i+k][j:m+j]!=b[k]:
                break
        else:
            print("Yes")
            exit()

print("No")



Measured memory_bytes: 3060
N, Q = list(map(int, input().split()))
S = input()

flags = [0] * N
for i in range(N):
    if i != 0 and S[i - 1:i + 1] == 'AC':
        flags[i] = 1

acc_sum = [0] * N
for i in range(1, N):
    if flags[i] == 1:
        acc_sum[i] = acc_sum[i - 1] + 1
    else:
        acc_sum[i] = acc_sum[i - 1]

for i in range(Q):
    l, r = list(map(int, input().split()))
    if l == r:
        print(0)
    else:
        print(acc_sum[r - 1] - acc_sum[l - 1])

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

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if (a < b&&b < c) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 1160
N =int(input())
H = list(map(int,input().split()))


max_cnt = 0
cnt = 0
for i in range(1,N):
    if H[i] <= H[i-1]:
        cnt += 1
    else:
        max_cnt = max(max_cnt, cnt)
        cnt = 0
max_cnt = max(max_cnt, cnt)
print(max_cnt)

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const double EPS = 1e-11;
const double PI = 2 * acos(0.0);
int CASE=0;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);

#define caseNo pf("Case %d: ",++CASE)
#define pf printf
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define sll(x,y) scanf("%lld %lld",&x,&y)

#define nl '\n'
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define uniq(a) a.erase(unique(a.begin(), a.end()), a.end())
#define out(x) cout <<"#x = "<<x<<endl
#define outt(x,y) cout <<x<<" "<<y<<endl
#define mem(array,value) memset(array,value,sizeof(array))

#define chkC(n) (flag[n>>6]&(1<<((n>>1)&31)))
#define setC(n) (flag[n>>6]|=(1<<((n>>1)&31)))

int fx4[]={1,-1,0,0};
int fy4[]={0,0,1,-1};

int fx8[]={0,0,1,-1,-1,+1,-1,1};
int fy8[]={-1,1,0,0,1,1,-1,-1};

#define MX 10005

int main()
{
    int a,b,c;
    cin >> a>>b>>c;
    if(a==b&&c==b)puts("Yes");
    else puts("No");
    return 0;
}









Measured memory_bytes: 256
class Dice:
  def __init__(self, top=1, front=2, left=4, right=3, back=5, bottom=6):
    self.d = {"TOP":top, "FRONT":front, "LEFT":left, "RIGHT":right, "BACK":back, "BOTTOM":bottom}

  def roll_x(self):
    self._roll("TOP", "FRONT", "BOTTOM", "BACK")
  
  def roll_y(self):
    self._roll("FRONT", "LEFT", "BACK", "RIGHT")
  
  def roll_z(self):
    self._roll("TOP", "LEFT", "BOTTOM", "RIGHT")
  
  def _roll(self, a, b, c, d):
    self.d[a], self.d[b], self.d[c], self.d[d] = \
    self.d[b], self.d[c], self.d[d], self.d[a]

n = list(map(int, input().split()))
q = input()
d = Dice(n[0], n[1], n[3], n[2], n[4], n[5])
for ele in q:
  if ele=="N":
    d.roll_x()
  elif ele=="S":
    for _ in range(3):
      d.roll_x()
  elif ele=="E":
    d.roll_z()
  elif ele=="W":
    for _ in range(3):
      d.roll_z()
print(d.d["TOP"])


Measured memory_bytes: 5604
import java.util.*;

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

        int lower = Math.max(A, C);
        int upper = Math.min(B, D);

        System.out.println(Math.max(0, upper - lower));
    }
}

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

int min(int a,int b){
  if(a<b){
    return a;
  } else {
    return b;
  }
}

int main()
{
  int N,a,b,x;
  cin >> N >> a >> b;
  x = min(a*N,b);
  cout << x << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
d=list(map(int,input().split()))
mx=max(d)
l=[0]*(10**5)
mx=0
for i in range(n):
    if (i==0 and d[i]!=0) or (i!=0 and d[i]==0):
        print(0)
        exit()
    l[d[i]]+=1
    mx=max(mx,d[i])
t=1
ans=1
for i in range(1,mx+1):
    ans *= t**l[i]
    t=l[i]

print(ans%998244353)

Measured memory_bytes: 20752
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define itrep(type, it, t) for(type::iterator it=t.begin(); it!=t.end(); it++)
using namespace std;

int solve(string s[], int H, int W, int i, int j);

int main(void) {

    int H, W;
    cin >> H >> W;

    string S[H+2];
    S[0] = string(W+2, '#');
    rep(i, H) {
        string s;
        cin >> s;
        S[i+1] = "#" + s + "#";

    }
    S[H+1] = string(W+2, '#');
    H += 2;
    W += 2;

    // rep(i, H+2) {
    //     cout << S[i] << endl;
    // }

    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            if(S[i][j] == '.') {
                ans = max(ans, solve(S, H, W, i, j));
            }
        }
    }

    cout << ans;
    return 0;
}

int solve(string s[], int H, int W, int i, int j) {
    int step[H][W];
    rep(ii, H) {
        rep(jj, W) {
            step[ii][jj] = -1;
            // cout << step[ii][jj] << " ";
        }
        // cout << endl;
    }
    step[i][j] = 0;

    int ret = 0;
    queue<pair<int, int>> q;
    q.push(make_pair(i, j));
    while(!q.empty()) {
        // cout << q.size() << endl;
        pair<int, int> p = q.front();
        q.pop();
        int h = p.first;
        int w = p.second;

        if(step[h-1][w] == -1 && s[h-1][w] == '.') {
            q.push(make_pair(h-1, w));
            step[h-1][w] = step[h][w]+1;
        }
        if(step[h+1][w] == -1 && s[h+1][w] == '.') {
            q.push(make_pair(h+1, w));
            step[h+1][w] = step[h][w]+1;
        }
        if(step[h][w-1] == -1 && s[h][w-1] == '.') {
            q.push(make_pair(h, w-1));
            step[h][w-1] = step[h][w]+1;
        }
        if(step[h][w+1] == -1 && s[h][w+1] == '.') {
            q.push(make_pair(h, w+1));
            step[h][w+1] = step[h][w]+1;
        }
        ret = step[h][w];
    }
    return ret;


}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
vector<vector<long long int>> dp(120);
int main() {
	int N, W;
	cin >> N >> W;
	vector<vector<int>> s(N + 20);
	for (int i = 1; i <= N; i++) {
		int a, b;
		cin >> a >> b;
		s[i].push_back(a);
		s[i].push_back(b);
	}
	for (int i = 0; i <= W; i++) {
		dp[0].push_back(0);

	}
	for (int i = 1; i <= N; i++) {
		int w, v;
		w = s[i][0];
		v = s[i][1];
		for (int j = 0; j <= W; j++) {
			if (j - w < 0) {
				dp[i].push_back(dp[i - 1][j]);
			}
			else {
				dp[i].push_back(max(dp[i - 1][j - w] + v, dp[i - 1][j]));
			}
		}

		if (i == N) {
			cout << dp[i][W];
		}
	}
}

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

using namespace std;

typedef pair < int, int >P;

P f(int x)
{
	int a = x % 10;
	int b = 0;
	while (x) {
		b = x;
		x /= 10;
	}
	return P(a, b);
}

int main()
{
	int N;
	cin >> N;
	map < P, int >freq;
	for (int i = 1; i <= N; i++) {
		P p = f(i);
		freq[p]++;
	}

	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		P p = f(i);
		P q(p.second, p.first);
		ans += freq[q];
	}

	cout << ans << endl;

	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

class modint {
  private:
    ll m_val;
    ll m_mod;
  public:
    constexpr modint() : m_val(0), m_mod() { m_mod = MOD; }
    constexpr modint(const ll x) : m_val(0), m_mod(0) { m_mod = MOD; m_val = x % m_mod; }
    constexpr modint(const ll x, const ll mod) : m_val(0), m_mod(0) { m_mod = mod; m_val = x % m_mod; }
    constexpr ll val() const { return m_val; }
    constexpr modint operator+(const modint &rhs) const { return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) {
      m_val += rhs.m_val;
      if (m_val >= m_mod) m_val -= m_mod;
      return *this;
    }
    constexpr modint &operator-=(const modint &rhs) {
      if (m_val < rhs.m_val) m_val += m_mod;
      m_val -= rhs.m_val;
      return *this;
    }
    constexpr modint &operator*=(const modint &rhs) {
      m_val = m_val * rhs.m_val % m_mod;
      return *this;
    }
    constexpr modint &operator/=(const modint &rhs) {
      *this *= rhs.inv();
      return *this;
    }
    constexpr modint pow(ll n) const {
      if (n == 0) return 1;
      modint o = pow(n >> 1);
      o *= o;
      if (n & 1) o *= *this;
      return o;
    }
    constexpr modint inv() const {
      return pow(m_mod - 2);
    }
    friend ostream& operator<<(ostream& os, const modint &a) { os << a.val(); return os; }
};

struct combination {
  vector<modint> fact, ifact;
  combination(ll n): fact(n+1), ifact(n+1) {
    fact[0] = 1;
    for (ll i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (ll i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  modint operator()(ll n, ll k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n-k];
  }
};

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

  string s;
  cin >> s;
  n = s.size();

  combination comb(n+k+100);

  modint ans = 0;
  for (ll i = 0; i <= k; ++i) {
    modint v = modint(26).pow(k-i);
    v *= modint(25).pow(i) * comb(i+(n-1), n-1);
    ans += v;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 66708
data=[]
for i in range(3):
    a=list(map(int,input().split()))
    data.append(a)
n=int(input())
cnt=[0]*8
for i in range(n):
    b=int(input())
    for j in range(3):
        for k in range(3):
            if b==data[j][k]:
                cnt[j]+=1
                cnt[k+3]+=1
                if j==k:
                    cnt[6]+=1
                if j+k==2:
                    cnt[7]+=1
ans="No"
for i in range(8):
    if cnt[i]==3:
        ans="Yes"
        break
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a,b,bin[65];
int main(){
	scanf("%lld%lld",&a,&b);
	if(a==b) return puts("1"),0;
	bin[0]=1;
	for(int i=1;i<=62;i++) bin[i]=bin[i-1]*2;
	int d;
	for(int i=60;~i;i--) if((a&bin[i])!=(b&bin[i])){
		d=i;break;
	}else if(a&bin[i]) a^=bin[i],b^=bin[i];
	int k=-1;
	for(int i=60,tot=0;~i;i--) if(b&bin[i]){
		tot++;
		if(tot==2){
			k=i;break;
		}
	}
	ll l=a,r=bin[d]+bin[k+1]-1;
	ll l1=bin[d]+a,r1=bin[d+1]-1;
	if(l>l1) swap(l,l1),swap(r,r1);
	ll ans=r-l+1+r1-l1+1;
	if(r>=l1) ans-=r-l1+1;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int H, W;

    scanf("%d%d", &H, &W);

    long long c[10][10];

    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            scanf("%lld", &c[i][j]);
        }
    }

    for(int k = 0; k <= 9; k++){
        for(int i = 0; i <= 9; i++){
            for(int j = 0; j <= 9; j++){
                if(c[i][j] > c[i][k] + c[k][j]){
                    c[i][j] = c[i][k] + c[k][j];
                }
            }
        }
    }

    int A[H][W];

    long long ans = 0;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            scanf("%d", &A[i][j]);
            if(A[i][j] != -1){
                ans += c[A[i][j]][1];
            }
        }
    }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1860
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    S = input()
    t = input()
    ans = 0
    for i in range(len(S)):
        if S[i] != t[i]:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9372
n = int(input())
a = list(map(int, input().split()))
ans = 0
flag = True
while True :
    if flag == False :
        break
    for j in range(n) :
        if a[j] % 2 != 0 :
            flag = False
        else :
            a[j] = a[j]/2
    ans += 1
print(ans-1)

Measured memory_bytes: 3060