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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n,k;
    cin2(n, k);
    lli a[n], f[n];
    ncin1(n,a);
    ncin1(n,f);
    sort(a,a+n);
    sort_r(f,f+n);

    //REP(i,0,n)
    //    cout2(i,a[i]);
    //REP(i,0,n)
    //    cout2(i,f[i]);

    lli max_cost = 0;
    REP(i,0,n) {
        max_cost = max(max_cost, a[i] * f[i]);
    }
    lli ans = max_cost;

    lli left = -1;
    lli right = max_cost;
    while (right - left > 1) {
        lli cur = (left+right)/2;
        bool is_ok = true;

        lli count = 0;
        REP(i,0,n) {
            // count を必要な分増やす

            count += max((lli)0, a[i] - (cur/f[i]));
            if (count > k) {
                is_ok = false;
                break;
            }
        }



        //cout3(cur, right, left);
        //cout1(is_ok);
        if (is_ok) {
            right = cur;
        }
        else {
            left = cur;
        }
    }
    ans = right;
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 44444
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
int v6[sz],c6;
int v2[sz],c2;
int v3[sz],c3;

int main()
{
	file();
	rep(i,1,3e4)
		if (i==2||i==4||i==3||i==9);
		else if (i%6==0) v6[++c6]=i;
		else if (i%3==0) v3[++c3]=i;
		else if (i%2==0) v2[++c2]=i;
	read(n);
	if (n==3) return puts("2 5 63"),0;
	if (n==4) return puts("2 5 20 63"),0;
	printf("2 4 3 9 ");n-=4;
	while (n>=2&&c2) printf("%d %d ",v2[c2],v2[c2-1]),c2-=2,n-=2;
	while (n>=2&&c3) printf("%d %d ",v3[c3],v3[c3-1]),c3-=2,n-=2;
	while (n--) printf("%d ",v6[c6--]);
	return 0;
}

Measured memory_bytes: 512
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int, input().split())))

a = sorted(a, key=lambda x: -x[2])

m = 0
mx = 0
my = 0

for cx in range(101):
    for cy in range(101):
        flag = True
        x, y, h = a[0]
        H = max(abs(x-cx) + abs(y-cy) + h, 0)
        for i in range(n):
            xx, yy, hh = a[i]
            if hh != max(H - abs(xx - cx) - abs(yy - cy), 0):
                flag = False

        if flag == True:
            mx = cx
            my = cy
            m = H

print(str(mx) + ' ' + str(my) + ' ' + str(m))


Measured memory_bytes: 3064
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

#define bitcount(n) __builtin_popcount(n)

#define debug(n) cout << n << endl;

#define PREC(n) setprecision(n)
#define DOTPREC(n) fixed << setprecision(n)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false); cin.tie(0)

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

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

const ll MOD = 1000000007;

#define INDEX_MAX 100000
#define SIZE 1000000000

ll H, W, N;

typedef unordered_map<ll, unordered_map<ll, bool>> BOARD;
BOARD blacks;
BOARD will_check;

int count(int i, int j) {
    int total = 0;
    for (int k = -1; k <= 1; k++) {
        for (int l = -1; l <= 1; l++) {
            if (i + k < 0 || i + k >= H) return -1;
            if (j + l < 0 || j + l >= W) return -1;

            total +=
                blacks.find(i+k) != blacks.end()
                && blacks[i+k].find(j+l) != blacks[i+k].end();
        }
    }
    return total;
}

void mark(int i, int j) {
    for (int k = -1; k <= 1; k++) {
        for (int l = -1; l <= 1; l++) {
            if (i + k < 0 || i + k >= H) continue;
            if (j + l < 0 || j + l >= W) continue;
            will_check[i+k][j+l] = true;
        }
    }
}

int main(void)
{
    cin >> H >> W >> N;

    rep(i, N) {
        ll a, b;
        scanf("%lld %lld", &a, &b);
        a--, b--;
        blacks[a][b] = true;
        mark(a, b);
    }

    ll counts[10] = {};
    for (auto& i_map : will_check) {
        const int i = i_map.first;
        for (auto& j_map : i_map.second) {
            const int j = j_map.first;
            const int c = count(i, j);
            if (c != -1) counts[c]++;
        }
    }

    ll total = (H - 2) * (W - 2);
    for (auto& count : counts) {
        total -= count;
    }
    counts[0] = total;

    rep(i, 10) {
        cout << counts[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 99636
import math

def main():
	S = int(input())
	if S <= 2:
		print(0)
		return 0

	p = 1000000007

	f = [1, 1]
	fi = [1, 1]
	for i in range(2001):
		f.append((f[-1] * (i + 2)) % p)
		fi.append((fi[-1] * inv(i + 2, p)) % p)

	cnt = 0
	for l in range(1, math.floor(S / 3) + 1):
		if S - 2 * l - 1 < l - 1:
			continue
		cnt += (((f[S - 2 * l - 1] * fi[l - 1]) % p) * fi[S - 3 * l]) % p
	print(cnt % p)

def inv(a, p):
	power = [a]
	for i in range(math.ceil(math.log2(p - 2)) + 1):
		power.append((power[-1] ** 2) % p)
	b_p = format(p - 2, 'b')
	r = 1
	for i in range(len(b_p)):
		if b_p[-i-1] == "1":
			r = (r * power[i]) % p
	return r

main()

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

cnt = (a[0] // 2) * 4
cnt += a[1] * 2
cnt += (a[3] // 2) * 4
cnt += (a[4] // 2) * 4

IJL = (a[0] % 2 + a[3] % 2 + a[4] % 2)
if IJL == 2 and bool(a[0]) + bool(a[3]) + bool(a[4]) >= 3:
    cnt += 2
elif IJL == 3:
    cnt += 6

print(cnt // 2)


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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> L(N + 1);
  L.at(0) = 0;
  for (int i = 0; i < N; ++i) {
    cin >> L.at(i + 1);
  }
  int now = 0;
  int ans = 0;
  for (int i = 0; i < N + 1; ++i) {
    now += L.at(i);
    if (now <= X) {
      ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

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

	int N, K; cin >> N >> K;
	vector<int> l(N, 0);
	rep (i, N) cin >> l[i];

	sort(ALL(l));

	int res = 0;
	for (int i = 0, j = N - 1; i < K; ++i, --j){
		res += l[j];
	} // end for

	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi           first
#define se           second
#define ll           long long
#define pb           push_back
#define mp           make_pair
#define pll          pair<ll,ll>
#define pii          pair<int,int>
#define all(x)       (x).begin(),(x).end()
#define isWorking()  cout<<"Wroking"<<endl
#define FOR(i,x,y)   for(int i=x; i<y; i++)
#define SORT(x)      sort(x.begin(),x.end())
#define PRINT(ok)    cout<<(ok? "YES":"NO")<<endl
#define Fast_Input   ios_base :: sync_with_stdio(false), cin.tie(NULL);
typedef vector < int > VI;
const ll mod= 1e9+7,INF=1e18,mx= 5e6+5,mn=100;
int testCase=1,cas=0;

const int fx[]={+1,-1,+0,+0};  //Four Side
const int fy[]={+0,+0,+1,-1};  //Four Side

int vis[25][25],dis[25][25];
int ans=0;
char grid[25][25];
int n,m;

void bfs(int x,int y){
    vis[x][y]=1;

    queue<pii> q;
    q.push({x,y});
    while(!q.empty()){
        x=q.front().first;
        y=q.front().second;

        q.pop();

        for(int i=0; i<4; i++){
            int xx=x+fx[i];
            int yy=y+fy[i];
            if(xx>=0 && yy>=0 && xx<n && yy<m && !vis[xx][yy] && grid[xx][yy]=='.'){
                vis[xx][yy]=1;
                q.push({xx,yy});
                dis[xx][yy]=dis[x][y]+1;
                ans=max(ans,dis[xx][yy]);
            }
        }
    }
}


int main() {
    Fast_Input

    //cin>>testCase;
    while(testCase--){
        cin>>n>>m;

        for(int i=0; i<n; i++) cin>>grid[i];

        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(grid[i][j]=='.'){
                    memset(vis,0,sizeof vis);
                    memset(dis,0,sizeof dis);
                    bfs(i,j);
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
cnt = 0
l.sort()
for i in l:
    for j in l:
        for k in l:
            if (i != j and i != k and j != k) and (i+j > k and j+k > i and k+i > j):
                cnt += 1
print(int(cnt/6))

Measured memory_bytes: 67760
#include <stdio.h>
int main(int argc, char *argv[])
{
	int n,m;
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		char num[15];
		getchar();
		gets(num);
		int count=0;
		for(int i=0;i<n+m+1;i++)
		{
			if(i==n)
			{
				if(num[n]=='-')
					count++;
			}
			else if(num[i]>='0'&&num[i]<='9')
			{
				count++;
			}
		}
		if(count==n+m+1)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int K;
    cin >> K;

    ll c = 0;
    FOR(h, 1, K + 1) {
        FOR(i, 1, K + 1) {
            FOR(j, 1, K + 1) {
                int a1, a2;
                a1 = max({h, i});
                a2 = min({h, i});
                int r = a1 % a2;
                while (r != 0) {
                    a1 = a2;
                    a2 = r;
                    r = a1 % a2;
                }
                r = a2;
                a1 = max({r, j});
                a2 = min({r, j});
                r = a1 % a2;
                while (r != 0) {
                    a1 = a2;
                    a2 = r;
                    r = a1 % a2;
                }
                c += a2;
            }
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3624
import numpy as np
N, K, Q = map(int, input().split())
score = np.array([K]*N)

for _ in range(Q):
    n = int(input())
    score[n-1] = score[n-1] + 1

score=score-Q

for i in score:
    print("Yes" if i>0 else "No")

Measured memory_bytes: 21264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A1 = sc.nextInt(), A2 = sc.nextInt(), A3 = sc.nextInt();
		sc.close();
		int a1 = Math.abs(A1 - A2), a2 = Math.abs(A2 - A3), a3 = Math.abs(A3 - A1);
		int max = Math.max(a1, Math.max(a2, a3));
		System.out.println(a1 + a2 + a3 - max);
	}
}


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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
constexpr int mx = 2000;
constexpr long long inf = 1ll << 60;

int N;
int a[mx + mx], c[mx + mx];
int sum[mx + mx][mx + 1][2];
int pos[mx][2];
long long dp[mx + mx + 1][mx + 1];

// solve
int main(){

    cin >> N;
    rep(i, N + N){
        char t;
        cin >> t >> a[i];
        c[i] = int(t == 'B');
        pos[--a[i]][c[i]] = i;
    }

    rep(i, N + N - 1){
        rep(j, N)rep(k, 2)sum[i + 1][j][k] += sum[i][j][k];
        rep(j, 0, a[i])sum[i + 1][j][c[i]]++;
    }

    rep(i, N + N + 1)rep(j, N + 1)dp[i][j] = inf;
    dp[0][0] = 0;

    rep(i, N + N){
        rep(j, 0, min(i, N)){
            if(i - j < N)chmin(dp[i + 1][j], dp[i][j] + sum[pos[i - j][1]][i - j][1] + sum[pos[i - j][1]][j][0]);
            if(j < N)chmin(dp[i + 1][j + 1], dp[i][j] + sum[pos[j][0]][i - j][1] + sum[pos[j][0]][j][0]);
        }
    }

    cout << dp[N + N][N] << '\n';
    return 0;

}


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

namespace ConsoleApplication1
{
    class Program
    {
        static readonly int MAX = 1000000;

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            var hamming = new List<int>();
            int j2 = 0, j3 = 0, j5 = 0;
            int x2 = 1, x3 = 1, x5 = 1;
            int min = 0;

            for (int i = 0; min < MAX; i++)
            {
                min = x2;
                min = Math.Min(min, x3);
                min = Math.Min(min, x5);

                hamming.Add(min);

                while (x2 <= min) x2 = 2 * hamming[j2++];
                while (x3 <= min) x3 = 3 * hamming[j3++];
                while (x5 <= min) x5 = 5 * hamming[j5++];
            }

            while (true)
            {
                int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                if (input[0] == 0) break;

                int l = LowerBound(hamming, input[0]);
                int r = UpperBound(hamming, input[1]);

                sb.AppendLine((r - l).ToString());
            }
            Console.Write(sb);
        }

        static int LowerBound(List<int> arr, int value)
        {
            int low = 0, high = arr.Count;

            while (low < high)
            {
                int mid = ((high - low) >> 1) + low;

                if (arr[mid] < value) low = mid + 1;
                else high = mid;
            }
            return low;
        }

        static int UpperBound(List<int> arr, int value)
        {
            int low = 0, high = arr.Count;

            while (low < high)
            {
                int mid = ((high - low) >> 1) + low;

                if (arr[mid] <= value) low = mid + 1;
                else high = mid;
            }
            return low;
        }
    }
}

Measured memory_bytes: 9060
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

typedef struct _dice {
    int surface[6];
    int init_surface[6];

    void input(){
        for(int i=0;i<6;i++) {
            cin >> init_surface[i];
        }
        init();
    }

    void init(){
        for(int i=0;i<6;i++) {
            surface[i] = init_surface[i];
        }
    }

    void roll_N(){
        int tmp = surface[5];
        surface[5] = surface[4];
        surface[4] = surface[0];
        surface[0] = surface[1];
        surface[1] = tmp;
    }

    void roll_E(){
        int tmp = surface[5];
        surface[5] = surface[2];
        surface[2] = surface[0];
        surface[0] = surface[3];
        surface[3] = tmp;
    }

    void roll_S(){
        int tmp = surface[5];
        surface[5] = surface[1];
        surface[1] = surface[0];
        surface[0] = surface[4];
        surface[4] = tmp;
    }

    void roll_W(){
        int tmp = surface[5];
        surface[5] = surface[3];
        surface[3] = surface[0];
        surface[0] = surface[2];
        surface[2] = tmp;
    }

} Dice;

int main(){
    Dice dice;
    dice.input();
    int n,a,b;
    cin >> n;
    while(n--){
        cin >> a >> b;
        dice.init();
        if(a == dice.init_surface[5]) {
            dice.roll_N();
            dice.roll_N();
        } else if(a == dice.init_surface[1]) {
            dice.roll_N();
        } else if(a == dice.init_surface[4]) {
            dice.roll_S();
        } else if(a == dice.init_surface[2]) {
            dice.roll_W();
        } else if(a == dice.init_surface[3]) {
            dice.roll_E();
        }

        if(dice.surface[1] == b) cout << dice.surface[2] << endl;
        else if(dice.surface[2] == b) cout << dice.surface[4] << endl;
        else if(dice.surface[4] == b) cout << dice.surface[3] << endl;
        else if(dice.surface[3] == b) cout << dice.surface[1] << endl;
    }
}


Measured memory_bytes: 3068
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string l;
    cin >> l;

    long long mod = 1000000007;

    vector<long long> dp0(l.size(), 0), dp1(l.size(), 0);
    dp0[0] = 2;
    dp1[0] = 1;
    for (int i = 1; i < static_cast<int>(l.size()); i++) {
        if (l[i] == '0') {
            dp0[i] += dp0[i - 1];
            dp1[i] += 3 * dp1[i - 1];
        } else {
            dp0[i] += 2 * dp0[i - 1];
            dp1[i] += dp0[i - 1];
            dp1[i] += 3 * dp1[i - 1];
        }

        dp0[i] %= mod;
        dp1[i] %= mod;
    }

    cout << (dp0[l.size() - 1] + dp1[l.size() - 1]) % mod << endl;
}


Measured memory_bytes: 2048
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        int num =1;
        for(int i = 0;i < N; i+=1){
            num = sc.nextInt();
            count += isPrime(num);
        }
        System.out.println(count);
    }
    public static int isPrime(int num){
        for(int i = 2;i*i <= num;i +=1){
            if( num %i == 0){return 0;}
        }
        return 1;
    }
}


Measured memory_bytes: 41068
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;

int main(){
  char find_str[10];
  int ling_qty;

  scanf("%s",&find_str);
  scanf("%d",&ling_qty);
 
  char str_buff[11];
  char str_sum[20];

  int find_count = 0;
  for(int i = 0; i < ling_qty; i++){
    scanf("%s",str_buff);
    strcpy(str_sum,str_buff); 
    strcat(str_sum,str_buff);
    if(strstr(str_sum,find_str) != NULL) find_count++;
  }
  printf("%d\n",find_count); 
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


struct edge { int to, cost; };
struct dijkstra {
    vector<vector<edge>> g;
    vector<int> d;
    vector<int> from_v;
    int V;
    
    dijkstra(int v){
        V = v;
        d.resize(V);
        g.resize(V);
        from_v.assign(V,-1);
    }
    
    void solve_d(int s){
        from_v[s] = 1;
        pq1<pii> que;
        rep(i,V) d[i] = infi;
        d[s] = 0;
        que.push({0,s});
        
        while (!que.empty()) {
            pii p = que.top();
            que.pop();
            int v = p.se;
            if(d[v] < p.fi) continue;
            rep(i,int(g[v].size())){
                edge e = g[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    from_v[e.to] = v;
                    que.push({d[e.to],e.to});
                }
            }
        }
    }
    
    int dis(int a){
        return d[a];
    }
};



int main(){

    int N;
    cin >> N;
    vi h(N);
    
    in(N,h);
    
    dijkstra G(N);
    rep(i,N-1) G.g[i].pb({i+1,abs(h[i]-h[i+1])});
    rep(i,N-2) G.g[i].pb({i+2,abs(h[i]-h[i+2])});
    
    G.solve_d(0);
    cout << G.d[N-1] << endl;
    
    

    return 0;
}


Measured memory_bytes: 7548
@n = gets.to_i
S = gets.split(' ').map(&:to_i)
q = gets.to_i
T = gets.split(' ').map(&:to_i)

count = 0

def linearSearch(arr, target)
  i = 0
  arr[@n] = target # 番兵
  while(arr[i] != target)
    i += 1

    return nil if(i == @n)
  end
  return true
end

T.each do |t|
  count += 1 if linearSearch(S.dup, t)
end

puts count



Measured memory_bytes: 15348
#include <cstdio>
#include <algorithm>
int readint() {
	char ch = getchar();
	int res = 0; bool f = false;
	if (ch == '-') {
		f = true;
		ch = getchar_unlocked();
	}
	while ('0' <= ch && ch <= '9') {
		res = res * 10 + ch - '0';
		ch = getchar_unlocked();
	}
	if (f) res = -res;
	return res;
}
int main() {
	int A[50176];
	// step #1. read input
	int N = readint();
	int H = (N >> 1);
	for (int i = 0; i < H; ++i) A[i] = readint();
	if (N & 1) readint();
	for (int i = H - 1; i >= 0; --i) A[i] += readint();
	// step #2. calculate the answer
	long long ans = 0;
	for (int i = 1; i < N; ++i) {
		long long sum = 0;
		int pos = i;
		while (pos < H) {
			sum += A[pos];
			ans = std::max(ans, sum);
			pos += i;
		}
		if ((N - 1) % i != 0) {
			pos = (N - 1) - pos;
			while (pos >= i) {
				sum += A[pos];
				ans = std::max(ans, sum);
				pos -= i;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1796
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String r = sc.next();
        String g = sc.next();
        String b = sc.next();
        int num = Integer.parseInt(r + g + b);
        if (num % 4 == 0) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    string t;
    int i,j=0;
    cin>>s>>t;
    int len1=s.length();
    int len2=t.length();
    for(i=0;i<len1;i++)
    {
        if(s[i]==t[i])
           j++;
    }
    if(j==len1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>
#include <cstring>

using namespace std;

#define ll long long
#define MOD 1000000007
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

//辺を表す構造体(行き先,容量、逆辺)
struct edge { int to, cap, rev; };

vector<edge> G[1000];
bool used[1000];

//　fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap) {
    G[from].push_back({ to, cap, (int)G[to].size() });
    G[to].push_back({ from, 0, (int)G[from].size() - 1 });
}

//増加パスをDFSで探す
int dfs(int v, int t, int f) {
    if (v == t) return f;

    used[v] = true;
    for (int i = 0; i < (int)G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t) {
    int flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if (f == 0)return flow;
        flow += f;
    }
}


int main() {
    int V, E;
    cin >> V >> E;

    rep(i, E) {
        int from, to, cap;
        cin >> from >> to >> cap;
        add_edge(from, to, cap);
    }

    cout << max_flow(0, V - 1) << endl;
}


Measured memory_bytes: 3196
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	cnt = input[0]-0;
	var t = [0];
	var x = [0];
	var y = [0];
	//文字列から10進数に変換するときはparseIntを使います
	var ret = "Yes";
	for (i=1; i<=cnt; i++)
	{
		tmp = input[i].split(" ");
		t.push(tmp[0]-0);
		x.push(tmp[1]-0);
		y.push(tmp[2]-0);
		if ( Math.abs(t[i-1]-t[i]) < Math.abs(x[i-1]-x[i]) + Math.abs(y[i-1]-y[i]) )
		{
			ret = "No";
			break;
		}
		if ( (Math.abs(t[i-1]-t[i]) - (Math.abs(x[i-1]-x[i]) + Math.abs(y[i-1]-y[i]))) % 2 != 0 )
		{
			ret = "No";
			break;
		}
	}
	//出力
	console.log('%s',ret);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 54580
MOD = 10 ** 9 + 7 

N = int(input())
A = list(map(int, input().split()))

S = sum(A) % MOD
ans = 0

for x in A:
    S -= x  
    S %= MOD  
    ans += S * x
    ans %= MOD

ans %= MOD 
print(ans)

Measured memory_bytes: 31388
N = int(input())
a = list(map(int,input().split()))
d = {}
for c in a:d[c]=d.get(c,0)+1
l = []
sq = []
for k in d.keys():
    if d[k]>=4:sq.append(k)
    if d[k]>=2:l.append(k)

area = 0
if len(sq)>=1:
    area = max(sq) * max(sq)

if len(l)>=2:
    l1 = sorted(l,reverse = True)
    area = max(area,l1[0]*l1[1])
    print(area)
else:print(0)

Measured memory_bytes: 18060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main (void){
    int a, b, c;
    cin >> a >> b >> c;
    if ((a == b && a != c) || (b == c && b != a) || (c == a && c != b)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;

int main(){
    int a, b; cin >> a >> b;
    double x = 0.08;
    double y = 0.1;
    int ans = -1;
    for(int i = 0; i < 2510; ++i){
        int m = (int)(i * x);
        int n = (int)(i * y);
        if(m == a && n == b) {ans = i; break;}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin >>a>>b;
    cout << a - 1 + (b>=a);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

	bool ok = false;
	if (n % 10 == 9) ok = true;
	if (n / 10 == 9) ok = true;

	cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] x = new int[N];
		for (int i = 0; i < N; i++)
			x[i] = sc.nextInt();
		long ans = Math.abs(X - x[0]);
		for (int i = 1; i < N; i++)
			ans = gcd(Math.abs(X - x[i]), ans);

		System.out.println(ans);
	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

int main(){
  char b;
  cin >> b;
  
  if(b == 'A'){
    cout << 'T' << endl;
  }else if(b == 'T'){
    cout << 'A' << endl;
  }else if(b == 'G'){
    cout << 'C' << endl;
  }else if(b == 'C'){
    cout << 'G' << endl;
  }
  
  return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, n) for(long i = x; i < n; i++)
#define erep(i, x, n) for(long i = x; i <= n; i++)
const long MOD = 1000000007;
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;

string sx, t;
bool check(string s){
  long N = s.size();
  rep(i, 0, N){
    if(s[i] != t[i] && s[i] != '?') return false;
  }
  return true;
}


int main(){
cin >> sx >> t;
string ans;
bool notfirst = false;
long sxn = sx.size(); long tn = t.size();
erep(i, 0, sxn-tn){
  string tmp = sx.substr(i, tn);
  if(check(tmp) == true){
    string sxtmp = sx;
    rep(j, 0, sxn){
      if(sxtmp[j] == '?'){
        if(j < i || j > i+tn-1){
          sxtmp[j] = 'a';
        }
        else{
          sxtmp[j] = t[j-i];
        }
      }
    }
    if(notfirst == false) {
      ans = sxtmp;
      notfirst = true;
    }
    if(sxtmp < ans && notfirst == true){
      ans = sxtmp;
    }
  }
}
if(notfirst == true) {
  show(ans);
}
else show("UNRESTORABLE");
return 0;
}

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

int main(){
    int a,b;
    char op;
    
   
    
    while(1){
        cin>>a>>op>>b;
    
    if(op=='+'){
        cout<<a+b<<endl;
    }else if(op=='-'){
        cout<<a-b<<endl;
    }else if(op=='*'){
        cout<<a*b<<endl;
    }else if(op=='/'){
        cout<<a/b<<endl;
    }else if(op=='?'){
        break;
    }
    
    }
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;
 
long long mod = 1000000007;
 
long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}
 
void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
 
int main() {
    long long n, a = 0, max = 0;
    cin >> n;
    vector<int> bs(n);
    vector<string> as(n);
    vector<string> cs(n, "0");
    map<string, int> cnt;
    for (int i = 0; i < n; i++){
        cin >> as[i];
        cnt[as[i]]++;
        if (cnt[as[i]] >= max){
            max = cnt[as[i]];
        }
    }
    for (int i = 0; i < n; i++){
        if (cnt[as[i]] >= max){
            bs[i] = 1;
            cnt[as[i]]--;
        }
    }
    for (int i = 0; i < n; i++){
        if (bs[i] == 1){
            cs[i] = as[i];
        }
    }
    sort(cs.begin(), cs.end());
    for (int i = 0; i < n; i++){
        if (cs[i] != "0"){
            cout << cs[i] << endl;
        }
    }
}

Measured memory_bytes: 27776
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func main() {
	io := NewIo()
	defer io.Flush()

	r := io.NextInt()
	D := io.NextInt()
	x_2000 := io.NextInt()

	for i := 2001; i <= 2010; i++ {
		x_2000 = r*x_2000 - D
		io.PrintLn(x_2000)
	}
}


Measured memory_bytes: 640
# 直接的な実装

n = int(input())
data_list = list()
for i in range(n):
    data = list(map(int,input().split()))
    data_list.append(data)

apart = [[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],'####################',[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],'####################',[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],'####################',[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0]]

for data in data_list:
    apart[((data[0]-1)*4)+(data[1]-1)][data[2]-1] = apart[((data[0]-1)*4)+(data[1]-1)][data[2]-1] + data[3]

for ridge in apart:
    if str(ridge[0]).isdigit():
        ridge = [str(i) for i in ridge]
        print('',' '.join(ridge))
    else:
        print(ridge)



Measured memory_bytes: 5632
import sys
sys.setrecursionlimit(2000)

N = int(input())

# def Lucas(x):
#     if x == 2:
#         return 1
#     if x == 1:
#         return 2
#     return Lucas(x - 1) + Lucas(x - 2)
# answer = Lucas(N)

L = [0] * (N+1)
L[0] = 2
L[1] = 1
for i in range(2, N+1):
    L[i] = L[i-1] + L[i-2]

print(L[N])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  if(n[0]=='1'){
    n[0]='9';
  } else if (
    n[0]=='9'
  ){
    n[0]='1';
  }
  if(n[1]=='1'){
    n[1]='9';
  } else if (
    n[1]=='9'
  ){
    n[1]='1';
  }
  if(n[2]=='1'){
    n[2]='9';
  } else if (
    n[2]=='9'
  ){
    n[2]='1';
  }

  cout << n << endl;
}


Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let ab = (0..n)
        .map(|_| (sc.read(), sc.read()))
        .collect::<Vec<(usize, usize)>>();

    if ab.iter().all(|&(a, b)| a == b) {
        println!("0");
    } else {
        let sum: usize = ab.iter().map(|&(_, b)| b).sum();
        let min_b = ab
            .iter()
            .filter(|&&(a, b)| a > b)
            .map(|&(_, b)| b)
            .min()
            .unwrap();
        println!("{}", sum - min_b);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
	using namespace std;
	#define xxx ios::sync_with_stdio(),cin.tie(0),cout.tie(0)
	#define rep(i,n) for(int i=0;i<n;i++)
	#define int long long
	
	
	
	signed main(){
		int test=1;
		//cin>>test;
		while(test--){
			int n;
			cin>>n;
			int a[n+1];
			int cont=0;
			for(int i=1;i<=n;i++){
				cin>>a[i];
				if(i%2==1 && a[i]%2 ==1) cont++;
			}

			cout<<cont<<endl;
		}
		return 0;
	}

Measured memory_bytes: 3628
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  string S;
  cin >> S;
  int l, r;
  r = S.size() / 2;
  l = S.size() - 1 - r;
  if (S[l] != S[r]) {
    cout << S.size() / 2 << endl;
    return 0;
  }
  char c = S[l];
  while (l >= 0 && r < S.size()) {
    if (S[l] != c || S[r] != c) break;
    l--;
    r++;
  }
  cout << r << endl;

  return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
import numpy as np


def solve(a: int, b: int, c: int, d: int):
    ans = max([a*c, a*d, b*c, b*d])
    print(ans)
    return

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    solve(a, b, c, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27152
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> d(N);
  for(int i=0;i<N;i++){
    cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  int s=1;
  for(int i=0;i<N-1;i++){
    if(d.at(i)!=d.at(i+1))
      s++;
  }
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int ans;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> L(N);
    for (auto &l : L) cin >> l;
    sort(L.begin(), L.end());
    for (int i = 0; i < N; ++i) for (int j = i+1; j < N; ++j) {
        int u = lower_bound(L.begin(), L.end(), L[i]+L[j])-L.begin();
        ans += max(0, u-(j+1));
    }
    printf("%d\n", ans);
    return 0;
}


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


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector <vector <long long> > DP;
    int N, WagaMax;
    cin >> N >> WagaMax;
    long long Suma = 0;
    vector <long long> A(N+1);
    vector <long long> W(N+1);
    for (int i = 1; i <= N; i++){
        cin >> W[i] >> A[i];
        Suma += A[i];
    }
    
    DP.resize(N+1, vector <long long>(Suma+1, WagaMax+1)); // dla danej sumy wartosci jaka jest najmniejsza waga
    DP[0][0] = 0;
    for (int i = 1; i<=N; i++){
        long long Wartosc = A[i];
        for (int j = Suma; j>=Wartosc; j--){
            DP[i][j] = min(DP[i][j], DP[i-1][j-Wartosc]+W[i]);
        }
        for (int j = Suma; j>=0; j--){
            DP[i][j] = min(DP[i][j], DP[i-1][j]);
        }
    }

    // for (auto v : DP){
    //     for (auto co : v){
    //         cerr << co << " ";
    //     }
    //     cerr << "\n";
    // }
    // cerr << "===========\n";
    long long Res = 0;
    for (int i = 0; i<=Suma; i++){
        if (DP[N][i] <= WagaMax){
            Res = i;
        }
    }
    cout << Res;



}

Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] line = sc.nextLine().split(" ");

        int[] data = new int[line.length];
        for (int i = 0; i < data.length; i++) {
        	data[i] = Integer.parseInt(line[i]);
		}

        Dice dice = new Dice(data);

        char[] moveData = sc.nextLine().toCharArray();
        for (int i = 0; i < moveData.length; i++) {
        	dice.move(moveData[i]);
        }

        System.out.println(dice.getTop());
        sc.close();
    }
}

class Dice {
	private int top;
	private int bottom;
	private int left;
	private int right;
	private int front;
	private int back;


	Dice(int[] data) {
		this.top    = data[1 - 1];
		this.bottom = data[6 - 1];
		this.left   = data[4 - 1];
		this.right  = data[3 - 1];
		this.front  = data[2 - 1];
		this.back   = data[5 - 1];
	}

	public void move(char m) {
		int temp = -1;
		switch (m) {
		case 'N':
			temp = this.top;
			this.top    = this.front;
			this.front  = this.bottom;
			this.bottom = this.back;
			this.back   = temp;

			break;

		case 'E':
			temp = this.top;
			this.top    = this.left;
			this.left   = this.bottom;
			this.bottom = this.right;
			this.right  = temp;

			break;

		case 'W':
			temp = this.top;
			this.top    = this.right;
			this.right  = this.bottom;
			this.bottom = this.left;
			this.left   = temp;

			break;

		case 'S':
			temp = this.top;
			this.top    = this.back;
			this.back   = this.bottom;
			this.bottom = this.front;
			this.front  = temp;

			break;
		}
	}

	public int getTop() {
		return this.top;
	}
}

Measured memory_bytes: 26160