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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int x, n;
    cin >> x >> n;
    int ans = -1;
    int dist = 1e5;
    int p[102];
    rep(i, 102) p[i] = 0;
    rep(i, n)
    {
        int tmp;
        cin >> tmp;
        p[tmp]++;
    }
    rep(i, 102)
    {
        if(p[i]!=0)
            continue;
        if(dist > abs(x-i)){
            dist = abs(x - i);
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
import java.util.Scanner;

public class Main {
    //Ferris Wheel
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int age = sc.nextInt();
        int cost = sc.nextInt();
        sln(age, cost);
    }

    public static void sln(int age, int cost) {
        if (age >= 13) System.out.println(cost);
        else if (age >= 6 && age <= 12) System.out.println(cost / 2);
        else if (age < 6) System.out.println(0);
    }
}

Measured memory_bytes: 21716
str1 = input()
li = list(str1)
flag = False
for i in range(len(li)):
    a = i+1
    x = li[i]
    while a < len(li):
        if x == li[a]:
            flag = True
            break
        a += 1
    if flag:
        break
if flag:
    print('no')
else:
    print('yes')

Measured memory_bytes: 8968
(defun main ()
  (let ((n (read))
        (k (read))
        (s (read-line))
        (LR 0)
        (RL 0)
        (ans -1))
    (loop for i from 0 below (- n 1)
          do (let ((temps (subseq s i (+ i 2))))
               (cond ((string= temps "LR") (incf LR))
                     ((string= temps "RL") (incf RL)))))
    ;;(format t "~A ~A~%" LR RL)
    (decf ans (cond ((<= (max LR RL) k) 0)
                    ((= LR RL) (* 2 (- RL (min k RL))))
                    (t (1- (* 2 (- (max RL LR) (min k (max RL LR))))))))
    (format t "~A~%" (+ n ans))))

(main)


Measured memory_bytes: 30308
#include <cstdio>
#include <iostream>
using namespace std;
typedef struct _data
{
    int time;
    int x;
    int y;
}Data;
Data point[100005];
int N, sx, sy, Time, result;
char word[2][5] = {"Yes", "No"};

int abs(int num)
{
    return num > 0 ? num : -num;
}

int main()
{
    scanf("%d", &N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d %d %d", &point[i].time, &point[i].x, &point[i].y);
    }
    for(int i = 0; i < N; i++)
    {
        int dis;
        dis = abs(sx - point[i].x) + abs(sy - point[i].y);
        if(dis > point[i].time - Time)
        {
            result = 1;
            break;
        }
        else if(dis < point[i].time - Time && (point[i].time - Time - dis) % 2 == 1)
        {
            result = 1;
            break;
        }
        Time = point[i].time;
        sx = point[i].x;
        sy = point[i].y;
    }
    printf("%s", word[result]);
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int X,A,B;cin >> X >> A >> B;
    if(abs(X-A)>abs(X-B)) cout << 'B' << endl;
    else cout << 'A' << 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;
using P=pair<int,int>;

int main(){
   int x; cin>>x;
   while(1){
      bool ok=true;
      for(int i=2;i<x;i++){
         if(x%i==0){
            //自分より前の数で割れないのが素数だから割れるときにfalse
            ok=false;
            break;
         }
      }
      //okがtrueになるときxは素数
      if(ok) break;
      ++x;
   }
   cout<<x<<endl;
   return 0;
}

Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		int[] ans = new int[1<<11];

		int[] bitNum = new int[1<<11];

		ans[0] = 0;

		for(int i = 0; i < 1<<10;i++){

			for(int j = 1, k =0; j < 1<<11 && k< 10; j = j <<1 , k++){

				if((i&j) == 0){

					ans[i|j] = ans[i]+ k;

					bitNum[i|j] = bitNum[i]+1;

				}

			}

		}

		

		for(;;){

			int n = sc.nextInt();

			int s = sc.nextInt();

			if((n|s) == 0){

				break;

			}

			int count = 0;

			for(int i =0; i < 1<<11;i++){

				if(bitNum[i] == n && ans[i] == s){

//					System.out.println(i);

					count ++;

				}

			}

			System.out.println(count);

		}

		

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

		

	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 2e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

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

  int n = s.size();
  rep(i, n) cout << 'x';
  cout << endl;


  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x, y, w, h, start = 0, point = 0, goal, count, k=0;    
        while(true){
            goal = 0;
            count = 0;
            w = sc.nextInt();
            h = sc.nextInt();
            int[] movex = {0, 1, 0, 0}, movey = {0, 0, 0, 1}, movexx = {-1, 1, 0, 0}, moveyy = {0, 0, -1, 1};
            if(w==0 && h==0) break;
            int[][] tate = new int[h+1][w+1];
            int[][] yoko = new int[h+1][w+1];
            int[][] data = new int[h+1][w+1];
            for(int i=0;i<w;i++){
                yoko[0][i] = 1;
                yoko[h][i] = 1;
            }
            for(int i=0;i<h*2-1;i++){
                for(int j=0;j<=w;j++){
                    if(i%2==0){
                        if(j==0 || j==w){
                            tate[i/2][j] = 1;
                        }else{
                            tate[i/2][j] = sc.nextInt();
                        }
                    }else{
                        if(j==w) break;
                        yoko[i/2+1][j] = sc.nextInt();
                    }
                }
            }
            Queue<Integer> queue = new LinkedList<Integer>();
            queue.add(start);
            while(!queue.isEmpty()){
                point = queue.remove();
                k = point/10000;
                point -= k*10000;
                x = point/100;
                y = point%100;
                if(x==w-1 && y==h-1){
                    count = k + 1;
                    goal++;
                    break;
                }
                data[y][x] = 1;
                for(int i=0;i<4;i++){
                    if((tate[y][x+movex[i]]==0 && data[y][x+movexx[i]]==0) || (yoko[y+movey[i]][x]==0 && data[y+moveyy[i]][x]==0)){
                        int c = k+1;
                        int p = x+movexx[i];
                        int q = y+moveyy[i];
                        int r = c*10000+p*100+q;
                        data[q][p] = 1;
                        queue.add(r);
                    }
                }
            }
            if(goal==1){
                System.out.println(count);
            }else{
                System.out.printf("0\n");
            }
            while(!queue.isEmpty()){
                int bag = queue.remove();
            }
        }
    }
}


Measured memory_bytes: 70348
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=x*10+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x>=10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int k,int mod){
	int res=1,bas=x;
	while(k){
		if(k&1) res=1ll*res*bas%mod;
		bas=1ll*bas*bas%mod,k>>=1;
	}
	return res;
}
int n;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n);
	int x=n/100,y=n%100;
	int t=(x>=1&&x<=12);
	int t1=(y>=1&&y<=12);
	if(t1&&t) puts("AMBIGUOUS");
	else if(t) puts("MMYY");
	else if(t1) puts("YYMM");
	else puts("NA");
	return 0;
}

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

int main(){
    int k;
    string s,m;
    cin >> k >> s;
if(s.size() <= k){
    cout << s << endl;
}else{
    s.erase(k);
    m = s+"...";
    cout << m << endl;
}

    }

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

int main(){
	double W,H,x,y;
	cin >> W >> H >> x >> y;
	
	if (x == W/2 && y == H/2){
		cout << W*H/2 << " " << 1 << endl;
	}else{
		cout << W*H/2 << " " << 0 << endl;
	}
	
}



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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll c = 0;
    FOR(i, n - 2)
    {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') c++;
    }
    cout << c << '\n';
}



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

typedef long long ll;

int main(){
    string s;
    cin>>s;
    int ans=s.size();
    int sz=ans;
    for(int i=1;i<sz;++i){
        if(s[i-1]!=s[i]){
            ans=min(ans,max(i,sz-i));
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

set<int> v;

int main()
{
    int n;
    cin>>n;
    int x;
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &x);
        v.insert(x);
    }
    cout<<(int)v.size();
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
s = input()
b = []
shio = 1
for i in range(n):
  if i == n-1:
    b.append(shio)
    break
  if s[i] == s[i+1]:
    shio += 1
    continue
  else:
    b.append(shio)
    shio = 1
ans = 0
for i in b:
  if i >= 2:
    ans += i-1
if (len(b)//2) - k <=0:
  ans = len(s)-1
if (len(b)//2) - k >= 1:
  ans += (k*2)
print(ans)
    



Measured memory_bytes: 45296
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var tsum = 0L;
        var count = 0L;
        for (int i = 0; i < n; i++)
        {
            var w = long.Parse(Console.ReadLine().Trim());
            if (w == 0) { count += tsum / 2; tsum = 0; }
            else tsum += w;
        }
        count += tsum / 2;
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 15312
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    int n,k;
    while(cin>>n>>k){
        cin.ignore();
        cin>>str;
        for(int i=0;i<n;i++){
            if(i==k-1)cout<<(char)tolower(str[i]);
            else cout<<str[i];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int arr[100000];
int each(int pos)
{
    int curr = 0;

    while((abs(arr[curr]+1-arr[curr+1])>1 || arr[curr]+1==10) && curr<pos)
    {
      curr++;
    }
    if(curr == pos)
    {
       if(arr[pos]==9)
       {  
           curr++;pos++;
           arr[curr]=1;
           for(int  i =pos-1;i>=0;i--)
           arr[i]=0;
       }
       else
       {
            arr[pos]++;
            int  k =arr[pos]-1;
            for(int  i =pos-1;i>=0;i--)
              {arr[i] = max(k,0);k--;}
       }
    }
    else
    {
        arr[curr]++;
        int  k =arr[curr]-1;
        for(int  i =curr-1;i>=0;i--)
            {arr[i] = max(k,0);k--;}
    }

  return pos;
}


signed main()
{
     int n;
     cin>>n;
     memset(arr,0,sizeof(arr));
     if(n<=10)
      {cout<<n<<endl;return 0;}
     arr[0]=1;
     arr[1]=1;
     int pos=1;
     for(int  i =12;i<=n;i++)
     {
          pos=each(pos);
     }

   for(int  i =pos;i>=0;i--)
    cout<<arr[i];
    cout<<endl;
    
}

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

long long gcd(long long a, long long b) {
  return b?gcd(b,a%b):a;
}

long long lcm(long long a, long long b) {
  return a*b/gcd(a,b);
}

int main(){
  long long a,b,ans=0;cin>>a>>b;
  cout<<lcm(a,b);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		String S = sc.next();
		sc.close();
		char c[] = S.toCharArray();
		if (c[A] == '-') {
			int sum = 0;
			for (int i = 0; i < S.length(); i++) {
				if ('0' <= c[i] && c[i] <= '9') {
					sum++;
				}
			}
			if (sum == S.length() - 1) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
	}
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < n; i++)

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

template <typename T> struct vector2 : public vector<vector<T>> { vector2(int n, int m, const T& k = T()) : vector<vector<T>>(n, vector<T>(m, k)) {} };
template <typename T> struct vector3 : public vector<vector2<T>> { vector3(int n, int m, int k, const T &l = T()) : vector<vector2<T>>(n, vector2<T>(m, k, l)) {} };

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  if (n == 1 && m == 1) {
    cout << 1 << endl;
  } else if (n == 1) {
    cout << m - 2 << endl;
  } else if (m == 1) {
    cout << n - 2 << endl;
  } else {
    cout << (m - 2) * (n - 2) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h> 
#define MAX 100005 
#define NIL -1 
struct Node_struct{int p, l, r;}; /*p: (parent), l: (left child), r:(right sibling)*/ 
typedef struct Node_struct Node; 
Node T[MAX]; 
int D[MAX]; 

void print(int u){ 
int i, c; 
printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]); 

if(T[u].p==NIL) printf("root, "); 
else if(T[u].l==NIL) printf("leaf, "); 
else printf("internal node, "); 

printf("["); 
for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){ 
if(i) printf(", "); 
printf("%d", c); 
} 
printf("]\n"); 

} 

void calcDepth(int u, int p){ 
D[u] = p; 
if(T[u].r!=NIL) calcDepth(T[u].r, p); 
if(T[u].l!=NIL) calcDepth(T[u].l, ++p); 
} 

int main(){ 
int i, j, k; 
int n; 
int id, sib, child; 
int root = NIL; 
scanf("%d", &n); 
for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL; 

for(i=0; i<n; i++){ 
    scanf("%d %d", &id, &k); 
    for(j = 0, sib = NIL; j<k; j++){ //(input children) 
        scanf("%d", &child); 
        T[child].p = id; 
        if(j == 0) T[id].l = child; //(the most left child of id) 
        else T[sib].r = child; //(connect to left sibling) 
        sib = child;//(the left sibling of the next child) 
    } 
} 

//(find the root) 
for(i=0; i<n; i++){ 
if(T[i].p == -1) root = i; 
} 

//(find depth of each node) 
calcDepth(root, 0); 

//(output) 
for(i=0; i<n; i++) print(i); 

return 0; 
}



Measured memory_bytes: 6412
//Bottom up solution
//Space complexity = O(W)
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	ll N, W;
	ll sum_val =0;
	cin>>N>>W;
	std::vector<ll> wt(N,0);
	std::vector<ll> v(N,0);
	for(ll i=0; i<N; i++){
		cin>>wt[i]>>v[i];
		sum_val += v[i];
	}
	std::vector<vector<ll>> memo(N+1, vector<ll>(sum_val+1, 0));
	fill(memo[0].begin()+1, memo[0].end(), INT_MAX);
	for(ll i=1; i<=N; i++){
		for(ll j = 1; j <= sum_val; j++){
			if(v[i-1] <= j){
				memo[i][j] = std::min(wt[i-1] + memo[i-1][j-v[i-1]], memo[i-1][j]);
			}
			else{
				memo[i][j] = memo[i-1][j];
			}
		}
	}
	// for(auto m : memo){
	// 	for(auto u: m){
	// 		cout<<u<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	for(ll i=sum_val; i>0; i--){
		if(memo[N][i] <= W){
			cout<<i<<"\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 80256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <map>
#include <iostream>
#include<math.h>
using namespace std;

int main() {
	long long N,pi=1;
	cin >> N;
	for (long i = 1; i <= N; i++) {
		pi =pi* i%1000000007;
	}

	cout << pi << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// youtube editorial

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;

  vector<ll> acc(n + 1);
  rep(i, n) acc[i + 1] = acc[i] + a[i];

  ll ans = INF;
  // 真ん中を探索
  // a に関して, 左の右端
  rep3(i, 1, n - 2) {
    vector<pair<ll, ll> > v(3), v2(3);
    // 左
    int it = ub(acc, (acc[i + 1] + 1) / 2);
    if (it == i + 1) it--;

    rep(j, 3) {
      v[j].F = acc[it];
      v[j].S = acc[i + 1] - acc[it];
      it--;
      if (it == 0) it++;
    }
    // debug
    /*
    cout << endl << v[0].F.F << " " << v[0].F.S << endl;
    cout << v[2].F.F << " " << v[2].F.S << endl;
    */

    // 右
    it = ub(acc, acc[i + 1] + ((acc[n] - acc[i + 1]) + 1) / 2);
    if (it == n) it--;
    rep(j, 3) {
      v2[j].F = acc[n] - acc[it];
      v2[j].S = acc[it] - acc[i + 1];
      it--;
      if (it == i + 1) it++;
    }
    /*
    cout << endl << v[0].S.F << " " << v[0].S.S << endl;
    cout << v[1].S.F << " " << v[1].S.S << endl;
    */
    rep(j, 3) rep(k, 3) {
      vector<ll> v3(4);
      v3[0] = v[j].F;
      v3[1] = v[j].S;
      v3[2] = v2[k].F;
      v3[3] = v2[k].S;
      sort(all(v3));
      chmin(ans, v3[3] - v3[0]);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#

import sys
input=sys.stdin.readline

def main():
    D=int(input())
    C=list(map(int,input().split()))
    S=[list(map(int,input().split())) for i in range(D)]
    T=[[0]]+[int(input()) for i in range(D)]
    last=[[0]*27 for i in range(D+1)]
    for i in range(1,D+1):
        for j in range(i,D+1):
            last[j][T[i]]=i
    sat=0
    for i in range(1,D+1):
        sat+=S[i-1][T[i]-1]
        for j in range(1,27):
            sat-=C[j-1]*(i-last[i][j])
        print(sat)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 68552
#include <stdio.h>

int main(void)
{
  int a, b, temp1, temp2;

  scanf("%d%d", &a, &b);

  temp1 = a+b;
  temp2 = a-b;

  temp1 =  ( temp1 > temp2 ? temp1:temp2);
  temp2 = a*b;
  temp1 =  ( temp1 > temp2 ? temp1:temp2);

  printf("%d", temp1);

  return 0;

}


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

const long long linf = (1LL<<60);
const int mod = 1e9+7;

long long dfs(int K, const vector<vector<int>>&graph, int now, int from) {
  int can_use_color_num;
  if(from == -1) {
    can_use_color_num = K-1;
  } else {
    can_use_color_num = K-2;
  }

  if(K < graph[now].size()) {
    return 0;
  } else {
    long long case_num = 1;
    for(auto e : graph[now]) {
      if(e == from) continue;

      case_num *= can_use_color_num;
      can_use_color_num--;
      case_num %= mod;
    }
    for(auto e : graph[now]) {
      if(e == from) continue;
      case_num *= dfs(K, graph, e, now);
      case_num %= mod;
    }
    return case_num;
  }
}

int main() {
  int N, K; cin >> N >> K;
  vector<vector<int> > graph(N);
  for(int i = 0; i < N - 1; ++i) {
    int a, b; cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  long long ans = K * dfs(K, graph, 0, -1);
  ans %= mod;
  cout << ans << endl;

  return 0;
}

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

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

  // ここにプログラムを追記
  string S = "", Num;
  for(int i = 0; i < N; i++) {
  	cin >> S;
    
    if(S == "Y") {
      Num = "Four";
      break;
    }
    else if( Num != "Four") {
      Num = "Three";
    }
  }
  cout << Num << endl;
}

Measured memory_bytes: 3628
def square(x)
  x * x
end

S = gets.to_i
N = gets.chomp.split(' ').map(&:to_i)

arr = Array.new(S*3)


for num1 in 0..arr.size - 1 do
  res = 0
  for num2 in 0..N.size - 1 do
    res += square(N[num2] - (num1+1))
  end
  arr[num1] = res
end

puts arr.min

Measured memory_bytes: 1788
n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
    for j in range(i, n):
        for k in range(j, n):
            if l[i] != l[j] and l[j] != l[k] and l[k] < l[i] + l[j]:
                cnt +=1
            else:
                pass
print(cnt)

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

using namespace std;

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

  vector<int> a(n, 0);
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    a[i] += a[i - 1];
  }

  int now = 0, ans = 0;
  for (int i = 0; i < m; i++) {
    int next;
    cin >> next;
    next += now;
    ans += abs(a[next] - a[now]);
    ans %= 100000;
    now = next;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18 
 
using namespace std;


signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,i;
    cin>>n;
    vi v(n);
    int ans=0;
    for(i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int k=n-1;
    ans+=v[n-1];
    k--;
    for(i=n-2;i>=0;i--)
    {
        if(k==0) break;
        ans+=v[i];
        k--;
        if(k==0) break;
        ans+=v[i];
        k--;
    }
    cout<<ans;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> hp(n);
  rep(i, n) cin >> hp[i];
  sort(hp.begin(), hp.end());
  if (hp.size() <= k) {
    cout << 0 << endl;
  } else {
    ll attack_times = 0;
    rep(i, n - k) attack_times += hp[i];
    cout << attack_times << endl;
  }
  return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<vector<double> > dp(n+1,vector<double> (n+1));
    vector<double>  a(n+1);
    for(int i=1;i<=n;i++)
    cin>>a[i];
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j]*(1-a[i])+dp[i-1][j-1]*a[i];
        }
    }
    double sum=0;
    for(int i=(n+1)/2;i<=n;i++)
    {
        sum+=dp[n][i];
    }
    printf("%.10lf",sum);
}

Measured memory_bytes: 74216
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MAX 100000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;


int main(void) {
    ll N;
    cin >> N;
    string s, t;
    cin >> s;
    cin >> t;
    ll i, ans=1;
    ll state=0;
    ll r;
    
    if(s[0]==s[1]) {
        state=0;
        ans*=3*2;
        r=2;
    }else {
        state=1;
        ans*=3;
        r=1;
    }
    
    for(i=r; i<N; i++) {
        if(state==0) {
            if(s[i]==t[i]) {
                state=1;
            }else {
                state=0;
                ans*=3;
                i++;
            }
        }else {
            if(s[i]==t[i]) {
                state=1;
                ans*=2;
            }else {
                state=0;
                ans*=2;
                i++;
            }
        }
        ans%=MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long d = scanner.nextLong();
        long lcm = c * d / gcd(c, d);
        long numC = compute(a, b, c);
        long numD = compute(a, b, d);
        long numLCM = compute(a, b, lcm);
        long ans = (b - a + 1) - numC - numD + numLCM;
        writer.println(ans);

        writer.close();
    }

    private static long compute(long a, long b, long c) {
        return b / c - (a / c + (a % c == 0 ? 0 : 1)) + 1;
    }

    private static long gcd(long a, long b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

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

Measured memory_bytes: 21332
/*

この問題はおかしい。
各コンテストでは「参加者」のレーティングが変動するとされている。
高橋くんがAtCodeで次に開催されるABC・ARC・AGCの「参加者」になるという条件は無い。
したがって、「参加者」になれば高橋くんのレーティング的には
レーティングが変動するコンテストであっても、「参加者」にならず、
レーティングが変動しない可能性がある。

クイズでは、問題文を素直に解釈して処理しても正解が得られるとは限らないことはよく知られている。

*/

#include <stdio.h>

int main(void) {
	int R;
	if (scanf("%d", &R) != 1) return 1;
	printf("A%cC\n", R < 1200 ? 'B' : (R < 2800 ? 'R' : 'G'));
	return 0;
}


Measured memory_bytes: 128
/*BY-ADITYA OJHA
  LEARN DSA SINCERELY*/
#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define forjn for(int j=0;j<n;j++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fas1  ios_base::sync_with_stdio(false)
#define fas2   cin.tie(NULL)
#define fas3   cout.tie(NULL)
#define  f   first
#define  s   second
#define mod 1000007
 const ll N=1e5+ 10;
using namespace std;

/*  MODULAR ARITHMETIC
  ******************
  1. (a+b)%c=(a%c + b%c)%c
  2. (a*b)%c=((a%c)*(b*c))%c
  3.  (a-b)%c = ((a%b)-(b%c) + c)%c
  4.   (a/b)%c=((a%c)*(b(inv)%c))%c*/

  int recursivepower(ll x,ll n)
  {
      if(n==0)
        return 1;
      return x*recursivepower(x,n-1);
  }
 /* int iterativepower(ll x,ll n)
  {
      int res=1;
      while(n)
      {
          res*=x;;
          n--;
      }
      return res;
  }*/
  //for large nos
 /* int binaryexp(ll x,ll n)
  {
      if(n==0)
        return 1;
      else if(n%2==0)
        return binaryexp(x*x,n/2);
      else
        return x*binaryexp(x*x,(n-1)/2);
  }*/
 /* int modularExp(ll x,ll n,ll m)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return modularExp((x*x)%m,n/2,m);
    else
        return (x*modularExp((x*x)%m,(n-1)/2,m))%m;
}*/

        //GCD
        /*int gcd(ll a,ll b)
        {
            if(b==0)
                return a;
            else
                return gcd(b,a%b);

        }*/





int main ()
{
    fas1,fas2,fas3;

      ll k,a,b;
      cin>>k>>a>>b;
      ll z=0;

      if(a%k!=0)
        z=a/k + 1;
     // cout<<z<<endl;
      if(a%k==0)
      {
          cout<<"OK"<<endl;
      }else if(k*z<=b)
      {
          cout<<"OK"<<endl;

      }else
      cout<<"NG"<<endl;




}
















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

string s;
int g[100000];
int rec(int from) {
  if (g[from] != -1) return g[from];
  if (s[from] == 'R' && s[from + 1] == 'L') return g[from] = from;
  if (s[from] == 'L' && s[from - 1] == 'R') return g[from] = from - 1;
  
  if (s[from] == 'L') return g[from] = rec(from - 1);
  return g[from] = rec(from + 1);
}

int a[100000];
int main() {
  cin >> s;
  fill(g, g + s.size(), -1);
  
  for (int i = 0; i < s.size(); ++i) {
    int j = rec(i);
    if ((i + j) % 2 == 0) {
      ++a[j];
    } else {
      ++a[j + 1];
    }
  }
  
  for (int i = 0; i < s.size(); ++i) {
    cout << a[i] << ' ';
  }
  cout << endl;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  long long W, H, x, y;
  cin >> W >> H >> x >> y;
  
  double S = W * H;
  cout << S / 2.0 << endl;
  
  if(W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2) {
    cout << 1 << endl;
  }
  else {
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 384
x, y = map(int, input().split())

all_crane_num = x * 2
diff = y - all_crane_num

turtle_num = int(diff / 2)
crane_num = x - turtle_num

if turtle_num >= 0 and crane_num >= 0 and turtle_num*4 + crane_num*2 == y:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9164
#include<bits/stdc++.h>
#define maxn 200010

int a[maxn],mx,mx2,n;

int main() {
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]>mx) {
			mx2=mx;
			mx=a[i];
		}
		else if (a[i]==mx) mx2=mx;
		else if (a[i]>mx2) mx2=a[i];
//		printf("%d %d\n",mx,mx2);
	}
//	printf("%d %d\n",mx,mx2);
	for (i=1;i<=n;i++) 
		if (a[i]==mx) printf("%d\n",mx2);
		else printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int count = scanner.nextInt();
			scanner.nextLine();
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < count; i++) {
				int number = scanner.nextInt();
				int result = devide2Count(number);
				if (result < min) {
					min = result;
				}
			}
			System.out.println(min);
		}
	}

	/**
	 * numberが何回2で割れるかを取得する
	 * 
	 * @param number
	 * @return
	 */
	private static int devide2Count(int number) {
		int result = 0;
		while (number % 2 == 0) {
			number = number / 2;
			result++;
		}
		return result;
	}
}

Measured memory_bytes: 23636
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		long sum = 0;
		long r =0;
		long g = 0;
		long b = 0;
		for (int i = 0; i < n; i++) {
			if (s.charAt(i) == 'R') {
				r++;
			} else if (s.charAt(i) == 'G') {
				g++;
			} else if (s.charAt(i) == 'B') {
				b++;
			}
		}
		sum = r*g*b;
		long sub =0;
		for (int i = 0; i < n; i++) {
			for (int j = i+1; j < n; j++) {
				if (s.charAt(j) == s.charAt(i)) {
					continue;
				}
				int k = j + j -i;
				if (k>=n || s.charAt(k) == s.charAt(i) || s.charAt(k) == s.charAt(j)) {
					continue;
				}
				sub++;
			}
		}
		System.out.println(sum-sub);
	}

}


Measured memory_bytes: 37660
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int a[100007];
	for (int i = 0; i < 100007; i++) {
		a[i] = 0;
	}
	int *b = a + 1;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		b[x - 1]++;
		b[x]++;
		b[x + 1]++;
	}
	int ans=0;
	for (int i = -1; i < 100006; i++) {
		ans = ans < b[i] ? b[i] : ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

using namespace std;

// change min/max
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; }

// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (typename std::vector<T>::const_iterator it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> void inputVec(std::vector<T>& vec) {
	for (typename std::vector<T>::iterator it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

void Main() {
	//int N; cin >> N;
	//const int N = inputVal<int>();
	//std::vector<int> vec(N);
	//inputVec(vec);
	//outputVec(vec);

	const string today = inputVal<string>();
	const string s = "Sunny";
	const string c = "Cloudy";
	const string r = "Rainy";

	if (today == s) {
		outputVal(c);		
	}
	else if (today == c) {
		outputVal(r);
	}
	else {
		outputVal(s);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	return 0;
}


Measured memory_bytes: 256
# ベクトルを固定して全探索まではわかる 実装がわからん
# いやべつに順番は関係ないのか？ 「残っているボールを 1つ選んで回収する。」

n = int(input())
if n == 1:
    print(1)  # 「ただし、1つ目に選んだボールについては必ずコスト 1かかる。」
    exit()
points = []
for _ in range(n):
    points.append(list(map(int, input().split())))

ans = 10**18
for p in range(n):
    for q in range(n):
        if p == q:
            continue
        vector = [points[p][0] - points[q][0], points[p][1] - points[q][1]]
        tmp = 0
        for i in range(n):
            for j in range(n):
                if i == j:
                    continue
                if points[i][0] - points[j][0] == vector[
                        0] and points[i][1] - points[j][1] == vector[1]:
                    tmp += 1

        ans = min(ans, n - tmp)

print(ans)

Measured memory_bytes: 9100
#include <stdio.h>
#define N 200010
int n,m,a[N],b[N],d[N];
inline int min(int a,int b){return a<b?a:b;}
inline int max(int a,int b){return a>b?a:b;}
int main() {
	int x,y,p,ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) scanf("%d",a+i),++b[a[i]];
	for(int i=1;i<=n;++i) if(b[i]) {
		++d[max(1,i-b[i]+1)];
		--d[i+1];
	}
	for(int i=1;i<=n;++i) {
		d[i]+=d[i-1];
		if(!d[i]) ++ans;
	}
	while(m--) {
		scanf("%d%d",&x,&y);
		p=a[x];a[x]=y;
		--b[p];
		if(p>b[p]&&!--d[p-b[p]]) ++ans;
		if(y>b[y]&&!d[y-b[y]]++) --ans;
		++b[y];
		printf("%d\n",ans);
	}
	return 0;
}

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

using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define all(v) v.begin(),v.end()
#define v vector
#define vi vector<int>
#define vi2 vector<vi>
#define vl vector<long long>
#define vl2 vector<vl>

template <class T> T maxAny(T a, T b){
    if(a > b) return a;
    else return b;
}

template <class T> T minAny(T a, T b){
    if(a > b) return b;
    else return a;
}

int main(){
    long long a, v1, b, w, t;
    cin >> a >> v1 >> b >> w >> t;
    long long dis = maxAny(a-b, b-a);
    if(v1 <= w){
        cout << "NO" << endl;
        return 0;
    }
    if(maxAny(v1-w, w-v1) * t >= dis) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3640
n=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[int(i) for i in input().split()]
sat=sum(b)
for i in range(n-1):
  if a[i+1]==a[i]+1:
    sat+=c[a[i]-1]
print(sat)


Measured memory_bytes: 38256
#include<stdio.h>
int main(void)
{
	int a,b,i,x;
	a=0; b=0;
	for(i=0;i<4;i++){
		scanf("%d",&x);
		a=a+x;
	}
	for(i=0;i<4;i++){
		scanf("%d",&x);
		b=b+x;
	}
	if(a>b) printf("%d\n",a);
	else printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 2728
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int solve(vector<int> &vec,int n){
  int x=0;
  int m=n-1;
  for(int i=0;i<n;i++){
    if(vec[i]==1){
      x+=((m&i)==i);
    }
  }
  return x%2;
}

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  int count=0;
  int z=1;
  string s;
  cin>>s;
  
  for(int i=0;i<n;i++){
    if(s.at(i)=='1'){
      vec[i]=0;
    }
    if(s.at(i)=='2'){
      vec[i]=1;
      count++;
    }
    if(s.at(i)=='3'){
      vec[i]=2;
    }
  }
  
  if(count==0){
    for(int i=0;i<n;i++){
      vec[i]/=2;
    }
    z++;
  }
  
  cout<<solve(vec,n)*z<<endl;
}

Measured memory_bytes: 9148
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
d = [abs(a-b) for (a,b) in zip(x,y)]
print(sum(d))
s = 0
for i in range(n):
    s += (x[i]-y[i])**2
print(math.sqrt(s))
s = 0
for i in range(n):
    s += abs(x[i]-y[i])**3
print(s**(1/3))
print(max(d))


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

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    long long int dp[n+1][n+1];
    for(int L=n-1;L>=0;L--)
    {
        for(int R=L;R<n;R++)
        {
            if(L==R)
            {
                dp[L][R] = a[L];
            }
            else
            {
                dp[L][R] = max(a[L]-dp[L+1][R],a[R]-dp[L][R-1]);
            }
            
        }
    }
    cout<<dp[0][n-1]<<endl;
    return 0;


}

Measured memory_bytes: 46336
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, d, s1, s2;
    cin >> a >> b >> c >> d;
    s1 = a*b;
    s2 = c*d;
    if (s1>=s2)
    {
        cout << s1 << endl;
    }
    else{
        cout << s2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cassert>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define pb         push_back

const double eps  = 1e-10;
const int inf = (1 << 21);

class state{
public:
  int t,now,ori;
  int cnt;
  bool operator<(const state & a)const{
    if (now*a.t != a.now*t)return now*a.t < a.now*t;
    return t > a.t;
  }
};

int solve(int n,vector<state>& in){
  int ans=0;
  sort(ALL(in));
  int m= n;

  while(n){
    int mint = inf;
    rep(i,n){
      mint = min(mint,in[i].t-in[i].now%in[i].t);
    }
    
    rep(i,n){
      in[i].now+=1;
      int tnow=in[i].now-1,tt=in[i].t;
      rep(j,n){
	if (i == j)continue;
	if ((tnow)*in[j].t >=(in[j].now)*tt)continue;
	if (in[i].t <= in[j].t)continue;
	if (in[j].now-in[i].now < 0)continue;
	double t = (in[i].t*in[j].t)*(in[j].now-in[i].now)/(double)(in[j].t-in[i].t);
	if (t <0)continue;
	if (t < mint){
	  mint=(int)(t+1);
	}
      }
      in[i].now-=1;
    }
    
    rep(i,n){
      in[i].now+=mint;
      int tnow=in[i].now-mint,tt=in[i].t;
      rep(j,n){
	if (i == j)continue;
	if ((tnow)*in[j].t >=(in[j].now)*tt)continue;
	if ((in[i].now)*in[j].t >= (in[j].now+mint)*in[i].t){
	  in[i].now=in[j].now+mint;
	  in[i].t=in[j].t;
	}
      }
      in[i].now-=mint;
    }

    rep(i,n){
      in[i].now+=mint;
    }

    rep(i,n){
      if (in[i].now%in[i].t == 0){
	if (in[i].now/in[i].t == 1){
	  in[i].t=in[i].ori;
	  in[i].now=in[i].ori;
	}else if (in[i].now/in[i].t==2){
	  in[i].t=in[i].ori;
	  in[i].now=0;
	  in[i].cnt--;
	  if (in[i].cnt == 0)in[i].now=inf,m--;
	}
      }
    }
    
    sort(ALL(in));
    for(int i=n-1;i>=0;i--){
      if (in[i].now == inf)n--;
    }
    ans+=mint;
  }
  return ans;
}

main(){
  int n;
  while(cin>>n && n){
    vector<state> in;
    rep(i,n){
      int t;
      int lap;
      cin>>t>>lap;
      in.pb((state){t,0,t,lap});
    }
    cout << solve(n,in) << endl;
  }
}

Measured memory_bytes: 912
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto N = RD;
	auto A = RDA;

	auto N2 = N / 2;
	auto dp = new long[long][](N+2);
	dp[0][0] = 0;
	foreach (i; 0..N)
	{
		auto remain = N - (i+1);
		auto cnt = (remain+1) / 2;
		auto base = N2 - cnt;
		foreach (key; dp[i].keys)
		{
			if (key >= base)
			{
				auto v = dp[i+1].get(key, long.min);
				dp[i+1][key] = max(v, dp[i][key]);
			}
			auto v = dp[i+2].get(key+1, long.min);
			dp[i+2][key+1] = max(v, dp[i][key]+A[i]);
		}
	}
	debug writeln(dp);

	long ans = long.min;
	foreach (key; dp[N].keys)
	{
		if (key == N2)
			ans.chmax(dp[N][key]);
	}
	foreach (key; dp[N+1].keys)
	{
		if (key == N2)
			ans.chmax(dp[N+1][key]);
	}
	writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 59160