akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define rep(i,N) For(i,0,N)
#define pb push_back
const ll inf=1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,N,M,L,a,b,c,Q,cnt;
  cin>>N>>M>>L;
  pmat v(N,pvec(N,datas(-1,0)));
  pmat g(N);
  rep(i,M){
    cin>>a>>b>>c;
    a--;b--;
    if(c<=L){
      g[a].pb(datas(b,c));
      g[b].pb(datas(a,c));
    }
  }
  tdata pbdata;
  rep(i,N){
    cnt=0;
    priority_queue<tdata,vector<tdata>,greater<tdata>> que;
    que.push(tdata(datas(0,0),i));
    while(cnt<N&&!que.empty()){
      auto x=que.top();que.pop();
      if(v[i][x.second].first!=-1)continue;
      cnt++;
      v[i][x.second]=x.first;
      for(auto j:g[x.second]){
        if(v[i][j.first].first!=-1)continue;
        Q=j.second+x.first.second;
        if(Q<=L){
          pbdata=tdata(datas(x.first.first,Q),j.first);
          que.push(pbdata);
        }else{
          pbdata=tdata(datas(x.first.first+1,j.second),j.first);
          que.push(pbdata);
        }
      }
    }
  }
  cin>>Q;
  while(Q--){
    cin>>a>>b;
    a--;b--;
    cout<<v[a][b].first<<endl;
  }
  return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

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

  int ans = 0;
  rep (i, n) {
    bool f = true;
    rep (j, i) if (h[i] < h[j]) f = false;
    if (f) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int R,C,i,j,r[105]={0},c[105]={0},t;
	scanf("%d%d",&R,&C);
	for(i=0;i<=R;i++)
		for(j=0;j<=C;j++)
		{
			if(i<R&&j<C)
			{
				scanf("%d",&t);
				r[i]+=t;c[j]+=t,c[C]+=t;
			}
			printf("%d%s",i==R?c[j]:j==C?r[i]:t,j==C?"\n":" ");
		}
	return 0;
}

Measured memory_bytes: 600
fun main(args: Array<String>) {
    val (A, B) = listOfLong()
    val G = gcd(A, B)
    val C = factorize(G)
    println(C.count() + 1)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
tailrec fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun factorize(N: Long): MutableList<Pair<Long, Int>> {
    val list = mutableListOf<Pair<Long, Int>>()
    var n = N
    var i = 2L
    while (i * i <= n) {
        if (n % i == 0L) {
            var m = 0
            while (n % i == 0L) {
                n /= i
                m += 1
            }
            if (m > 0) list.add(Pair(i, m))
        }
        i += 1L
    }
    if (n != 1L) list.add(Pair(n, 1))
    return list
}


Measured memory_bytes: 37900
#include <bits/stdc++.h>
#define MOD 100000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }


int main(){
    ll N;
    cin >> N;
    VL A(N);
    FOR(i, 0, N) cin >> A[i];

    sort(ALL(A));

    bool ans = true;
    for (ll i = 0; i < N - 1; i++){
        if(A[i] == A[i + 1]) ans = false;
    }

    cout << (ans ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	class P implements Comparable<P> {
		double x;
		int y;

		P(double x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(P t) {
			return (this.x - t.x) > 0 ? 1 : -1;
		}
	}

	class S implements Comparable<S> {
		int s;
		int e;
		double cost;

		S(int s, int e, double cost) {
			this.s = s;
			this.e = e;
			this.cost = cost;
		}

		public int compareTo(S t) {
			return (cost - t.cost) > 0 ? 1 : -1;
		}

	}

	void run() {
		for (;;) {
			int N = sc.nextInt();
			if (N == 0) {
				break;
			}
			int x[] = new int[N];
			int y[] = new int[N];

			boolean[] map = new boolean[1001];

			LinkedList<P> l = new LinkedList<P>();

			for (int i = 0; i < N; i++) {
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
				map[y[i]] = true;
				l.add(new P(x[i], y[i]));
			}

			for (int h = 0; h < 1001; h++) {
				if (map[h]) {
					for (int i = 0; i < N - 1; i++) {
						if ((y[i + 1] - h) * (h - y[i]) > 0) {
							double r = ((double) h - y[i]) / (y[i + 1] - y[i]);
							double x2 = (x[i + 1] - x[i]) * r + x[i];

							l.add(new P(x2, h));
						}
					}
				}
			}

			Collections.sort(l);

			P[] p = l.toArray(new P[0]);
//			System.err.println(p.length);
			boolean cost[][] = new boolean[p.length][p.length];
			for(int i = 0; i < p.length;i++){
				Arrays.fill(cost[i], false);
			}
			PriorityQueue<S> q = new PriorityQueue<S>();
			q.add(new S(0, p.length - 1, 0));

			double answer = Double.MAX_VALUE;
			for (;;) {
				if (q.isEmpty()) {
					break;
				}

				S s = q.poll();

				
				if (cost[s.s][s.e]) {
					continue;
				}
				cost[s.s][s.e] = true;
				if(s.s == s.e){
					answer = Math.min(s.cost,answer);
					continue;
				}
//				System.out.println(s.s+" "+s.e);
				
				for (int i = -1; i < 2; i++) {
					for (int j = -1; j < 2; j++) {
						if ((i | j) == 0) {
							continue;
						}

						if (s.s + i < 0) {
							continue;
						}
						if (s.e + j > p.length - 1) {
							continue;
						}
						if( s.s+i > p.length-1){
							continue;
						}
						if(s.e+j < 0){
							continue;
						}
						if(p[s.s+i].y == p[s.e+j].y){
//							System.out.println("here");
							double dc = 0;
							dc += ( p[s.s+i].x - p[s.s].x )*( p[s.s+i].x - p[s.s].x );
							dc += ( p[s.s+i].y - p[s.s].y )*( p[s.s+i].y - p[s.s].y );
							dc = Math.sqrt(dc);

							double dd = 0;
							dd += ( p[s.e+j].x - p[s.e].x )*( p[s.e+j].x - p[s.e].x );
							dd += ( p[s.e+j].y - p[s.e].y )*( p[s.e+j].y - p[s.e].y );
							dd = Math.sqrt(dd);

							if(!cost[s.s+i][s.e+j]){
//								System.out.println("abs");
								q.add(new S(s.s+i,s.e+j,dc+dd+s.cost));
							}
						}
					}
				}
			}
			System.out.println(answer);
		}

	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 54000
import java.io.*;
import java.util.regex.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        reader.readLine();
        String S = reader.readLine();
        Matcher m = Pattern.compile("ABC").matcher(S);
        int ans = 0;
        while (m.find())
            ans++;
        System.out.println(ans);
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <tuple>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <bitset>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define all(v) (v).begin(),(v).end()
#define clr(a,b) memset((a),(b),sizeof(a))
#define sz size()
#define pb push_back
#define print(x) cout << x << endl
int n,m,l,o;
string s,t,ans;
int x[100];
char fes[50],p;

int main(){
  cin >> fes;
  t = "FESTIVAL";
  n = 0;
  while(p != '\n'){
    if(fes[n] == t[0] && fes[n+1] == t[1] && fes[n+2] == t[2] &&
        fes[n+3] == t[3] && fes[n+4] == t[4] && fes[n+5] == t[5] &&
        fes[n+6] == t[6] && fes[n+7] == t[7] && fes[n+8] == t[8])break;
    s += fes[n];
    n++;
  }
  print(s);
  return 0;
}


Measured memory_bytes: 384
N, A, B = map(int, input().split())
S = input()
a = 0
b = 0
for i in range(N):
  if S[i] == "a" and a + b < A + B:
    print("Yes")
    a += 1
  elif S[i] == "b" and a + b < A + B and b < B:
    print("Yes")
    b += 1
  else:
    print("No")

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

int dp[2222][(1<<11)];
int R[2222][2222];
int S,N,M;
int n;
const int INF = (1000000009);

bool update(int &a,int b){
  if( a > b ) { a = b; return true; }
  return false;
}

void update(int id,int a,int b,int l,int r){
  int j = (a+b)/2;
  if( a>b ) return;
  int mk = 0;
  for(int k=l;k<=min(j-1,r);k++){
    if( update( dp[id][j], dp[id-1][k] + R[j][k] ) ){
      mk = k;
    }
  }
  if( b-a == 0 ) return;
  update(id,a,j-1,l,mk);
  update(id,j+1,b,mk,r);  
}


int solve(){
  fill( dp[0],dp[M+1], INF );
  dp[0][0] = 0;
  for(int i=1;i<=min(N,M);i++){
    update(i,i,N,0,N);      
  }
  return dp[min(M,N)][N];
}

int K[2222][2222];
int solvek(){
  fill( dp[0],dp[M+1], INF );
  memset(K,0,sizeof(K));
  for(int i=0;i<=max(N,M);i++) K[i][i] = i;
  dp[0][0] = 0;
  for(int i=1;i<=M;i++){
    for(int j=1;j<=N;j++){
      for(int k=0;k<j;k++){
        if( update( dp[i][j], dp[i-1][k] + R[j][k] ) ){
          K[i][j] = k;
        } 
      }
    }
    for(int j=0;dp[i][j]!=0;j++)
      dp[i][j] = 0;    
  }
  return dp[M][N];
}

int main(){
  cin >> S >> N >> M;
  int X[2222],Y[2222];
  for(int i=0;i<S;i++) cin >> X[i];
  
  for(int i=0;i<N;i++){
    int t,p; cin >> t >> p; p--;
    Y[i] = t-X[p];
  }

  sort( Y,Y+N );

  fill( R[0], R[M+1], INF );
  for(int i=0;i<N;i++){
    int sum = 0;
    //cout << " y " << Y[i] << endl;
    for(int j=i;j>-1;j--){
      sum += Y[i] - Y[j];
      R[i+1][j] = sum;
      //cout << "[ " << j << ", " << i+1 << " ) = " << R[i+1][j] << endl;
    }
  }

  cout << solve() << endl;
  
}

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

result = 2020202020
num_left = 0
num_right = sum(a)

for i in range(n):
    num_left += a[i]
    num_right -= a[i]
    result = min(result, abs(num_left - num_right))
print(result)

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

void dfs(const vector<vector<int>> &to, vector<int> &color, int index) {
  for (auto next : to.at(index)) {
    if (color.at(next) != -1) continue;
    color.at(next) = 1 - color.at(index);
    dfs(to, color, next);
  }
}

int main() {
  int n;
  cin >> n;
  vector<vector<int>> to(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to.at(a).push_back(b);
    to.at(b).push_back(a);
  }
  vector<int> color(n, -1);
  color.at(0) = 0;
  dfs(to, color, 0);
  int zeros = 0;
  for (int i = 0; i < n; i++) {
    if (color.at(i) == 0) zeros++;
  }
  vector<int> ans(n), q;
  int i0 = 0, i1 = 0;
  for (int i = 0; 3 * i + 1 <= n; i++) {
    q.push_back(3 * i + 1);
  }
  for (int i = 0; 3 * i + 2 <= n; i++) {
    q.push_back(3 * i + 2);
  }
  for (int i = 0; 3 * i + 3 <= n; i++) {
    q.push_back(3 * i + 3);
  }
  if (zeros <= n / 3) {
    for (int i = 0; i < n; i++) {
      if (color.at(i) == 0) {
        ans.at(i) = q.at(n - 1 - i0);
        i0++;
      } else {
        ans.at(i) = q.at(i1);
        i1++;
      }
    }
  } else if (n - zeros <= n / 3) {
    for (int i = 0; i < n; i++) {
      if (color.at(i) == 1) {
        ans.at(i) = q.at(n - 1 - i0);
        i0++;
      } else {
        ans.at(i) = q.at(i1);
        i1++;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (color.at(i) == 0) {
        ans.at(i) = q.at(((n - 1) / 3 - i0 + n) % n);
        i0++;
      } else {
        ans.at(i) = q.at(((n + 2) / 3 + i1) % n);
        i1++;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans.at(i);
    if (i < n - 1) {
      cout << " ";
    } else {
      cout << endl;
    }
  }
}


Measured memory_bytes: 20984
# D
import sys
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x: x[1])
time = 0
for work in ab:
    if time+work[0] <= work[1]:
        time+=work[0]
    else:
        print('No')
        sys.exit()
print('Yes')

Measured memory_bytes: 88024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
typedef pair<ll,ll> Pair;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }

const ll INF=99999999999999;
const ll MOD=1000000007;
 
int main() {
  ll n;
  cin >> n;
  vl a,b,c;
  inputv(a,n);
  inputv(b,n);
  inputv(c,n-1);
  ll ans = 0;
  ll num = -1;
  rep(i,n){
    if(a[i] == num+1){
      ans += c[num-1];
    }
    ans += b[a[i]-1];
    num = a[i];
  }
  cout << ans;
    
 return 0;
}

Measured memory_bytes: 256
W, H, N = map(int, input().split())
WX = [0, W]
HY = [0, H]
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if WX[0] < x:
            WX[0] = x
    elif a == 2:
        if WX[1] > x:
            WX[1] = x
    elif a == 3:
        if HY[0] < y:
            HY[0] = y
    elif a == 4:
        if HY[1] > y:
            HY[1] = y
if WX[1]-WX[0] < 0 or HY[1]-HY[0] < 0:
    print(0)
else:
    print((WX[1]-WX[0])*(HY[1]-HY[0]))

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>

#define N 4
#define N2 16

typedef struct{
  int f[N2];
  int space;
  int m;
}Puz;

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

int MDT[N2][N2];

int lim;
int path[100];
Puz st;

int getAllMD(Puz Z){
  int i,sum=0;
  for(i=0;i<N2;i++){
    if(Z.f[i] == N2) continue;
    sum+=MDT[i][Z.f[i]-1];
  }
  return sum;
}

void swap(int *a,int *b){
  int tmp;
  tmp=*a;
  *a=*b;
  *b=tmp;
}

char dfs(int df,int p){
  int sx,sy,tx,ty,i,max,min;
  Puz tmp;

  if(st.m==0)return 1;
  if(df+st.m>lim)return 0;

  sx=st.space/N;
  sy=st.space%N;

  for(i=0;i<4;i++){
    tx=sx+dx[i];
    ty=sy+dy[i];

    if(tx<0||tx>=N||ty<0||ty>=N) continue;

    if(p>i){max=p;min=i;}
    else {max=i;min=p;}
    
    if(max-min==2)continue;
    tmp=st;

    st.m-=MDT[tx*N+ty][st.f[tx*N+ty]-1];
    st.m+=MDT[sx*N+sy][st.f[tx*N+ty]-1];

    //printf("st.m=%d\n",st.m);

    swap(&st.f[tx*N+ty],&st.f[sx*N+sy]);

    st.space=tx*N+ty;
    if(dfs(df+1,i)){
      path[df]=i;
      return 1;
    }
    st=tmp;
  }
  return 0;
}

int id(Puz in){
  int i;
  int ans=0;

  in.m=getAllMD(in);

  for(lim=in.m;lim<=100;lim++){
      //  printf("aaa\n");
    st=in;
    if(dfs(0,-100)){
      ans=0;;
      for(i=0;i<lim;i++) ans++;
      return ans;
    }
  }
  return -1;
}

int main(){
  int i,j;
  Puz in; 
  for(i=0;i<N2;i++)
    for(j=0;j<N2;j++)
      MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
  
  for(i=0;i<N2;i++){
    //printf("aaa\n");
    scanf("%d",&in.f[i]);
    if(in.f[i]==0){
      in.f[i]=N2;
      in.space=i;
    }
  }
  
  printf("%d\n",id(in));

  return 0;
}







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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};
 
//debug
//--------------------------------------------
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//roop
//--------------------------------------------
#define rep(i,s,n) for(LL i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < COUNTOF(x);i++) { cout << x[i] << SP; } cout << BR;

int main(){
    LL a, b, x;
    LL cnt = 0;
    cin >> a >> b >> x;
    if (a) cnt = b / x + 1 - ((a-1) / x + 1);
    else cnt = b / x + 1;
    cout << cnt << BR;
}

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

bool	is_removable(const vector<int> &w_vec, int i0, int i1)
{
	return (abs(w_vec.at(i0) - w_vec.at(i1)) < 2);
}

int	main()
{
	int	n;
	while (cin >> n) {
		if (n == 0) break;
		if (n == 1) {
			cout << 0 << endl;
			continue;
		}
		vector<int>	w_vec(n);
		for (int i = 0; i < n; ++i)
			cin >> w_vec.at(i);
		vector<vector<int>>	cnt(n, vector<int>(n, 0));
		for (int i = 0; i < n - 1; ++i) {
			if (is_removable(w_vec, i, i + 1)) {
				cnt.at(i).at(i + 1) = 2;
			}
		}
		for (int i = 1; i < n; ++i) {
			int	k;
			int	tmp_cnt;	
			for (int j = 0; (k = i + j) < n; ++j) {
				if (k < n - 1) {
					tmp_cnt = cnt.at(j).at(k);
					if (cnt.at(j).at(k + 1) < tmp_cnt)
						cnt.at(j).at(k + 1) = tmp_cnt;
				}
				if (0 < j) {
					tmp_cnt = cnt.at(j).at(k);
					if (cnt.at(j - 1).at(k) < tmp_cnt)
						cnt.at(j - 1).at(k) = tmp_cnt;
				}
				if (k < n - 2) {
					for (int l = k + 2; l < n; ++l) {
						tmp_cnt = cnt.at(j).at(k) + cnt.at(k + 1).at(l);
						if (cnt.at(j).at(l) < tmp_cnt)
							cnt.at(j).at(l) = tmp_cnt;
					}
				}
				if (0 < j && k < n - 1 && cnt.at(j).at(k) == k - j + 1) {
					if (is_removable(w_vec, j - 1, k + 1)) {
						tmp_cnt = cnt.at(j).at(k) + 2;
						if (cnt.at(j - 1).at(k + 1) < tmp_cnt)
							cnt.at(j - 1).at(k + 1) = tmp_cnt;
					}
				}
				if (1 < j) {
					for (int l = 0; l < j - 1; ++l) {
						tmp_cnt = cnt.at(j).at(k) + cnt.at(l).at(j - 1);
						if (cnt.at(l).at(k) < tmp_cnt)
							cnt.at(l).at(k) = tmp_cnt;
					}
				}
			}
		}
		cout << cnt.at(0).at(n - 1) << endl;
	}
}



Measured memory_bytes: 3276
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())


l, r = inintm()

ans = 2019

for i in range(l, min(l+2019,r)):
    for j in range(i+1,min(l+2020,r+1)):
        if i*j % 2019 < ans:
            ans = i*j % 2019

print(ans)


Measured memory_bytes: 9352
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n) for(int i=a; i<n; i++)
#define SPEED ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(0)
int main() 
{
	SPEED; 
	int n,m;
	cin>>n>>m;
	if(n==m) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

# . : white
# # : black
# no '#.' sequence

# a list that represents no of stones seen up to the index
nwhite, nblack = [], []

nwhite_current, nblack_current = 0, 0

for c in S:
    if c == '.':
        nwhite_current += 1
    else:
        nblack_current += 1

    nwhite.append(nwhite_current)
    nblack.append(nblack_current)

ans = 0

if nwhite_current != 0 and nblack_current != 0:

    ans = N + 1

    # set a index that starts sequence of black(#)
    for i in range(N):

        ans_current = 0

        # flip all black(#) left to it
        if i > 0:
            ans_current = nblack[i-1]

        # flip all white(.) right to it    
        ans_current += (nwhite_current - nwhite[i])

        ans = min(ans, ans_current)

print(ans)


Measured memory_bytes: 12780
/*
 * D.cpp
 *
 *  Created on: 2020/08/02
 *      Author: 17k1028
 */



#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define REPD(i,n) for(ll i=n-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=a; i<=ll(b); i++)
#define FORD(i,a,b) for(ll i=a; i>=ll(b); i--)

int main(){
	ll N;
	cin >> N;
	char c[N];
	REP(i,N) {
		cin >> c[i];
	}

	ll Rcounter=0;
	REP(i,N){
		if(c[i]=='R') Rcounter++;
	}
	ll Wcounter=0;
	REP(i,Rcounter){
		if(c[i]=='W') Wcounter++;
	}
	cout << Wcounter << endl;
}





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

static constexpr double pi = 3.14159265358979323846;

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double ht = 30 * h + 0.5 * m;
    double mt = 6 * m;

    double t1 = max(ht, mt);
    double t2 = min(ht, mt);
    double t = t1 - t2;

    double c = sqrt(a * a + b * b - 2 * a * b * cos((t / 360) * 2 * pi));

    cout << setprecision(15) << c << endl;
}

Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };
constexpr auto MAX = 100010;

// ──────────────────────────────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.size() - 2; ++i) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
			cnt++;
		}
	}
	cout << cnt << endl;
}

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

int main()
{
    long long n, r1, r2, r3, r4, r5, r6, r7, r8, r9, sum;
    cin >> n;
    r1 = n%10;
    r2 = (n%100)/10;
    r3 = (n%1000)/100;
    r4 = (n%10000)/1000;
    r5 = (n%100000)/10000;
    r6 = (n%1000000)/100000;
    r7 = (n%10000000)/1000000;
    r8 = (n%100000000)/10000000;
    r9 = (n%1000000000)/100000000;
    sum = r1+r2+r3+r4+r5+r6+r7+r8+r9;
    if((n % sum) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[derive(Copy,Clone)]
pub struct Edge{
    to: usize,
    cost: usize,
}

impl Edge{
    pub fn new(to: usize, cost:usize) -> Self{
        Edge{
            to,
            cost,
        }
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        e: [(usize,usize,usize);n-1],
    }

    let mut g :Vec<Vec<Edge>>= vec![vec![];n];

    for (u,v,w) in e{
        g[u-1].push(Edge::new(v-1,w));
        g[v-1].push(Edge::new(u-1,w));
    }

    let mut st = vec![];
    let mut visit = vec![false;n];
    let mut ans = vec![0;n];

    st.push(0);

    while !st.is_empty(){
        let nown = st.pop().unwrap();
        visit[nown] = true;

        for ed in &g[nown]{
            if !visit[ed.to]{
                st.push(ed.to);
                if ed.cost%2 != 0{
                    ans[ed.to] = 1 - ans[nown];
                }else{
                    ans[ed.to] = ans[nown];
                }
            }
        }
    }

    for x in &ans{
        println!("{}",x);
    }
}




Measured memory_bytes: 13776
using System;
using System.Linq;

namespace abc172b
{
    class Program
    {
        static void Main()
        {
            var s = Console.ReadLine();
            var t = Console.ReadLine();
            var cnt = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i])
                {
                    ++cnt;
                }
            }
            System.Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 27240
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    IO
    int N;
    cin>>N;
    ll sum=(ll)N*(N+1)/2;

    for(int X=2;X<=N;X++)
    {
        int Y=N/X;
        sum+=(ll)X*Y*(Y+1)/2;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;
	vector<int>L(N);
	for (int n = 0;n<N;++n) {
		cin >> L[n];
	}
	int ans = 1e9;
	for (int n = 0;n<(1<<2*N);++n) {
		int a = 0;
		int b = 0;
		int c = 0;
		int count = 0;
		int anstmp = 0;
		for (int m = 0;m<N;++m) {
			int tmp = (n>>(2*m))&3;
			if (0 == tmp) {
				a += L[m];
				count++;
			}
			else if (1 ==tmp) {
				b += L[m]; 
				count++;
			}
			else if ( 2== tmp){
				c += L[m]; 
				count++;
			}
		}
		count -= 3;
		if ((0 == a)||(0==b)||(0==c)) {
			continue;
		}
		anstmp += abs(a - A) + abs(b - B) + abs(c - C) + 10*count;
		ans = min(ans,anstmp);
	}
	cout << ans <<endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int main() {

	int n;
	long long int ans =1;

	cin >> n;

	for (int i = n; i > 1; i--) {
		ans *= i;
	}

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

Measured memory_bytes: 1152
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int count = 0;
    string S,T;
    cin >> S >> T;
    for(int i = 0;i < 3;i++){ 
        if(S[i] == T[i]){count++;}
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int e;
    while(cin>>e&&e!=0){
        int minSum=100000000;
        for(int z = 0; z <= 100; z++){
            if(e-(z*z*z)<0)
                break;
            int y = (int)(sqrt((1.0)*e-z*z*z)+(1e-10));
            int x = e-z*z*z-y*y;
            minSum=min(minSum,y+z+x);
            //for(int y = 0; y <= 1000; y++){
            //    if(e-y*y-z*z*z<0)
            //        break;
            //    int x=e-y*y-z*z*z;
            //    minSum=min(minSum,x+y+z);
            //}
        }
        cout<<minSum<<endl;
    }
    return 0;
}

Measured memory_bytes: 0
try:
    while True:
        #標準入力
        num = int(input())
        kei = 0
        #全パターン試す
        for num1 in range(0,10):
            for num2 in range(0,10):
                for num3 in range(0,10):
                    for num4 in range(0,10):
                        #合計が入力値と同じならカウントを増やす
                        if num1 + num2 + num3 + num4 == num:kei += 1
                        else:pass
        #出力
        print(kei)
#EOFErrorをひろう
except EOFError:
    pass


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main() 
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string S; cin >> S;
  int r=0;
  for (auto s : S){
    if (s=='1')r++;
  }

  cout << r << endl;    
  
  return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readLine()?.split(" ")?.map(String::toInt) ?: return
    if (b == 1) {
        println("0")
        return
    }
    var r = a
    var c = 1
    while (r < b) {
        c++
        r += (a - 1)
    }
    println(c.toString())
}

Measured memory_bytes: 37936
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end();
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;

int n;

void update(vector<vector<int>> &dist, vector<vector<bool>> &emp, int y, int x)
{
	int z = dist[y][x];
	if (!emp[y][x])
		++z;

	if (y > 0)
	{
		if (dist[y-1][x] > z)
		{
			dist[y-1][x] = z;
			update(dist, emp, y-1, x);
		}
	}
	if (y < n-1)
	{
		if (dist[y+1][x] > z)
		{
			dist[y+1][x] = z;
			update(dist, emp, y+1, x);
		}
	}
	if (x > 0)
	{
		if (dist[y][x-1] > z)
		{
			dist[y][x-1] = z;
			update(dist, emp, y, x-1);
		}
	}
	if (x < n-1)
	{
		if (dist[y][x+1] > z)
		{
			dist[y][x+1] = z;
			update(dist, emp, y, x+1);
		}
	}
}

int		main(void)
{
	cin >> n;

	vector<int> P(n*n);
	for (int i = 0; i < n*n; ++i)
	{
		cin >> P[i];
	}
	
	vector<vector<bool>> emp(n, vector<bool>(n, false));
	vector<vector<int>> dist(n, vector<int>(n));
	// 00000
	// 01110
	// 01210
	// 01110
	// 00000
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			dist[i][j] = min(min(j, n-j-1), min(i, n-i-1));
		}
	}

	int ans = 0;
	for (int i = 0; i < n*n; ++i)
	{
		int x = P[i] % n - 1;
		if (P[i] % n == 0)
			x = n-1;
		int y = P[i] / n; 
		if (P[i] % n == 0)
			y--;

		ans += dist[y][x];
		emp[y][x] = true;

		update(dist, emp, y, x);
	}
	cout << ans << endl;
}



Measured memory_bytes: 31596
test=raw_input().split(" ")

a=int(test[0])
b=int(test[1])
c=int(test[2])

if b==1 and c==2:
    print("Borys")

else:
    if (b-c-1)%2==0:
        print("Borys")
    else:
        print("Alice")

Measured memory_bytes: 2568
#include <stdio.h>
int main(void){
    int data[100]={0},i,k,n=0;
    for(i=0;i<100;i++){
        scanf("%d",&data[i]);
        n++;
    }
    
    for(i=0;i<n;i++){
        if(data[i]==0){
            for(k=i;k>=0;k--){
                if(data[k]!=0){
                    printf("%d\n",data[k]);
                    data[k]=0;
                    break;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1752
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N;
	vector< string > S(N);
	cout << 0 << endl;
	cout.flush();
	string ret;
	cin >> ret;
	if (ret == "Vacant")
		return 0;
	S[0] = ret;
	cout << N / 2 << endl;
	cout.flush();
	cin >> ret;
	if (ret == "Vacant")
		return 0;
	S[N / 2] = ret;
	int l, r;
	if (S[0] == S[N / 2]) {
		if (N % 4 == 1) {
			l = N / 2;
			r = N;
		} else {
			l = 0;
			r = N / 2;
		}
	} else {
		if (N % 4 == 1) {
			l = 0;
			r = N / 2;
		} else {
			l = N / 2;
			r = N;
		}
	}
	while (r - l > 1) {
		int m = (l + r) / 2;
		cout << m << endl;
		cout.flush();
		cin >> ret;
		if (ret == "Vacant")
			return 0;
		S[m] = ret;
		if ((m - l) % 2 == 0) {
			if (S[l] == S[m]) {
				l = m;
			} else {
				r = m;
			}
		} else {
			if (S[l] == S[m]) {
				r = m;
			} else {
				l = m;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1620
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;

int main(){
  int n, m;cin>>n>>m;
  vector<bool> st(n, false), go(n, false);
  for(int i=0;i<m;i++){
    int a, b;cin>>a>>b;
    a--;b--;
    if(a>b)swap(a, b);
    if(a==0)st[b]=true;
    if(b==n-1)go[a]=true;
  }
  bool ans=false;
  for(int i=0;i<n;i++){
    if(st[i] && go[i]){ans=true;break;}
  }
  cout<<(ans?"POSSIBLE":"IMPOSSIBLE")<<endl;
}


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

int main() {
  int a , b;
  char c;
  cin >> a >> c >> b;

  if (c == '+'){
  	 cout << a+b << endl;
  }
  
  
  else if (c == '-'){
  	 cout << a-b << endl;
  }
 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,a[100]={0},i,j,k,m1,m2;
	long long a1[101][21]={0};
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	k=a[0];
	a1[0][k]+=1;
	for(i=1;i<n-1;i++){
		for(j=0;j<21;j++){
			if(a1[i-1][j]!=0){
				m1=j+a[i];
				m2=j-a[i];
				if(m1<=20){
					a1[i][m1]+=a1[i-1][j];
				}
				if(m2>=0){
					a1[i][m2]+=a1[i-1][j];
				}
			}
		}
	}
	m1=a[n-1];
	cout<<a1[n-2][m1]<<endl;
	return 0;
}

Measured memory_bytes: 3124
#pypyは内包表記使わない, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 1000000007

    a, b = map(int, input().split())
    x = b - a
    print(x*(x-1)//2 - a)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>
int isprime(int );

int main() {
  int n,N=10000,i,arr[N],count=0;
  scanf("%d",&n);  
  for(i=0;i<n;i++){
    scanf("%d",&arr[i]);
    if(arr[i]>=1000*1000*100) i=i-1;
  }
  
 for(i=0;i<n;i++){
   if(isprime(arr[i])==1)count++;
 }
 printf("%d\n",count);
 return 0;
}
   
  int isprime(x) {
    int i;
    if(x == 2 ) return 1;
    
  if(x<2 || x%2==0)
    return 2;
  
   i=3;
  while (i <= sqrt(x)) {
    if(x%i==0)
      return 2;
    i = i+2;
  }
  return 1;
  }

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"a < b"<<endl;
	}
	if(a>b){
		cout<<"a > b"<<endl;
	}
	if(a==b){
		cout<<"a == b"<<endl;
	}
	return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int lenMax = 100005;
    vector<int> sum(lenMax);
    
    int n, c; cin >> n >> c;
    vector<vector<int>> start(c);
    vector<vector<int>> end(c);

    for(int i = 0; i < n; i++){
        int s, t, ch; cin >> s >> t>> ch;
        ch--;
        start[ch].push_back(s);
        end[ch].push_back(t);
    }

    for(int i = 0; i < c; i++){
        vector<int> a(lenMax);
        for(int j = 0; j < start[i].size(); j++){
            a[start[i][j]]++;
            a[end[i][j]+1]--; 
        }
        for(int k = 1; k < lenMax; k++) a[k] += a[k-1];
        for(int k = 0; k < lenMax; k++){
            if(a[k] > 0) sum[k]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < lenMax; i++){
        ans = max(ans, sum[i]);
    }
    cout << ans << endl;
   
    return 0;
}


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

using ll = long long;

const ll maxValue = 1e+9;

ll myPow(ll x, int n) {

    ll retValue = 1;

    while(n > 0) {

        if(n & 1) {
            retValue *= x;
            n--;
        }
        else {
            x *= x;
            n >>= 1;
        }

    }

    return retValue;
}

int main() {

    ll x;
    cin >> x;

    ll a, b;
    a = -1000;

    while(1) {

        ll left = -1000, right = 1000;
        ll a5 = myPow(a, 5);
        ll sum;
        ll mid;
        while(right - left > 1) {
            mid = (right + left) / 2;
            sum = a5 - myPow(mid, 5);

            if(x > sum)
                right = mid;
            else
                left = mid;

        }

        if(sum == x) {
            b = mid;
            break;
        }

        a++;

    }
    

   cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 3564
#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 <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
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;
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=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint A,B;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		A.pb(a);
	}
	for(int i=0;i<N;i++){
		int b;
		cin>>b;
		B.pb(b);
	}
	for(int i=1;i<N;i++){
		A[i]+=A[i-1];
		B[i]+=B[i-1];
	}
	int ans=A[0]+B[N-1];
	for(int i=1;i<N;i++){
		ans=max(ans,A[i]+B[N-1]-B[i-1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
string s;
long long d[100001][2], M = 1e9+7;
long long f(int x, int y){
    long long r = 1;
    if(d[x][y] != -1)return d[x][y];
    if(x == n-1){
        if(y == 1 || s[x] == '1')r = 2 + 1;
        else r = 1;
    }else{
        if(y == 1)r *= f(x+1, 1) * 2 + f(x+1, 1);
        else if(s[x] == '1'){
            r *= f(x+1, 0) * 2 + f(x+1, 1);
        }else{
            r *= f(x+1, 0);
        }
    }
    return d[x][y] = r % M;
    
}
int main(void){
    cin >> s;
    n = s.length();
    for(int i=0;i<n;i++){
        d[i][0] = d[i][1] = -1;
    }
    cout << f(0, 0) << endl;
}


Measured memory_bytes: 6656
N, A, B = map(int, input().split())
if A > B:
    print(0)
    exit()
else:
    if N == 1:
        if A != B:
            print(0)
            exit()
        else:
            print(1)
            exit()
    else:
        # (N-1)*A+B以上 A+(N-1)*B以下の全ての値が可能
        ans = (N - 2) * (B - A) + 1
        print(ans)


Measured memory_bytes: 9064
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  long int a,b=0;cin>>a;
  rep(i,a){
    rep(o,a){
      rep(j,a){
        b+=gcd(i+1,gcd(o+1,j+1));
      }
    }
  }
  cout<<b;
}

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

#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

const int N = 305;

double p[N][N][N], ev[N][N][N];

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

    vector<int> cnt(4);

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

    p[cnt[1]][cnt[2]][cnt[3]] = 1;

    for(int c = n; c >= 0; c--) {
        for(int b = n; b >= 0; b--) {
            for(int a = n; a >= 0; a--) {

                if(a == 0 && b == 0 && c == 0)
                    continue;

                int k = a + b + c;
                if(k > n)
                    continue;

                double p_waste = (double) (n - k) / n;
                double ev_waste = p_waste / (1 - p_waste) + 1;
                ev[a][b][c] += p[a][b][c] * ev_waste;

                if(a) {
                    double p_go = (double) a / k;
                    p[a - 1][b][c] += p[a][b][c] * p_go;
                    ev[a - 1][b][c] += ev[a][b][c] * p_go;
                }

                if(b) {
                    double p_go = (double) b / k;
                    p[a + 1][b - 1][c] += p[a][b][c] * p_go;
                    ev[a + 1][b - 1][c] += ev[a][b][c] * p_go;
                }

                if(c) {
                    double p_go = (double) c / k;
                    p[a][b + 1][c - 1] += p[a][b][c] * p_go;
                    ev[a][b + 1][c - 1] += ev[a][b][c] * p_go;
                }
            }
        }
    }

    cout << setprecision(12) << fixed; 
    cout << ev[0][0][0] << endl;

    return 0;
}

Measured memory_bytes: 221324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

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

  string ans = "";
  while (N > 0) {
    N--;
    ans.push_back('a' + N % 26);
    N /= 26;
  }

  for (int i = 0; i < ans.length(); i++) {
    cout << ans[ans.length() - i - 1];
  }

  cout << endl;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int k; cin >> k;
    set<string> m;
    for(int i = 0; i < s.size(); i++) {
        for(int j = i; j < s.size() && j <i+k+1; j++) {
            string s2 = s.substr(i,j-i+1);
            m.insert(s2);
        }
    }
    auto ans = m.begin();
    rep(i,k-1) {
        ans++;
    }
    cout << *ans << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

double dp_table(int i, int j, int k, const int n,
                vector<vector<vector<double>>>& dp)
{
    if (dp[i][j][k] > 0.0) return dp[i][j][k];
    if (i == 0 && j == 0 && k == 0) return 0.0;

    double next = static_cast<double>(n);
    if (i > 0) next += dp_table(i - 1, j, k, n, dp) * i;
    if (j > 0) next += dp_table(i + 1, j - 1, k, n, dp) * j;
    if (k > 0) next += dp_table(i, j + 1, k - 1, n, dp) * k;
    return dp[i][j][k] = (next / static_cast<double>(i + j + k));
}

int main()
{
    int n;
    cin >> n;
    int n1{0}, n2{0}, n3{0};
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        if (a == 1)
            n1++;
        else if (a == 2)
            n2++;
        else
            n3++;
    }

    vector<vector<vector<double>>> dp(
        n1 + n2 + n3 + 5,
        vector<vector<double>>(n1 + n2 + n3 + 5,
                               vector<double>(n1 + n2 + n3 + 5, 0.0)));
    cout << setprecision(12) << dp_table(n1, n2, n3, n, dp) << endl;
    return 0;
}

Measured memory_bytes: 225664
N, M = map(int, input().split())
res = [0] * (M + 1)
res2 = 0
for _ in range(N):
  a = list(map(int, input().split()))
  for i in range(1, a[0] + 1):
    res[a[i]] += 1
for i in range(M + 1):
  if res[i] == N:
    res2 += 1
print(res2)

Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <cmath>
#include <set>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define v g[i].y
using namespace std;
typedef long long ll;
typedef double db;
int n, m = 100, p, q;
char s[205];
int main()
{
	cin >> n >> s + 1;
	Rep(i, 1, n) {
		p += (s[i] == '(' ? 1 : -1);
		q = min(p, q);
	}
	Rep(i, 1, -q) printf("(");
	Rep(i, 1, n) printf("%c", s[i]);
	Rep(i, 1, p - q) printf(")");
	puts("");

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
main()
{
	int A,B,C;
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	if(A!=B&&B!=C&&C!=A){
		printf("3");}
	else if(A==B&&B==C&&A==C){
		printf("1");}
	else{
		printf("2");}
		return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc150/tasks/abc150_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int c, int d) { return c / gcd(c, d) * d; }

void solve() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) { cin >> A[i]; }
    int t = A[0];
    REP(i, N) { t = lcm(t, A[i]); }
    REP(i, N) {
        if ((t / A[i]) % 2 == 0) {
            cout << "0\n";
            return;
        }
    }
    cout << (M + t / 2) / t << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 4000
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <sstream>
#include <set>
typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}
using namespace std;
int main(){
   int a,b;

   cin >> a >> b;
   a *= 3;
   a+= b;

   cout << a/2<<endl;

}

Measured memory_bytes: 256