akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string N; cin >> N;
    if(N[0]=='7' || N[1]=='7' || N[2]=='7'){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3036
using System;

public class Program
{
    private string S;

    private int L = 1 << 26;
    private int[] Dp;

    public void Solve()
    {
        var sc = new Scanner();
        S = sc.Next();


        Dp = new int[L];
        for (int i = 0; i < L; i++)
        {
            Dp[i] = 200000;
        }

        Dp[0] = 0;

        int state = 0;

        foreach (char c in S)
        {
            state ^= 1 << (c - 'a');
            int ans = int.MaxValue;
            for (char cc = 'a'; cc <= 'z'; cc++)
            {
                int tmp = state ^ (1 << (cc - 'a'));
                ans = Math.Min(ans, Dp[tmp] + 1);
            }

            Dp[state] = Math.Min(Dp[state], ans);

            // Console.WriteLine($"{Convert.ToString(state, 2)} {Dp[state]}");
        }
        
        if (state == 0)
        {
            Console.WriteLine(1);
        }
        else
        {
            Console.WriteLine(Dp[state]);
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

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

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

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

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 276704
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;
 
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=1e6+5;

int n,k;
int a[N];
int dp[N];
int32_t main()
{
    IOS;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i-j<0) break;
            if(dp[i]==-1)
            {
                dp[i]=dp[i-j]+abs(a[i-j]-a[i]);
            }
            else
            {
                dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
    // for(int i=0;i<n;i++)
    // {
    //     cout<<dp[i]<<" ";
    // }

}

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

struct edge{
	int t;
	int c;
	edge(){}
	edge(int tt,int cc){
		t=tt;
		c=cc;
	}
};

int n,m,tgt;
vector<edge> G[151];
int dp[151][151];
int prev[151][151];
int cyc_max[151][151];
int to_max[151][151];
int from_max[151][151];
int ft_max[301][301];

bool C(int v){
	for(int i=0;i<n;i++){
		for(int j=0;j<=min(n*2,v);j++){
			ll all=ft_max[i][j];
			if(all>=(ll)tgt)return true;
			ll rest=v-j;
			for(int l=1;l<=n;l++){
				ll va=(ll)rest/l;
				if(all+va*cyc_max[i][l]>=(ll)tgt)return true;
			}
		}
	}
	return false;
}

void get_route(int size){
	memset(dp,-1,sizeof(dp));
	memset(dp[0],0,sizeof(dp[0]));
	for(int i=0;i<size;i++){
		for(int j=0;j<n;j++){
			if(dp[i][j]>=0){
				for(int l=0;l<G[j].size();l++){
					edge e=G[j][l];
					if(dp[i+1][e.t]<dp[i][j]+e.c){
						dp[i+1][e.t]=dp[i][j]+e.c;
						prev[i+1][e.t]=j;
					}
				}
			}
		}
	}
	int maxi=tgt;
	for(int i=0;i<n;i++){
		maxi=max(maxi,dp[size][i]);
	}
	for(int i=0;i<n;i++){
		if(dp[size][i]>=maxi){
			int now=i;
			vector<int> ans;
			for(int j=0;j<size;j++){
				ans.push_back(now);
				now=prev[size-j][now];
			}
			ans.push_back(now);
			reverse(ans.begin(),ans.end());
			for(int j=0;j<=size;j++){
				printf("%d%c",ans[j],j==size?'\n':' ');
			}
			return;
		}
	}
}

int main(void){
	scanf("%d%d%d",&n,&m,&tgt);
	for(int i=0;i<m;i++){
		int f,t,c;
		scanf("%d%d%d",&f,&t,&c);
		G[f].push_back(edge(t,c));
	}
	for(int i=0;i<n;i++){
		memset(dp,-1,sizeof(dp));
		dp[0][i]=0;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				if(dp[j][k]>=0){
					for(int l=0;l<G[k].size();l++){
						edge e=G[k][l];
						dp[j+1][e.t]=max(dp[j+1][e.t],dp[j][k]+e.c);
					}
				}
			}
			cyc_max[i][j+1]=dp[j+1][i];
			for(int k=0;k<n;k++){
				from_max[i][j+1]=max(from_max[i][j+1],dp[j+1][k]);
				to_max[k][j+1]=max(to_max[k][j+1],dp[j+1][k]);
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=n;j++){
			for(int k=0;k<=n;k++){
				ft_max[i][j+k]=max(ft_max[i][j+k],from_max[i][j]+to_max[i][k]);
			}
		}
	}
	int l=-1,r=10000007;
	while(l+1<r){
		int mid=(l+r)/2;
		if(C(mid))r=mid;
		else l=mid;
	}
	if(r==10000007){
		printf("-1\n");
		return 0;
	}
	printf("%d\n",r);
	if(r<=100){
		get_route(r);
	}
	return 0;
}

Measured memory_bytes: 3872
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main() {
    int N;
    cin>>N;
    int F[N][10];
    ll P[N][11];
    rep(i, N){
        rep(j, 10){
            cin>>F[i][j];
        }
    }
    rep(i, N){
        rep(j, 11){
            cin>>P[i][j];
        }
    }
    int bit=0;
    ll ans;
    int count;
    ll answer=0;
    for (bit=1;bit<(1<<10);bit++){
        ans=0;
        rep(i, N){
            count=0;
            rep(j, 10){
                if((bit>>j)&1==1&&F[i][j]==1){
                    count++;
                }
            }
            ans+=P[i][count];
        }
        if(bit==1){
            answer=ans;
        }
        else{
            answer=max(answer, ans);
        }
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int, input().split()))
cnt=[0]*N

for i in range(N):
    cnt[a[i]-1]+=1

c_sum=0
for i in range(N):
    c_sum+=(cnt[i]*(cnt[i]-1))//2

for i in range(N):
    k=(cnt[a[i]-1])*(cnt[a[i]-1]-1) //2
    l=(cnt[a[i]-1]-1)*(cnt[a[i]-1]-2) //2
    d=k-l
    print(c_sum-d)

Measured memory_bytes: 86176
//
//  code_festival_2017_equal_B.cpp
//  
//
//  Created by Yoshida Satoshi on 2018/11/06.
//

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

#define MAX 100005

typedef long long ll;

using namespace std;

struct Graph
{
    ll n,m,a,b;
    vector<ll> v[MAX];
    ll c[MAX]={};
    ll odd=0;
    ll even=0;
    bool flag=false;//false<->2部ぐらふ
    
    void input()
    {
        cin>>n>>m;
        for(ll i=0;i<m;i++)
        {
            cin>>a>>b;
            v[a].push_back(b);
            v[b].push_back(a);
        }
    }
    
    void dfs(ll x,ll col)
    {
        if(flag) return;
        for(ll i=0;i<v[x].size();i++)
        {
            ll y=v[x][i];
            if(c[y]==0)
            {
                c[y]=col;
                if(col==1) even++;
                    else       odd++;
                dfs(y,-1*col);
            }
            else if(c[y]!=col)
            {
                flag=true;break;
            }
        }
    }
    
    void solve()
    {
        dfs(1,1);
        ll ans;
        if(flag) ans=(n*(n-1))/2-m;
        else     ans=odd*even-m;
        
        cout<<ans<<endl;
    }
    
};

int main()
{
    Graph g;
    
    g.input();
    
    g.solve();
    
    return 0;
}


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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

int main()
{
    int N; cin >> N;
    map<int, int> m;
    rep(i, N) {
        int a; cin >> a;
        m[a]++;
    }
    
    int ans = 0;
    int MAX = 1000000+1;
    vector<int> f(MAX);
    for (const auto& p : m) {
        int a = p.first;
        int c = p.second;
        if (c >= 2) f[a] = 1;
        for (int d = a+a; d <= MAX; d += a) {
            f[d] = 1;
        }
        if (f[a] == 0) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 16304
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int m;
int solve(int n, int k) {
  n -= k;
  return (n + m - 2) / (m - 1);
}

int main() {
  int n;
  scanf("%d%d", &n, &m);
  int k = -1;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x == 1) {
      k = i;
    }
  }
  int ret = INF;
  for (int i = 1; i <= m; ++i) {
    if (k + 1 < i || n - k < m - i + 1) continue;
    int cur = solve(k + 1, i) + solve(n - k, m - i + 1) + 1;
    // int L = solve(k + 1, i);
    // int R = solve(n - k, m - i + 1);
    // trace(i, L, R);
    ret = min(cur, ret);
  }
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a,b,i;
    cin>>a>>b;
    if(b==100)
        a=a*1000+100;
    else
    {
        if(b<=9)
            a=a*10+b;
        else
            a=a*100+b;
    }
    for(i=1;i*i<a;i++)
    {}
    if(i*i==a)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
N=10
M=10
sumW=0
sumK=0
I=[int(input()) for _ in range(N)]
I.sort()
sumW=sumW+I[9]+I[8]+I[7]
J=[int(input()) for _ in range(M)]
J.sort()
sumK=sumK+J[9]+J[8]+J[7]
print(sumW,sumK)


Measured memory_bytes: 5604
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int main()
{
	int N = 0;
	char S[10000];

	scanf("%d", &N);

	scanf("%s", S);
	
	for (int i = 0; S[i] != NULL; i++)
	{
		S[i] = ((S[i]+ N)-'A') % 26 + 'A';

		printf("%c", S[i]);
	}

	return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

int N, cnt, fa[200005]; ll D, A[200005], L[200005], R[200005], ans;
struct edge {int u, v; ll w;} ed[4000005];

inline bool operator < (const edge &ed1, const edge &ed2) {return ed1.w < ed2.w;}
int getf(const int &u) {return fa[u] == u ? u : fa[u] = getf(fa[u]);}

inline int findmin(const ll *a, int l, const int &r){
	register int res = l;
	while(++l <= r) if(a[l] < a[res]) res = l;
	return res;
}

void build(const int &l, const int &r){
	if(l == r) return; const int mid = l + r >> 1;
	const int Lmin = findmin(L, l, mid), Rmin = findmin(R, mid + 1, r);
	for(register int i = l; i <= mid; i++) ed[++cnt] = (edge){i, Rmin, L[i] + R[Rmin]};
	for(register int i = mid + 1; i <= r; i++) ed[++cnt] = (edge){Lmin, i, L[Lmin] + R[i]};
	build(l, mid), build(mid + 1, r);
}

int main(){
	getint(N), getint(D);
	for(register int i = 1; i <= N; i++) getint(A[i]), fa[i] = i;
	for(register int i = 1; i <= N; i++) L[i] = A[i] - i * D, R[i] = A[i] + i * D;
	build(1, N), sort(ed + 1, ed + cnt + 1);
	for(register int i = 1, bl = N; i <= cnt && bl > 1; i++){
		const int fu = getf(ed[i].u), fv = getf(ed[i].v);
		if(fu != fv) bl--, fa[fv] = fu, ans += ed[i].w;
	}
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 63104
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def readLine_int_list_reverse(): return list(map(int, stdin.readline().split())).reverse()
def readAll_int(): return list(map(int, stdin))
def readLine_str_list():return list(map(str, stdin.readline().split()))
def readAll_str(): return list(map(str, stdin))


def main():
	a,b = readAll_int()
	print((2*b)-a)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3436
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int N = int.Parse(str);
		string[] str2 = Console.ReadLine().Split();
		int[] a = new int[N];
		int[] b = new int[N];
		for(var i=0;i<N;i++){
			a[i] = int.Parse(str2[i]);
			b[i] = a[i];
		}
		Array.Sort(b);
		int[] d = new int[N];
		int tmax = N;
		int tmin = 0;
		while(true){
			if(tmin + 1 == tmax){
				break;
			}
			int t = (tmin + tmax) / 2;
			int ct = 0;
			long count = 0;
			for(var i=0;i<N;i++){
				if(a[i] >= b[t]){
					ct += 1;
					d[i] = ct;
				} else {
					ct -= 1;
					d[i] = ct;
				}
				if(ct >= 0){
					count += 1;
				} else {
					count -= 1;
				}
				count += i;
			}
			//Console.WriteLine(b[t]+" "+count);
			count -= 2 * margecount(d);
			//Console.WriteLine(b[t]+" "+count);
			if(count >= 0){
				tmin = t;
			} else {
				tmax = t;
			}
		}
		Console.WriteLine(b[tmin]);
	}
	
	public static long margecount(int[] a){
		long count = 0;
		int n = a.Length;
		if(n>1){
			int[] b = new int[n/2];
			Array.Copy(a,0,b,0,n/2);
			int[] c = new int[n - n/2];
			Array.Copy(a,n/2,c,0,n - n/2);
			count += margecount(b);
			count += margecount(c);
			for(int i=0,j=0,k=0;i<n;i++){
				if(k==c.Length){
					a[i] = b[j++];
				} else if(j==b.Length){
					a[i] = c[k++];
				} else if(b[j] <= c[k]){
					a[i] = b[j++];
				} else {
					a[i] = c[k++];
					count += n/2-j;
				}
			}
		}
		return count;
	}
}

Measured memory_bytes: 42412
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
const double PI = acos(-1);
typedef long long ll;


int main() {
  int N;cin>>N;
  cout<<(N+1)/2-1<<endl;
}









Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		String S  =sc.next();
		sc.close();
		char[] ch = S.toCharArray();
		int[] cnt = new int[ch.length];
		for(int i = 0;i < ch.length;i++) {
			if(ch[i]=='A'||ch[i]=='T'||ch[i]=='G'||ch[i]=='C') {
				cnt[i]++;
			}
		}
		int[] sum = new int[ch.length+1];
		for(int i = 0;i < ch.length;i++) {
			if(cnt[i]!=0) {
				sum[i+1] = sum[i] + cnt[i];
			}else {
				sum[i+1] = 0;
			}
		}
		Arrays.sort(sum);
		System.out.println(sum[sum.length-1]);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define W(x) cout<<x<<endl;
#define Debug(x) cout<<"#DEBUG "<<x<<endl;
#define INF (1<<29)
using namespace std;
int min(int x,int y){if(y<x)return y;else return x;}
int max(int x,int y){return x+y-min(x,y);}
int fact(int x){int i=1;rep(j,x){i*=(j+1);} return i;}
//ARC098
bool color[10000];//white=true,black=false
int main()
{
    int n;
    cin>>n;
    int d[n+1],sum[n];
    char c;
    d[0]=0;
    rep(i,n)
    {
        cin>>c;
        if(c=='W')
        {
            d[i+1]=1;
        }
        else
        {
            d[i+1]=0;
        }
    }
    rep(i,n)
    {
        d[i+1]+=d[i];
    }
    rep(i,n)
    {
        sum[i]=d[i]+(n-i-1-d[n]+d[i+1]);
    }
    sort(sum,sum+n);
    W(sum[0])
    return 0;
}

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

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

int H, W, C;
int panel[8][8];
int ans;
int used[8][8];

int dfs2(int x, int y, int c) {
	int ret = 0;
	used[y][x] = 1;	
	for ( int i = 0; i < 4; i++ ) {
		int nx = x+dx[i], ny = y+dy[i];
		if ( nx < 0 || ny < 0 || nx >= W || ny >= H ||
				 used[ny][nx] || panel[ny][nx] != c ) continue;
		ret += dfs2(nx, ny, c); 
	}

	return ret+1;	
}

void dfs3(int x, int y, int c, int d) {
	used[y][x] = 1;
	panel[y][x] = d;	
	for ( int i = 0; i < 4; i++ ) {
		int nx = x+dx[i], ny = y+dy[i];
		if ( nx < 0 || ny < 0 || nx >= W || ny >= H ||
				 used[ny][nx] || panel[ny][nx] != c ) continue;
		dfs3(nx, ny, c, d);		
	}
}

void dfs(int cnt) {
	int tmp[8][8];
	for ( int i = 0; i < H; i++ )
		for ( int j = 0; j < W; j++ )				
			tmp[i][j] = panel[i][j];

	if ( cnt == 5 ) {
		if ( panel[0][0] == C ) {
			fill_n(*used, 8*8, 0);		
			ans = max(ans, dfs2(0, 0, panel[0][0]));
		}
	} else {
		for ( int i = 1; i <= 6; i++ ) {
			//if ( panel[0][0] == i ) continue;
			fill_n(*used, 8*8, 0);		
			dfs3(0, 0, panel[0][0], i);		
			dfs(cnt+1);
			for ( int k = 0; k < H; k++ )
				for ( int j = 0; j < W; j++ )				
					panel[k][j] = tmp[k][j];
		}
	}
	
}

int main() {
	while ( cin >> H >> W >> C, H ) {
		ans = 0;
		for ( int i = 0; i < H; i++ )
			for ( int j = 0; j < W; j++ )				
				cin >> panel[i][j];

		dfs(0);		
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n-1;i>=0;i--)
#define Pool(i, m, n) for(ll i=n-1;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define Gput(a,b) G[a].push_back(b)
int main() {
 double w,h,x,y;
 cin>>w>>h>>x>>y;
 double ans=w*h/2;
 putout(ans);
if(x==w/2&&y==h/2)putout(1);
else putout(0);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;

class Main {

    public static void main(String[] args) throws IOException {
        doit(args, System.in, System.out);
    }

    static void doit(String[] args, InputStream in, PrintStream out)
            throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null && !line.isEmpty()) {
            String[] values = line.split(" ");
            int[] orders = new int[10];
            for (int i = 0; i < 4; i++) {
                orders[Integer.parseInt(values[i])] = i + 1;
            }
            values = reader.readLine().split(" ");
            int hit = 0;
            int blow = 0;
            for (int i = 0; i < 4; i++) {
                int order = orders[Integer.parseInt(values[i])];
                if (order == i + 1) {
                    hit++;
                } else if (order != 0) {
                    blow++;
                }
            }
            out.println(hit + " " + blow);
        }
    }
}

Measured memory_bytes: 9164
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;


int main(){
  int x,y;
  cin>>x>>y;
  int gcd=0;
  for(int i=1;i<=min(x,y);i++){
    if(x%i==0 && y%i==0){
      gcd=max(gcd,i);
    }
  }
  cout<<x+y+1-gcd<<endl;
  
  
  /*int a,b,N;
  cin>>a>>b;
  cin>>N;
  int s[100],f[100];
  for(int i=0;i<N;i++){
    cin>>s[i]>>f[i];
  }
  int judge=0;
  for(int i=0;i<N;i++){
      if(s[i]<=a && f[i]>a){
        judge=judge+1;
      }
      if(s[i]<b && f[i]>=b){
        judge=judge+1;
      }
      if(a<=s[i] && b>s[i]){
        judge=judge+1;
      }
      if(a<f[i] && b>=f[i]){
        judge=judge+1;
      }
  }
  if(judge==0){
    cout<<0<<endl;
  }
  else{
    cout<<1<<endl;
  }*/
  
 /* int X;
  cin>>X;
  if(X%7==0){
    cout<<"thu"<<endl;
  }
  if(X%7==1){
    cout<<"fri"<<endl;
  }
  if(X%7==2){
    cout<<"sat"<<endl;
  }
  if(X%7==3){
    cout<<"sun"<<endl;
  }
  if(X%7==4){
    cout<<"mon"<<endl;
  }
  if(X%7==5){
    cout<<"tue"<<endl;
  }
  if(X%7==6){
    cout<<"wed"<<endl;
  }
 */
	
	/*int m,f,b;
	cin>>m>>f>>b;
	if(b-m<=0){
		cout<<0<<endl;
	}
	if(b-m>0 && b-m<=f){
		cout<<b-m<<endl;
	}
	if(b-m>0 && b-m>f){
		cout<<"NA"<<endl;
	}*/
	/*int a,b;
	cin>>a>>b;
	cout<<(a+b)/2<<endl;*/
	
	/*random_device rnd;
	mt19937 mt(rnd());
	uniform_int_distribution<> rnd3(1, 3);
	
	string p1, p2, p3, p4;
	cin >> p1 >> p2 >> p3 >> p4;
	
	int t = rnd()%3;
	
	if(t == 0){
		cout << "1:" << p1 << ',' << p2 << endl;
		cout << "2:" << p3 << ',' << p4 << endl;
	}
	if(t == 1){
		cout << "1:" << p1 << ',' << p3 << endl;
		cout << "2:" << p2 << ',' << p4 << endl;
	}
	if(t == 2){
		cout << "1:" << p1 << ',' << p4 << endl;
		cout << "2:" << p2 << ',' << p3 << endl;
	}*/
	
	/*
	switch(type){
		case 0:
			cout << "1:" << p1 << ',' << p2 << endl;
			cout << "2:" << p3 << ',' << p4 << endl;
			break;
		case 1:
			cout << "1:" << p1 << ',' << p3 << endl;
			cout << "2:" << p2 << ',' << p4 << endl;
			break;
		case 2:
			cout << "1:" << p1 << ',' << p4 << endl;
			cout << "2:" << p2 << ',' << p3 << endl;
			break;
	}
	*/
	
	
	return 0;
}



Measured memory_bytes: 3112
from bisect import bisect_left

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

L.sort()
result = 0
for i in range(N - 2):
    for j in range(i + 1, N - 1):
        result += bisect_left(L, L[i] + L[j], j + 1) - j - 1
print(result)


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
#include<stack>
#include<list>

#define endl "\n"
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
using Graph = vector<vector<int>>;

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());

    if(a[0] == 0){
        cout<<0<<endl;
        return 0;
    }

    ll ans = 1;
    for(ll i=0;i<n;i++){
        if(ans > INF / a[i]){ // ans * a[i] はllの範囲を越える可能性有り
            cout<<-1<<endl;
            return 0;
        }
        ans *= a[i];
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4008
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{

	int n, k,sum=0;
	cin >> n >> k;
	vi l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}

	sort(l.rbegin(), l.rend());
	for (int i = 0; i < k; i++) {
		sum += l[i];
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        long N=gl();
        
        long min=N-1;
        long i=2;
        long k=N;
        while (i<=k) {
        	if(N%i==0) {
        		long a=i;
        		long b=N/i;
        		long c=a+b-2;
        		if (c<min) {
        			min=c;
        		}
        		k=b-1;
        	} else {
                k=Math.floorDiv(N,i)+1;
            }
        	i++;
        }
	    System.out.println(min);
	    
//        if (a>0) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35648
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
using namespace std;


int main() {
    int  a,b;
    cin >>a>>b;
    if (a >= b) {
        cout << a - b << endl;
    }
    else cout << "0" << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
x = int(input())
for i in range(100000):
    if(i ** 5 -x > 0):
        b = int(pow(i**5-x,1/5))
        if(b**5 == i**5-x):
            print(i,b)
            break
    else:
        b = int(pow(-i**5+x,1/5))
        if(b**5 == -i**5+x):
            print(i,-b)
            break

Measured memory_bytes: 27116
package main

import (
	"fmt"
)

type Otoshidama struct {
	Value float64
	Unit  string
}

func main() {
	var n int
	fmt.Scanln(&n)

	o := make([]Otoshidama, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f %s", &o[i].Value, &o[i].Unit)
	}

	fmt.Println(logic(o))
}

func logic(o []Otoshidama) float64 {
	var sum float64

	for _, otoshidama := range o {
		if otoshidama.Unit == "BTC" {
			sum += 380000.0 * otoshidama.Value
		} else {
			sum += otoshidama.Value
		}
	}

	return sum
}


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

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

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

    long long mod = 1e09 + 7;
    vector<long long> dp(n+1);
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j <= min(n, i+2); ++j) {
            if (a[j] == 0) {
                dp[j] += dp[i];
                dp[j] %= mod;
            }
        }
    }
    cout << dp[n] << endl;

}



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

int main() {
 
  long long N;
  cin >> N;
  
  long long answer = 0;

  if (N % 2 == 0) {
    int current = 1;
    long long d = 0;
    while (d < N) {
      d = pow(5, current) * 2;
      answer += N / d;
      current++;
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int even;
	int odd;
	int ans = 0;
	scanf("%d %d", &even, &odd);
	int ans1 = even * (even - 1)/2;
	int ans2 = odd * (odd - 1)/2;
	
	printf("%d", ans1 + ans2);
	return 0;
}

Measured memory_bytes: 1696
#include<cstdio>
using namespace std;
int N,K,cnt,F[1005][1005],l[1005],i,j;
int main(){
	scanf("%d",&N);
	while(K*(K-1)/2<N)++K;
	if(K*(K-1)/2!=N){
		puts("No");
		return 0;
	}
	printf("Yes\n%d\n",K);
	for(i=1;i<K;++i)for(j=K;j>i;--j)F[i][++l[i]]=++cnt,F[j][++l[j]]=cnt;
	for(i=1;i<=K;++i){
		printf("%d ",l[i]);
		for(j=1;j<l[i];++j) printf("%d ",F[i][j]);
		printf("%d\n",F[i][l[i]]);
	}
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  ll hu=0;
  ll MIN=INF;
  REP(i, N){
    cin >> A[i];
    if(A[i]<0){
      hu++;
    }
    MIN=min(MIN,abs(A[i]));
    sum+=abs(A[i]);
  }
  
  if(hu%2==0){
    cout << sum << endl;
  }else{
    cout << sum-MIN*2 << endl;
  }
}

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

int main(){
  int N;
  cin >> N;
  int ans=0;
  int maxx=0;
  int A;
  for (int i=0;i<N;i++){
    cin >> A;
    ans+=A;
    maxx=max(A,maxx);
  }
  cout << ans-maxx/2 << endl;
}

Measured memory_bytes: 256
import 'dart:io';

void main() {
  String s = stdin.readLineSync();
  String t = stdin.readLineSync();

  List ss = s.split("");
  List sortS = ss..sort();
  String stringS = sortS.join();
  List tt = t.split("");
  List sortT = tt..sort((b, a) => a.compareTo(b));

  String stringT = sortT.join();
  List before = [stringS, stringT];
  String before1 = stringS;
  String after1 = (before..sort())[0];
  String before2 = stringT;
  String after2 = (before..sort())[1];
  if (before1 == before2 && after1 == after2) {
    print("No");
  } else if (before1 != after1) {
    print("No");
    return;
  } else if (before1 == after1) {
    print("Yes");
    return;
  }
}


Measured memory_bytes: 13136
program coins
  implicit none
  integer :: a, b, c, x
  integer :: y, z
  integer :: i, j, m
  read(*,*) a
  read(*,*) b
  read(*,*) c
  read(*,*) x

  if (x .gt. 500*a+100*b+50*c) then
     write(*,'(i0)') 0
     stop
  end if

  m = 0
  do i = 0, a
     y = x - 500*i
     if (y .lt. 0) exit
     do j = 0, b
        z = y - 100*j
        if (z .lt. 0) exit
        if (z/50 .le. c) m = m + 1
     end do
  end do

  write(*,'(i0)') m
  
  stop
end program coins

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
int n,n2,d1,d2,c1 = 0,c2 = 0,cnt = 0,tot;
int main()
{
	scanf("%d%d%d",&n,&d1,&d2);n2 = n << 1,tot = n * n;
	while(!(d1 % (1 << (c1 + 1)))) ++c1;
	while(!(d2 % (1 << (c2 + 1)))) ++c2;
	for(int i = 0;i < n2 && cnt < tot;i++) for(int j = 0;j < n2 && cnt < tot;j++)
	{
		int b1 = (c1 & 1) ? (!((i >> (c1 >> 1)) & 1)) : (((i >> (c1 >> 1)) & 1) == ((j >> (c1 >> 1)) & 1));
		int b2 = (c2 & 1) ? (!((i >> (c2 >> 1)) & 1)) : (((i >> (c2 >> 1)) & 1) == ((j >> (c2 >> 1)) & 1));
		if(b1 && b2 && (++cnt)) printf("%d %d\n",i,j);
	}
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	string s;
	cin>>s;
	ll i,count=0;
	for(i=0;i<s.size();i++){
		if(s[i]=='-'){
			count--;
		}
		else{
			count++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

void dfs(VVI &es, VLL &cnt, int par, int i) {
    for (auto &&dst: es[i]) {
        if (dst == par) continue;
        cnt[dst] += cnt[i];
        dfs(es,cnt,i,dst);
    }
}

void solve() {
    LL n,q;
    cin >> n >> q;
    VVI es(n);
    int a,b,p,x;
    VLL cnt(n);
    REP(i,0,n-1) {
        cin >> a >> b;
        --a; --b;
        es[a].push_back(b);
        es[b].push_back(a);
    }
    REP(i,0,q) {
        cin >> p >> x;
        --p;
        cnt[p] += x;
    }
    dfs(es,cnt,-1,0);
    REP(i,0,n) cout << cnt[i] << " ";
    cout << endl;
}

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

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

#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
int M, T, P, R;
struct Team {
  int ACtime[11] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
  int WAcnt[11] = {};
  int timecost = 0;
  int ACcnt = 0;
  int id;
  bool operator<(const Team &o) const {
    if (ACcnt == o.ACcnt) {
      if (timecost == o.timecost) {
        return id > o.id;
      } else {
        return timecost < o.timecost;
      }
    } else {
      return ACcnt > o.ACcnt;
    }
  }
};
signed main() {
  while (cin >> M >> T >> P >> R) {
    if (M == 0 && T == 0 && P == 0 && R == 0) break;
    vector<Team> tm(T);
    rep(i, T) tm[i].id = i + 1;
    rep(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      t--;
      p--;
      if (j == 0) { // AC
        tm[t].ACtime[p] = m;
        tm[t].ACcnt++;
      } else { // WA
        // int tmp = tm[i].WAcnt[p];
        // tmp++;
        // tm[t].WAcnt[p] = tmp;
        tm[t].WAcnt[p]++;
      }
    }
    // rep(i, T) {
    //   rep(j, P) cout << tm[i].WAcnt[j] << ' ';
    //   cout << endl;
    // }

    // score計算
    rep(i, T) rep(j, P) tm[i].timecost += (tm[i].ACtime[j] >= 0 ? tm[i].ACtime[j] + tm[i].WAcnt[j] * 20 : 0);
    sort(all(tm));
    // cout << '\n';
    //
    // cout << "id" << ' ' << "ACcnt" << ' ' << "timecost" << endl;
    // rep(i, T) { cout << tm[i].id << ' ' << tm[i].ACcnt << ' ' << tm[i].timecost << ' ' << endl; }
    // cout << '\n';

    rep(i, T) {
      if (i == 0)
        cout << tm[i].id;
      else {
        if (tm[i - 1].ACcnt == tm[i].ACcnt && tm[i - 1].timecost == tm[i].timecost) {
          cout << "=" << tm[i].id;
        } else
          cout << ',' << tm[i].id;
      }
    }
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3120
#define _CRT_SECURE_NO_WARNINGS
//#include <stdafx.h>
//#include "targetver.h"
#include <stdio.h>
//#include <tchar.h>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif>

#define LL long long
#define MOD 1000000007
#define INF 1000000000
#define LINF 10000000000000000

using namespace std;

const int N = 2e6 + 10;

LL a[N];
LL b[N];
LL pr[N];
LL dp[3005][3005];
vector<int>vec;

int main() {

	LL n;
	scanf("%lld", &n);

	for (LL i = 0; i < n; i++)
		scanf("%lld", &a[i]);

	//dp[n - 1][n - 1] = a[n - 1];
	for (LL L = n - 1; L >= 0; L--)
		for (LL R = L; R < n; R++) {
			
			if (L == R)
				dp[L][R] = a[L];
			else
				dp[L][R] = max(a[L] - dp[L + 1][R], a[R] - dp[L][R - 1]);
			
		}
	printf("%lld\n", dp[0][n - 1]);
	//cin >> n;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << max(0, C - (A - B)) << endl;
    return 0;
}



Measured memory_bytes: 256
abcd = input()
a = int(abcd[0])
b = int(abcd[1])
c = int(abcd[2])
d = int(abcd[3])

op = ["+", "-"]
for op1 in op:
    for op2 in op:
        for op3 in op:
            val = a
            if op1 == "+":
                val += b
            else:
                val -= b

            if op2 == "+":
                val += c
            else:
                val -= c

            if op3 == "+":
                val += d
            else:
                val -= d
            
            if val==7:
                print("{}{}{}{}{}{}{}=7".format(a,op1,b,op2,c,op3,d))
                exit(0)

Measured memory_bytes: 3064
# coding: utf-8
input_lines = input().split()
N = int(input_lines[0])
Y = int(input_lines[1])

flag = 0
for i in range(N+1):
  if flag ==1:
    break
  for j in range(N+1-i):
    if Y-10000*i-5000*j-1000*(N-i-j)==0:
      print(str(i)+" "+str(j)+" "+str(N-i-j))
      flag = 1
      break
if flag == 0:
  print("-1 -1 -1")



Measured memory_bytes: 3060
#include"iostream"
#include"string"
using namespace std;

int main()
{
	string s;
	cin >> s;
	int ans = 0;
	if (s[0] == '1')ans++;
	if (s[1] == '1')ans++;
	if (s[2] == '1')ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c;
    int answer = 0;
    scanf("%d %d %d",&a,&b,&c);
    if(a == b && b != c) answer = 1;
    if(a == c && b != c) answer = 1;
    if(b == c && a != c) answer = 1;
    if(answer == 1) printf("Yes");
    else printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;


struct UnionFind {
    int N;
    vector<int> parents;

    UnionFind(int _N) : N(_N){
        parents.assign(N,-1);
    }

    int find(int x) { //xの親を返す
        if (parents[x] < 0) return x;
        return parents[x] = find(parents[x]);
    }
    
    void unite(int x, int y) {  //xとyの含むグループを併合
        int px = find(x);
        int py = find(y);
        if (parents[px] > parents[py]) swap(px,py); 
        if (px != py) {
            parents[px] += parents[py];
            parents[py] = px;
        }     
    }

    bool same(int x, int y) { //x,yが同じグループにいるか判定
        return find(x) == find(y);
    }

    int size(int x) { //xと同じグループのメンバーの個数
        return -parents[find(x)];
    }
    
    vector<int> root() {//ufの根を列挙
        vector<int> res;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) res.push_back(i);
        }
        return res;
    }

    int group_count() { //ufのグループの数を数える
        int cnt = 0;
        for (int i = 0; i < N; i ++) {
            if (parents[i] < 0) cnt ++;
        }
        return cnt;
    }
};

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

    int N,Q; cin >> N >> Q;
    UnionFind uf(N);
    rep(i,Q) {
        int t,a,b; cin >> t >> a >> b;
        if (t == 0) {
            uf.unite(a,b);
        } else {
            if (uf.same(a,b)) cout << 1 << '\n';
            else cout << 0 << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 3964
#include<cstdio>
#include<cstring>
using namespace std;
int i,j,k,t,x,y;
char a[100000];
int main(){
	gets(a);
	t=strlen(a);
	for(i=0;i<=t-1;i++)
	    if(a[i]=='C'){
	    	x=i; k=1; break;
		}
    if(k==1)
	   for(i=x;i<=t-1;i++)
	      if(a[i]=='F'){
	      	  y=1;break;
		  }
	if(k==1&&y==1) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      long[] A = new long[N];
      long ans = 0;
      for(int i=0;i<N;i++){
        A[i] = sc.nextLong();
        if(i>0 && A[i]<A[i-1]){
          ans+=A[i-1]-A[i];
          A[i] = A[i-1];
        }
      }
        System.out.println(ans);
    }
}


Measured memory_bytes: 63368
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
    ll l,r;
    std::cin >> l>>r;
    ll result = 1e9;
    if(r-l < 5000){
        for (int i = l; i < r; i++) {
            for (int j = i+1; j <= r; j++) {
                result = min(result,(ll)i%2019*j%2019);
            }
        }
        std::cout << result << std::endl;
    }else{
        for (int i = l; i <= l+2020; i++) {
            for (int j = r-2020; j <= r; j++) {
                result = min(result,(ll)i%2019*j%2019);
            }
        }
        std::cout << result << std::endl;
    }
}

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

int group[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};

int main(){
    int x, y;
    cin >> x >> y;
    cout << (group[x] == group[y] ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            int a = Integer.parseInt(br.readLine());
            
            System.out.println(a + a*a + a*a*a);
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 32368
def main():
    from bisect import bisect_right as br
    from collections import Counter as ct
    check=[]
    i=1
    while i<=10**10:
        check.append(i)
        i*=2
    n=int(input())
    c=ct(list(map(int,input().split())))
    c_l=sorted(list(c.keys()),reverse=True)
    ans=0
    for i in c_l:
        j=check[br(check,i)]-i
        if i==j:
            ans+=c[i]//2
        else:
            ans+=min(c[i],c[j])
            c[j]-=min(c[i],c[j])
    print(ans)
main()

Measured memory_bytes: 55988
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int n,x;
ll sum;
ll b[100010],l[100010],u[100010],num[100010],pfsum[100010];
pair<ll,int> p[100010];

bool isOK(ll k){
    ll q=k/x;
    ll r=k-q*x;
    for(int i=0;i<n;i++){
        ll score=min(b[i],r)*l[i]+max(0LL,r-b[i])*u[i];
        if(q-1<num[i]){
            if(pfsum[q]+score>=sum)return true;
        }else{
            if(pfsum[q+1]-pfsum[num[i]+1]+pfsum[num[i]]+score>=sum)return true;
        }
    }
    return false;
}

int main(){
    cin>>n>>x;
    for(int i=0;i<n;i++){
        cin>>b[i]>>l[i]>>u[i];
        sum+=b[i]*l[i];
    }
    for(int i=0;i<n;i++){
        p[i]={b[i]*l[i]+(x-b[i])*u[i],i};
    }
    sort(p,p+n,greater<pair<ll,int>>());
    for(int i=0;i<n;i++){
        num[p[i].second]=i;
        pfsum[i+1]=pfsum[i]+p[i].first;
    }
    ll ok=(ll)n*x;
    ll ng=-1;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        (isOK(mid)?ok:ng)=mid;
    }
    cout<<ok<<endl;
}


Measured memory_bytes: 5760
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
char buf[1<<20],*p;sz;
main()
{
	read(0,buf,1<<20);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	p=buf+sz;
	int s=0,f=0;
	for(int i=0;i<N;i++)
	{
		s+=!(-N&i)*(p[i]-'1');
		f|=p[i]=='2';
	}
	printf("%d\n",s&3>>f);
}

Measured memory_bytes: 1152