akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().Trim();

        var k = 1;
        var c = s[0];
        for (int i = 1; i < s.Length; ++i)
        {
            if (s[i] == c)
            {
                continue;
            }

            ++k;
            c = s[i];
        }
        
        Console.WriteLine(k);
    }
}


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

/*2進数配列+1*/
vector<int> twoadd(vector<int> v, int N){
    v[N-1]+=1;
    int ind = N-1;
    int j=N-1;
    for(j=N-1;j>=1;j--){
        if(v[j]>1){
            v[j-1]+=1;
            v[j]=0;
        }
    }
    return v;
}

/*フィボナッチ*/
long long fibonatti(long long d){
    long long count = 0;
    long long f1 = 1;
    long long f2 = 1;/*ここを変える*/
    long long temp;
    if(d == 1){
        count = f1;
    }else if(d == 2){
        count = f2;
    }else if(d==0){
        count = 1;
    }else{
        for(int i=0;i<d-2;i++){
            temp = f1+f2;
            f1 = f2;
            f2 = temp;
        }
        count = temp;
    }
    return count;
}

/*最大公約数*/
unsigned long long GCD(long long L,long long R){
    if(L>R){
        long long temp=R;
        R = L;
        L = temp;
    }
    unsigned long long pp=0,ppt=0;
    unsigned long long ans=0;
    if(R%L==0){
        ans = L;
    }else{
        while(true){
            ppt = pp;
            pp=R%L;
            if(pp == 0){
                ans = ppt;
                break;
            }
            R = L;
            L = pp;
        }
    }    
    return ans;    
}

/*最小公倍数*/
unsigned long long LCM(long long L,long long R){
    unsigned long long ans;
    unsigned long long gcd = GCD(L,R);
    ans = (L/gcd)*R;
    return ans;
}

/*Combination set*/
#define mod 1000000007
#define maxcomb 3000/*大きいものを求めるときはここを変える*/
vector<long long> fc(maxcomb+1);
vector<long long> ifc(maxcomb+1);
long long modpow(long long x,long long n){
    long long ans = 1;
    while(n > 0){
        if(n & 1) {
            ans = ans*x%mod;
        }
        x = x*x%mod;
        n >>= 1;
    }
    return ans;
}
void Conb(){
    fc[0]= 1;
    ifc[0]=1;
    for(long long i=0;i<maxcomb;i++){
        fc[i+1] = fc[i]*(i+1)%mod;//n!(mod)
        ifc[i+1] = ifc[i]*modpow(i+1,mod-2)%mod;//k!^{M-2} (mod)
    }
}
unsigned long long Combination(long long L,long long R){
    unsigned long long up=1,ans;
    Conb();
    if(L==0&&R==0){
        return 1;
    }else if(L<R||L<0){
        return 0;
    }else{
        long long t = ifc[L-R]*ifc[R]%mod;
        ans = t*fc[L]%mod;
    }
    return ans;
}
/*Combination set ここまで*/

/*ここから*/
int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    vector<int> pa(N);
    for(int i=0;i<N;i++){
        cin >> p[i];
        pa[i] = p[i];
    }
    int count = 0;
    sort(pa.begin(),pa.end());
    for(int i=0;i<N;i++){
        if(p[i]!=pa[i]){
            count++;
        }
        if(count==3){
            cout << "NO" << endl;
            exit(0);
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define sz(a) (int)a.size()
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define ll long long        
#define f first
#define s second 
#define y1 Emilia_Clarke
#define dracarys ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 
const int inf = (int)1e9;
const int mod = (int)1e9 + 7;

const int maxn = (1 << 18) + 111;
int n, a[maxn], mx1[maxn], mx2[maxn], ans[maxn];
int main(){dracarys
	cin >> n;
	for(int i = 0; i < (1 << n); ++i) cin >> a[i], mx1[i] = a[i];
	for(int i = 0; i < n; ++i)
	{
		for(int mask = 0; mask < (1 << n); ++mask)
		{
			if((mask & (1 << i)) == 0)
			{
				int nmask = mask + (1 << i);
				int v1 = mx1[mask], v2 = mx2[mask];
				if(mx1[nmask] < v1)
				{
					mx2[nmask] = mx1[nmask];
					mx1[nmask] = v1;
					if(mx2[nmask] < v2) mx2[nmask ] = v2;
				}
				else if(mx2[nmask] < v1)
				{
					mx2[nmask ] = v1;
				}
			}
		}
	}
	for(int k = 0; k < (1 << n); ++k)
	{
		if(k - 1 >= 0)
			ans[k] = ans[k - 1];
		ans[k] = max(ans[k], mx1[k] + mx2[k]);
	}
	for(int i = 1; i < (1 << n); ++i)
		cout << ans[i] << "\n";
	return 0;	
}     

Measured memory_bytes: 7168
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  vec b(a);
  ll c=0;
  For(i,0,a){
    ci(b[i]);
    c+=b[i];
  }
  sort(b,b);
  For(i,0,a){
    if(c%10!=0)
      break;
    else if(b[i]%10==0)
      continue;
    else
      c-=b[i];
  }
  if(c%10==0)
    c=0;
  co(c);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {

	int dataNum;
	int hen[1000][3];

	cin >> dataNum;
	for (int i = 0; i < dataNum; i++) {
		cin >> hen[i][0] >> hen[i][1] >> hen[i][2];
	}

	for (int i = 0; i < dataNum; i++) {
		//cout << "for i datanum=" <<dataNum << endl;
		//????????????????????§?????????
		for (int j = 3 - 1; j >0; j--) {
			//cout << "for j" << endl;
			for (int k = 0; k < j; k++) {
				//cout << hen[i][k] << "," << hen[i][k + 1] << endl;
				if (hen[i][k] > hen[i][k + 1]) {
					//cout << "swap" <<endl;
					int dummy = hen[i][k];
					hen[i][k] = hen[i][k + 1];
					hen[i][k + 1] = dummy;
				}
			}
		}

		//??´?§?????????§??????
		if (hen[i][0] * hen[i][0] + hen[i][1] * hen[i][1] == hen[i][2] * hen[i][2]) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO"  << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3100
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char n[5];
  scanf("%s", n);
  if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
    puts("Yes");
  else
    puts("No");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x;
  int y;
  char type;
  Point() {;}
  Point(double x, double y, int type) : x(x), y(y), type(type) {;}
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) { return y < rhs.y; }
    return x < rhs.x;
  }
};

struct Event {
  int x;
  Point p;
  char in;
  Event() {;}
  Event(int x, Point p, int in) : x(x), p(p), in(in) {;}
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) { return x < rhs.x; }
    return in > rhs.in;
  }
};

inline int square(int x) { return x * x; }

inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}

int an, bn, n;
int r;
Event event[500000];

int PlaneSweep() {
  int ans = 0;
  int r4 = 4 * r;
  int r2 = 16 * r * r;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower = open[(int)p.type ^ 1].lower_bound(Point(0, p.y - r4, 0));
      set<Point>::iterator upper = open[(int)p.type ^ 1].upper_bound(Point(1000000000, p.y + r4, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= r2) { ans++; }
      }
      open[(int)p.type].insert(p);
    } else {
      open[(int)p.type].erase(open[(int)p.type].find(p));
    }
  }
  return ans;
}

int main() {
  while (scanf("%d %d %d", &an, &bn, &r), an|bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
const int N = 100000+5;
int mp[15][15];
const int inf = 10000;
int d[15][15];
int main()
{
   int n;
   while(cin >> n && n)
   {
   for(int i = 0; i <= 10; i++)
   {
       for(int j = 0; j <= 10; j++)
       {
           mp[i][j] = inf;
       }
       mp[i][i] = 0;
   }
   int m = 0;
   for(int i = 0; i < n; i++)
   {
       int a,b,c;
       scanf("%d%d%d",&a,&b,&c);
       mp[a][b] = mp[b][a] = min(mp[a][b],c);
       m = max(m,max(a,b));
   }
   for(int k = 0; k <= m; k++)
   {
       for(int i = 0; i <= m; i++)
       {
           for(int j = 0; j <= m; j++)
           {
               mp[i][j] = min(mp[i][k] + mp[k][j],mp[i][j]);
           }
       }
   }
   int ans = 10000,p = 0;
   for(int i = 0; i <= m; i++)
   {
       int now = 0;
    //   cout <<i <<endl;
       for(int j = 0; j <= m; j++)
       {
           if(mp[i][j] != inf)
           {
               now += mp[i][j];
             //  cout <<now <<"      " <<mp[i][j] << endl;
           }
       }
       if(now < ans)
       {
           p = i;
           ans = now;
       }
   }
   printf("%d %d\n",p,ans);
  }
}



Measured memory_bytes: 3160
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<list>
using namespace std;

int n;
bool my_search(int key, vector<int> v) {
	int up = n;
	int down = 0;
	while (down < up) {
		int mid = (up + down) / 2;
		if (v[mid] > key) {
			up = mid;
		}
		else if (v[mid] == key) {
			return 1;
		}
		else {
			down = mid + 1;
		}
	}
	return 0;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)cin >> v[i];
	sort(v.begin(), v.end());

	int q;
	cin >> q;
	int t;
	int cnt = 0;
	for (int i = 0; i < q; i++) {
		cin >> t;
		if (my_search(t, v)) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int A[]=new int[N];
		long min=2020202020;
		long sum=0,sum2=0;
		for(int i=0;i<N;i++){
			A[i]=stdIn.nextInt();
			sum2+=A[i];
		}
		for(int i=0;i<N;i++){
			sum2-=A[i];
			sum+=A[i];
			if(Math.abs(sum2-sum)<min)
				min=Math.abs(sum2-sum);
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 86652
import sys
input = sys.stdin.readline
import bisect
from collections import deque


def read():
    N = int(input().strip())
    P = list(map(int, input().strip().split()))
    Q = list(map(int, input().strip().split()))
    return N, P, Q


def next_permutation(a):
    l = -1
    for i in range(len(a)-1):
        if a[i] < a[i+1]:
            l = i
    if l == -1:
        return False
    for j in range(len(a)-1, -1, -1):
        if a[l] < a[j]:
            break
    tmp = a[l]
    a[l] = a[j]
    a[j] = tmp
    j = l + 1
    k = len(a) - 1
    while j < k:
        tmp = a[k]
        a[k] = a[j]
        a[j] = tmp
        j += 1
        k -= 1
    return True


def solve(N, P, Q):
    a, b = 0, 0
    while next_permutation(P):
        a += 1
    while next_permutation(Q):
        b += 1
    return abs(b - a)
            
    
if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("{}".format(outputs))


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

#define INF -2000000000

int main() {
	int n, b[1000],c[1000][4];
	memset(b, -128, sizeof(b));
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i <= n; i++) {
		cout << "node " << i << ": key = " << b[i] << ", ";
		if (b[i / 2] >= INF) {
			cout << "parent key = " << b[i / 2] << ", ";
		}
		if (b[i * 2] >= INF) {
			cout << "left key = " << b[i * 2] << ", ";
		}
		if (b[i * 2 + 1] >= INF) {
			cout << "right key = " << b[i * 2 + 1] << ", ";
		}
		cout << endl;
	}
	return 0;
}

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

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

    int ma[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            ma[i][j] = 0;
        }
    }

    for(int i = 0; i < b; i++){
        for(int j = 0; j < a; j++){
            ma[i][j] = 1;
        }
    }

    for(int i = b; i < h; i++){
        for(int j = a; j < w; j++){
            ma[i][j] = 1;
        }
    }

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ma[i][j];
        }
        cout << endl;
    }
}

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

int n, k, x, y, ans = 0;

int main() {
  cin >> n >> k >> x >> y;
  if(n <= k)
    ans = x * n;
  else
    ans = x * k + (n - k) * y;
  cout << ans << endl;
  return 0;
}

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

int main()
{
	int n, br=0, j, a[99999], k=0, br2=0;
	cin >> n;

	for(int i=11; i<=55555; i++){
		for(j=2; j<i; j++){
			if(i%j == 0){
				br++;
				break;
			}
		}
		if(br == 0 && j%5==1 && br2<=55){
			a[k] = j;
			k++;
			br2++;
		}
		br=0;
	}

	for(int i=0; i<n; i++){
		cout << a[i] << " ";
	}
	
    return 0;
}


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 chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    int a, b; cin >> a >> b;
    out(max({a - b, a + b, a * b}));
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.D
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			int q = cin.NextInt();
			var connected = new List<List<int>>();
			var va = new List<int>();
			var ans = new List<int>();
			var seen = new List<bool>();
            for (int i = 0; i < n; i++)
			{
				connected.Add(new List<int>());
				va.Add(0);
				ans.Add(0);
				seen.Add(false);
            }
            for (int i = 0; i < n-1; i++)
			{
				int a = cin.NextInt() - 1;
				int b = cin.NextInt() - 1;
				connected[a].Add(b);
				connected[b].Add(a);
			}
            for (int i = 0; i < q; i++)
            {
				int p = cin.NextInt() - 1;
				int x = cin.NextInt();
				va[p] += x;
            }
			var que = new Queue<int>();
			que.Enqueue(0);
			seen[0] = true;
			ans[0] = va[0];
            while (que.Count > 0)
            {
				var i = que.Dequeue();
                foreach (var item in connected[i])
                {
					if (seen[item]) continue;
                    else
                    {
						seen[item] = true;
						ans[item] = ans[i];
						ans[item] += va[item];
						que.Enqueue(item);
                    }
                }
            }
            Console.WriteLine(string.Join(" ", ans));

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 52676
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b,c=0;cin>>a;
  rep(i,a){
    cin>>b;
    c+=b;
  }
  cout<<c-a;
  }


Measured memory_bytes: 23680
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int Mxn=1005,MxN=1e9+7;

ll solve(char a[Mxn][Mxn],int m,int n)
{
    vector<vector<ll>>dp(m, vector<ll>(n, 0));

//    for(int i=0;i<m;++i)
//        dp[i][0]=0;
//    for(int i=1;i<=n;++i)
    dp[0][0]=1;
    for(int i=0;i<m;++i)
    {
        for(int j=0;j<n;++j)
        {
            if(i>0)
                (dp[i][j]+=dp[i-1][j])%=MxN;
            if(j>0)
                (dp[i][j]+=dp[i][j-1])%=MxN;
            if(a[i][j]=='#')
                dp[i][j]=0;


        }
    }
//    for(int i=0;i<m;++i)
//    {
//        for(int j=0;j<n;++j)
//            cout<<dp[i][j]<<" ";
//    cout<<"\n";
//    }
    return dp[m-1][n-1];

}
int main()
{
    int m,n;
    cin>>m>>n;
    //string s[Mxn];
    char s1[Mxn][Mxn];
    for(int i=0;i<m;++i)
    {
        cin>>s1[i];
    }
    if((m==1 and n==1)or solve(s1, m, n)==1)
    {
        cout<<0<<endl;
    }
       else
    cout<<solve(s1, m, n)<<endl;
    return 0;
}


Measured memory_bytes: 12168
fn main() {
    let n = read::<usize>();
    let mut v = read_vec::<u32>();
    v.sort();

    let mut e = 0;
    if n % 2 != 0 {
        for i in 0..n {
            //println!("{} {} {}", i, v[i], (i as u32 + 1) / 2 * 2);
            if (i as u32 + 1) / 2 * 2 != v[i] {
                println!("0");
                return;
            }
        }
        e = (v.len() - 1) / 2;
    } else {
        for i in 0..n {
            //println!("{} {} {}", i, v[i], (i as u32 + 2) / 2 * 2);
            if (i as u32 + 2) / 2 * 2 - 1 != v[i] {
                println!("0");
                return;
            }
        }
        e = v.len() / 2;
    }
    let mut ans = 1;
    for _ in 0..e {
        ans *= 2;
        ans %= 1000000007;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

const long long INF = 1LL << 60;
const int MAX_V = pow(10, 3) * 100 + 1;

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

    int MAX_N = N + 2;

    vector<long long> weight(MAX_N), value(MAX_N);
    for (int i = 0; i < N; ++i)
        cin >> weight[i] >> value[i];

    vector<vector<long long>> dp(MAX_N, vector<long long>(MAX_V, INF));

    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i)
    {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
        {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0)
                chmin(dp[i + 1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v)
    {
        if (dp[N][sum_v] <= W)
            res = sum_v;
    }
    cout << res << endl;
}


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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  ll ans = 0;
  for(int i=0; i<(1<<(n-1)); ++i){
    ll cnt = 0;
    for(int j=0; j<n; ++j){
      cnt += s[j] -'0';
      if(j==n-1) ans += cnt;
      else{
        if(i>>j&1){
          ans += cnt;
          cnt = 0;
        }else{
          cnt *= 10;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <iostream>
#include <fstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <iterator>
typedef long long ll;
#define f(i,a,b) for(i=a;i<b;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],j;
    f(j,0,n)cin>>a[j];
    sort(a, a+n);
	int st = (n % 2) + 1;
	if (n % 2 && a[0] != 0) {cout << 0; return 0;}
	int i = (n % 2);
	for (; i < n; i += 2, st += 2) {
		if (a[i] != st || a[i+1] != st) {cout << 0; return 0;}
	}
	ll ans = 1;
	ll M = 1e9 + 7;
	for (i = 0; i < n/2; i++) {
		ans *= 2;
		ans %= M;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 640
def main():
    S = input().split(' ')
    a = S[0]
    b = S[1]
    if a == 'H' and b == 'D':
        print('D')
    elif a == 'H':
        print("H")
    elif a == 'D' and b == 'D':
        print("H")
    else:
        print("D")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
 
    ll n,i,j,k,ans=-LLONG_MAX;
    cin>>n>>k;
    ll p[n+2],c[n+2];
    for(i=1;i<=n;i++) cin>>p[i];
    for(i=1;i<=n;i++) cin>>c[i];

    for(i=1;i<=n;i++)
    {
    	vector<ll> v;
    	ll tot=0;
    	ll cur = i;
    	while(1)
    	{
    		cur = p[cur];
    		v.pb(c[cur]);
    		tot += c[cur];
    		if(cur==i) break;
    	}
    	ll sum=0;
    	ll si = v.size();
    	for(j=0;j<si;j++)
    	{
    		if(j+1 > k) break;
    		sum += v[j];
    		ll ha = sum;
    		if(tot>0)
    		{
    			ha += ((k-(j+1))/si) * tot;
    		}
    		ans = max(ans,ha);
    	}
    }
    cout<<ans;

}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((c>b&&a<d)||(b>c&&a>d))
    {
        cout<<0<<NL;
    }
    else
    {
        if(a<c)
        {
        int ans=b-c;
        if(b>d)
        {
            ans-=b-d;
        }
        cout<<ans<<NL;
        }
        else
        {
            int cnt=b-a;
            if(b>d)
            {
                cnt-=b-d;
            }
            cout<<cnt<<NL;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
int d[3];
signed main() {
	int a, b, c; cin >> a >> b >> c;
	d[0] = a, d[1] = b, d[2] = c;
	sort(d, d + 3); cout << d[2] * 10 + d[1] + d[0]<<endl;
}


Measured memory_bytes: 256
n = int(input())
buttons = [0]
target_index = 0
for _ in range(n):
    buttons.append(int(input()))

count = 0
prev_index = 1
while count < n:
    if prev_index < 1 or len(buttons) <= prev_index:
        count = -1
        break

    next_index = buttons[prev_index]
    count += 1
    if next_index == 2:
        break
    else:
        prev_index = next_index

print(count if count < n else -1)


Measured memory_bytes: 7080
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;

int main(){
  int n,m,a,b;
  cin >> n >> m;
  map<int,int> city;
  for(int i = 0; i < m; i++){
    cin >> a >> b;
    city[a-1]++;
    city[b-1]++;
  }
  for(int i = 0; i < n; i++){
    cout << city[i] << endl;
  }
}


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

#define ll long long
#define int long long
#define loop(i,s,e) for(int i=s;i<e;i++)
#define rloop(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
#define lb(v,x) lower_bound(v.begin(),v.end(),x);
#define ub(v,x) upper_bound(v.begin(),v.end(),x);
const long mod =1e8;
const int N = 5e6+5;
const long long inf= 1e18;

ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}
ll add(ll a, ll b){return (a%mod + b%mod)%mod;}

bool isp(string str)
{
    int n=str.size();
    for(int i=0;i<n/2;i++)
    {
        if(str[i]!=str[n-1-i])return 0;
    }
    return 1;
}
void solve()
{
     
  string str;cin>>str;
  int n =str.size();
  string sb1,sb2;
  loop(i,0,n/2)
  {
      sb1+=str[i];
  }
  loop(i,n/2+1,n)
  {
      sb2+=str[i];
  }
  if(isp(str) && isp(sb1) && isp(sb2))
  {
      cout<<"Yes\n";
  }
  else
  {
      cout<<"No\n";
  }
   
}

int32_t main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;//cin>>t;
	while(t--){
        solve();
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long bai(long long N){
  long long count=0;
  while(N%2==0){
    N=N/2;
    count++;
  }
  return count;
}

int main(){
  int N;
  cin>>N;
  vector<long long>A(N);
  long long sum=0;
  for(int i=0;i<N;i++){
    cin>>A.at(i);
    sum=sum+bai(A.at(i));
  }
  cout<<sum<<endl;
}

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

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

ll pro = 1, d, n, cnt;

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> d >> n;
	while(d--)
		pro *= 100;
	for (int i = 1;; i++) {
		if(i % 100)
			cnt++;
		if(cnt == n) {
			cout << pro * i;
			return 0;
		}
	}
	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;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    ll a;
    double t;
    cin>>a>>t;
    ll b=100*t+0.5;
    cout<<(a*b)/100<<endl;
}


Measured memory_bytes: 3732
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;
        vector<ll> a(n + 1);
        repone(i, n) {
            ll tmp;
            cin >> tmp;
            a[tmp] = i;
        }

        set<ll> s = {0, n + 1};
        ll ans = 0;
        repone(i, n) {
            auto p = s.upper_bound(a[i]);
            ll right = *p;
            ll left = *(--p);
            ans += i * (right - a[i]) * (a[i] - left);
            s.insert(a[i]);
        }

        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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


typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define mp make_pair
#define snd second
#define fst first
#define debug printf("--%d--\n",__LINE__)
#define ll long long int
#define MODP 1000000007;

int N;
ll x[114514];
int main(void){
	cin >> N;
	for(int i=0;i<N;i++) cin >> x[i];
	ll ans = 1;
	ll cnt = 0;
	for(int i=0;i<N;i++){
		if (i>0){
			cnt = max(cnt, i - (x[i-1]+1)/2);
		}
		ans = (ans * (i+1-cnt)) % MODP;
	}
	cout << ans << endl;
	
	
	
	return 0;
}


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

int s;
bool a[1000100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s;
	a[s] = true;
	for(int i=2; ; ++i){
		s = s % 2 == 0 ? s / 2 : 3 * s + 1;
		if(a[s]){
			cout << i << "\n";
			return 0;
		}
		a[s] = true;
	}
}

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

int main(){
  int a,b,c;
  cin >> a >> b;
  vector<int> vec(5);
  vector<int> vec2(5);
  c = 0;
  for(int i = a;i < b+1;i++){
    vec.at(0) =i/10000;
    vec.at(1) =i%10000/1000;
    vec.at(2) =i%1000/100;
    vec.at(3) =i%100/10;
    vec.at(4) =i%10;
    vec2 = vec;
    reverse(begin(vec2),end(vec2));
    if(vec == vec2){
      c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
h,n = map(int, input().split())
a = [list(map(int,input().split())) for i in range(n)]

dp = [float('inf') for i in range(h+1)]
dp[0]=0
for i in range(h):
    for j in range(n):
        dp[min(h,i+a[j][0])] = min(dp[min(h,i+a[j][0])],dp[i]+a[j][1])
print(dp[-1])


Measured memory_bytes: 44380
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x==25)
        cout<<"Christmas"<<endl;
    else if(x==24)
        cout<<"Christmas Eve"<<endl;
    else if(x==23)
        cout<<"Christmas Eve Eve"<<endl;
    else
        cout<<"Christmas Eve Eve Eve"<<endl;

    return 0;
}


Measured memory_bytes: 256
import itertools
import collections
N = int(input())
S = [input() for i in range(N)]
candi = []
for s in S:
    if s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H':
        candi.append(s[0])
col_s = collections.Counter(candi)
combi_s = itertools.combinations(list(col_s),3)
counter = 0 
for i in combi_s:
    counter += col_s[i[0]]*col_s[i[1]]*col_s[i[2]]
print(counter)

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

int main(){
    
    int N;cin>>N;
    vector<int> S(100000,0);
    for(int i=0;i<N;i++){
        int a;cin>>a;
        a--;
        S[a]++;
    }
    int even=0,odd=0;
    for(int i=0;i<100000;i++){
        if(S[i]!=0&&S[i]%2==0) even++;
        if(S[i]!=0&&S[i]%2==1) odd++;
    }
    if(even%2==0) cout<<even+odd<<endl;
    else cout<<even+odd-1<<endl;
}


Measured memory_bytes: 640
N = int(input())
L = [int(i) for i in input().split()]
L.sort()
Ln = []
cnt = 1
for j in range(1,N):
    if L[j-1]==L[j]:
        cnt+=1
        if j==N-1:
            Ln.append(cnt)
    else:
        Ln.append(cnt)
        cnt=1
        if j==N-1:
            Ln.append(cnt)
L1 = list(set(L))
L1.sort()
len_L1 = len(L1)
tri = 0
for k in range(len_L1-2):
    for l in range(k+1,len_L1-1):
        for m in range(l+1,len_L1):
            if (L1[k]+L1[l])>L1[m]:
                tri += Ln[k]*Ln[l]*Ln[m]
print(tri)

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

#define FOR(i, l, r) for(size_t i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;

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

    if((a == b && a != c) || (a == c && a != b) || (b == c && a != b)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math

L = int(input())
n = int(math.log2(L))

dag = []
for i in range(1, n+1):
    dag.append(' '.join(map(str, [i, i+1, 2**(i-1)])))
    dag.append(' '.join(map(str, [i, i+1, 0])))

for i in range(n, 0, -1):
    if L - 2**(i-1) >= 2**n:
        L -= 2**(i-1)
        dag.append(' '.join(map(str, [i, n+1, L])))

print(n+1, len(dag))
print('\n'.join(dag))


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>

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

const int MAX = 410;
const ll INF = 1e18;
int N;
ll dp[MAX][MAX], size[MAX];

ll get_size(int l, int r) {
  return size[r+1] - size[l];
}

ll solve(int l, int r) {
  if (l >= r) return 0;
  if (dp[l][r] >= 0) return dp[l][r];

  ll ret = INF;
  FOR (i, l, r) ret = min(ret, solve(l, i) + solve(i+1, r) + get_size(l, r));
  return dp[l][r] = ret;
}

int main () {
  cin >> N;
  REP (i, MAX) REP (j, MAX) dp[i][j] = -1;
  size[0] = 0;
  REP (i, N) {
    ll a;
    cin >> a;
    size[i+1] = size[i] + a;
  }
  cout << solve(0, N-1) << endl;
}

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


using namespace std;
typedef long long ll;
ll n, a[3010], dp[3010][3010][2];

ll diff(int i, int j, int player)
{
  if(i == j && player)
    return -a[i];
  else if(i == j && !player)
    return a[i];
  if(dp[i][j][player])
    return dp[i][j][player];
  if(player)
    return dp[i][j][player] = min(diff(i+1,j,player ^ 1) - a[i],diff(i, j-1, player ^ 1) - a[j]);
  else
    return dp[i][j][player] = max(diff(i+1,j,player ^ 1) + a[i],diff(i, j-1, player ^ 1) + a[j]);
}

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

  cout << diff(0,n-1,0);
  
  return 0;
}


Measured memory_bytes: 141824
import java.io.*;
import java.util.StringTokenizer;
public class Main{
    public static void main(String[] args) throws IOException {
        scanner sc = new scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum+= 1/sc.nextDouble();
        }
        out.print(1/sum);

        out.flush();

    }
}
class scanner{
    StringTokenizer st;
    BufferedReader br;
    public scanner(InputStream s){
        br = new BufferedReader(new InputStreamReader(s));
    }
    public scanner (String s) throws FileNotFoundException { br = new BufferedReader(new FileReader(s));}

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

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

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

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

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

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

Measured memory_bytes: 23252
fun main(arg: Array<String>) {
    val (A, B, C, D) = next().map { it - '0' }
    fun sign(a: Int) = if (a < 0) '-' else '+'
    for (bit in 0 until (1 shl 3)) {
        val b = if (bit.shr(0).and(1) == 1) -B else B
        val c = if (bit.shr(1).and(1) == 1) -C else C
        val d = if (bit.shr(2).and(1) == 1) -D else D
        if (A + b + c + d == 7) {
            return println("$A${sign(b)}$B${sign(c)}$C${sign(d)}$D=7")
        }
    }
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { Integer.parseInt(it) + d }
fun listOfLong() = listOfString().map(String::toLong)


Measured memory_bytes: 33408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s,t;
    cin>>s;
    int n=s.size();
    rep(i,n){
        if(s[i]=='0') t+='0';
        else if(s[i]=='1') t+='1';
        else if(t.size()!=0) t.pop_back();
    }
    cout<<t;
}

Measured memory_bytes: 3592
#include <cstdio>
int main() {
	int N, K, P;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &K, &P);
		if (K%P == 0) {
			printf("%d\n", P);
		}
		else {
			printf("%d\n", K%P);
		}
	}
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>

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

using namespace std;

const int INF = 2000000000;

int n;
int S[500100];
int res = 0;
int L[500000];
int R[500000];

void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    rep(i, n1) L[i] = A[left+i];
    rep(i, n2) R[i] = A[mid+i];
    L[n1] = R[n2] = INF;

    int i = 0; int j = 0;
    for (int k = left; k < right; ++k) {
        if(L[i] <= R[j]) A[k] = L[i++];
        else A[k] = R[j++];
        ++res;
    }

}

void mergeSort(int A[], int left, int right) {
    if (left < right -1) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
int main() {
    cin >> n;
    rep(i, n) cin >> S[i];
    mergeSort(S, 0, n);
    rep(i, n) {
        if(i > 0) cout << " ";
        cout << S[i];
    }
    cout << endl << res << endl;
}



Measured memory_bytes: 6996
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>


#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S,False(1,-1);
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

template<typename A,size_t N,typename T>
void Fill(A(&array)[N],const T &val){
    fill((T*)array,(T*)(array+N),val);
}

const ll INF = 1e10;
int main(){
    ll a, b;
    cin >> a >> b;
    if(0 < a)cout << "Positive" << endl;
    else if(a <= 0 && 0 <= b)cout << "Zero" << endl;
    else {
        if((b - a) % 2 == 0)cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int nums[1009];

void prim(int x){
    int tmp=x;
    for(int i=2; i<=tmp; i++){
        while(tmp%i==0){
            nums[i]++;
            tmp /= i;
        }
    }
}

int main() {
    int N;
    cin>>N;
    
    mem(nums,0);
    rep1(i,N) prim(i);
    
    ll ans=1, mod=1e9+7;
    rep1(i,N) ans = (ans*(nums[i]+1))%mod;
    
    cout1(ans);
}

Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()
    val ls = readLine()!!.split(' ').map { it.toInt() }.sorted()
    var ans = 0

    for (i in 2..n - 1)
        for (j in 1..i - 1)
            for (k in 0..j - 1) {
                if (ls[k] + ls[j] > ls[i] && ls[k] != ls[j] && ls[k] != ls[i] && ls[j] != ls[i]) {
                    ans++
                }
            }

    println(ans)
}


Measured memory_bytes: 40864
# import math
# import statistics
# a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#     c.append(i)
e1,e2 = map(int,input().split())
#f = list(map(int,input().split()))
#g = [input() for _ in range(a)]
h = []
for i in range(e2):
    h.append(list(map(int,input().split())))
L=[]
R=[]
for i in range(len(h)):
    L.append(h[i][0])
for i in range(len(h)):
    R.append(h[i][1])

if min(R)>=max(L):
    print(min(R)-max(L)+1)
else:
    print(0)




Measured memory_bytes: 28864
#include<bits/stdc++.h>
using namespace std;
int main()
{
  char s[5];
  cin>>s;
  bool f = false;
  for(char ch : s)
  {
    if(ch == '7')
    {
      cout<<"Yes\n";
      f = true;
      break;
    }
  }
  if(!f)
    cout<<"No\n";
}

Measured memory_bytes: 3640
using System;

class Task1
{

    public static void Main(string[] args)
    {
        string[] max = Console.ReadLine().Split(' ');
        int A = int.Parse(max[0]);
        int B = int.Parse(max[1]);
        int C = A + B;
        int D = A - B;
        int E = A * B;
        int F = Math.Max(C, D);
        int G = Math.Max(F, E);
        Console.WriteLine(G);
    }
}

Measured memory_bytes: 13140