akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    V<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(ALL(a));
    reverse(ALL(a));

    if (n & 1) {
        ll total = 0;
        for (int i = 0; i < n / 2; i++) total += (ll)a[i] * 2;
        total -= (ll)a[n / 2] + (ll)a[n / 2 + 1];
        for (int i = n / 2 + 2; i < n; i++) total -= (ll)a[i] * 2;

        ll total2 = 0;
        for (int i = 0; i < n / 2 - 1; i++) total2 += (ll)a[i] * 2;
        total2 += (ll)a[n / 2 - 1] + (ll)a[n / 2];
        for (int i = n / 2 + 1; i < n; i++) total2 -= (ll)a[i] * 2;
        cout << max(total, total2) << '\n';
    } else {
        ll total = 0;
        for (int i = 0; i < n / 2 - 1; i++) total += (ll)a[i] * 2;
        total += a[n / 2 - 1] - a[n / 2];
        for (int i = n / 2 + 1; i < n; i++) total -= (ll)a[i] * 2;
        cout << total << '\n';
    }
    return 0;
}


Measured memory_bytes: 640
#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() {
    ll n;
    cin>>n;
  	ll m=n;
    string s;
	ll e;//sotonidasitemiru
    rep(i,n){
        e=m%26;
        if(e==0){
            m=m/26-1;
        }else {
            m=m/26;
        }
        //cout<<e<<":"<<m<<endl;//後で消す


        if(e==1){s.insert(0,"a");}
        else if(e==2){s.insert(0,"b");}
        else if(e==3){s.insert(0,"c");}
        else if(e==4){s.insert(0,"d");}
        else if(e==5){s.insert(0,"e");}
        else if(e==6){s.insert(0,"f");}
        else if(e==7){s.insert(0,"g");}
        else if(e==8){s.insert(0,"h");}
        else if(e==9){s.insert(0,"i");}
        else if(e==10){s.insert(0,"j");}
        else if(e==11){s.insert(0,"k");}
        else if(e==12){s.insert(0,"l");}
        else if(e==13){s.insert(0,"m");}
        else if(e==14){s.insert(0,"n");}
        else if(e==15){s.insert(0,"o");}
        else if(e==16){s.insert(0,"p");}
        else if(e==17){s.insert(0,"q");}
        else if(e==18){s.insert(0,"r");}
        else if(e==19){s.insert(0,"s");}
        else if(e==20){s.insert(0,"t");}
        else if(e==21){s.insert(0,"u");}
        else if(e==22){s.insert(0,"v");}
        else if(e==23){s.insert(0,"w");}
        else if(e==24){s.insert(0,"x");}
        else if(e==25){s.insert(0,"y");}
        else if(e==0){s.insert(0,"z");}//あまり26はあり得ない
        
      	if(m<1){break;}//詰めが甘い　条件があれ
      

        
    }
    cout<<s<<endl;
    
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int x;
  cin>>x;
  if(x==3||x==5||x==7)cout<<"YES";
  else cout<<"NO";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e9
typedef long long ll;
using namespace std;
//�I�[�o�[�t���[�ɋC���‚���您����������
//�m�F�Y���Ȃ您����������

int main() {
    int a, b; cin >> a >> b;
    cout << a*b << endl;

    return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il void getmin(T &x,const T &y){if(y<x) x=y;}
template<typename T> il void getmax(T &x,const T &y){if(y>x) x=y;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=2e5+7;

int a[N],n;
int pos1[N],pos2[N];
ll sum[N];

int main(){
//	fileio("test");
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i),sum[i]=sum[i-1]+a[i];
	pos1[2]=1;
	rep(i,3,n){
		int p=pos1[i-1];
		while(p+1<i&&sum[p+1]<=sum[i]-sum[p+1]) ++p;
		pos1[i]=p;
	}
	pos2[n-2]=n-1;
	per(i,n-3,1){
		int p=pos2[i+1];
		while(p-1>i&&sum[n]-sum[p-1]<=sum[p-1]-sum[i]) --p;
		pos2[i]=p;
	}
	ll mx,mn,v1,v2,v3,v4;
	ll ans=linf;
	rep(i,2,n-2){
		mx=-linf,mn=linf;
		int p1=pos1[i],p2=pos2[i];
		v1=sum[i]-sum[p1],v2=sum[p1];
		if(v1<v2) swap(v1,v2);
		v3=sum[p1+1],v4=sum[i]-sum[p1+1];
		if(v3<v4) swap(v3,v4);
		if(p1==i-1||v1-v2<=v3-v4){
			getmax(mx,v1);
			getmin(mn,v2);
		}else{
			getmax(mx,v3);
			getmin(mn,v4);
		}
		assert(mx>=mn);
		v1=sum[p2]-sum[i],v2=(sum[n]-sum[p2]);
		if(v1<v2) swap(v1,v2);
		v3=sum[n]-sum[p2-1],v4=(sum[p2-1]-sum[i]);
		if(v3<v4) swap(v3,v4);
		if(p2==i+1||v1-v2<=v3-v4){
			getmax(mx,v1);
			getmin(mn,v2);
		}else{
			getmax(mx,v3);
			getmin(mn,v4);
		}
		assert(mx>=mn);
		getmin(ans,mx-mn);
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4096
s = input()
ans = 0
cnt = 0

for i in range(len(s)):
    if s[i] == 'R':
        if i > 0 and s[i-1] == 'R':
            cnt += 1
        else:
            cnt = 1
    else:
        cnt = 0
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 9092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <utility>
#include <map>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;


int main()
{
    string s;
    cin>>s;
    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else
        cout<<"Sunny"<<endl;
    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter

import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

S = input()
#N, K = map(int, input().split())
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入

if 'A' in S and 'B' in S:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
stack =[]
line = input().split(' ')
for i in line:
    if i == '+':
        num1 = stack.pop()
        num2 = stack.pop() 
        stack.append(num1 + num2)
    elif i == '-':
        num1 = stack.pop()
        num2 = stack.pop() 
        stack.append(num2 - num1)
    elif i == '*':
        num1 = stack.pop()
        num2 = stack.pop() 
        stack.append(num2 * num1)
    else:
        stack.append(int(i))
print(stack.pop())



Measured memory_bytes: 5596
#include <stdio.h>
int main(void){
    // Your code here!
    int a, b, c, temp;
    int cR = 0,cA = 0, cO =0;
    while(1){
        //三辺を取得
        scanf("%d %d %d",&a, &b,&c);
        //一番大きい辺を探す
        if(b > a) {temp = a; a = b; b = temp;}
        if(c > a) {temp = a; a = c; c = temp;}
        //三角形が成立するか？
        if(a >= b + c)break;
        temp = b*b + c*c;
        a *= a;
        if(a == temp)cR++;
        else if(a < temp)cA++;
        else cO++;
    }
    printf("%d %d %d %d\n",cR+cA+cO,cR,cA,cO);
}



Measured memory_bytes: 2100
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] lot = new int[w];
		sc.nextLine();
		for(int i = 0 ; i < w ; i++){
			lot[i] = i+1;
		}
		for(int i = 0; i < n; i++){
			swap(lot, sc.nextLine().split(","));
		}
		sc.close();
		for(int i = 0; i < w; i++){
			System.out.println(lot[i]);
		}
	}
	static void swap(int[] source, String[] s){
		int a = Integer.parseInt(s[0])-1;
		int b = Integer.parseInt(s[1])-1;
		int tmp = source[a];
		source[a] = source[b];
		source[b] = tmp;
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int comb[] = new int[51];
		for(int a = 0;a <= 9;a++){
			for(int b = 0;b <= 9;b++){
				for(int c = 0;c <= 9;c++){
					for(int d = 0;d <= 9;d++){
						comb[a+b+c+d]++;
					}
				}
			}
		}
		String s = "";
		while((s = br.readLine()) != null){
			int input = Integer.parseInt(s);
			System.out.println(comb[input]);
		}
	}
}

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

int main()
{
  unsigned long N;
  cin >> N;
  
  unsigned long sum = 0;
  for(unsigned long i = 1; i <= N; i++)
  {
    if(i%3 != 0 && i%5 != 0)
    {
      sum += i;
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  int n,a[10],m;
  cin >> n;
  a[0]=n%10;
  a[1]=n/10%10;
  a[2]=n/100%10;
  a[3]=n/1000%10;
  a[4]=n/10000%10;
  a[5]=n/100000%10;
  a[6]=n/1000000%10;
  a[7]=n/10000000%10;
  a[8]=n/100000000%10;
  a[9]=n/1000000000%10;
  rep(i,10)m+=a[i];
  if(n%m==0)printf("Yes");
  else printf("No");
}

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

int main()
{
    int n, x[100],y[100];
    cin >> n;

    for (int i = 0; i <  n; i++)
    {
        cin >> x[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> y[i];
    }
    for (int p = 1; p <= 3; p++)
    {
        double sum = 0;
        for (int i = 0; i < n; i++)
        {
            sum += pow(abs(x[i] - y[i]),p);
        }
        cout << fixed << setprecision(6) << pow(sum,1./p) << endl;
    }
    double max = 0;
    
    for (int i = 0; i < n; i++)
    {
        if (max < abs(x[i] - y[i]))
        {
            max = abs(x[i] - y[i]);
        }
    }
    cout << fixed << setprecision(6) << max << endl;
    return 0;
}



Measured memory_bytes: 3444
N, M = map(int, input().split())
k = []
lis = []
P = []
for _ in range(M):
    x = list(map(int, input().split()))
    k.append(x[0])
    lis.append(x[1:])
for p in map(int, input().split()):
    P.append(p)
count = 0
for i in range(2**N):
    flag = True
    string = str(bin(i)[2:])[::-1]
    for index in range(M):
        total = 0
        for s in lis[index]:
            if s <= len(string):
                if string[s - 1] == '1':
                    total += 1
        if total % 2 != P[index]:
            flag = False
            break
    if flag:
        count += 1
print(count)

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    int n = s.length();
    int cnt = 0;
   for(int i = 0; i<n/2; i++) {
      if(s.charAt(i) != s.charAt(n-1-i)){
        cnt += 1;
      }
    }
    System.out.println(cnt);
  }
}

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); ++i)
#define rrep(i, k, n) for (int i = (int)(n) - 1; i >= (int)(k); --i)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vv_ii;
typedef pair<int,ii> i_ii;
typedef vector<i_ii> vi_ii;

template <class T>
inline ostream& operator<<(ostream & o, vector<T> const& v) {
    for (int i = 0; i < (int)(v.size()) - 1; ++i)
        o << v[i] << ' ';
    if (!v.empty())
        o << v.back();
    return o;
}

template <class T, class Q>
inline ostream& operator<<(ostream & o, pair<T,Q> const& p) {
    o << "(" << p.fi << "," << p.se << ")";
    return o;
}


int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    ll n;
    cin >> n;
    ll ans = 1000 * (n / 500);
    n %= 500;
    ans += 5 * (n / 5);
    cout << ans << '\n';
    
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
int main()
{
   ll n,m;
   cin>>n>>m;
   ll a[n+1];
   unordered_map<ll,ll> m1;
   for(ll i=1;i<=n;i++)
   {
       cin>>a[i];
       m1[i]=a[i];
   }
   unordered_map<ll,ll> m2;
   while(m--)
   {
       ll x,y;
       cin>>x>>y;
       if(m2[x]!=-1)
       {
           if(m1[x]>m1[y])
           {
              m2[x]=1;   
           }
           else
           {
               m2[x]=-1;
           }
       }
       if(m2[y]!=-1)
       {
           if(m1[y]>m1[x])
           {
               m2[y]=1;
           }
           else
           {
               m2[y]=-1;
           }
       }
   }
   ll ans=0;
   for(ll i=1;i<=n;i++)
   {
       if(m2[i]!=-1)
       {
           ans++;
        //   cout<<i<<" ";
       }
   }
   cout<<ans;
   return 0;
}


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

int main()
{
    string s,n;
    cin>>s>>n;
    int c;

    c= n.size();

    n.erase(n.end()-1);
    //cout<<n;
    if(s==n)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;


}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
using namespace std;

unsigned long long gcd(unsigned long long a, unsigned long long b)
{
	if (b == 0)
	{
		return a;
	}

	return gcd(b, a % b);
}

int main()
{
	long long N, X;
	cin >> N >> X;

	auto isFirst = true;
	auto result = 0llu;
	for (auto i = 0; i < N; ++i)
	{
		long long x;
		cin >> x;
		unsigned long long diff = abs(X - x);
		if (isFirst)
		{
			result = diff;
			isFirst = false;
		}
		else
		{
			result = gcd(diff, result);
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main{
	public static void main(String[] args){
		BufferedReader insBR = new BufferedReader(new InputStreamReader(System.in));
		try{

			//文字を読み取る。
			String strW = insBR.readLine();
			char[] chW = new char[strW.length()];
			chW = strW.toCharArray();
			/*for(int i = 0; i < chW.length; i++){
				chW[i] = Character.toLowerCase(chW[i]);
			}*/
			List<String> list = new ArrayList<String>();
			while(true){
				String strLine = insBR.readLine();
				if(!"END_OF_TEXT".equals(strLine)){
					list.add(strLine);
				}else{
					break;
				}
			}

			char[][] chT = new char[list.size()][1000];
			for(int i = 0; i < list.size(); i++){
				chT[i] = list.get(i).toCharArray();
			}

			for(int i = 0; i < chT.length; i++){
				for(int j = 0; j < chT[i].length; j++){
					chT[i][j] = Character.toLowerCase(chT[i][j]);
				}
			}
			list.clear();
			for(int i = 0; i < chT.length; i++){
				//list.add(String.valueOf(chT[i]));
				String strLine = String.valueOf(chT[i]);
				String[] strLine2 = strLine.split(" ");
				for(int j = 0; j < strLine2.length; j++){
					list.add(strLine2[j]);
				}
			}

			int intCount = 0;
			for(int i = 0; i < list.size(); i++){
				String strT = list.get(i);
				if(strW.equals(strT)){
					intCount++;
				}
			}


			/*String[] strCount = strT.split(strW);
			if(strT.indexOf(strW,0) == 0){
				intCount = strCount.length - 1;
			}else{
				intCount = strCount.length;
			}*/


			//含まれている数を調べる。
			/*int intCount = 0;
			for(char chT : strT.toCharArray()){
				if(chW.equals(chT)){
					System.out.println("if文はいった");
					intCount++;
				}
			}*/

			//出力。
			System.out.println(intCount);

		}catch(IOException e){
			e.printStackTrace();
		}catch(NumberFormatException e){
			e.printStackTrace();
		}
	}

}
/*
aaa aizu xxx xx x xxx aizu y yyyy a a a a a a aizu
aaa aa xxx WWW AAA aize aiza AIZZ AAA III a i z u aizu aizu aizu
SSS SS S aizu AAAAAAA a a a a a x x x x aizu zia uzia uzia aizu aizu aizu aizu
Aizu hyoooon pupupupu ohohohoh
aa eee fff eee fff ee f f f f f f f AIZU bebebebebebe ai zu a izu aiz u
Aizu aizu Aizu AIzU
end_of_text
END_OF_TEXP
aizu Aizu
 */



Measured memory_bytes: 24228
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val (n, k) = br.readLine().split(" ").map { it.toInt() }
  val a = br.readLine().split(" ").map { it.toInt() }

  tailrec fun rec(a: Int, b: Int): Int =
    if(b == 0) a
    else rec(b, a%b)

  val diff = a.filter { it >= k }.map { it - k}
  val res = a.reduce { a, b -> rec(a, b) }

  val ans = when {
    diff.isEmpty() -> "IMPOSSIBLE"
    diff.any { it % res == 0 } -> "POSSIBLE"
    else ->  "IMPOSSIBLE"
  }

  println(ans)
}

Measured memory_bytes: 51508
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <time.h>
#include <string>
#include <stack>
#include <set>
#include <map>
#include <iostream>
#include <bitset>
#include <algorithm>
#include <assert.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define mst(a,b) memset((a),(b),sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vii;
const int inf = 0x3f3f3f3f;
const LL INF = (1uLL << 63) - 1;
const int mod = 1e9 + 7;
const double Pi = acos(-1.0);
const int maxn = 1e3 + 5;
const int N = 1e3 + 5;
const ULL hashmod = 2908361;
const double eps = 1e-8;
Vii k;
LL sum[4][N];
int num[4];
LL W[4];
int main() {
#ifdef local
    freopen("input", "r", stdin);
    //freopen("input", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    LL n,V;
    int w,v;
    cin>>n>>V;
    for(int i = 0; i < n; i++){
        cin>>w>>v;
        k.PB(MP(w,v));
    }
    sort(k.begin(),k.end());
    k.PB(MP(-1,-1));
    int cnt = 0;
    int last = 0;
    for(int i = 0; i <= n; i++){
       // cout<<k[i].first<<" "<<k[i].second<<endl;
        if(k[i].first != k[last].first){
            for(int j = i - 1; j >= last; j--){
                sum[cnt][i - j] = sum[cnt][i - j - 1] + k[j].second;
            }
            W[cnt] = k[last].first;
            num[cnt++] = i - last;
            last = i;
        }
    }
  //  cout<<num[0]<<" "<<num[1]<<" "<<num[2]<<" "<<num[3]<<endl;
    LL res = 0;
    for(int i = 0; i <= num[0]; i++){
        for(int j = 0; j <= num[1]; j++){
            for(int z = 0; z <= num[2]; z++){
                LL l = V - i * W[0] - j * W[1] - z * W[2];
                if(l < 0)continue;
                if(W[3]){
                    int k = l / W[3];
                    res = max(res,sum[0][i] + sum[1][j] + sum[2][z] + sum[3][k]);
                }
                else {
                    res = max(res,sum[0][i] + sum[1][j] + sum[2][z]);
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mods 1000000007
#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef long long int lint;
typedef unsigned long long int ulint;

lint n,k,dp[100020],dizi[100020];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	lint i,j,l;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>dizi[i];
	}
	dp[1]=0;
	dp[2]=abs(dizi[1]-dizi[2]);
	for(i=3;i<=n;i++){
		lint temp=LONG_MAX;
		for(j=1;j<=k && i-j>0;j++){
			temp=fmin(temp,dp[i-j]+abs(dizi[i]-dizi[i-j]));
		}
		dp[i]=temp;
		
	} 
	cout<<dp[n];
	
	
	
	
	
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int ans;
int primecheck(int n){
  int i;
  if(n <= 1)return 0;
  if(n == 2)return 1;
  if(n % 2 == 0)return 0;
  for(i=3;i*i<=n;i+=2){
    if(n % i == 0)return 0;
  }
  return 1;
}
int main(){
  int datanum,temp,ans=0,i;
  scanf("%d",&datanum);
  for(i=0;i<datanum;i++){
    scanf("%d",&temp);
    if(primecheck(temp) == 1)ans++;
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 2104
N = int(input())
XList = list(map(int, input().split()))

Z = 0
for i in range(N):
    Z += XList[i]

result = 0
if Z % N == 0:
    Z //= N
    for i in range(N):
        result += (XList[i] - Z) ** 2
else:
    Z //= N
    tmp = 0
    for i in range(N):
        tmp += (XList[i] - Z) ** 2
    Z += 1
    for i in range(N):
        result += (XList[i] - Z) ** 2
    if tmp < result:
        result = tmp

print(result)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int ll;
#define ipair pair<int,int>
#define mod 1000000007


int main()
{
  int n;
  cin>>n;
  vector<vector<ll> > v(n,vector<ll>(n,0));
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
        cin>>v[i][j];  
    }
  }
  ll res=0;
  int f=0;
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      {
          ll m=mod;
          for(int k=0;k<n;k++)
          {
              if(k!=i && k!=j)
              {
                  m=min(m,v[i][k]+v[k][j]);
              }
          }
          if(m<v[i][j])
          {
             f++;
             break;
          }
          else
          {
              if(m>v[i][j])
              {
                //cout<<i<<" "<<j<<" ";
                //cout<<m<<endl;
                  res+=v[i][j];
              }
          }
      }
      if(f>0)
      {
        res=-1;
        break;
      }
  }
  cout<<res<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll h,w;cin>>h>>w;
    vector<ll> cnt(26,0) , req(5,0);
    for(ll i=0;i<h*w;i++){
        char ch;cin>>ch;
        cnt[ch-'a']++;
    }

    for(ll i=0;i<=h-i-1;i++){
        for(ll j=0;j<=w-j-1;j++){
            ll tot=1;
            if(i<h-i-1)tot*=2;
            if(j<w-j-1)tot*=2;
            req[tot]++;
        }
    }

    for(ll i=0;i<26;i++){
        while(req[4]>0 && cnt[i]>=4)req[4]--,cnt[i]-=4;
        while(req[2]>0 && cnt[i]>=2)req[2]--,cnt[i]-=2;
        if(cnt[i]>req[1])return cout<<"No" , 0;
        req[1]-=cnt[i];
    }
    cout<<"Yes";

}





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

int main() {

    ll H, W;
    cin >> H >> W;

    int ch, cw, dh, dw;
    cin >> ch >> cw;
    cin >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;

    vector<string> S(H);
    vector<vector<bool>> M(H, vector<bool>(W, false));
    vector<vector<bool>> V(H, vector<bool>(W, false));
    vector<vector<int>> D(H, vector<int>(W, 1e9));
    rep(i, H) {
        cin >> S[i];
    }
    rep(i, H) rep(j, W) if(S[i][j] == '#') V[i][j] = false;

    queue<pair<int, int>> q;
    q.push(make_pair(ch, cw));
    queue<pair<int, int>> qq;

    M[ch][cw] = true;
    V[ch][cw] = true;
    D[ch][cw] = 0;

    while(!q.empty() || !qq.empty()) {
        pair<int, int> p;
        if (!q.empty()) {
            p = q.front();
            q.pop();
        }
        else {
            p = qq.front();
            qq.pop();
        }

        int h = p.first;
        int w = p.second;
        M[h][w] = false;

        FOR(i, h-2, h+3) {
            FOR(j, w-2, w+3) {
                if (i >= 0 && i < H && j >= 0 && j < W && S[i][j] == '.') {
                    if (i == h && j == w) continue;
                    if (((i == h-1 && j == w) ||
                         (i == h+1 && j == w) ||
                         (i == h && j == w-1) ||
                         (i == h && j == w+1))) {
                        if (D[i][j] > D[h][w] && !M[i][j]) {
                            q.push(make_pair(i, j));
                            M[i][j] = true;
                        }
                        D[i][j] = min(D[i][j], D[h][w]);
                    }
                    else {
                        if (D[i][j] > D[h][w]+1 && !M[i][j]) {
                            qq.push(make_pair(i, j));
                            M[i][j] = true;
                        }
                        D[i][j] = min(D[i][j], D[h][w]+1);
                    }
                }
            }
        }
    }

    if (D[dh][dw] == 1e9) cout << -1 << endl;
    else cout << D[dh][dw] << endl;

    return 0;
}


Measured memory_bytes: 9840
#include <bits/stdc++.h>
using namespace std;
 
#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define debug(x) cerr << #x " = " << (x) << '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
 
lli MOD  = 1000000007;
lli inf = 1e15;
 
void scan(scantype &x);

lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli div(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

bool isprime(long long int n)
{
    if(n ==1 )
        return false;
    if(n == 2)
        return true;
    for(long long int i =2;i<=n/i;i++)
    {
        if(n%i == 0)
            return false;
    }
    return true;
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    int t;
    t = 1;
    while(t--)
    {
        int a,b,c;
        cin>>a>>b>>c;
        a = 100*a + 10*b + c;
        if(a%4)
            cout<<"NO";
        else
            cout<<"YES";

    }    


    
    return 0;    
}
 

void scan(scantype &x)
{
    register int c = getchar(); //for negative/positive
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = getchar());
    if(c=='-') {neg=1;c=getchar();}
    for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for(ll i=(k);i<(ll)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
 
using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long double a,b;
  cin>>a>>b;
  auto x = a*b;
  ll ans = floor(x);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3748
n = int(input())
s = input()
cnt_w, cnt_b = s.count("."), 0
ans = cnt_w
if s.count(".") == n or s.count("#") == n:
    ans = 0
else:
    for i in range(n):
        if s[i] == "#":
            cnt_b += 1
        else:
            cnt_w -= 1
        if i == n - 1 or s[i] != s[i + 1]:
            ans = min(ans, cnt_w + cnt_b)
print(ans)


Measured memory_bytes: 9432
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////




int main() {
	int N; cin >> N;
	int ans = 0; 
	int A[N] = {};
	rep(i,N){cin >> A[i];}
	for (int i = 1; i < N-1; i++)
	{
		if(A[i] < A[i+1] && A[i] > A[i-1]){ans++;}
		else if(A[i] > A[i+1] && A[i] < A[i-1]){ans++;}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <array>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	string s; cin >> s;
	if (s.back() == 's') s.push_back('e');
	s.push_back('s');
	cout << s;

	return 0;
}

Measured memory_bytes: 3664
Q=int(input())
Numbers=[0]*100001
Primes=[]
Flag=0
Flag2=0
n=0
for i in range(2,50001):
  for p in Primes:
    if (2*i-1)%p==0:
      Flag=1
      break
    elif p>(2*i-1)**(1/2):
      break
  if Flag==0:
    Primes.append(2*i-1)
    for q in Primes:
      if i!=q and i!=2:
        if i%q==0 or i%2==0:
          Flag2=1
          break
      elif q>i**(1/2):
        break
    if Flag2==0:
      n+=1      
  Numbers[2*i-1]=n
  Numbers[2*i]=n
  Flag=0
  Flag2=0
for i in range(Q):
  l,r=map(int,input().split()) 
  print(Numbers[r]-Numbers[l-1])



Measured memory_bytes: 4584
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
using namespace std;

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

int main() {
	int A,P;
	cin >> A >> P;

	int ans;
	P += A*3;
	ans = P/2;

	cout << ans << endl;
}


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


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

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
X,Y,A,B,C = map(int,input().split())
l = list(map(int,input().split()))
m = list(map(int,input().split()))
n = list(map(int,input().split()))

l = (sorted(l, reverse=True))[:X]
m = (sorted(m, reverse=True))[:Y]
print(sum((sorted(l+m+n, reverse=True))[:X+Y]))

Measured memory_bytes: 23328
#include <iostream>
#include <string.h>
#include <stack>
using namespace std;

int main(){
    string S;
    while(true){
        getline(cin,S);
        if(S==".") break;
        stack<char> st;
        bool yes = true;
        for(auto c:S){
            if(c=='(' || c=='[') st.push(c);
            if(c==')'){
                if(st.empty()) yes = false;
                else if(st.top()=='(') st.pop();
                else yes = false;
            }
            if(c==']'){
                if(st.empty()) yes = false;
                else if(st.top()=='[') st.pop();
                else yes = false;
            }
        }
        if(!st.empty()) yes = false;
        cout << (yes? "yes":"no") << endl;
    }
}


Measured memory_bytes: 3176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int op=0;
    for(int i=0;i<s.length();i++)
    {
        if((i+1)%2 ==0 && s[i]=='R')
        {
            cout<<"No"<<endl;
            op=1;
            break;

        }
        else if((i+1)%2 == 1)
        {
            if(s[i]=='L')
            {
                cout<<"No"<<endl;
                op=1;
                break;
            }
        }

    }
    if(op==0)
        cout<<"Yes"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
using namespace std;
int a[1000] ; 
int main() {
    long long  n , x ;
     cin>>n>>x;
     for(int i=0 ; i < n ; i++){
         cin>>a[i]; 
     }
     sort(a , a+ n ) ;
        int l =0 ;
        int  i =0 ;
     for(  i=0 ; i < n ; i++){
         if(x >= a[i] ) {
             l++;
             x-=a[i] ;
         }
         else break;
     }
     if(i==n ){
         if(x==0)
            cout<<l;
        else
            cout<<l-1;
     }
     else{
             cout<<l ;
        
     }
    return 0;
    
}

Measured memory_bytes: 256
package main

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

const (
	maxN = 200005
	mod  = 1000000007
)

var (
	f    [maxN]int
	invf [maxN]int
)

func main() {
	n := nextInt()
	as := make([]int, n+2)
	var maxNum int
	for i := 1; i <= n+1; i++ {
		as[i] = nextInt()
		maxNum = max(maxNum, as[i])
	}
	var s int
	vis := make([]bool, maxNum+1)
	for i := 1; i <= n+1; i++ {
		if vis[as[i]] {
			s = as[i]
		}
		vis[as[i]] = true
	}
	var pre int
	for i := 1; i <= n+1 && as[i] != s; i++ {
		pre++
	}
	var nex int
	for i := n + 1; i >= 0 && as[i] != s; i-- {
		nex++
	}
	f[0], invf[0] = 1, 1
	inv := make([]int, maxN)
	inv[1], f[1], invf[1] = 1, 1, 1
	for i := 2; i <= nex+pre || i <= n+1; i++ {
		inv[i] = mod - (mod/i)*inv[mod%i]%mod
		f[i] = f[i-1] * i % mod
		invf[i] = invf[i-1] * inv[i] % mod
	}
	for i := 1; i <= n+1; i++ {
		ans := (c(n+1, i) - c(pre+nex, i-1) + mod) % mod
		fmt.Println(ans)
	}
}

func c(n, m int) int {
	if n < m {
		return 0
	}
	return f[n] * invf[m] % mod * invf[n-m] % mod
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


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

d = []
mx = -1
for i in range(N-1):
    d.append(A[i+1] - A[i])
    mx = max(mx, A[i+1] - A[i])

d.append(K - A[N-1] + A[0])
mx = max(mx, K - A[N-1] + A[0])


# print(mx)
# print(d)
ans = K - mx
print(ans)

Measured memory_bytes: 26444
#include <cassert>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

ll as[3010];
ll memo[3010][3010];
bool visited[3010][3010];

ll solve(int bg, int ed, int turn) {
  ll &res = memo[bg][ed];
  if(!visited[bg][ed]) {
    visited[bg][ed] = true;
    if(bg == ed) {
      res = 0;
    } else {
      if(turn == 0) {
        res = as[bg] + solve(bg+1, ed, !turn);
        res = max(res, as[ed-1] + solve(bg, ed-1, !turn));
      } else {
        res = solve(bg+1, ed, !turn) - as[bg];
        res = min(res, solve(bg, ed-1, !turn) - as[ed-1]);
      }
    }
  }
  return res;
}

int main(void) {
  int N;
  scanf("%d", &N);
  REP(i, N) {
    scanf("%lld", &as[i]);
  }
  ll res = solve(0, N, 0);
  printf("%lld\n", res);
  return 0;
}


Measured memory_bytes: 78464
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
}

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

int main(){
    long long n;
    cin >> n;
    if(n == 1){
        printf("0\n");
        return 0;
    }

    map<long long, long long> T;
    long long num = n;
    for(long long i = 2; i*i <= num+1; i++){
        if(num % i != 0){
            continue;
        }
        bool first = true;
        while(num % i == 0){
            if(first == true){
                T[i] = 1;
                first = false;
                num /= i;
            }
            else{
                T[i]++;
                num /= i;
            }
        }
    }
    if(num != 1){
        T[num] = 1;
    }

    long long count = 0;
    map<long long, long long>::iterator it;
    for(it = T.begin(); it != T.end(); it++){
        long long j = 1;
        long long sum = 0;
        //printf("it first %lld it second %lld\n", it->first, it->second);
        while(1){
            if(sum+j > it->second){
                break;
            }
            count++;
            sum += j;
            j++;
        }
        //printf("count %lld sum %lld\n", count, sum);
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3588
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<endl
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 998244353; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


char ans[1010][1010];
void tate(int i, int j, char c) {
	ans[i][j] = c;
	ans[i + 1][j] = c;
}
void yoko(int i, int j, int c) {
	ans[i][j] = c;
	ans[i][j + 1] = c;
}
string three[3] = {
	".bb",
	"a..",
	"a.."
};
string four[4] = {
	"abcc",
	"abdd",
	"ccab",
	"ddab"
};
string five[5] = {
	"abb.d",
	"a.ccd",
	"ef.gg",
	"efh..",
	"iihjj"
};
string seven[7] = {
	"abbc...",
	"a..cdd.",
	".f..eeh",
	".fgg..h",
	"i.j..kk",
	"i.j...n",
	"ll.mm.n"
};
void solve(int n) {
	if (n <= 2) {
		print(-1); return;
	}
	REP(i, n)REP(j, n)ans[i][j] = '.';
	if (n % 3 == 0) {
		for (int i = 0; i < n; i += 3) {
			REP(x, 3)REP(y, 3)ans[x + i][y + i] = three[x][y];
		}
	}
	else if (n == 7) {
		REP(x, n)REP(y, n)ans[x][y] = seven[x][y];
	}
	else if (n == 11) {
		REP(x, 4)REP(y, 4)ans[x][y] = four[x][y];
		REP(x, 7)REP(y, 7)ans[x + 4][y + 4] = seven[x][y];
	}
	else {
		if (n % 5 == 0) {
			for (int i = 0; i < n; i += 5) {
				REP(x, 5)REP(y, 5)ans[x + i][y + i] = five[x][y];
			}
		}
		else {
			int c4 = 5 - (n % 5);
			int c5 = (n - c4 * 4) / 5;
			REP(i, c4) {
				REP(x, 4)REP(y, 4)ans[x + 4 * i][y + 4 * i] = four[x][y];
			}
			REP(i, c5) {
				REP(x, 5)REP(y, 5)ans[x + 4 * c4 + 5 * i][y + 4 * c4 + 5 * i] = five[x][y];
			}
		}
	}
	REP(i, n) {
		REP(j, n)cout << ans[i][j];
		cout << endl;
	}
}
void solve() {
	int N; cin >> N;
	solve(N);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

long double memo[10000][32];
struct edge {
	int id;
	int from;
	int to;
	int lim;
	long double dis;
};
struct aa {
	int id;
	int speed;
	long double  time;
};
class Compare {
public:
	//keiroが昇順に並ぶ
	bool operator()(const aa&l, const aa&r) {
		return l.time> r.time;
	}
};
int main() {
	while (1) {
		for (int i = 0; i < 10000; ++i) {
			for (int j = 0; j < 32; ++j) {
				memo[i][j] = 999999999;
			}
		}
		int n, m; cin >> n >> m;
		if (!n)break;
		int s, g; cin >> s >> g; s--; g--;
		vector<edge>edges;
		vector<vector<int>>edgeids(n);
		for (int i = 0; i < m; ++i) {
			long double d;
			int x, y, c; cin >> x >> y >> d >> c;
			x--; y--;
			edges.push_back(edge{ 2*i,x,y,c,d });
			edges.push_back(edge{ 2*i+1,y,x,c,d });
			edgeids[x].push_back(2 * i);
			edgeids[y].push_back(2 * i + 1);
		}
		priority_queue<aa, vector<aa>, Compare>que;
		for (auto i : edgeids[s]) {

			que.push(aa{ i,1,edges[i].dis });
			memo[i][1] = edges[i].dis;
		}
		while (!que.empty()) {
			aa atop(que.top());
			que.pop();
			const edge oldedge(edges[atop.id]);
			const int oldsp(atop.speed);
			const long double oldtime(atop.time);
			for (auto i : edgeids[oldedge.to]) {
				const edge nextedge(edges[i]);
				if (nextedge.to == oldedge.from)continue;
				else {
					for (int change = -1; change <= 1; ++change) {
						const int nextsp = oldsp + change;
						if (nextsp == 0)continue;
						else {
							if (nextsp <= nextedge.lim) {
								const long double nexttime= nextedge.dis / nextsp + oldtime;
								if (memo[i][nextsp] > nexttime) {
									memo[i][nextsp] = nexttime;
									que.push(aa{ i,nextsp,nexttime });
								}
							}
						}
					}
				}
			}
		}
		long double amin = 999999999;
		for (int i = 0; i < edges.size(); ++i) {
			if (edges[i].to == g) {
				amin = min(amin, memo[i][1]);
			}
		}
		if (amin > 99999999) {
			cout << "unreachable" << endl;
		}
		else {
			cout << amin << endl;

		}
		
	}
	return 0;
}

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

using namespace std;
 
int main(){
    int N;
    string S;
 
    cin >> N >> S;

    int xmax = 0;
    int x = 0;

    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'I'){
            x++;
        }else{
            x--;
        }

        if(x > xmax){
            xmax = x;
        }
    }

    cout << xmax << endl;

    return 0;
}


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

using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);

  int x; cin>>x;
  while (true) {
    bool skip = false;
    for (int i = 2; i <= sqrt(x); i++) {
      if (x % i == 0) {
        skip = true;
        break;
      }
    }
    if (not skip) {
      cout << x << endl;
      break;
    }
    x++;
  }

  return 0;
}


Measured memory_bytes: 256