akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
    	BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] list = reader.readLine().split(" ");
        int N = Integer.parseInt(list[0]);
        int K = Integer.parseInt(list[1]);
        int[] numlist = new int[K];
        String[] l = reader.readLine().split(" ");
        for(int i=0;i<K;i++){
            numlist[i] = Integer.parseInt(l[i]);
        }
        Arrays.sort(numlist);
        System.out.println(solve(N,numlist));
	}
    public static int solve(int a,int[] numlist){
        int i = a;
        while(i<Integer.MAX_VALUE){
            if(valid(i,numlist)){
                return i;
            }
            i++;
        }
        return Integer.MAX_VALUE;
    }
    public static boolean valid(int a,int[] numlist){
        String s = String.valueOf(a);
        for(int i = 0;i<s.length();i++){
            if(search(numlist,Integer.parseInt(s.charAt(i)+""))){
                return false;
            }
        }
        return true;
    }
    public static boolean search(int[] numlist, int a){
        for(int i = 0;i<numlist.length;i++){
            if(numlist[i]==a){
                return true;
            }
        }
        return false;
    }
}
        

Measured memory_bytes: 38232
#include <cstdio>

// 10万まで確保していればOK
// 15 -> f[15], b[15]
bool np[1000001];	// not prime. default : false
int c[100001];	// accumulative sum. default : 0
// L,Rは一つで十分
int N,L,R;

int main(int argc, char const *argv[])
{
	int imax=100000;
	// 素数の倍数は not prime = true をセット
	for(int i=2;i<=imax;i++)
		if(!np[i]){
			for(int j=i+i; j<=imax; j+=i)
				np[j]=true;
		}
	// 累積和を計算。
	// 1.各iについて2017likeか判定し真であれば１をセット、2は該当しないため3から。
	// 奇数のみ判定すればよいので計算量 1/2
	for(int i=3;i<=imax;i+=2)if(!np[i] && !np[(i+1)/2])c[i]++;
	// 2.各iについて足し挙げて累積和を計算
	for (int i=3; i <= imax; ++i)c[i]+=c[i-1];

	// 結果出力
	scanf("%d", &N);
	for(int i=1; i<=N; i++){
		scanf("%d%d", &L, &R);
		printf("%d\n", c[R]-c[L-1]);
	}
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        int cnt=0;
        int ans=0;
        if(s[0]=='R')
            cnt++;
        if(s[1]!='R')
        {
            ans=max(ans,cnt);
            cnt=0;
        }
        else cnt++;
        if(s[2]!='R')
        {
            ans=max(ans,cnt);
        }
        else
            cnt++;
        ans=max(ans,cnt);
        cout<<ans;
    }

    return 0;
}

Measured memory_bytes: 3648
use std::io::*;
use std::str::FromStr;
use std::collections::HashSet;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let ai: Vec<u64> = (0..n).map(|_| read()).collect();
    let ai_len = ai.len();
    let uniq: HashSet<u64> = ai.into_iter().collect();

    if ai_len == uniq.len() {
        println!("YES");
    } else {
        println!("NO");
    }
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  vll a(m), b(m);
  vll c(m);
  rep(i,m){
    cin>>a[i]>>b[i];
    rep(j,b[i]){
      ll x; cin>>x; x--;
      c[i]|=(1<<x);
    }
  }
  
  vvll dp(m+1, vll((1<<n), LINF));
  rep(i,m) dp[i][0]=0;
  
  rep(i,m){
    rep(bit,1<<n){
      chmin(dp[i+1][bit], dp[i][bit]);
      chmin(dp[i+1][bit | c[i]], dp[i][bit]+a[i]);
    }
  }
  if(dp[m][(1<<n)-1]==LINF) cout<<-1<<endl;
  else cout<<dp[m][(1<<n)-1]<<endl;
}

Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  cout << (n+k-3)/(k-1) << endl;

}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int slen = s.length();
	int tlen = t.length();
	vector<vector<int> > dp(slen + 1, vector<int>(tlen + 1));
	for (int i = 0; i < slen; ++i) {
		for (int j = 0; j < tlen; ++j) {
			dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
			if (s[i] == t[j]) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
			}
		}
	}
	int spos = slen, tpos = tlen;
	string ans;
	while (spos >= 1 && tpos >= 1) {
		if (s[spos - 1] == t[tpos - 1] && dp[spos][tpos] == dp[spos - 1][tpos - 1] + 1) {
			ans += s[--spos];
			--tpos;
		}
		else if (dp[spos][tpos] == dp[spos][tpos - 1]) {
			--tpos;
		}
		else {
			--spos;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 35584
#include <stdio.h>

void qsort(int len, char a[len][11], int f, int l);
int ft_strcmp(char s1[11], char s2[11]);
void ft_strcpy(char s1[11], char s2[11]);

int main()
{
  int n;
  scanf("%d",&n);
  char s[n][11];
  int i;
  i = 0;
  while (i < n)
  {
    scanf("%s",&s[i]);
    i++;
  }
  i = 0;
  /*
  int j,k;
  j = 0;
  k = 0;
  char tmp[11];
  while (i < n)
  {
    j = i + 1;
    while (j < n)
    {
      if (ft_strcmp(s[i], s[j]) > 0)
      {
        ft_strcpy(tmp,s[i]);
        ft_strcpy(s[i],s[j]);
        ft_strcpy(s[j],tmp);
      }
      j++;
    }
    i++;
  }
  */
  qsort(n, s, 0, n - 1);
  //printf("%s\n%s",s[0],s[n-1]);
  i = 0;
  int counter;
  counter = 0;
  while (i < n)
  {
    if (i + 1 < n && ft_strcmp(s[i], s[i+1]) == 0)
    {
      i++;
      continue;
    }
    i++;
    counter++;
  }
  printf("%d",counter);
}

void ft_strcpy(char s1[11], char s2[11])
{
  int i;
  int j;
  i = 0;
  while (s2[i])
  {
    s1[i] = s2[i];
    i++;
  }
  s1[i] = '\0';
}

int ft_strcmp(char s1[11], char s2[11])
{
  int i,j;
  i = 0;
  j = 0;
  while (s1[i] && s2[i])
  {
    if (s1[i] != s2[i])
    {
      return (s1[i] - s2[i]);
    }
    i++;
  }
  return (s1[i] - s2[i]);
}

void qsort(int len, char a[len][11], int f, int l)
{
  int i = f;
  int j = l;
  char threshold[11];
  char tmp[11];
  ft_strcpy(threshold, a[(f+l)/2]);
  while (1)
  {
    while (ft_strcmp(threshold, a[i]) < 0)
    {
      i++;
    }
    while (ft_strcmp(threshold, a[j]) > 0)
    {
      j--;
    }
    if (i >= j)
      break;
    ft_strcpy(tmp, a[i]);
    ft_strcpy(a[i], a[j]);
    ft_strcpy(a[j], tmp);
    i++;
    j--;
  }
  if (f < i - 1)
    qsort(len, a, f, i - 1);
  if (l > j + 1)
    qsort(len, a, j + 1, l);
}

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
    int num=0;
    char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) num*=10,num+=ch-48,ch=getchar();
    return num;
}
int fa[1000003];
int find(int x){
    if( x == fa[x])
        return x;
    fa[x] = find(fa[x]);
    return fa[x];
}
void un(int x,int y){
    int tx = find(x);
    int ty = find(y);
 
    if( tx != ty)
        fa[ty] = tx;
}
set<int> st;
signed main()
{
	int n=read(),m=read();
	for(int i=1; i<=n; i++) fa[i]=i;
	while(m--)
	{
		int u=read(),v=read();
		un(u,v);
	}
	for(int i=1; i<=n; i++) fa[i]=find(i);
	for(int i=1; i<=n; i++) st.insert(fa[i]);
	int ANS=(int)st.size()-1;
	printf("%d\n",ANS);
	return 0;
}

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

int main(){
ll X,K,D,dis,m,z;
cin>>X>>K>>D;

if(X<0)
    {
        X=X*(-1);
    }
if(D>=X && K%2==1){
    dis=D-X;
}
else if(D>=X && K%2==0){
    dis=X;
}
else if(D<X){
       z=X/D;
        m=min(z,K);
    if((z%2==0 && K%2==0)||(z%2==01 && K%2==1)||K<z)
    {
        dis=X-m*D;
    }
    else{
        dis=abs(X-(m+1)*D);
    }
}
cout<<dis<<endl;
}


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

int max(int x, int y) {
  return (x > y) ? x : y;
}

int min(int x, int y) {
  return (x > y) ? y : x;
}

int main() {
  int n;
  scanf("%d", &n);
  int *p;
  p = (int *)malloc(sizeof(int) * n);
  int i;
  for(i = 0; i < n; i++) scanf("%d", &p[i]);
  int count = 0;
  int maxp, minp;
  for(i = 1; i < n - 1; i++) {
    maxp = max(p[i - 1], p[i + 1]);
    minp = min(p[i - 1], p[i + 1]);
    if(maxp != minp && maxp > p[i] && minp < p[i]) count++;
  }

  printf("%d\n", count);

  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<int, int>;

bool solve(int lim, vector<int>& a) {
    vector<int> v;
    for (int i = 0; i < a.size(); i++) {
        int x = min(a[i], 100);
        if (v.size() < x) {
            int rest = x - (int)v.size();
            for (int i = 0; i < rest; i++) {
                v.push_back(1);
            }
            continue;
        }

        if (i > 0 && a[i] > a[i - 1]) continue;

        while (v.size() > x) {
            v.pop_back();
        }

        v[x - 1]++;
        for (int i = (int)v.size() - 1; i >= 0; i--) {
            if (v[i] > lim) {
                v[i] = 1;
                if (i == 0) return false;
                else {
                    v[i - 1]++;
                }
            } else {
                break;
            }
        }
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a, aa;
    int ng = 0, ok = n;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        if (tmp < 100) a.push_back(tmp);
        aa.push_back(tmp);
    }
    sort(aa.begin(), aa.end());

    for (int i = 1; i < n; i++) {
        if (aa[i] == aa[i - 1]) ng = 1;
    }

    while (ok - ng > 1) {
        int mid = (ok + ng) / 2;
        if (solve(mid, a)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;

    /*
    int ng2 = 0, ok2 = n;
    while (ok2 - ng2 > 1) {
        int mid = (ok2 + ng2) / 2;
        if (solve(mid, aa)) ok2 = mid;
        else ng2 = mid;
    }
    cout << min(ok, ok2) << endl;*/
    return 0;
}

Measured memory_bytes: 2036
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 999999.
       01 B PIC 999999.
       01 C PIC 999999999.
       01 REN PIC 9999999.
       01 RE PIC Z(7).
       01 temp1 PIC 9999.
       01 temp2 PIC 9999.
       01 N PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
       	ACCEPT INP.
      	PERFORM VARYING temp1 FROM 1 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	SUBTRACT 1 FROM temp1.
      	MOVE INP(1:temp1) TO A.
      	ADD 2 TO temp1.
      	PERFORM VARYING temp2 FROM temp1 BY 1 UNTIL INP(temp2:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp2 - temp1.
      	MOVE INP(temp1:N) TO B.
      	ADD 1 TO temp2.
      	PERFORM VARYING temp1 FROM temp2 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp1 - temp2.
      	MOVE INP(temp2:N) TO C.
      	IF A = B AND B NOT = C THEN
      		DISPLAY 2
      	ELSE IF A NOT = B AND B = C THEN
      		DISPLAY 2
      	ELSE IF A = C AND B NOT = C THEN
      		DISPLAY 2
      	ELSE IF A = C AND B = C THEN
      		DISPLAY 1
      	ELSE 
      		DISPLAY 3
      	END-IF.
        STOP RUN.


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

int main() {
    int N, count;
    string S;
    cin >> N >> S;

    count = 0;
    for(int i=0; i<N-2; i++) {
        if (S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C') {
            count++;
        } 
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
//#define int long long
#define ll long long
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()

int n,m;
char a[14][14];
bool ok;
bool seen[14];

void f(int cur){
    bool en = 1;
    if(ok)return;
    for2(i,cur+1,n-cur){
        en = 0;
        for2(j,0,m) swap(a[n-cur-1][j],a[i][j]);
        f(cur+1);
        for2(j,0,m) swap(a[n-cur-1][j],a[i][j]);
    }
    if(en){
        fill(seen,seen+m,0);
        int  cnt = 0;
        for2(i,0,m)if(!seen[i]) for2(k,i+1,m) if(!seen[k]){
            bool same = 1;
            for2(j,0,n) same &= (a[j][i]==a[n-j-1][k]);
            if(same){
                seen[i] = seen[k] = 1;
                cnt += 2;
                break;
            }
        }
        for2(i,0,m) if(!seen[i]){
            bool same = 1;
            for2(j,0,n) same &= (a[j][i]==a[n-j-1][i]);
            if(same){
                cnt++;
            }
            break;
        }
        if(cnt == m ) ok = 1;
    }
}

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for2(i,0,n) for2(j,0,m) cin >> a[i][j];
    for2(i,0,n)if(!ok){
        for2(j,0,m) swap(a[i][j],a[n/2][j]);
        f(0);
        for2(j,0,m) swap(a[i][j],a[n/2][j]);
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 384
def read():
    S = str(input().strip())
    return S,

def solve(S):
    WEEK = ['SUN','MON','TUE','WED','THU','FRI','SAT',]
    idx = WEEK.index(S)
    return len(WEEK) - idx

if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 38384
#include <string>
#include <vector>
#include <cmath>
#include <list>
#include <set>
#include <algorithm>
#include <map>
#include <iostream>
#include <sstream>
#include <queue>
#include <iomanip>

#include <string.h>

using namespace std;

#define MIN(a, b) a < b ? a : b

int main()
{
	unsigned long long n, A, B;

	cin >> n >> A >> B;

	vector<unsigned long long> X;

	X.resize(n, 0);

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

	unsigned long long answer = 0;

	for(int i = 0; i < n-1; i++)
	{
		answer += MIN((X[i+1] - X[i]) * A , B);
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
const int mod = 1e9 + 7;
vector<ull> allPrimes;

void sieve(int n) {
    vector<bool> prime(n+1, true);

    for (int p=2; p*p<=n; p++) {
        if (prime[p] == true) {
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }

    for (int p=2; p<=n; p++)
        if (prime[p])
            allPrimes.push_back(p);
}

ull factorialDivisors(ull n) {
    sieve(n);  // create sieve

    ull result = 1;

    for (int i=0; i < allPrimes.size(); i++) {
        ull p = allPrimes[i];
        ull exp = 0;
        while (p <= n) {
            exp = exp + (n/p);
            p = p*allPrimes[i];
        }
            result = ((result%mod)*((exp+1)%mod))%mod;
    }
    return result;
}

int main() {
    int n;
    cin >> n;
    cout << factorialDivisors(n);
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(void){
    int N,i,count;
    int V[256];
    int C[256];
    count = 0;
    scanf("%d\n",&N);
    for (i = 0; i < N; i++){
        scanf("%d",&V[i]);
    }
    for (i = 0; i < N; i++){
         scanf("%d",&C[i]);
            if (V[i] > C[i]){
                count = count + (V[i] - C[i]);
            }
    }
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

negative_number_count = list(map(lambda x: x < 0, A)).count(True)
B_tmp = sorted(map(abs, A))

if negative_number_count % 2 == 0:
    print(sum(B_tmp))
else:
    print(sum(B_tmp[1:]) - B_tmp[0])

Measured memory_bytes: 66792
// AOJ 2710 An Equation in a Mine
// 2018.2.14 bal4u

#include <stdio.h>
#include <ctype.h>
#include <string.h>

#define INF 0x10101010

unsigned char s[202], sgn[202], num[202];
int min[202][202], max[202][202];

int main()
{
	int n, i, j, k, l, x;
	unsigned char *p, *qs, *qn;

	fgets(p=s, 202, stdin);
	qs = sgn, qn = num;	for (i = 0; *p >= ' '; i++) {
		if (isdigit(*p)) *qn++ = i;
		else if (*p == '+' || *p == '-') *qs++ = i;
		p++;
	}
	n = qn - num;

	memset(min,  INF, sizeof(min));
	memset(max, -INF, sizeof(max));
    for (i = 0; i < n; i++) min[i][i] = max[i][i] = s[num[i]] & 0xf;

	for(l = 1; l < n ; l++) for(i = 0; (j=i+l) < n; i++) {
		for (k = i; k < j; k++) {
			if (  i != k && (s[num[  i]+1] == ')' || s[num[k]-1] == '(')) continue;
			if (k+1 != j && (s[num[k+1]+1] == ')' || s[num[j]-1] == '(')) continue;

			if (s[sgn[k]] == '+') {
				x = max[i][k] + max[k+1][j];
				if (max[i][j] < x) max[i][j] = x;
				x = min[i][k] + min[k+1][j];
				if (min[i][j] > x) min[i][j] = x;
			} else {
				x = max[i][k] - min[k+1][j];
				if (max[i][j] < x) max[i][j] = x;
				x = min[i][k] - max[k+1][j];
				if (min[i][j] > x) min[i][j] = x;
            }
        }
    }
    printf("%d\n", max[0][n-1]);
    return 0;
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
    cin>>n;
    if(n==1)
    {
        cout<<1;return 0;
    }
    if(n==2){
        cout<<2;return 0;}
    int ans=2;
    while(true)
    {
        if(ans*2>n)
            break;
        else
            ans=ans*2;
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    queue<pair<int, int>> que;
    for (int i = 0; i < h; i++)
    {
        cin >> a[i];
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == '#') {
                que.push(pair<int, int>(i, j));
            }
        }
    }
    que.push(pair<int, int>(-1, -1));
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    int ans = 0;

    while (!que.empty()) {
        int nowh = que.front().first;
        int noww = que.front().second;
        que.pop();
        if (nowh == -1 && noww == -1) {
            if (que.empty()) continue;
            // cout << "-----------" << endl;
            // for (int i = 0; i < h; i++)
            // {
            //     cout << a[i] << endl;
            // }
            ans++;
            que.push(pair<int, int>(-1, -1));
        }
        // bool ok = false;
        for (int i = 0; i < 4; i++)
        {
            int nexth = nowh+dx[i];
            int nextw = noww+dy[i];
            if (nexth < 0 || nexth >= h || nextw < 0 || nextw >= w) {
                continue;
            }

            if (a[nexth][nextw] == '#') {
                continue;
            }

            a[nexth][nextw] = '#';
            que.push(pair<int, int>(nexth, nextw));
            // ok = true;
        }
        
    }    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9488
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(long long a, long long b) {
  return a > b;
}

int main(int argc, char* argv[]) {
  long long N;
  cin >> N;

  vector<long long> a(3 * N);
  for (long long i = 0; i < 3 * N; ++i)
    cin >> a[i];

  sort(a.begin(), a.end(), comp);

  long long ret = 0;
  for (long long i = 0; i < N; ++i) {
    long long index = i * 2;
    ret += a[index + 1];
  }

  cout << ret << endl;

  return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (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--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int a, b;
  cin >> a >> b;
  pr(b * 2 - a);

  return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#include <string.h>
#include <stdint.h>

int main() {

  char buf[11], output[11];
  uint32_t cnt = 0;
  scanf("%s", buf);

  for(uint32_t i=0;i<strlen(buf);i++) {
    if(buf[i] != 'B')
      output[cnt++] = buf[i];
    else
      if(cnt > 0)
        cnt--;
  }

  output[cnt] = '\0';
  puts(output);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <valarray>
#include <cstdio>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	valarray<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	valarray<int> b = a;
	int max1 = b.max();
	valarray<bool> m = b != max1;
	valarray<int> r = b[m];
	int max2 = r.size() != b.size() - 1 ? max1 : r.max();
	for (int i = 0; i < n; ++i) {
		if (b[i] == max1) {
			cout << max2 << "\n";
		}
		else {
			cout << max1 << "\n";
		}
	}
}


Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <iostream>
#include <forward_list>
using namespace std;

#define SCAN_INT(i) scanf("%d", i)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define PRINT_INT(i) printf("%d\n", i)
#define PRINT_TWO_INT(i, j) printf("%d %d\n", i, j)
#define PRINT_THREE_INT(i, j, k) printf("%d %d %d\n", i, j, k)

int main()
{
    int N, Q;
    char S[100000];
    int ans[100000];
    int ac[100000];

    scanf("%d %d", &N, &Q);
    scanf("%s", S);
    int count = 0;
    for (int i = 0; i < N - 1; i++)
    {
        if (S[i] == 'A' && S[i + 1] == 'C')
        {
            count++;
            ac[i] = count;
        }
        else
        {
            ac[i] = 0;
        }
    }
    ac[N - 1] = 0;

    for (int i = 0; i < Q; i++)
    {
        int l;
        int r;
        SCAN_INT(&l);
        SCAN_INT(&r);
        int start = -1;
        int end = -1;
        if (r - 2 >= l - 1)
        {
            for (int j = l - 1; j < r - 1; j++)
            {
                if (ac[j] != 0)
                {
                    start = ac[j];
                    break;
                }
            }
            if (start != -1)
            {
                for (int j = r - 2; j >= l - 1; j--)
                {
                    if (ac[j] != 0)
                    {
                        end = ac[j];
                        break;
                    }
                }
            }
        }
        if (start == -1)
            ans[i] = 0;
        else
            ans[i] = end - start + 1;
    }

    for (int i = 0; i < Q; i++)
        PRINT_INT(ans[i]);
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
 #include<string>
 #include<algorithm>
 using namespace std;
 
 int main()
 {
 	int a,b,c,d;
 	while(cin>>a>>b>>c>>d)
 	{
 		int total=0;
 		if(a<=b) total+=a; else total+=b;
 		if(c<=d) total+=c; else total+=d;
 		cout<<total<<endl;
	 }
 	return 0;
 }

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


int main() {
  vector<int> a(12);
  a = {1,3,1,2,1,2,1,1,2,1,2,1};
  int x, y;
  cin >> x >> y;
  if(a[x-1] == a[y-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;
class Main
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        char ch = in.readLine().charAt(0);
        if (ch >= 'a' && ch <= 'z')
            System.out.println('a');
        else
            System.out.println('A');
    }
}
class Reader
{
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader()
    {
        din = new DataInputStream(System.in);
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException
    {
        din = new DataInputStream(new FileInputStream(file_name));
        buffer = new byte[BUFFER_SIZE];
        bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException
    {
        byte[] buf = new byte[64]; // line length
        int cnt = 0, c;
        while ((c = read()) != -1)
        {
            if (c == '\n')
                break;
            buf[cnt++] = (byte) c;
        }
        return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException
    {
        int ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do
        {
            ret = ret * 10 + c - '0';
        }  while ((c = read()) >= '0' && c <= '9');

        if (neg)
            return -ret;
        return ret;
    }

    public long nextLong() throws IOException
    {
        long ret = 0;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();
        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');
        if (neg)
            return -ret;
        return ret;
    }

    public double nextDouble() throws IOException
    {
        double ret = 0, div = 1;
        byte c = read();
        while (c <= ' ')
            c = read();
        boolean neg = (c == '-');
        if (neg)
            c = read();

        do {
            ret = ret * 10 + c - '0';
        }
        while ((c = read()) >= '0' && c <= '9');

        if (c == '.')
        {
            while ((c = read()) >= '0' && c <= '9')
            {
                ret += (c - '0') / (div *= 10);
            }
        }

        if (neg)
            return -ret;
        return ret;
    }

    private void fillBuffer() throws IOException
    {
        bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
        if (bytesRead == -1)
            buffer[0] = -1;
    }

    private byte read() throws IOException
    {
        if (bufferPointer == bytesRead)
            fillBuffer();
        return buffer[bufferPointer++];
    }

    public void close() throws IOException
    {
        if (din == null)
            return;
        din.close();
    }
}


Measured memory_bytes: 32528
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs
    string s;int n,p;ll t=0;
    cin>>n>>p>>s;
    if(p==2) {
        rep(i,n) {
            if((s[i]-'0')%2==0) t+=i+1;
        }
    }
    else if(p==5) {
        rep(i,n) {
            if((s[i]-'0')%5==0) t+=i+1;
        }
    }
    else {
        map<int,int> pam;int tt=0,base=1;
        pam[0]++;
        Repp(i,n-1,0) {
            tt+=(s[i]-'0')*base;
            tt%=p;
            t+=pam[tt];
            pam[tt]++;
            base=(base*10)%p;
        }
    }
    cout<<t;
}

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

long long int N, K, l, i, d[100000], b;
vector<long long int> a, p;

int main(){
    scanf("%lld%lld", &N, &K);
    a.push_back(0);
    p.push_back(0);
    for(i = 0; i < N; ++i){
        scanf("%lld", &l);
        a.push_back(l);
        if(l > 0){
            b += l;
        }
        p.push_back(b);
    }
    partial_sum(a.begin(), a.end(), a.begin());
    for(i = 0; i <= N - K; ++i){
        d[i] = (i>0?p[i]:0) + max(a[i + K] - a[i], 0LL) + ((i+K<N)?b - p[i + K]:0);
    }
    cout << *max_element(d, d + N) << endl;
    return 0;
}


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

int main () {
#ifdef _test
    freopen( "in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    string s;
    cin >> k >> s;
    int n = s.size();
    if (n > k) {
        for (int i = 0; i<k; i++) {
            cout << s[i] ;
        }
        cout << "..." << '\n';
    }
    else cout << s << '\n';
    return 0;
}


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define LL long long
#define NUM 1000000007

using namespace std;

int main()
{
    LL n, ans1 = -1, ans2 = -1;
    cin >> n;
    map<LL, LL> m;
    for (size_t i = 0; i < n; i++)
    {
        LL tmp;
        cin >> tmp;
        auto iter = m.find(tmp);
        if (iter == m.end())
        {
            m.insert(make_pair(tmp, 1));
        }
        else
        {
            iter->second++;
        }
    }
    for (auto itrr = m.rbegin(); itrr != m.rend(); itrr++)
    {
        if (itrr->second >= 2 && ans1 == -1)
        {
            if (itrr->second >= 4)
            {
                cout << (itrr->first) * (itrr->first) << endl;
                return 0;
            }
            ans1 = itrr->first;
            continue;
        }

        if (ans1 != -1)
        {
            if (itrr->second >= 2)
            {
                ans2 = itrr->first;
                cout << ans1*ans2 << endl;
                return 0;
            }
        }
    }
    if (ans1 == -1 || ans2 == -1)
    {
        cout << 0 << endl;
    }

}

Measured memory_bytes: 6528
def evenStringChecker(s):
    mid = len(s) // 2
    if s[:mid] == s[mid:]:
        return True
    else :
        return False

S = input()

if len(S) % 2 == 1:
    S = S[:len(S)-1]
else :
    S = S[:len(S)-2]

while True:
    flag = evenStringChecker(S)
    if flag :
        break
    S = S[:len(S)-2]

print(len(S))

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <cassert>
#include <vector>
#include <deque>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    long long int n;
    cin>>n;
    int a=0,b=0,c=0,d=0;
    for(int i=0;i<n;i++){
		string s;
		cin>>s;
		if(s.compare("AC") == 0)
		{
			a+=1;
		}
		else if(s.compare("WA") == 0)
		{
			b+=1;
		}
		else if(s.compare("TLE") == 0)
		{
			c+=1;
		}
		else if(s.compare("RE") == 0)
		{
			d+=1;
		}
	}
		cout<<"AC x "<<a<<endl;
		cout<<"WA x "<<b<<endl;
		cout<<"TLE x "<<c<<endl;
		cout<<"RE x "<<d<<endl; 
	return 0;
}


Measured memory_bytes: 3616
n=int(input())
a=[]
for i in range(n):
    x=int(input())
    aa=[[int(i) for i in input().split()] for i in range(x)]
    a.append(aa)
#print(a)

ans=0
for i in range(2**n):
    status=[True]*n
    for j in range(n):
        if ((i>>j)&1):
            status[j]=False
    check=[None]*n
    flag=True
    for i in range(n):
        if status[i]==True:
            for x,y in a[i]:
                if y==1 and status[x-1]==True and (check[x-1]==None or check[x-1]==True):
                    check[x-1]=True
                elif y==1 and (check[x-1]==False or status[x-1]==False):
                    flag=False
                elif y==0 and status[x-1]==False and (check[x-1]==None or check[x-1]==False):
                    check[x-1]=False
                elif y==0 and (check[x-1]==True or status[x-1]==True):
                    flag=False
    if flag:
        #print(status,check)
        cnt=status.count(True)
        ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

// const ll mod = 998244353ll;
const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}


ll fact[fact_table + 5],rfact[fact_table + 5];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}


bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

ll dp[600006];
ll table[500005];

string s, t;

void solve() {
    cin >> n >> m;
    c3_init();
    dp[1] = 0;
    dp[2] = 1;
    for(ll i=3;i<=m;i++){
        dp[i] = (i - 1) * (dp[i-1] + dp[i-2]);
        dp[i] %= mod;
    }
    table[0] = dp[m];
    for(ll i=1;i<=m-n;i++){
        table[i] = c3(m - n, i) * dp[m-i];
        table[i] %= mod;
    }
    ll ans = 0;
    for(ll i=0;i<=m-n;i++){
        ans += table[i];
        ans %= mod;
    }
    ans *= fact[m];
    ans %= mod;
    ans *= rfact[m-n];
    ans %= mod;
    ans *= rfact[m-n];
    ans %= mod;
    p(ans);
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 61332
#-- グループ分けされてない隣接ノード番号を返す
def next_neighbor nodes, x
  nodes[x][:neighbors].each do |neighbor|
    return neighbor if nodes[neighbor][:group_id] == nil
  end
  nil
end

#-- メイン処理開始
n, m = gets.split.map(&:to_i)
nodes = Array.new(n) do {neighbors: []} end

#-- 隣接リストを格納
m.times do
  f_node, t_node = gets.split.map(&:to_i)
  nodes[f_node][:neighbors] << t_node
  nodes[t_node][:neighbors] << f_node
end

#-- グループ分けされていないノードに関してDFSする
group_id = 0; stack = []
nodes.each_with_index do |node, i|
  if node[:group_id] == nil
    stack.push i; group_id += 1
    while stack != []
      x = stack.last
      neighbor = next_neighbor nodes, x
      if neighbor
        stack.push neighbor
        nodes[neighbor][:group_id] = group_id
      else
        stack.pop
      end
    end
  end
end

#-- 判定して出力
c = gets.to_i
c.times do
  f_node, t_node = gets.split.map(&:to_i)
  f = nodes[f_node][:group_id]
  t = nodes[t_node][:group_id]

  if f == nil || t == nil || f != t then puts "no" else puts "yes" end
end


Measured memory_bytes: 40588
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace CountingSort
{
    internal class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var array = ReadLine().Split(' ').Select(int.Parse).ToArray();
            var result = new int[n];
            var k = array.Max();

            MyCountingSort(array, result, k);
            
            

            WriteLine(string.Join(" ", result));
        }

        private static void MyCountingSort(int[] array, int[] result, int k)
        {
            // データの個数をカウント
            var count = new int[k + 1];

            for (var i = 0; i < array.Length; i++)
            {
                // 対象の個数をカウントアップ
                count[array[i]]++;
            }

            for (var i = 1; i <= k; i++)
            {
                count[i] += count[i - 1];
            }

            for (var j = result.Length - 1; j >= 0; j--)
            {
                result[count[array[j]] - 1] = array[j];
                count[array[j]]--;
            }
        }
        

    }
}


Measured memory_bytes: 180120
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let nk = readn::<usize>(" ");
    let n = nk[0];
    let k = nk[1];
    let mut ans = k;
    for _ in 1..n {
        ans *= k - 1;
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const long long MOD = 1000000007;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(long long n, std::vector<long long> a){
    i64 r = 0;
    i64 sum = 0;
    for(auto x : a){
        sum += r * x;
        r += x;
        r %= MOD;
        sum %= MOD;
    }
    cout << sum % MOD << endl;
}


signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

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

  ll h, w; cin >> h >> w;
  
  if (h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return (0);
  }

  ll ans = MOD;

  rep2(i, 1, w) {
    ll x = h * i;
    ll y = (h / 2) * (w - i);
    ll z = ((h + 1) / 2) * (w - i);

    ll mx = max({x, y, z});
    ll mn = min({x, y, z});

    chmin(ans, mx - mn);
  }

  rep2(i, 1, h) {
    ll x = w * i;
    ll y = (w / 2) * (h - i);
    ll z = ((w + 1) / 2) * (h - i);

    ll mx = max({x, y, z});
    ll mn = min({x, y, z});

    chmin(ans, mx - mn);
  }

  rep2(i, 1, h) {
    ll x = w * i;

    ll diff = h - i;
    ll y = (diff / 2) * w;
    ll z = ((diff + 1) / 2) * w;

    ll mx = max({x, y, z});
    ll mn = min({x, y, z});

    chmin(ans, mx - mn);
  }

  rep2(i, 1, w) {
    ll x = h * i;

    ll diff = w - i;
    ll y = (diff / 2) * h;
    ll z = ((diff + 1) / 2) * h;

    ll mx = max({x, y, z});
    ll mn = min({x, y, z});

    chmin(ans, mx - mn);
  }

  cout << ans << endl;

  return (0);
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int h, w; cin >> h >> w;
	string s[100]; REP(i, h) cin >> s[i];

	REP(i, w+2) cout << '#';
	cout << endl;

	REP(i, h) cout << '#' << s[i] << '#' << endl;

	REP(i, w+2) cout << '#';
	cout << endl;

	rtn 0;
}

Measured memory_bytes: 256
s=input()
cnt1=0
cnt2=1
ans=0
for i in range(len(s)-1):
    if s[i]==">" and s[i+1]=="<":
        a=max(cnt1,cnt2)
        b=max(min(cnt1,cnt2)-1,0)
        #print(cnt1,cnt2)
        ans+=(a*(a+1)+b*(b+1))//2
        cnt1=0
        cnt2=1
    elif s[i]=="<":
        cnt1+=1
    else:
        cnt2+=1
if s[len(s)-1]=="<" and s[len(s)-2]=="<":
    cnt1+=1
#print(cnt1,cnt2)
a=max(cnt1,cnt2)
b=max(min(cnt1,cnt2)-1,0)
ans+=(a*(a+1)+b*(b+1))//2
print(ans)



Measured memory_bytes: 44268
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;

int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll a,b;
	cin>>a>>b;
	cout<<(a%b!=0);
	return 0;
}


Measured memory_bytes: 256
R,G,B,N = map(int, input().split())

count = 0

for r in range(3001):
    for g in range(3001):
        redball = r*R
        greenball = g*G
        tempbull = N - (redball + greenball)
        
        if (redball >= 0) and (greenball >= 0) and (tempbull >= 0):
            if (redball + greenball + tempbull == N) and (tempbull % B == 0):
                count = count + 1

print(count)

Measured memory_bytes: 68732
import collections

N = int(input())
L = sorted(list(map(int, input().split())))

col = collections.Counter(L)
cmemo = [0] * 1010
for x in list(col.keys()):
    cmemo[x] += col[x]
for i in range(1, 1010):
    cmemo[i] += cmemo[i-1]

ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        a, b = L[i], L[j]
        cmin, cmax = b-a, min(a+b, 1009)
        if cmin < a:
            ans += cmemo[cmax-1] - cmemo[cmin] - 2
        else:
            ans += cmemo[cmax-1] - cmemo[cmin] - 1
print(ans//3)

Measured memory_bytes: 3564
A = list(map(int,input().split(" ")))

five_cnt = 0
seven_cnt = 0


for i in A :
    if i == 5:
        five_cnt += 1
    if i == 7:
        seven_cnt += 1


if five_cnt == 2 and seven_cnt == 1:
    print("YES")
else:
    print("NO")

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

vector<bool> getPrime(int N);

int main(void) {
    int X;
    cin>>X;
    vector<bool> vc = getPrime(X);
    int c = count(vc.begin(), vc.end(), true);
    if (vc.at(X)) {
        cout << X << endl;
    } else {
        int result = X + 1;
        vector<bool> tmp = getPrime(result);
        while (c == count(tmp.begin(), tmp.end(), true)) {
            tmp = getPrime(++result);
        }
        cout << result << endl;
    }
    return 0;
}

// エラトステネスの篩
vector<bool> getPrime(int N) {
    vector<bool> p = vector<bool>(N + 1, true);
    p.at(0) = false;
    p.at(1) = false;
    for (int i = 2; i * i <= N; i++) {
        for (int j = 2; i * j <= N; j++) {
            p.at(i * j) = false;
        }
    }
    return p;
}

Measured memory_bytes: 256