akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans*=(A-i);
    }
    for (int i = 0; i < B; i++) {
        ans /=i+1;
    }
    return ans;
}
int main(){
    int N;
    cin>>N;
    vector<int>X(N);
    int a=100000;
    int b=0;
    rep(i,N){
        cin>>X[i];
        if(X[i]<a){
            a=X[i];
        }
        else if(b<X[i]){
            b=X[i];
        }
    }
    int ans=100000000;
  	bool d=false;
    for(int i=a; i<b+1; i++){
        int cnt=0;
        rep(j,N){
            cnt+=abs(i-X[j])*abs(i-X[j]);
        }
        if(cnt<ans){
            ans=cnt;
          d=true;
        }
    }
  if(d==true){
    cout<<ans<<endl;
  }
  else{
    cout<<0<<endl;
  }
}


Measured memory_bytes: 3536
#include <stdio.h>
int main(){
	int N,K,X,Y;
	int F;
	scanf("%d %d %d %d",&N,&K,&X,&Y);
	if(N <= K){
		F = X*N ;
		printf("%d\n",F);
	}
	else if(N > K){
		F = K*X+(N-K)*Y;
		printf("%d\n",F);
	}
	



	return 0;
}




Measured memory_bytes: 128
// https://atcoder.jp/contests/abc085/tasks/abc085_b

#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int n, m;
    map<int, int> dic;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> m;
        if (dic.count(m) == 0) {
            dic[m] = m;
        }
    }
    cout << dic.size() << endl;

    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N; 
	cin >> N;
	vector<PII>a(N);
	FOR(i, 0, N) {
		cin >> a[i].first >> a[i].second;
	}
	SORT(a);
	int low = a.back().second;
	int lowidx = a.back().first;
	DD(de(lowidx, low));
	ans = lowidx + max(0, low);
	
	
	cout << ans << "\n";

	return 0;
}


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

int main()
{
  string S;
  cin >> S;
  sort(S.begin(), S.end());
  for (int i=1; i<S.size(); i++){
    if(S.at(i-1)==S.at(i)){
      S.erase(i-1,2);
      i=0;
    }
  }
  if (S.size()==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define int long long 

 int dp[100001];


int solve(vector<vector<int>>&v,int i){
    if(dp[i]!=-1)
    return dp[i];
    
    int ans =0;
    for(int j=0;j<v[i].size();j++){
        ans = max(ans,solve(v,v[i][j])+1);
    }
    dp[i]=ans;
    return ans;
}



int32_t main(){
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    int n;
    cin>>n;
    int m;
    cin>>m;
    
    for(int i=0;i<n;i++)
    dp[i]=-1;
    
    vector<vector<int>>v;
    for(int i=0;i<n;i++){
        vector<int>temp;
        v.push_back(temp);
    }
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        int y;
        cin>>y;
        x--;
        y--;
        v[x].push_back(y);
    }
    int ans =0;
    for(int i=0;i<n;i++){
        if(dp[i]==-1){
            dp[i] = solve(v,i);
        }
        ans = max(ans,dp[i]);
        
    }
   cout << ans << endl;
    
 

 
}

  
    
    
    
    


  
    
    
    
    

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

using namespace std;

int max3(int a,int b,int c){
	return max(a,max(b,c));
}

int main(){	
	

		int n,k;
		cin>>n>>k;

		for(int i = (k-n+1); i<=(k+n-1);i++){
			if(i>=-1000000&&i<=1000000){
				cout<<i<<" ";
			}
		}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

int main(){
	string input;
	while(getline(cin, input)){
		stack<char> bracket;
		if(input.size() == 1 && input[0] == '.') break;
		for(int i = 0; i < input.size(); i++){
			if(input[i] == '(' || input[i] == '[') bracket.push(input[i]);
			if(bracket.size() == 0){
				if(input[i] == ')' || input[i] == ']'){
					bracket.push(input[i]);
					break;
				}
				continue;
			}
			if(input[i] == ')'){
				if(bracket.top() == '(') bracket.pop();
				else break;
			}
			else if (input[i] == ']'){
				if(bracket.top() == '[') bracket.pop();
				else break;
			}
		}
		cout << (!bracket.size() ? "yes" : "no") << endl; 
	}
	return 0;
}

Measured memory_bytes: 1172
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int Q = sc.nextInt();
			String[] name = new String[N];
			int[] ey = new int[N];
			int[] wy = new int[N];
			for (int i = 0; i < N; ++i) {
				name[i] = sc.next();
				ey[i] = sc.nextInt();
				wy[i] = sc.nextInt();
			}
			for (int i = 0; i < Q; ++i) {
				int q = sc.nextInt();
				boolean found = false;
				for (int j = 0; j < N; ++j) {
					if (wy[j] - ey[j] < q && q <= wy[j]) {
						System.out.println(name[j] + " " + (q - (wy[j] - ey[j])));
						found = true;
						break;
					}
				}
				if (!found) System.out.println("Unknown");
			}
		}
	}
}

Measured memory_bytes: 61480
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n,m;
	bool en=false;
	while(cin>>n>>m&&!(n==0&&m==0)){


		char chair[101];
		char ch;
		fill(chair,chair+101,'#');
		for(int i = 0; i < m; i++){
			cin>>ch;
			if(ch=='A'){
				for(int j = 0; j < n; j++){
					if(chair[j]=='#'){
						chair[j]=ch;
						break;
					}
				}
			}
			else if(ch=='B'){
				bool f=false;
				for(int j = n-1; j >=0; j--){
					if(chair[j]=='#'&&((j-1<0||chair[j-1]!='A')&&(j+1>=n||chair[j+1]!='A'))){
						chair[j]=ch;
						f=true;
						break;
					}
				}
				// ÀêÈ©Á½ê
				if(!f){
					for(int j = 0; j < n; j++){
						if(chair[j]=='#'){
							chair[j]=ch;
							break;
						}
					}
				}
			}
			else if(ch=='C'){
				bool f=false;
				for(int j = 0; j < n; j++){
					if(chair[j]!='#'){
						f=true;
						break;
					}
				}
				if(!f){
					chair[n/2]=ch;
				}
				else{
					for(int j = 0; j < n; j++){
						if(chair[j]!='#'){
							if(j+1<n&&chair[j+1]=='#'){
								chair[j+1]=ch;
								f=true;
								break;
							}
							else if((j-1>=0)&&chair[j-1]=='#'){
								chair[j-1]=ch;
								f=true;
								break;
							}
						}
					}
				}
			}
			else if(ch=='D'){
				int dists[101];
				fill(dists,dists+101,1000000);
				bool fff=false;
				for(int j = 0; j < n; j++){
					if(chair[j]!='#'){
						fff=true;
						break;
					}
				}
				if(fff==false){
					chair[0]=ch;
				}
				else{
					for(int j = 0; j < n; j++){
						if(chair[j]!='#'){
							for(int k = 0; k < n; k++){
								dists[k]=min(dists[k],abs(j-k));
							}
						}
					}
					int maxCost=-1;
					int idx;
					for(int j = 0; j < n; j++){
						if(chair[j]=='#'){
							if(maxCost<dists[j]){
								maxCost=dists[j];
								idx=j;
							}
						}
					}
					chair[idx]=ch;
				}
			}
		}
		for(int i = 0; i < n; i++){
			cout<<chair[i];
		}
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <functional>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const ll MOD = 1000000007;
const double EPS = 1e-10;
const int MAX = 200000;

int main() {
  int k;
  vector<int> a;
  rep(i,9) {
    cin >> k;
    a.push_back(k);
  }
	int n;
	cin >> n;
  rep(i,n) {
    cin >> k;
    rep(i,9) {
      if(a[i] == k) a[i] = 0;
    }
  }
  rep(i,3) {
    if(a[i*3] == 0 && a[i*3+1] == 0 && a[i*3+2] == 0) {
      	cout << "Yes" << endl;
        return 0;
    }
  }
  rep(i,3) {
    if(a[i] == 0 && a[i+3] == 0 && a[i+6] == 0) {
      	cout << "Yes" << endl;
        return 0;
    }
  }
  if(a[0] == 0 && a[4] == 0 && a[8] == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  if(a[2] == 0 && a[4] == 0 && a[6] == 0) {
    cout << "Yes" << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i];
  }
  int next = 1;
  int ans = 1;
  while (vec[next - 1] != 2) {
    next = vec[next - 1];
    ans++;
    if (ans > n) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int n,p[51],t,i,j;
	scanf("%d", &n);
	for(i=1; i<=n; i++)
	scanf("%d", &p[i]);
	for(i=1; i<n; i++)
	{
		if(i!=p[i])
		{
			for(j=i+1; j<=n; j++)
			{
				if(i==p[j])
				{
					t=p[i];
					p[i]=p[j];
					p[j]=t;
					break;
				}
			}
			break;
		}
	}
	for(i=1; i<=n; i++)
	{
		if(i!=p[i])
		{
			printf("NO\n");
			break;
		}
		if(n==i)
		printf("YES\n");
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;
char s[7];

int main(void) {
    scanf("%s", s);
    if (s[2] == s[3] && s[4] == s[5]) 
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}

Measured memory_bytes: 256
def A():
    a, b = map(int, input().split())
    lt = [
        a + b,
        a - b,
        a * b
    ]
    print(max(lt))


def B():
    k, x = map(int, input().split())
    
    answer = ''
    for i in range(2*k-1):
        answer += str(x-k+1+i) + ' '
    
    answer = answer[:-1]
    print(answer)
    

if __name__ == '__main__':
    B()

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) if (a[i] > 0) cnt++;
  sort(a.begin(), a.end());
  vector<bool> pm(n);

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] <= 0) {
      pm[i] = true;
    }
    sum += abs(a[i]);
  }
  if (cnt == 0) {
    pm[n - 1] = false;
    sum += 2 * a[n - 1];
  }
  if (cnt == n) {
    pm[0] = true;
    sum -= 2 * a[0];
  }
  int def = 0;
  for (int i = 0; i < n; i++) if (pm[i]) def = i;
  vector<int> p, m;
  for (int i = 0; i < n; i++) {
    if (i == def) continue;
    if (pm[i]) m.push_back(i);
    else p.push_back(i);
  }

  cout << sum << endl;
  ll now = a[def];
  for (int i = 1; i < p.size(); i++) {
    cout << now << " " << a[p[i]] << endl;
    now -= a[p[i]];
  }
  cout << a[p[0]] << " " << now << endl;
  now = a[p[0]] - now;

  for (int i = 0; i < m.size(); i++) {
    cout << now << " " << a[m[i]] << endl;
    now -= a[m[i]];
  }

  return 0;
}


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

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main(){
  int a,b,c;
  cin >> a >> b;
  a %= 3;
  b %= 3;
  c = (a+b)%3;

  if(c == 0 || a ==0 || b == 0){
    printf("Possible\n");
  }
  else printf("Impossible\n");

  return 0;
}

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

int n,m,ans;
int st[N],ed[N],c[N],pre[N],res[N];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d%d%d",&st[i],&ed[i],&c[i]);
	
	for (int i=1;i<=m;i++)
	{
		memset(pre,0,sizeof(pre));
		for (int j=1;j<=n;j++) if (c[j]==i) pre[st[j]]++,pre[ed[j]+1]--;
		for (int j=1;j<=100000;j++) pre[j]+=pre[j-1];
		for (int j=1;j<=100000;j++) if (pre[j]>0) res[j]++;
	}
	for (int i=1;i<=100000;i++) ans=max(ans,res[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

typedef long long ll;
const int maxn=1e6;
vector<int> mp[maxn];
int flag,vis[maxn];

void dfs(int u,int c)
{
    vis[u]=c;
    for(int i=0;i<mp[u].size();i++)
    {
        int v=mp[u][i];
        if(vis[v]==-1)
            dfs(v,1-c);
        else
        {
            if(vis[u]==vis[v])
                flag=0;
        }
    }
}

int main()
{
    int n,m;
    cin >> n >> m;
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin >> a >> b;
        mp[a].pb(b);
        mp[b].pb(a);
    }
    memset(vis,-1,sizeof(vis));
    flag=1;
    dfs(1,0);
    if(!flag)
    {
        printf("%lld\n",1LL*n*(n-1)/2-m);
    }
    else
    {
        int cnt0=0,cnt1=0;
        for(int i=1;i<=n;i++)
        {
            if(vis[i])
                cnt1++;
            else
                cnt0++;
        }
        printf("%lld\n",1LL*cnt0*cnt1-m);
    }
    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <vector>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cmath>

using namespace std;

typedef complex<double> P;
int n;
class Circle{
public:
  P cp;
  double r;
};

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

const double INF=-1;
const int band=100;
int main(){
  int n;
  while(cin>>n&&n!=0){
    int xsortedIdxs[100001];
    int ysortedIdxs[100001];
    vector<Circle> cs;
    vector<pair<double,int> > xsorted;
    vector<pair<double,int> > ysorted;
    double x,y,r;
    for(int i = 0; i < n; i++){
      Circle c;
      cin>>r>>x>>y;
      c.r=r;
      c.cp=P(x,y);
      cs.push_back(c);
      xsorted.push_back(make_pair(x,i));
      ysorted.push_back(make_pair(y,i));
    }
    sort(xsorted.begin(),xsorted.end());
    sort(ysorted.begin(),ysorted.end());
    for(int i = 0; i < n; i++){
      xsortedIdxs[xsorted[i].second]=i;
      ysortedIdxs[ysorted[i].second]=i;
    }
    double minDist=INF;
    for(int i = 0; i < n; i++){
      // x,zÀW»ê¼êÉÂ¢ÄA
      // ©ªÌê©ç-10,+10ÌÆ±ëðTõ
      int xsidx=xsortedIdxs[i];
      int ysidx=ysortedIdxs[i];
      for(int j = xsidx; j < min(xsidx+band,n);j++){
	int idx=xsorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
      for(int j = xsidx; j >= max(0,xsidx-band); j--){
	int idx=xsorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
      for(int j = ysidx; j < min(ysidx+band,n);j++){
	int idx=ysorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
      for(int j = ysidx; j >= max(0,ysidx-band); j--){
	int idx=ysorted[j].second;
	if(i==idx)continue;
	double d=abs(cs[idx].cp-cs[i].cp)
	  -cs[idx].r-cs[i].r;
	if(EQ(minDist,INF)||minDist>d)
	  minDist=d;
      }
    }
    printf("%.8f\n",minDist);
    //cout<<minDist<<endl;
  }

  return 0;
}

Measured memory_bytes: 6600
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

ll dp[109][4][2]; // 桁、未満フラグ、0の個数
int a[109];

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

	string S; cin >> S;
	int K; cin >> K;
	int N = S.size();
	for (int i = 0; i < S.size(); i++) a[i] = S[i] - '0';

	dp[0][1][1] = a[0] - 1;
	dp[0][1][0] = 1;
	dp[0][0][1] = 1;
	dp[0][0][0] = 0;

	for (int i = 1; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			dp[i][j][1] = dp[i - 1][j][1];
			if (j > 0)dp[i][j][1] += dp[i - 1][j - 1][1] * 9;
			if (a[i] > 0) {
				dp[i][j][1] += dp[i - 1][j][0];
				if (j > 0) dp[i][j][1] += dp[i - 1][j - 1][0] * (a[i] - 1);
			}

			if (a[i] > 0) { if (j > 0) dp[i][j][0] = dp[i - 1][j - 1][0]; }
			else dp[i][j][0] = dp[i - 1][j][0];
		}
	}
	cout << dp[N - 1][K][1] + dp[N - 1][K][0] << endl;

	/*
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= K; j++) {
			cout << "("<<dp[i][j][1] << ","<< dp[i][j][0]<<")" << " ";
		}
		cout << endl;
	}
	*/

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

#define INF	(1 << 30)

#define MASK	((1LL << (4 * 9)) - 1)
#define BWB	(1LL << (4 * 10))

/* typedef */

typedef long long ll;
typedef vector<ll> vl;
typedef map<ll,int> mli;

/* global variables */

//## pos&mv
//##   x y z
//## c 0 1 2 a
//## a 3 4 5 b
//## b 6 7 8 c
//##   x y z

int nbrs[9][4] = {
  // R, L, U, D
  {1, 8, 6, 3},	// 0
  {2, 0, 7, 4}, // 1
  {3, 1, 8, 5}, // 2
  {4, 2, 0, 6}, // 3
  {5, 3, 1, 7}, // 4
  {6, 4, 2, 8}, // 5
  {7, 5, 3, 0}, // 6
  {8, 6, 4, 1}, // 7
  {0, 7, 5, 2}, // 8
};

mli dists;

struct g_dist {
  bool operator()(const ll& a, const ll& b) const {
    return dists[b] < dists[a];
  }
};

/* subroutines */

ll read() {
  int bpos = 0, pos = 0;
  ll flds = 0;

  for (int y = 0; y < 3; y++) {
    for (int x = 0; x < 3; x++) {
      int d;
      cin >> d;
      flds |= (ll)d << (pos * 4);
      if (d == 0) bpos = pos;
      pos++;
    }
  }

  return (flds | (ll)bpos << (9 * 4));
}

/* main */

int main() {
  int ch, cv;
  ll st, gl;
  
  for (;;) {
    cin >> ch >>  cv;
    if ((ch | cv) == 0) break;

    st = read();
    gl = read() | BWB;

    dists.clear();
    dists[st] = dists[gl] = 0;

    priority_queue<ll,vl,g_dist> q;
    q.push(st);
    q.push(gl);

    int min_cost = INF;
    int min_check = 10;
    
    while (! q.empty()) {
      ll u = q.top();
      q.pop();

      bool bwd = ((u & BWB) != 0);
      
      if ((! bwd && dists.find(u | BWB) != dists.end()) ||
	  (bwd && dists.find(u & ~BWB) != dists.end())) {
	int c = dists[u | BWB] + dists[u & ~BWB];
	if (min_cost > c) min_cost = c;
	if (--min_check <= 0) break;
      }

      int ud = dists[u];
      int upos = (u >> (9 * 4)) & 0xf;

      for (int i = 0; i < 4; i++) {
	int vpos = nbrs[upos][i];
	int nvd = ud + (i < 2 ? ch : cv);

	int k = (u >> (vpos * 4)) & 0xf;
	ll v =
	  (u & (MASK | BWB) & ~(0xfLL << (vpos * 4))) |
          ((ll)k << (upos * 4)) | ((ll)vpos << (4 * 9));

	if (dists.find(v) == dists.end()) {
	  dists[v] = nvd;
	  q.push(v);
	}
	else if (dists[v] > nvd) {
	  dists[v] = nvd;
	}
      }
    }

    cout << min_cost << endl;
  }

  return 0;
}

Measured memory_bytes: 3536
N, M = map(int, input().split())
ac = [False for _ in range(N)]
n_wa_list = [0 for _ in range(N)]
n_ac = 0
for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if not ac[p]:
        if s == 'WA':
            n_wa_list[p] += 1
        else:
            n_ac += 1
            ac[p] = True

n_wa = 0
for c, n in zip(ac, n_wa_list):
    if c:
        n_wa += n
print(n_ac, n_wa)


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

#define mk make_pair
#define pb push_back

typedef long long lld;
typedef pair<lld,lld> pr;
typedef priority_queue <lld> max_heap;
typedef priority_queue <lld, vector<lld>, greater<lld> > min_heap;
lld const mod = 1e9+7;

lld power(lld x, lld y)
{
    lld res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

lld power_mod(lld base, lld y)
{
    lld t = 1;
    while (y > 0)
    {

        if (y % 2 != 0)
            t = (t * base) % mod;
        base = (base * base) % mod;
        y /= 2;
    }
    return t % mod;
}

lld nCrModp(lld n, lld r, lld p)
{
    if (r > n - r)
        r = n - r;
    lld C[r + 1]={0};
    C[0] = 1;

    for (lld i = 1; i <= n; i++)
    {
      for (lld j = min(i, r); j > 0; j--)
      {
        C[j] = (C[j] + C[j - 1]) % p;

      }
    }
    return C[r];
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lld t;
  cin>>t;
  lld ac=0;
  lld wa=0;
  lld tle=0;
  lld re=0;
  while(t--)
  {
    string s;
    cin>>s;
    if(s=="AC")
      ac++;
    else if(s=="WA")
      wa++;
    else if(s=="TLE")
      tle++;
    else if(s=="RE")
      re++;
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;

}


Measured memory_bytes: 3652
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
string st;
long long p;
int main()
{
    cin>>st;
    for(int i=0;i<st.size();i++)
    {
	  if(st[i]=='C'){p=1;}
	  if(p==1&&st[i]=='F'){cout<<"Yes";return 0;}
    }
	cout<<"No";
    return 0;
}


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


int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  int x = s.size();
  int ask = 65;
  rep(i,x){
    char y = s.at(i);
    y -= ask;
    y+=n;
    y%=26;
    y+=ask;
    s.at(i) =y;

  }
  cout << s <<endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int[][] a = new int[n+1][2];
        for (int i = 1; i <= n; i++) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
        }
        int b = a[1][0];
        for (int i = 1; i <= n; i++) {
            a[i][0] -= b;
        }
        long[][][] dp = new long[n+1][n+1][301];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                for (int k = 0; k <= 300; k++) {
                    if(k < a[i][0]) dp[i][j][k] = dp[i-1][j][k];
                    else dp[i][j][k] = Math.max(dp[i-1][j-1][k-a[i][0]] + a[i][1], dp[i-1][j][k]);
                }
            }
        }
        long ans = 0L;
        for (int i = 1; i <= n; i++) {
            if(w < b*i) break;
            int r = Math.min(w - (b * i), 300);
            long t = 0L;
            for (int j = 0; j <= r; j++) {
                t = Math.max(t, dp[n][i][j]);
            }
            ans = Math.max(ans, t);
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 55892
#include <stdio.h>
#include <algorithm>


int main(){
	
	char S[111];
	int N;	scanf("%d", &N);
	
	scanf("%s", S);
	
	int adf = 0, cntd = 0, cnti = 0, adc = 0;
	
	for(int i = 0; i < N; ++i){
		if(S[i] == '('){
			cntd++;
		}else{
			if(cntd > 0)
				cntd--;
			else
				adf++;
		}
	}
	
	for(int i = N - 1; i >= 0; --i){
		if(S[i] == ')'){
			cnti++;
		}else{
			if(cnti > 0)
				cnti--;
			else
				adc++;
		}
	}
	
	for(int i = 0; i < adf; ++i)
		printf("(");
	
	printf("%s", S);
	
	for(int i = 0; i < adc; ++i)
		printf(")");
		
return 0;	
}




Measured memory_bytes: 128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
ab = [inpl() for _ in range(n)]
ab.sort(key=lambda x:x[1])
now = 0
for a,b in ab:
    now += a
    if now > b:
        print('No')
        break
else:
    print('Yes')
    

Measured memory_bytes: 108760
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();
        scanner.close();
        char[] sChar = s.toCharArray();
        char[] tChar = t.toCharArray();
 
        int sum = 0;
        for(int i = 0; i < 3; i++){
            if(sChar[i]==tChar[i]){
                sum++;
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

#define int long long
//#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 998244353;

bool check(int l, int r, string& s) {
    for (int i = l, j = r; i < j; i++, j--) {
        if (s[i] != s[j]) return false;
    }
    return true;
}

void solve() {
    string s;
    cin >> s;
    cout << (check(0, s.size() - 1, s) && check(0, (s.size() - 1) / 2 - 1, s) && check((s.size() + 3) / 2 - 1, s.size() - 1, s) ? "Yes" : "No");
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(12);
    srand(time(0));
    cout << fixed;
    solve();
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		sc.close();
		int ans = (a + b) * h;
		ans /= 2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21972
//2018-6-4
//miaowey
//
#include <bits/stdc++.h>
using namespace std;

#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (200000 + 5)

struct nodel{
	int o, v;
	bool operator <(const nodel &rhs)const{return v < rhs.v;}
};

struct noder{
	int o, v;
	bool operator <(const noder &rhs)const{return v > rhs.v;}
};

priority_queue<nodel> ql;
priority_queue<noder> qr;

int n, L[N], R[N];
bool use[N];

long long Work(int op){
	while(!ql.empty()) ql.pop(); while(!qr.empty()) qr.pop();
	For(i, 1, n) ql.push((nodel){i, L[i]}), qr.push((noder){i, R[i]}), use[i] = 0;

	long long ans = 0;
	int now = 0, lo, ro, lv, rv, ld, rd;
	
	For(i, 1, n){
		while(!ql.empty() && use[ql.top().o]) ql.pop();
		while(!qr.empty() && use[qr.top().o]) qr.pop();
		lv = rv = ld = rd = 0;

		if(!ql.empty()) lo = ql.top().o, lv = ql.top().v, ld = lv - now;
		if(!qr.empty()) ro = qr.top().o, rv = qr.top().v, rd = now - rv;
		
		if(ld <= 0 && rd <= 0) break;
		
		if(i == 1 && ld > 0 && rd > 0){
			if(op == 0) {ans += rd; use[ro] = true; now = rv;}
			else {ans += ld; use[lo] = true; now = lv;}
			continue;
		}

		if(rd > ld) {ans += rd; use[ro] = true; now = rv;}
		else {ans += ld; use[lo] = true; now = lv;}
	}

	ans += abs(now);
	return ans;
}

int main(){	
	scanf("%d", &n);
	For(i, 1, n) scanf("%d%d", &L[i], &R[i]);
	printf("%lld\n", max(Work(0), Work(1)));

	return 0;
}

Measured memory_bytes: 2924
INTEGER N
CHARACTER(100) S
CHARACTER(26)::A="abcdefghijklmnopqrstuvwxyz"
INTEGER B,P
INTEGER M,U
READ*,N,S
P=0
DO I=1, N-1
  B=0
  DO J=1,26
    M=SCAN(S,A(J:J))
    IF(M==0)CYCLE
    U=SCAN(S,A(J:J),.TRUE.)
    IF( M<=I .AND. I<U )B=B+1
  END DO
  P=MAX(P,B)
END DO
PRINT"(I0)",P
END

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    string s,t;cin >> s >> t;
    bool res = true;
    rep(i,s.size()){
        if(s[i]!=t[i]) res =false;
    }
    if(res ) cout << "Yes";
    else cout << "No";
    // cout << (res)?"Yes":"No" << endl;
}


Measured memory_bytes: 3628
A,B,C,X,Y = list(map(int, input().split()))
p = 0
while max(X,Y) > 0:
    if ((min(X, Y) >= 1) & (A+B > C*2)) | ((X >= 1) & (A > C*2)) | ((Y >= 1) & (B > C*2)):
        p += C * 2
        X -= 1
        Y -= 1
    elif (X >= 1) & (A < C*2):
        p += A*1
        X -= 1
    elif (Y >= 1) & (B < C*2):
        p += B*1
        Y -= 1
print(p)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
	string abcd;
	cin >> abcd;
	int a = abcd[0] - '0', b = abcd[1] - '0', c = abcd[2] - '0', d = abcd[3] - '0';
	if (a + b + c + d == 7) { cout << a << "+" << b << "+" << c << "+" << d << "=7"; return 0; }
	if (a + b + c - d == 7) { cout << a << "+" << b << "+" << c << "-" << d << "=7"; return 0; }
	if (a + b - c + d == 7) { cout << a << "+" << b << "-" << c << "+" << d << "=7"; return 0; }
	if (a + b - c - d == 7) { cout << a << "+" << b << "-" << c << "-" << d << "=7"; return 0; }
	if (a - b + c + d == 7) { cout << a << "-" << b << "+" << c << "+" << d << "=7"; return 0; }
	if (a - b + c - d == 7) { cout << a << "-" << b << "+" << c << "-" << d << "=7"; return 0; }
	if (a - b - c + d == 7) { cout << a << "-" << b << "-" << c << "+" << d << "=7"; return 0; }
	if (a - b - c - d == 7) { cout << a << "-" << b << "-" << c << "-" << d << "=7"; return 0; }
}

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



int main() {
	int n;
	int a[100];
	cin >> n;
	for (int i = n - 1; i > -1; i--) {
		cin >> a[i];
	}
	for (int j = 0; j < n - 1; j++) {
		cout << a[j] << " ";
	}

	cout << a[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  set<string> st;
  map<string, vector<pair<int, int> > > mp;
  REP(i, N){
    string S; int P; cin >> S >> P;
    st.insert(S);
    mp[S].push_back({P, i});    
  }
  while(!st.empty()){
    auto itr = st.begin();
    string cur = *itr;
    st.erase(cur);
    vector<pair<int, int> > V = mp[cur];
    sort(V.begin(), V.end(), greater<pair<int, int> >());
    for(auto i : V){
      cout << i.second+1 << endl;
    }
  }
}

Measured memory_bytes: 3696
import java.util.*;

class Restaurant {
	public int index;
	public String city;
	public int point;

	public Restaurant(int index, String city, int point) {
		this.index = index;
		this.city = city;
		this.point = point;
	}
}

class CityComparator implements Comparator<Restaurant> {
	@Override
	public int compare(Restaurant r1, Restaurant r2) {
		if (!r1.city.equals(r2.city)) {
			return r1.city.compareTo(r2.city);
		} else {
			return r1.point > r2.point ? -1 : 1;
		}
	}
}

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Restaurant> restaurants = new ArrayList<Restaurant>();
		for (int i = 0; i < N; i++) {
			restaurants.add(new Restaurant(i + 1, sc.next(), sc.nextInt()));
		}
		sc.close();

		// sort
		Collections.sort(restaurants, new CityComparator());

		restaurants.forEach(r -> {
			System.out.println(r.index);
		});
	}
}


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

void solve(long long N, std::vector<long long> L)
{
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < i; j++)
        {
            for (int k = 0; k < j; k++)
            {
                if (L[i] == L[j] || L[j] == L[k] || L[i] == L[k])
                    continue;
                long long mx = max(L[i], max(L[j], L[k]));
                long long sum = L[i] + L[j] + L[k];
                if (sum > mx * 2)
                {
                    // cout << i + 1 << ' ' << j + 1 << ' ' << k + 1 << endl;
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> L(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));
	rep(i,n){
		cin >> c[i];
		rep(j,m) cin >> a[i][j];
	}
	ll ans = INF;
	for(int bit = 0; bit < (1<<n); bit++){
		vector<int> t(m,0);
		ll cost = 0;
		rep(i,n){
			if(1&bit>>i){
				cost += c[i];
				rep(j,m) t[j] += a[i][j];
			}
		}
		bool ok = true;
		rep(i,m){
			if(t[i]<x) ok = false;
		}
		if(ok) chmin(ans, cost);
	}
	if(ans==INF) cout << -1;
	else cout << ans; 
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

long long factorial(long long i){ // 階乗
 if(i > 0)
   return i * factorial(i-1);
 else
   return 1;
}
//// 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;
}

//// a^(-1) mod
long long modinv(long long a, long long mod) {
 return modpow(a, mod-2, mod);
}

int main() {
	const ll MOD = 1000000000 + 7;

	ll N;
	cin >> N;
	string S; // len 2N
	cin >> S;
	string LR;

	char pre = 'L';
	ll restL = 1;
	ll ans = 1;
	if(S[0]=='W' || S[2*N-1]=='W') {
		cout << 0 << endl;
		return 0;
	}
	
	ll cntL = 1, cntR = 0;
	rep(i, 2*N-1) {
		if(S[i]==S[i+1]) {
			if(pre=='L') {
				ans *= restL;
				ans %= MOD;
				restL--;
				cntR++;
				pre = 'R';
			} else {
				restL++;
				cntL++;
				pre = 'L';
			}
		} else {
			if(pre=='L') {
				restL++;
				cntL++;
			} else {
				ans *= restL;
				ans %= MOD;
				restL--;
				cntR++;
			}
		}
	}	

	if(cntL==cntR) {
		for(int i=2; i<N+1; i++) {
			ans *= i;
			ans %= MOD;
		}
		cout << ans << endl;
	} else cout << 0 << endl;


	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int mi=1e8;
  for(int i=0;i<S.size()-2;i++){
    int X=stoi(S.substr(i,3));
    if(mi>abs(X-753)){
      mi=abs(X-753);
    }
  }
  cout << mi << endl;
  return 0;
}


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

#define MAXN 100001
#define ll long long
#define mod 1000000009

using namespace std;

int n;

string s[MAXN];
int t[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		cin >> s[i] >> t[i];
	}	
	string st;
	cin >> st;
	for (int i = 1; i <= n; i++) {
		if (st == s[i]) {
			int ans = 0;
			for (int j = i + 1; j <= n; j++) {
				ans += t[j];
			}
			cout << ans << endl;
			return 0;
		}
	}
	cout << 0 << endl;
	return 0;
}

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

int main(){
    long long n;
    long long temp;
    cin >> n;
    temp = n;
    int sum=0;

    while(temp){
        sum += temp % 10;
        temp /= 10;
    }

    if(n % sum == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <set>
 #include <iomanip>
using namespace std;


int main(){
	int a,b;
	cin >> a >>b;
	if(a >= 13)cout << b<<endl;
	else if(a >=6) cout << b/2 << endl;
	else cout << "0" << endl;
	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k;
int a[1000005];
ll f[3005][3005];
ll solve(int l,int r)
{
	if(f[l][r]!=-1) return f[l][r];
	int ty=((l+r)%2==n%2)?-1:1;
	//printf("l=%d r=%d ty=%d\n",l,r,ty);
	if(l==r) return f[l][r]=a[l]*ty;
	if(ty==1) return f[l][r]=max(solve(l+1,r)+a[l],solve(l,r-1)+a[r]);
	else return f[l][r]=min(solve(l+1,r)-a[l],solve(l,r-1)-a[r]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	memset(f,-1,sizeof(f));
	printf("%lld\n",solve(1,n));
	return 0;
}

Measured memory_bytes: 72064
def resolve():
    MOD = 10**9+7
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [[0]*(K+1) for _ in range(N+1)]
    # init 0個配る状態は1通り
    for i in range(N+1):
        dp[i][0] = 1

    for i in range(N):
        cum = [0]*(K+2)
        for j in range(K + 1):
            cum[j+1] = (cum[j] + dp[i][j]) % MOD
        for j in range(K+1):
            idx = max(0, j - A[i])
            dp[i+1][j] = cum[j+1] - cum[idx]
            dp[i + 1][j] = (dp[i+1][j]+MOD)%MOD

    print(dp[N][K])

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 213244
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        int place;
        double tSurf, tA;
        Scanner sc = new Scanner(System.in);
        place = sc.nextInt();
        tSurf = sc.nextDouble();
        tA = sc.nextDouble();
        double[] ts = new double[place];
        
        int result = 1;
        double min = 0;
        for(int i = 0; i < place; i++){
            ts[i] = tSurf - sc.nextInt() * 0.006;
            if(i == 0) {
                min = Math.abs(tA - ts[0]);
                continue;
            }
            if(Math.abs(tA - ts[i]) < min){
                min = Math.abs(tA - ts[i]);
                result = i + 1;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 26072
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[1010][1010];
vector<int> G[1000010];
int H[1000010];
int D[1000010];
uset<int> U;

signed main(){
	cin>>N;
	REP(i,N){
		REP(j,N-1){
			cin>>A[i][j];
			A[i][j]--;
		}
	}
	REP(i,N){
		REP(j,N-2){
			int s=min(i,A[i][j]);
			int t=max(i,A[i][j]);
			int z=1000*s+t;
			s=min(i,A[i][j+1]);
			t=max(i,A[i][j+1]);
			int z2=1000*s+t;
			G[z].push_back(z2);
			H[z2]++;
			U.insert(z);U.insert(z2);
		}
	}
	stack<int> st;
	for(int x:U){
		if(H[x]==0){
			st.push(x);
		}
	}
	DEB(st.size())END
	vector<int> G2;
	while(!st.empty()){
		int p=st.top();
		st.pop();
		G2.push_back(p);
		for(auto x:G[p]){
			H[x]--;
			if(H[x]==0){
				st.push(x);
			}
			D[x]=max(D[x],D[p]+1);
		}
	}
	if(G2.size()!=U.size()){
		cout<<-1<<endl;
		return 0;
	}
	int ans=0;
	for(int x:U){
		ans=max(ans,D[x]);
	}
	ans++;
	cout<<ans<<endl;
	return 0;
}


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

int main() {
	int n,k;
	cin >> n >> k;
	vector<vector<int>> b(2*k+1,vector<int>(2*k+1,0));
	for (int i = 0;i < n;++i) {
		int x,y;
		char c;
		cin >> x >> y >> c;
		if (c == 'B') b[x%(2*k)+1][y%(2*k)+1]++;
		else b[(x+k)%(2*k)+1][y%(2*k)+1]++;
	}
	for (int i = 0;i < 2*k;++i) {
		for (int j = 0;j < 2*k+1;++j) {
			b[i+1][j] += b[i][j];
		}
	}
	for (int i = 0;i < 2*k+1;++i) {
		for (int j = 0;j < 2*k;++j) {
			b[i][j+1] += b[i][j];
		}
	}
	
	int ans = 0,sum_b = 0;
	for (int i = 0;i < k;++i) {
		for (int j = 0;j < k;++j) {
			sum_b = b[2*k-i][2*k]+b[2*k][2*k-j]+2*b[2*k-i][k-j]+2*b[k-i][2*k-j]-b[2*k][k-j]-b[k-i][2*k]-2*b[2*k-i][2*k-j]-2*b[k-i][k-j];
			ans = max(ans,max(sum_b,n-sum_b));
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 16000
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int p[110][110];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int W, H, N;
    cin >> W >> H >> N;
    rep(i, W) rep(j, H) p[i][j] = 1;
    rep(i, N) {
        int x, y, a; cin >> x >> y >> a;
        x--; y--;
        if (a == 1) {
            REP(X, 0, x) {
                REP(Y, 0, H - 1) {
                    p[X][Y] = 0;
                }
            }
        }
        if (a == 2) {
            REP(X, x + 1, W - 1) {
                REP(Y, 0, H - 1) {
                    p[X][Y] = 0;
                }
            }
        }
        if (a == 3) {
            REP(X, 0, W - 1) {
                REP(Y, 0, y) {
                    p[X][Y] = 0;
                }
            }
        }
        if (a == 4) {
            REP(X, 0, W - 1) {
                REP(Y, y + 1, H - 1) {
                    p[X][Y] = 0;
                }
            }
        }
    }
    int ans = 0;
    rep(i, W) {
        rep(j, H) {
            ans += p[i][j];
            //cout << p[i][j];
        }
        //cout << endl;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int d[] = new int[k];
        for (int i = 0; i < k; i++) {
            d[i] = in.nextInt();
        }

        while (true) {
            if (include(n, d)) n++;
            else break;
        }

        System.out.println(n);
    }

    static boolean include(int n, int ng[]) {
        while (n > 0) {
            int t = n % 10;
            for (int i = 0; i < ng.length; i++) {
                if (t == ng[i]) return true;
            }
            n /= 10;
        }

        return false;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

int main(){
    vector<int> A(3);
    cin>>A[0]>>A[1]>>A[2];
    ll ans = INF;
    REP(i,3){
        REP(j,3){
                    ll tmp = 0;
            if (i==j) continue;
            tmp += abs(A[i]-A[j]);
            REP(k,3){
                if (k==i) continue;
                if (k==j) continue;
                tmp += abs(A[j]-A[k]);
                //cout<<i<<j<<k<<endl;
                //cout<<A[i]<<A[j]<<A[k]<<endl;
                ans = min(ans,tmp);
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)


bool hantei(int m, int x, vector<int> rikaido) {
    rep(i, m) {
        if (rikaido[i] < x) return false;
    }
    return true;
}

void search(int n, int m, int x, vector<int> kingaku, vector<vector<int>> book, int s, int i, int& min, int sum, vector<int> rikaido) {

    if (i == 0 || s > n) {
        if (sum < min && hantei(m, x, rikaido)) {
            min = sum;
        }
        return;
    }

    for (int j = s; j < n; j++) {
        vector<int> newRikaido(m);
        rep(a, m) newRikaido[a] = rikaido[a]+book[j][a];
        search(n, m, x, kingaku, book, j+1, i-1, min, sum+kingaku[j], newRikaido);
    }
}


int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> kingaku(n);
    vector<vector<int>> book(n, vector<int>(m));
    rep(i, n) {
        cin >> kingaku[i];
        rep(j, m) {
            cin >> book[i][j];
        }
    }

    int min = 2147483647;
    for (int s = 0; s < n; s++) {
        for (int i = 1; i <= n; i++) {
            vector<int> rikaido(m);
            rep(a, m) rikaido[a] += book[s][a];
            search(n, m, x, kingaku, book, s+1, i-1, min, kingaku[s], rikaido);
        }
    }

    if (min == 2147483647) cout << "-1" << endl;
    else cout << min << endl;

}

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

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

    while(n > 0){
        n -= 1;
        s.push_back('a' + n % 26);
        n /= 26;
    }
    reverse(s.begin(), s.end());
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3616