akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int inf=1e9+7;
signed main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=0;
    for(int i=0;i<n-1;i++)
        if(s[i]!=s[i+1])
            ans++,i++;
    cout<<ans<<endl;
}



Measured memory_bytes: 3340
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

long long a,b,x;
cin>>a>>b>>x;
if(b/x==a/x){
    if(a%x==0){
        cout<<1<<endl;
        return 0;
    }else{
        cout<<0<<endl;
        return 0;
    }
}

if(a%x==0){
    cout<<b/x-a/x+1<<endl;
}else{
cout<<b/x-a/x<<endl;
}

return 0;
}

Measured memory_bytes: 256
// AOJ 2253: Brave Force Story
// 2017.11.10 bal4u@uu

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

#define BASE 100

typedef struct { int x, y, k; } Q;
Q q[4000]; int top, end;

char b[200][200];
char mk[200][200];
int mv[6][2] = {{1,1},{-1,-1},{0,-1},{-1,0},{0,1},{1,0}};

int main()  
{  
	int t, n, i, x, y, x2, y2, k, ans;

	while (scanf("%d%d", &t, &n) && t > 0) {
		memset(mk, 0, sizeof(mk)), memset(b, 0, sizeof(b));
		while (n--) {
			scanf("%d%d", &x, &y);
			b[x+BASE][y+BASE] = 1;
		}
		scanf("%d%d", &x, &y); x += BASE, y += BASE;
		q[0].x = x, q[0].y = y, q[0].k = 0; top = 0, end = 1;
		ans = 1; mk[x][y] = 1;
		while (top < end) {
			x = q[top].x, y = q[top].y, k = q[top++].k;
			if (k++ >= t) continue;
			for (i = 0; i < 6; i++) {
				x2 = x + mv[i][0];
				y2 = y + mv[i][1];
				if (b[x2][y2] || mk[x2][y2]) continue;
				ans++, mk[x2][y2] = 1;
				q[end].x = x2, q[end].y = y2, q[end++].k = k;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

const long long INF = 1LL << 60;

int main(){
    int N;
    int h[110000];
    cin >> N;
    for(int i=0;i<N;++i) cin >> h[i];
    long long dp[110000];
    fill(dp,dp+N,INF);
    dp[0] = 0;
    
    for(int i=1;i<N;++i){
        // for(int k=1;k<=K;++k){
        dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
        if(i>1) dp[i] = min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
        // }
    }

    cout << dp[N-1] << endl;
    
    return 0;

}

Measured memory_bytes: 1408
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int q= sc.nextInt();
        int[]a = sc.nextIntArr(n);
        int[]b=a.clone();
        Arrays.sort(b);
        int ans =(int)2e9;
        for (int j=0;j<n;j++){
            PriorityQueue<Integer>pq = new PriorityQueue<>(),all= new PriorityQueue<>();
            for (int i =0;i<n;i++){
                if (a[i]<b[j])
                {
                    while (pq.size()>=k){
                        all.add(pq.poll());
                    }
                    pq.clear();
                }
                else pq.add(a[i]);
            }
            while (pq.size()>=k){
                all.add(pq.poll());
            }
            int c=q;
            if (all.size()<q)
                break;
            while (c-->1)all.poll();
            if (!all.isEmpty())
            ans=Math.min(ans,(all.poll()-b[j]));
        }
        pw.println(Math.max(ans,0));
        pw.flush();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

Measured memory_bytes: 61712
#include<bits/stdc++.h>
using namespace std;
int main()
{
  vector<char> V(26);
  int N;
  cin >> N;
  string S;
  cin >> S;
  V.at(0)='A';
  V.at(1)='B';
  V.at(2)='C';
  V.at(3)='D';
  V.at(4)='E';
  V.at(5)='F';
  V.at(6)='G';
  V.at(7)='H';
  V.at(8)='I';
  V.at(9)='J';
  V.at(10)='K';
  V.at(11)='L';
  V.at(12)='M';
  V.at(13)='N';
  V.at(14)='O';
  V.at(15)='P';
  V.at(16)='Q';
  V.at(17)='R';
  V.at(18)='S';
  V.at(19)='T';
  V.at(20)='U';
  V.at(21)='V';
  V.at(22)='W';
  V.at(23)='X';
  V.at(24)='Y';
  V.at(25)='Z';
  vector<int> number(S.size());
  for(int i=0; i<S.size(); i++){
    for(int j=0; j<26; j++){
      if(S.at(i)==V.at(j)){
        number.at(i)=j;
      }
    }
  }
  for(int i=0; i<S.size(); i++){
    number.at(i)+=N;
    if(number.at(i)<26){
      cout << V.at(number.at(i));
    }
    else{
      cout << V.at(number.at(i)-26);
    }
  }
  cout << endl;
}

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

void solve(long long N, long long L)
{
    auto taste_min = L;
    auto taste_max = L + N - 1;
    auto sum = (taste_min + taste_max) * N / 2;

    if (taste_min > 0) {
        sum -= taste_min;
    } else if (taste_max < 0) {
        sum -= taste_max;
    }
    cout << sum << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long N;
    scanf("%lld",&N);
    long long L;
    scanf("%lld",&L);
    solve(N, L);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

ll power(ll n, ll k);
ll inv(ll n);
ll genfact(ll n, ll k);
ll fact(ll n);
ll nck(ll n, ll k);

int main(void){
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200)
    cout << s << endl;
  else
    cout << "red" << endl;

  return 0;
}


ll power(ll n, ll k){
  ll res = 1;
  while(k > 0){
    if (k & 1) 
      res = res * n % MOD;
    n = n * n % MOD;
    k >>= 1;
  }
  return res;
}

ll genfact(ll n, ll k){

  ll res = 1;
  while (k >= 0){
    res = (res * (n - k)) % MOD;
    k--;
  }

  return res;
}

ll inv(ll n){
  return power(n, MOD - 2);
}

ll fact(ll n){
  return genfact(n, n - 1);
}

ll nck(ll n, ll k){
  if (k == 0)
    return 1;
  if (n <= 0)
    return 0;

  return ((genfact(n, k) % MOD) * inv(fact(k))) % MOD;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

#define scanf(...) scanf(__VA_ARGS__)+1

int main() {
	int N, count[5] = {0,};

	scanf("%d", &N);

	char str[16];
	for (int i = 0; i < N; i++) {
		scanf("%s", str);
		switch (str[0]) {
		case 'M':
			count[0]++;
			break;
		case 'A':
			count[1]++;
			break;
		case 'R':
			count[2]++;
			break;
		case 'C':
			count[3]++;
			break;
		case 'H':
			count[4]++;
			break;
		default:
			break;
		}
	}

	int b0=1, b1=2, b2=4, b3=8, b4=16;
	long long ans = 0;
	for (int i = 0;i < 32; i++) {
		int b = 0;
		if (i & b0) b++;
		if (i & b1) b++;
		if (i & b2) b++;
		if (i & b3) b++;
		if (i & b4) b++;
		if (b != 3)	continue;
		long long total = 1;
		if (i & b0) total *= count[0];
		if (i & b1) total *= count[1];
		if (i & b2) total *= count[2];
		if (i & b3) total *= count[3];
		if (i & b4) total *= count[4];
		ans += total;

	}

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

	return 0;
}


Measured memory_bytes: 128
import sys

MOD = 10 ** 9 + 7

def make_factorial_mod(n, mod):
    fac = [None] * (n + 1)
    fac[0] = 1
    for i in range(n):
        fac[i+1] = fac[i] * (i + 1) % mod
    return fac

fac = make_factorial_mod(10**5, MOD)

n, m = map(int, sys.stdin.readline().split())
if n < m:
    n, m = m, n

def main():

    if n == m:
        return fac[n] * fac[m] * 2 % MOD
    elif n == m + 1:
        return fac[n] * fac[m] % MOD
    else:
        return 0

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 6900
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    string s, t = "keyence";
    cin >> s;
    int sLength = s.size();
    if (sLength < 7) {
        cout << "NO" << endl;
        return 0;
    }
    for (int i = 0;i < 8; i++) {
        if(s.substr(0,i) + s.substr(sLength - (7 - i)) == t) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
#define allchar(c) for(char c='a';c<='z';c++)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef queue<int> qi;

const int mod=1e9+7;

ll modpow(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    S s;
    cin >> s;
    vc t(s.size());
    rp(i,t.size()){
        t.at(i)=s.at(i);
    }
    ll ans=0,p=0;
    llrp(i,s.size()){
        if(s.at(i)=='W'){
            ans+=i-p;
            p++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 788
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

struct UnionFind{
    vector<int> par;
    vector<int> sizes;

    UnionFind(int n) : par(n),sizes(n,1){
        for(int i=0;i<n;i++) par[i] = i;
    }

    int root(int x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        par[rx] = ry;
        sizes[ry] += sizes[rx];
    }

    bool same(int x,int y){ 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){     //ノードxの連結成分サイズ
        return sizes[root(x)];
    }

    int max_sizes(){
        int maxi = 0;
        for(auto s : sizes){
            maxi = max(s,maxi);
        }
        return maxi;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    UnionFind uf(N);
    for(int i = 0; i < M; i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }
    cout << uf.max_sizes() << endl;
    return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::string S){
    string ans = NO;
    if (N % 2 == 0) {
        if (S.substr(0, N / 2) == S.substr(N/2, N/2)) ans = YES;
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
Int E[444][444];
signed main(){
  Int n,m;
  cin>>n>>m;
  vector<Int> x(m),y(m);
  for(Int i=0;i<m;i++) cin>>x[i]>>y[i];
  reverse(x.begin(),x.end());
  reverse(y.begin(),y.end());
  memset(E,0,sizeof(E));
  for(Int i=0;i<m;i++){
    x[i]--;y[i]--;
    E[x[i]][y[i]]=E[y[i]][x[i]]=1;
  }
  
  vector<Int> lp(n,0);
  vector<vector<Int> > G(n);
  for(Int i=0;i<n;i++){
    vector<Int> used(n,0);
    used[i]=1;
    for(Int k=0;k<m;k++){
      if(!used[x[k]]&&!used[y[k]]) continue;
      lp[i]|=used[x[k]]&&used[y[k]];
      used[x[k]]=used[y[k]]=1;
    }
    G[i]=used;
  }
  
  Int ans=0;
  for(Int i=0;i<n;i++){
    if(lp[i]) continue;
    for(Int j=0;j<i;j++){
      if(E[i][j]||lp[j]) continue;
      Int flg=1;
      for(Int k=0;k<n;k++)
	flg&=!G[i][k]||!G[j][k];
      ans+=flg;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(a, a + n);
	int b = a[n / 2];
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += abs(a[i] - b);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static long[] steps;

    public static void Main()
    {
        var W = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N, M;
        N = W[0];
        M = W[1];
        steps = new long[N + 1];
        List<int> a = new List<int>();

        for (int i = 0; i < M; i++)
        {
            int read = int.Parse(Console.ReadLine());
            if (a.Count == 0) a.Add(read);
            else if (!(read == a[a.Count-1])) a.Add(read);

        }
        a.Add(-1);

        int iter_a = 0;
        for (int i = 0; i <= N; i++)
        {
            if (i == 0)
            {
                steps[i] = 1;
            }
            else if (i == 1)
            {
                if (a[0] == i)
                {
                    iter_a++;
                    steps[i] = 0;
                    continue;
                }
                else
                {
                    steps[i] = 1;
                }

            }
            else
            {
                if (a[iter_a] == i)
                {

                    steps[i] = 0;
                    iter_a++;
                }
                else
                {
                    steps[i] = steps[i - 1] + steps[i - 2];
                    if (steps[i] >= 1000000007)
                    {
                        steps[i] -= 1000000007;
                        //1000000007

                    }
                }

            }

        }
        Console.WriteLine(steps[N]);

    }



}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const double eps = 1e-6;

int n;
int a[N];

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    int res = a[1];
    for(int i = 2; i <= n; i++) res = __gcd(res, a[i]);

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


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    double n,average = 0;
    cin >> n;
    double a[(int)n],ans;
    rep(i, n){
        cin >> a[i];
        average += a[i];
    }
    average = average / n;
    rep(i, n)a[i] = abs(a[i] - average);
    ans = 0;
    rep(i, n)if(a[(int)ans] > a[i])ans = i;
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    final static long mod = 1_000_000_007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        // i番目まで見たとき、３つ前の文字、２つ前の文字、1つ前の文字で条件に違反していない組み合わせ数
        // 文字は、0: 'A', 1: 'C', 2: 'G', 3: 'T';
        long[][][][] dp = new long[N][4][4][4];

        char[] chars = new char[]{'A', 'C', 'G', 'T'};
        Map<Character, Integer> map = new HashMap<>();
        map.put('A', 0);
        map.put('C', 1);
        map.put('G', 2);
        map.put('T', 3);

        for (char c1 : chars) {
            for (char c2 : chars) {
                for (char c3 : chars) {
                    if (!isLegal(c1, c2, c3)) {
                        dp[2][map.get(c1)][map.get(c2)][map.get(c3)] = 1;
                    }
                }
            }
        }

        for (int i = 3; i < N; i++) {
            for (char c1 : chars) {
                for (char c2 : chars) {
                    for (char c3 : chars) {
                        for (char c4 : chars) {
                            if (!isLegal(c2, c3, c4) && !isLegal2(c1, c2, c4) && !isLegal2(c1, c3, c4)) {
                                dp[i][map.get(c2)][map.get(c3)][map.get(c4)] += dp[i - 1][map.get(c1)][map.get(c2)][map.get(c3)];
                                dp[i][map.get(c2)][map.get(c3)][map.get(c4)] %= mod;
                            }
                        }
                    }
                }
            }
        }

        long ans = 0;
        for (int c1 = 0; c1 < 4; c1++) {
            for (int c2 = 0; c2 < 4; c2++) {
                for (int c3 = 0; c3 < 4; c3++) {
                    ans += dp[N - 1][c1][c2][c3];
                    ans %= mod;
                }
            }
        }

        out.println(ans);
    }

    public static boolean isLegal(char c1, char c2, char c3) {
        if ((c1 == 'A' && c2 == 'C' && c3 == 'G') ||
                (c1 == 'A' && c2 == 'G' && c3 == 'C') ||
                (c1 == 'G' && c2 == 'A' && c3 == 'C')) {
            return true;
        }
        return false;
    }

    public static boolean isLegal2(char c1, char c2, char c3) {
        if(c1 == 'A' && c2 == 'G' && c3 == 'C'){
            return true;
        }
        return false;
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll memo[1000+1][1000+1];
ll n,a,b,c,d;


ll modpow(ll b, ll e, ll p) {
  if(e==0) return 1;
  if(e%2==0) {
    ll t = modpow(b,e/2,p);
    return (t*t)%p;
  }
  return (b*modpow(b,e-1,p))%p;
}

ll modinv(ll n, ll p) {
  return modpow(n,p-2,p);
}

const ll p = 1e9+7;
const int MX = 1000;
ll modFact[MX+1];
ll modFactInv[MX+1];
void precalc() {
  modFact[0]=1;
  modFactInv[0]=1;
  repeat(i,1,MX+1) {
    modFact[i]=(modFact[i-1]*i)%p;
    modFactInv[i]=modinv(modFact[i],p);
  }
}

ll fastModComb(ll n, ll k, ll p) {
  // call precalc() first.
  ll ret=modFact[n];
  ret=ret*modFactInv[n-k];
  ret%=p;
  ret=ret*modFactInv[k];
  ret%=p;
  return ret;
}

ll f(ll j, ll i, ll k) {
  ll ret=modFact[j];
  ret*=modFactInv[j-i*k];
  ret%=p;
  ret*=modpow(modFactInv[i],k,p);
  ret%=p;
  ret*=modFactInv[k];
  ret%=p;
  return ret;
}

ll dp(ll i, ll j) {
  if(i<a&&j!=0) {
    return 0;
  }
  if(j==0) {
    return 1;
  }
  if(memo[i][j]!=-1)
    return memo[i][j];
  ll ret=0;
  ret+=dp(i-1,j);
  repeat(k,c,d+1) {
    if(j-k*i<0)
      break;
    ret+=f(j,i,k)*dp(i-1,j-k*i);
    ret%=p;
  }
  return memo[i][j]=ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  memset(memo,-1,sizeof(memo));
  cin>>n>>a>>b>>c>>d;
  precalc();
  cout << dp(b,n) << endl;
  //cout << f(4,2,1) << endl;
  return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <utility>
using namespace std;
int main() {
	int x,y,i;
	for (i = 0; i < 3000; i++) {
		cin >> x >> y;
		if (x != 0 || y != 0) {
			if (x > y) swap(x, y);
			cout << x << ' ' << y << endl;
		}
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for (int i=(a); i>=(b); --i)
#define REP(i,b) for (int i=0; i<(b); ++i)
#define endl '\n'
#define sz(x) (int) x.size()
#define mod %
#define fillchar(x,y,z) memset(x,z,y)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define sqr(x) ((x)*(x))
typedef long long int64;
typedef unsigned long long qword;
using namespace std;
const int maxn=3e3+5;
int64 f[maxn][maxn];
int64 a[maxn];
int n;
void Input()
{
    cin >> n;
    FOR(i,1,n) {
        cin >> a[i];
        a[i]+=a[i-1];
    }
}
int64 calc(int l, int r)
{
    if (l==r) return a[l]-a[l-1];
    int64 &res=f[l][r];
    if (res!=f[0][0]) return res;
    return res=a[r]-a[l-1]-min(calc(l+1,r),calc(l,r-1));
}
void Solve()
{
    fillchar(f,sizeof(f),63);
    cout << calc(1,n)*2-a[n] << endl;
}
int main()
{
    #ifdef meomeomeooooo
        freopen("input.txt","r",stdin);
        //freopen(".out","w",stdout);
    #endif // meomeomeooooo
    iostream::sync_with_stdio(false);
    cin.tie(0);
    Input();
    Solve();
    return 0;
}



Measured memory_bytes: 70912
#include <iostream>
#include <string>

using namespace std;

bool D[10];

bool check(int ans)
{
	string x = to_string(ans);
	for (int i = 0; i < x.length(); i++)
	{
		int d = x[i] - '0';
		
		if (D[d])
			return false;
	}

	return true;
}

int main()
{
	int N, K, d, ans;

	for (int i = 0; i < 10; i++)
		D[i] = false;
	
	cin >> N >> K;
	ans = N;

	for (int i = 0; i < K; i++)
	{
		cin >> d;
		D[d] = true;
	}

	while (ans <= N * 10)
	{
		if (check(ans))
			break;

		ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int w[10]={1,2,4,8,16,32,64,128,256,512};
  int i,n,ans[10],end;
  
  while(~scanf("%d",&n)){
    end=-1;
    for(i=0;i<10;i++)ans[i]=0;
    for(i=9;i>=0;i--){
      if(w[i]<=n){
	n-=w[i];
	ans[i]=1;
	if(end<0)end=i;
      }
    }
    for(i=0;i<10;i++){
      if(ans[i]==1 && i==end)printf("%d\n",w[i]);
      else if(ans[i]==1 && i!=end)printf("%d ",w[i]);
    }
  }
  return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

int readint(){
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int ans[505][505];

int main(){
	n=readint();
	if(n==1){
		printf("Yes\n");
		printf("1\n");
		return 0;
	}
	if(n&1) return printf("No\n"),0;
	for(int i=1;i<=n;i++) ans[i][i]=2*n-1;
	for(int i=1;i<n;i++){
		ans[n][i]=2*i-1,ans[i][n]=2*i;
		int nl=i%(n-1)+1,nr=i-1;
		if(nr==0) nr=n-1;
		for(int j=1;j<=n/2-1;j++){
			ans[nl][nr]=2*i-1,ans[nr][nl]=2*i;
			nl=nl%(n-1)+1,nr--;
			if(nr==0) nr=n-1;
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			printf("%d",ans[i][j]);
			if(j<n) printf(" ");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 4132
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);(i)++)
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);(i)--)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

int cnt[10];

int main(){
    int n;
    cin >> n;
    REP(i,0,n){
        int a;
        cin >> a;
        REP(j,1,9){
            if (a < 400 * j){
                cnt[j]++;
                break;
            }
        }
        if (a >= 3200) cnt[9]++;
    }

    int sum = 0;
    REP(i,0,9){
        if (cnt[i] > 0) sum++;
    }

    cout << max(1, sum) << " " << sum + cnt[9] << endl;
    
    return 0;
}

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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<int>>data(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      char a;
      cin >> a;
      if(a=='.') data.at(i).at(j)=0;
      else data.at(i).at(j)=-1;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data.at(i).at(j)==0){
        int count=0;
        if(i!=0){
          if(data.at(i-1).at(j)==-1) count++;
        }
        if(i!=0&&j!=0){
          if(data.at(i-1).at(j-1)==-1) count++;
        }
        if(i!=0&&j!=W-1){
          if(data.at(i-1).at(j+1)==-1) count++;
        }
        if(j!=0){
          if(data.at(i).at(j-1)==-1) count++;
        }
        if(j!=W-1){
          if(data.at(i).at(j+1)==-1) count++;
        }
        if(i!=H-1){
          if(data.at(i+1).at(j)==-1) count++;
        }
        if(i!=H-1&&j!=0){
          if(data.at(i+1).at(j-1)==-1) count++;
        }
        if(i!=H-1&&j!=W-1){
          if(data.at(i+1).at(j+1)==-1) count++;
        }
        data.at(i).at(j)=count;
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(data.at(i).at(j)==-1) cout << "#";
      else cout << data.at(i).at(j);
    }
    cout << endl;
  }
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 998244353
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a, b;
li c, d;

li dp[3030][3030];

int main() {
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    repp(i, a + 1, c + 1) {
        dp[i][b] = dp[i - 1][b] * b % MOD;
    }
    repp(j, b + 1, d + 1) {
        dp[a][j] = dp[a][j - 1] * a % MOD;
    }
    repp(i, a + 1, c + 1) {
        repp(j, b + 1, d + 1) {
            dp[i][j] = (dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1) % MOD + MOD) % MOD;
        }
    }
    cout << dp[c][d] << endl;

    return 0;
}

Measured memory_bytes: 74624
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

ll ans=0;
ll n;
string s;
ll cnt=0;
vector<P> p;
ll sz;
int main()
{
	cin>>s;
	p.reserve(1000001);
	n=s.length();
	rep(i,n){
		if(i==0){
			if(s[0]=='J') p.pb(P(1,0));
			else if(s[0]=='O') p.pb(P(1,1));
			else p.pb(P(1,2));
		}
		else{
			if(s[i]!=s[i-1]){
				if(s[i]=='J') p.pb(P(1,0));
				else if(s[i]=='O') p.pb(P(1,1));
				else p.pb(P(1,2));
			}
			else{
				p[p.size()-1].fr++;
			}
		}
	}
	for(ll i=0;i+2<p.size();i++){
		if(p[i].sc==0&&p[i+1].sc==1&&p[i+2].sc==2&&p[i].fr>=p[i+1].fr&&p[i+1].fr<=p[i+2].fr){
			ans = max(ans , p[i+1].fr );
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

int n, x, y;

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

    cin >> n;

    x = 800 * n;
    y = 200 * (n / 15);

    cout << x - y << endl;

    return 0;
}


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

typedef long long int number;

const number MOD = 1e9 + 7;
const int XMAX = 4e5 + 8;
number fact[XMAX], invfact[XMAX];
number N, M, K;

number pow(number a, number n) {
  if (n == 0) {
    return 1;
  } else if (n % 2 == 0) {
    number rt = pow(a, n / 2) % MOD;
    return rt * rt % MOD;
  } else {
    return pow(a, n - 1) * a % MOD;
  }
}

void construct_factorial(int n) {
  fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  invfact[0] = 1;
  for (int i = 1; i <= n; i++) {
    invfact[i] = pow(fact[i], MOD - 2);
  }
}

number Comb(number n, number k) {
  return fact[n] * invfact[k] % MOD * invfact[n - k] % MOD;
}

number Uncomb(number n, number k) {
  return (Comb(n+k, k) + MOD - Comb(n+k, k-1)) % MOD;
}

number solve() {
  number ans = 0;
  for (number k = 0; k <= K; k++) {
    number j = K - k;
    ans += Uncomb(N+k, k) * Uncomb(M+j, j) % MOD * 
      Comb(N+M+2*K, N+2*k) % MOD;
    ans %= MOD;
  }
  return ans;
}

int main() {
  cin >> N >> M >> K;
  construct_factorial(4e5);
  cout << solve() << endl;
}

Measured memory_bytes: 7404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple


signed main() {
#ifdef LC
	assert(freopen("input.txt", "r", stdin));
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	int ans = 0;
	int cnt = 0;
	for (int i = 0; i < (int)s.size(); ++i) {
		if (s[i] == 'B') {
			++cnt;
			ans += (int)s.size() - i;
		}
	}
	ans -= cnt * (cnt + 1) / 2;
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 720
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  ll a[1010], b[1010], c[1010];
  for (int i = 0; i < x; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < y; i++)
  {
    cin >> b[i];
  }
  for (int i = 0; i < z; i++)
  {
    cin >> c[i];
  }

  vector<ll> ab;
  for (int i = 0; i < x; i++)
  {
    for (int j = 0; j < y; j++)
    {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.begin(), ab.end());
  reverse(ab.begin(), ab.end());

  vector<ll> abc;
  for (int i = 0; i < min(x * y, k); i++)
  {
    for (int j = 0; j < z; j++)
    {
      abc.push_back(ab[i] + c[j]);
    }
  }
  sort(abc.begin(), abc.end());
  reverse(abc.begin(), abc.end());
  for (int i = 0; i < k; i++)
  {
    cout << abc[i] << "\n";
  }
}

Measured memory_bytes: 42980
s,t=input(),input()

dp=[[0]*(len(t)+1) for i in range(len(s)+1)]

for i in range(len(s)):
    for j in range(len(t)):
        if s[i]==t[j]:
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1,dp[i][j+1],dp[i+1][j])

        dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j],dp[i][j+1])
#print(dp)

#部分配列を復元する

ans_str=''
i=len(s)
j=len(t)
while i>0 and j>0:
    if dp[i][j]==dp[i-1][j]:
        i=i-1
    elif dp[i][j]==dp[i][j-1]:
        j=j-1
    else:
        ans_str=s[i-1]+ans_str
        i=i-1
        j=j-1
print(ans_str)

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

int main() {
  int l, n;
  cin >> n >> l;
  vector<string> s(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  for (i = 0; i < n; i++) {
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A = [x - i - 1 for i, x in enumerate(A)]
A.sort()
mid = A[N // 2]
res1 = 0
for a in A:
    res1 += abs(a - mid)

mid += 1
res2 = 0
for a in A:
    res2 += abs(a - mid)


print(min(res1, res2))


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

int main(){
    int N;
    cin >> N;
    for (int i = 0; i <= (N / 4); i ++){
        for (int j = 0; j <= (N / 7); j ++){
            if ((4 * i + 7 * j) == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  string S,T;
  cin >> S;
  cin >> T;
  int ans = 0;
  for(int i = 0; i < S.size(); i++){
    if(S[i] != T[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3816
#include<bits/stdc++.h>
#define LL long long
using namespace std;
typedef vector<int>V;
typedef priority_queue<int,V,greater<int>>PQ;
int main(void){
	int n,m;
	int x;
	int i,j;
	LL sum;
	PQ que;
	sum=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>m;
		for(j=0;j<m;j++){
			cin>>x;
			que.push(x);
		}
		for(j=0;j<m-1;j++)	que.pop();
	}
	for(i=0;i<n;i++){
		x=que.top();
		//cout<<x<<endl;
		sum+=(LL)x;
		que.pop();
	}
	cout<<sum<<endl;
	return 0;
}
	
	


Measured memory_bytes: 4940
#include <stdio.h>

int N, a[401];
long long dp[401][401] = {}, sum[401];
const long long sup = (long long)1 << 60;

long long recursion(int l, int r)
{
	if (dp[l][r] != 0 || l == r) return dp[l][r];
	else dp[l][r] = sup;
	
	int k;
	long long tmp;
	for (k = l + 1; k <= r; k++) {
		tmp = recursion(l, k - 1) + recursion(k, r);
		if (tmp < dp[l][r]) dp[l][r] = tmp;
	}
	dp[l][r] += sum[r] - sum[l-1];
	return dp[l][r];
}

int main()
{
	int i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	for (i = 1, sum[0] = 0; i <= N; i++) sum[i] = sum[i-1] + a[i];
	printf("%lld\n", recursion(1, N));
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 3024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main() {
    long long N;
    cin >> N;
    long long A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    bool isWin = true;
    for(int i = 0; i < N; i++){
        if(A[i] % 2 == 1){
            isWin = false;
        }
    }
    if(isWin){
        cout << "second" << endl;
    }else{
        cout << "first" << endl;
    }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int w,n;
  int cnt = 1;
  char c;
  while(cin >> w){
    if(w == 0) break;
    cin >> n;
    vary(int,vs,n,0);
    vary(int,ws,n,0);
    vector<vector<pii>> dp(n+1,vector<pii>(w+1,make_pair(0,0)));
    rep(i,n){
      cin >> vs[i] >> c >> ws[i];
    }
    REP(i,0,n){
      rep(j,w+1){
        if(j <ws[i]){
          dp[i+1][j] = dp[i][j];
        }
        else{
          pii tmp;
          if(dp[i][j].fi < dp[i][j-ws[i]].fi+vs[i]){
            int k = dp[i][j-ws[i]].fi+vs[i];
            tmp = make_pair(k,j);
          }
          else{
            tmp = dp[i][j];
          }
          dp[i+1][j] = tmp;
        }
      }
    }
    cout << "Case " + to_string(cnt) + ":"<<endl;
    cout << dp[n][w].fi <<endl;
    rep(i,w+1){
      if(dp[n][i].fi == dp[n][w].fi){
        cout << i << endl;
        break;
      }
    }
    ++cnt;
  }
  return 0;
}

Measured memory_bytes: 10792
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

int main() {
SS(ll,n)
ll renzoku=0;
bool OK=false;
rep(i,n){
    SS(ll,a,b)
    if(a==b)renzoku++;
    else renzoku=0;
    if(renzoku==3)OK= true;
}
Yes(OK);
}

Measured memory_bytes: 3608
R,G,B,N= map(int,input().split())
count =0
l = [R,G,B]
l.sort(reverse = True)
for i in range(3002):
    if l[0]*i > N:
        break
    for j in range(3002):
        if l[0]*i + l[1]*j >N:
            break
        if (N-(l[0]*i + l[1]*j))%l[2] ==0:
            count +=1

print(count)

Measured memory_bytes: 40940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k, n, a[200005];
ll mod = 1000000000 + 7;
int main(void) {
	scanf("%lld%lld", &n, &k);
	ll _1 = 0, _2 = 0, _3 = 0;
	for (ll i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		if (a[i] < 0)
			_1++;
		else if (a[i] == 0)
			_2++;
		else
			_3++;
	}
	sort(a, a + n);
	ll ans = 1;
	if (k % 2 == 1){
		if (_3 == 0)
		{
			for (ll i = 0; i < k; i++)
			{
				ans *= a[n - i - 1];
				ans %= mod;
			}
			printf("%lld", (ans % mod + mod) % mod);
			return 0;
		}
		ans = a[n - 1];
		n--;
		_3--;
		k--;
	}
	ll bg = 0, ed = n - 1;
	while (true)
		if (k == 0) break;
		else if (_3 > 1 && _1 > 1)
		{
			if (a[bg] * a[bg + 1] > a[ed] * a[ed - 1])	{
				ans *= a[bg] * a[bg + 1] % mod;
				ans %= mod;
				bg += 2;
				_1 -= 2;
				k -= 2;
			}else{
				ans *= a[ed] * a[ed - 1] % mod;
				ans %= mod;
				ed -= 2;
				_3 -= 2;
				k -= 2;
			}
		}else if (_3 > 1){
			ans *= a[ed] * a[ed - 1] % mod;
			ans %= mod;
			ed -= 2;
			_3 -= 2;
			k -= 2;
		}else if (_1 > 1){
			ans *= a[bg] * a[bg + 1] % mod;
			ans %= mod;
			bg += 2;
			_1 -= 2;
			k -= 2;
		}else{
			for (ll i = ed; i > ed - k; i--)
			{
				ans *= a[i];
				ans %= mod;
			}
			break;
		}
	printf("%lld", (ans % mod + mod) % mod);
}

Measured memory_bytes: 5284
#include "bits/stdc++.h"
#define long int64_t
using namespace std;

struct Solver {
	static const long mod = 1000000007;

	void solve() {
		int N;
		cin >> N;
		vector<int> A( N );
		for( int i = 0; i < N; ++i ) { cin >> A[i]; }
		vector<long> B( N+1 );
		for( int i = 1; i <= N; ++i ) {
			B[i] = B[i-1] + A[i-1];
		}
		long ans = 0;
		for( int i = 0; i < N; ++i ) {
			ans += (B[N] - B[i+1]) % mod * A[i];
			ans %= mod;
		}
		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 5548
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>

using namespace std;

int main() {
	
	while (1) {

		int n;
		cin >> n;
		if (n == 0)break;
		typedef pair<int, char> pea;
		vector<char> name;
		vector <pea> vote;

		for (int i = 0;i < n;i++) {
			char c;
			cin >> c;
			name.push_back(c);
		}

		for (int i = 1;i <= n;i++) {
			//cout << i << endl;
			/*char C;
			cin >> C;*/

			char C = name[i - 1];

			if (n == 1) {
				cout << C << ' ' << 1 << endl;
				break;
			}
		
			//add vote
			bool ex=false;
			for (int j = 0;j < vote.size();j++) {
				if (vote[j].second == C) {
					vote[j].first++;
					ex = true;
				}
			}

			if (!ex) vote.push_back(make_pair(1, C));

			
			if (vote.size() == 1 && vote[0].first>n-i){
				cout << vote[0].second << ' ' << i << endl;
				break;
			}

			if (vote.size() >= 2) {
				//find first and second
				sort(vote.begin(), vote.end());
				pair<char, int> fst = make_pair(vote[vote.size() - 1].second, vote[vote.size() - 1].first);
				int scd = vote[vote.size() - 2].first;

				if (fst.second > scd + (n - i)) {
					cout << fst.first << ' ' << i << endl;
					break;
				}
				else if (i == n) {
					cout << "TIE" << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e6)+10;
int n,d[maxn],sum;
char s[maxn];
int c[2][2];
bool in(int t,int i) {
	if (t&(1<<i)) return 1;
	return 0;
}
int C(int y,int x) {
	int res=1;
	for (int i=0;i<=25;i++) {
		res=res*c[in(y,i)][in(x,i)];
		if (!res) return 0;
	}
	return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	c[0][0]=1;
	c[1][0]=1;
	c[0][1]=0;
	c[1][1]=1;
	read(n);
	scanf("%s",s+1);
	for (int i=1;i<=n;i++) {
		if (C(n-1,i-1)) sum=(sum+s[i]-'0')%2;
	}
	if (sum&1) { printf("1\n"); return 0; }
	for (int i=1;i<n;i++) d[i]=abs(s[i]-s[i+1]);
	n--;
	if (n==1) { printf("%d\n",d[1]); return 0; }
	bool flag=1;
	for (int i=1;i<=n;i++)
		if (d[i]==1) { flag=0; break; }
	if (!flag) { printf("0\n"); return 0; }
	sum=0;
	for (int i=1;i<=n;i++)
		if (C(n-1,i-1)&&d[i]==2) sum++;
	if (sum&1) printf("2\n");
	else printf("0\n");
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 5120
#include<stdio.h>

int main(void)
{
	int a, b;
	scanf("%d %d", &a, &b);
	if (a > b)
		printf("a > b\n");
	else if (a == b)
		printf("a == b\n");
	else
		printf("a < b\n");
	return 0;
}


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

int main()
{    
    string s, t;
    cin >> s >> t;

    int dp[s.size()+1][t.size()+1]={0};

    for (int i = 0; i < s.size()+1; ++i) {
        for (int j = 0; j < t.size()+1; ++j) {
            dp[i][j]=0;
            
        }
    }

    for (int i = 0; i < s.size(); ++i) {
        for (int j = 0; j < t.size(); ++j) {
            if (s[i]==t[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }
            if (dp[i][j+1]>dp[i+1][j+1]){
                dp[i+1][j+1]=dp[i][j+1];
            }
            if (dp[i+1][j]>dp[i+1][j+1]){
                dp[i+1][j+1]=dp[i+1][j];
            }
        }
    }
    
    string result="";
    
    int i=s.size()-1;
    int j=t.size()-1;
    
    while (i>=0 && j>=0){
        if (dp[i+1][j+1]==0){break;}
        if (dp[i+1][j+1]==dp[i][j+1]){
            i-=1;
        } else if (dp[i+1][j+1]==dp[i+1][j]){ 
            j-=1;
        } else {
            result=s[i]+result;
            i-=1;
            j-=1;
        }

    }
    
    
    cout << result << endl;
    
    return 0;
}

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

int main(){
  int n,i;
  cin >> n;
  vector<int> x(n),y(n);
  
  for(i=0;i<n;i++){
    cin >> x.at(i);
    y.at(i)=x.at(i);
  }
  
  sort(y.begin(),y.end());
  for(i=0;i<n;i++){
    if(x.at(i)<=y.at(n/2-1)){
      cout << y.at(n/2) << endl;
    }else{
      cout << y.at(n/2-1) << endl;
    }
  }
}

Measured memory_bytes: 4856
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1e9+7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  rep(i, n)
    cin >> x[i];
  rep(i, m)
    cin >> y[i];
  ll xsum = 0, ysum = 0, prev = 0;
  for (int i = 1; i < n; i++) {
    ll dist = (x[i]-x[i-1])%MOD;
    (xsum += prev+dist*i) %= MOD;
    prev = (prev+dist*i)%MOD;
  }
  prev = 0;
  for (int i = 1; i < m; i++) {
    ll dist = (y[i]-y[i-1])%MOD;
    (ysum += prev+dist*i) %= MOD;
    prev = (prev+dist*i)%MOD;
  }
  cout << xsum*ysum%MOD << endl;
  return 0;
}

Measured memory_bytes: 1792