akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int dp[30][100000];

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    Yes(n % digsum(n) == 0);


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 	string a;
  	cin >> a;
  	cout << 700 + (a[0] == 'o'?100:0) + (a[1] == 'o'?100:0) + (a[2] == 'o'?100:0) << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[4]={0,1,0,-1},mdy[4]={-1,0,1,0};


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

struct edge{ll from,to,cost;};
ll n;
ll m;
ll a[2010],b[2010],c[2010];
vector<Pi> t[1010];
vector<ll> s[1010];
edge es[2010];
ll route[1010];
ll dis[1010];

bool find_positive_loop(){
	memset(dis,0,sizeof(dis));
	for(ll i=0;i<n;i++){
		for(ll j=0;j<m;j++){
			edge e=es[j];
			if(route[e.from]==0||route[e.to]==0)continue;
			if(dis[e.to]<dis[e.from]+e.cost){
				dis[e.to]=dis[e.from]+e.cost;
				if(i==n-1){
					//cout<<n-1<<endl;
					//cout<<j<<endl;
					return true;
				}
			}
		}
		//REP(i,n)cout<<dis[i]<<endl;
	}
	return false;
}

void longest_path(ll s){
	for(ll i=0;i<n;i++)dis[i]=-1e12;
	dis[s]=0;
	while(true){
		bool update=false;
		for(ll i=0;i<m;i++){
			edge e=es[i];
			if(route[e.from]==0||route[e.to]==0)continue;
			if(dis[e.from]!=-1e8&&dis[e.to]<dis[e.from]+e.cost){
				dis[e.to]=dis[e.from]+e.cost;
				update=true;
			}
		}
		if(!update)break;
	}
}

int main(){
	cin>>n>>m;
	REP(i,m){
		cin>>a[i]>>b[i]>>c[i];
		a[i]--,b[i]--;
		t[a[i]].push_back(Pi(b[i],c[i]));
		s[b[i]].push_back(a[i]);
		es[i]={a[i],b[i],c[i]};
	}
	REP(i,1010)route[i]=0;
	route[n-1]=1;
	queue<ll> q;
	q.push(n-1);
	while(q.size()){
		ll t1=q.front();q.pop();
		for(ll i=0;i<s[t1].size();i++){
			if(route[s[t1][i]])continue;
			route[s[t1][i]]=1;
			q.push(s[t1][i]);
		}
	}
	if(find_positive_loop()){
		cout<<"inf"<<endl;
		return 0;
	}
	longest_path(0);
	cout<<dis[n-1]<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int sum = 0;
	int sque = 0;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
		sque += (a[i] * a[i]);
	}

	printf("%d", (sum * sum - sque) / 2);



	return 0;
}


Measured memory_bytes: 256
<?php
$input_line = trim(fgets(STDIN));
$input_line = (int)$input_line;
$sum = 0;
for ($i = 0; $i <= $input_line; $i++) {
  if ($i % 3 != 0 && $i % 5 != 0){
    $sum += $i;
  }
}
echo $sum;
?>

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

constexpr int INF = 1145141919;

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

    long long H, W;
    std::cin >> H >> W;

    if(H==1){
        std::cout << 1;
    }else if(W==1){
        std::cout << 1;
    }else if( H%2==0 || W%2==0 ){
        long long n = H*W/2;
        std::cout << n;
    }else{
        long long n = (H+1)*W/2 - (long long)W/2.0 + 1;
        std::cout << n;
    }

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<int> ans(26, 100);
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		vector<int> cnts(26);
		for (char c : s) cnts[c-'a']++;
		for (int v = 0; v < 26; v++) ans[v] = min(ans[v], cnts[v]);
	}
	for (int v = 0; v < 26; v++) {
		while (ans[v] --> 0) cout << char(v+'a');
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 100005;

int n, k, tab[2][N], a, akt, prevv, sum, i, j;

int main() {
scanf("%d %d", &n, &k);
tab[0][0] = 1;
for (i=1;i<=n;i++) {
	scanf("%d", &a);
	akt = i % 2;
	prevv = 1 - akt;
	sum = 0;
	for (j=0;j<=k;j++) {
		sum = (sum + tab[prevv][j]) % MOD;
		if (j - a > 0) sum = (sum - tab[prevv][j - a - 1] + MOD) % MOD;
		tab[akt][j] = sum;
	}
}
printf("%d\n", tab[akt][k]);
return 0;
}

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

#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)

#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FFE(i,L,R) for (int i = L; i >= R; i--)

#define wez(n) int (n); cin >> n
#define wez2(n,m) int (n),(m); cin >> n >> m
#define wez3(n,m,k) int (n),(m),(k); cin >> n >> m >> k

#define whileZ int T; cin >> T; while(T--)

#define ALL(c) (c).begin(),(c).end()
#define ll long long 
#define ull unsigned long long
#define ld long double

#define fi first
#define se second

// for debug
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) if(a.size()) printA(a,0,a.size()-1)

#define pb push_back
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> ii;
//  priority_queue <int, vector<int>, greater<int> > pq; // min heap

string s,t;
int best(int x) {
    int n = t.size();
    int cnt = 0;
    for (int i=0; i<n; i++)
        cnt += (s[i+x]!=t[i]);
    return cnt;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> s >> t;

    int n = s.size();
    int m = t.size();

    int ans = m;
    for (int i=0; i<=n-m; i++) 
        ans = min(ans, best(i));

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
//#define A abs
#define M min
using namespace std;
//int n,m;
/*signed main()
{
	scanf("%d%d",&n,&m);
	((!(n+m))?(putchar(49)):(printf("%d",((A(n-m))+((((n>0)&&(m<0))||((n<0)&&(m>0)))?(1):((((n>0)&&(m>0))?(0):(((n<m)?(0):(2))))))))));
	return putchar(10),0;
}*/




long long n,m;
signed main()
{
	scanf("%lld%lld",&n,&m);long long ans(1LL<<60);
	if(m>=n){ans=(M(ans,(m-n)));}
	if(-m>=n){ans=(M(ans,(-m-n+1)));}
	if(m>=-n){ans=(M(ans,(m+n+1)));}
	if(-m>=-n){ans=(M(ans,(-m+n+2)));}
	printf("%lld",ans);
	return putchar(10),0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
struct Res{
    string name;
    int point;
    int number;
};
int comp(Res G,Res H){
    if(G.name<H.name) return 1;
    if(G.name>H.name) return 0;
    return G.point>H.point;
}
Res A[101];
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>A[i].name>>A[i].point,A[i].number=i+1;
    sort(A,A+n,comp);
    rep(i,n) cout<<A[i].number<<endl;
}

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

int main(){
  int n, m, q;
  cin >> n >> m >> q;
  vector<int> a(q);
  vector<int> b(q);
  vector<int> c(q);
  vector<int> d(q);
  vector<int> e(0);
  for(int i = 0; i < q; i++){
    cin >> a.at(i);
    a.at(i) -= 1;
    cin >> b.at(i);
    b.at(i) -= 1;
    cin >> c.at(i);
    cin >> d.at(i);
  }
  for(int i = 1; i < m+1; i++){
    for(int j = i; j < m+1; j++){
      for(int k = j; k < m+1; k++){
        for(int l = k; l < m+1; l++){
          for(int o = l; o < m+1; o++){
            for(int p = o; p < m+1; p++){
              for(int r = p; r < m+1; r++){
                for(int s = r; s < m+1; s++){
                  for(int t = s; t < m+1; t++){
                    for(int u = t; u < m+1; u++){
                      vector<int> A(10);
                      A ={i, j, k, l, o, p, r, s, t, u};
                      int count = 0;
                      for(int v = 0; v < q; v++){
                        if(A.at(b.at(v)) - A.at(a.at(v)) == c.at(v)){
                          count += d.at(v);
                        }
                        e.push_back(count);                     
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  sort(e.begin(), e.end());
  reverse(e.begin(), e.end());
  cout << e.at(0);
  return 0;
}

Measured memory_bytes: 36256
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N, R;
  cin >> N >> R;

  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a_min = [0] * (n + 1)
a_min[n] = a[n]
for i in range(n - 1, -1, -1):
    a_min[i] = a[i] + a_min[i + 1]

b = [1]
for i in range(n):
    tmp = b[i] - a[i]
    b.append(min(tmp * 2, a_min[i + 1]))
    if tmp < 1 or tmp * 2 < a[i + 1]:
        print(-1)
        break
else:
    if n == 0:
        ans = 1 if a[0] == 1 else -1
        print(ans)
    else:
        print(sum(b))


Measured memory_bytes: 22376
#include<stdio.h>
#include<math.h>

int main(void){
  double a,b,PI=acos(-1),S,L,h;
  int C;
  scanf("%lf %lf %d",&a,&b,&C);
  S=(1.0/2.0)*a*b*sin((C*PI)/180);
  L=a+b+sqrt(a*a+b*b-2*a*b*cos((C*PI)/180));
  h=b*sin((C*PI)/180);
  printf("%lf\n%lf\n%lf\n",S,L,h);
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int MAXN=9e5+1e1,Mod=1e9+7,Tp=9e5;

int fac[MAXN],inv[MAXN],p[MAXN],f[MAXN];
int n,m,k,ans1=0,ans2=0;

int Qpow(int A,int B)
{
	int res=1;
	while(B>0)
	{
		if(B&1) (res*=A)%=Mod;
		(A*=A)%=Mod,B>>=1;
	}
	return res;
}

int C(int A,int B)
{
	if(A<0 || B<0 || A<B) return 0;
	else return fac[A]*inv[B]%Mod*inv[A-B]%Mod;
}

signed main(void)
{
	scanf("%lld%lld%lld",&n,&m,&k);
	fac[0]=inv[0]=p[0]=f[0]=1;
	for(int i=1;i<=Tp;i++) fac[i]=fac[i-1]*i%Mod;
	inv[Tp]=Qpow(fac[Tp],Mod-2);
	for(int i=Tp;i;i--) inv[i-1]=inv[i]*i%Mod;
	for(int i=1;i<=Tp;i++) p[i]=p[i-1]*3%Mod;
	for(int i=1;i<=Tp;i++) f[i]=(f[i-1]*2%Mod-C(i-1,m)-C(i-1,i-n)+Mod*2)%Mod;
	for(int i=0;i<n+m;i++) (ans1+=C(i+k,i)*p[n+m-i-1]%Mod*f[i]%Mod)%=Mod;
	for(int i=1;i<=Tp;i++) f[i]=(f[i-1]*2%Mod-C(i-1,k)-C(i-1,i-n)+Mod*2)%Mod;
	for(int i=0;i<n+k;i++) (ans2+=C(i+m,i)*p[n+k-i-1]%Mod*f[i]%Mod)%=Mod;
	printf("%lld\n",(p[n+m+k]-ans1-ans2+Mod*2)%Mod);
	return 0;
}
//300000 300000 300000
//415274335

Measured memory_bytes: 31780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == -1) break;

                double x = 1.0, y = 0.0, rd = Math.PI;

                for (int i = 1; i < n; i++)
                {
                    rd -= Math.PI / 2;
                    x += Math.Cos(rd);
                    y += Math.Sin(rd);
                    rd = Math.Atan2(y, x) - Math.PI;
                }
                sb.AppendLine(x.ToString());
                sb.AppendLine(y.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9528
n = int(input())
s = []
for _ in range(n):
    s.append(input())

sBA = [ss for ss in s if ss[0] == 'B' and ss[-1] == 'A']
sXA = [ss for ss in s if ss[0] != 'B' and ss[-1] == 'A']
sBX = [ss for ss in s if ss[0] == 'B' and ss[-1] != 'A']
sXX = [ss for ss in s if ss[0] != 'B' and ss[-1] != 'A']

ans = sXX
if sXA:
    ans.append(sXA.pop())
ans.extend(sBA)
while sXA or sBX:
    if sBX:
        ans.append(sBX.pop())
    if sXA:
        ans.append(sXA.pop())

#print(ans)

ans = ''.join(ans)

nans = 0
for i in range(len(ans) - 1):
    if ans[i] == 'A' and ans[i+1] == 'B':
        nans += 1

print(nans)

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

int main() {
  int n;
  int ans = 0;

  cin >> n;

  map<int, int> m;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m[a]) {
      ans--;
      m[a] = 0;
    } else {
      ans++;
      m[a] = 1;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int h,w,k;
vector<int> board[35];
void check(){
    rep(i,h){
        rep(j,w) cout<<board[j][i];
        cout<<endl;
    }
}
int search(){
    int ret=0;
    rep(i,h){
        int pre=-1,cnt=0;
        rep(j,w){
            if(board[j][i]!=pre){
                if(pre!=-1&&cnt>=k){
                    ret+=pre*cnt;
                    rep(d,cnt){
                        board[j-1-d][i]=0;
                    }
                }
                cnt=1,pre=board[j][i];
            }else{
                cnt++;
            }
        }
        if(pre!=-1&&cnt>=k){
            ret+=pre*cnt;
            rep(d,cnt){
                board[w-1-d][i]=0;
            }
        }
    }
    return ret;
}
void del(){
    for(int i=h-1;i>=0;i--)rep(j,w){
        if(board[j][i]==0){
            board[j].erase(board[j].begin()+i);
            board[j].push_back(-1);
        }
    }
}
int main(){
    cin>>h>>w>>k;
    rep(i,h)rep(j,w){
        char c; cin>>c;
        board[j].push_back(c-'0');
    }
    rep(i,w) reverse(all(board[i]));
    // check();
    long long ans=0;
    rep(i,h)rep(j,w){
        vector<int> save[35]=board;
        board[j].erase(board[j].begin()+i);
        board[j].push_back(-1);
        // if(i==0&&j==2)check();
        long long cnt=0,tmp=0;
        while(1){
            int x=search();
            del();
            if(x>0){
                tmp+=pow(2,cnt)*x;
                cnt++;
            }
            else break;
        }
        // cout<<tmp<<endl;
        ans=max(ans,tmp);
        // check(); cout<<endl;
        rep(i,h)rep(j,w) board[j][i]=save[j][i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int a = 0, x, c = 1, N, K;
  cin >> N >> K;
  for (int j = 0; j < N; j++){
    cin >> x;
    if (x < abs(K - x)){
      a += 2 * x;
    }
    else {
      a += 2 * abs(K - x);
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using TP = tuple<ll, int,int,int>;
using T2 = tuple<int,int,int>;
const int MX = 1005;
int x, y ,z, k, ai, bi, ci;
ll a[MX], b[MX], c[MX], sc;
TP tp;
priority_queue<TP> qu;
map<T2, bool> mp;
int main(){
	scanf("%d%d%d%d", &x, &y, &z, &k);
	rep(i,x) scanf("%lld", a+i); sort(a, a+x, greater<ll>());
	rep(i,y) scanf("%lld", b+i); sort(b, b+y, greater<ll>());
	rep(i,z) scanf("%lld", c+i); sort(c, c+z, greater<ll>());
	qu.push(TP(a[0]+b[0]+c[0],0,0,0));
	rep(i,k){
		tie(sc, ai, bi, ci) = qu.top(); qu.pop();
		printf("%lld\n", sc);
		if(ai+1 < x && !mp[T2(ai+1, bi, ci)]){
			mp[T2(ai+1, bi, ci)] = true;
			qu.push(TP(a[ai+1]+b[bi]+c[ci],ai+1,bi,ci));
		}
		if(bi+1 < y && !mp[T2(ai, bi+1, ci)]){
			mp[T2(ai, bi+1, ci)] = true;
			qu.push(TP(a[ai]+b[bi+1]+c[ci],ai,bi+1,ci));
		}
		if(ci+1 < z && !mp[T2(ai, bi, ci+1)]){
			mp[T2(ai, bi, ci+1)] = true;
			qu.push(TP(a[ai]+b[bi]+c[ci+1],ai,bi,ci+1));
		}
	}
}

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

typedef long long ll;

int main()
{
	

	set<int> s;

	int a, b, c;
	cin >> a >> b >> c;

	s.insert(a);
	s.insert(b);
	s.insert(c);

	cout << s.size() << "\n";

}

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

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


Measured memory_bytes: 3660
N = int(input())
arr = list(map(int, input().split()))
dp = [0,0,0]
ans = 1
mod = 1000000007

for i in range(N):
  cnt = dp.count(arr[i])
  for j in range(3):
    if dp[j]==arr[i]:
      dp[j] = arr[i]+1
      break  
  ans *= cnt
print(ans%mod)

Measured memory_bytes: 14020
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n - 1); i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using priority_queuel = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-9;
ll mod = static_cast<ll>(1e9 + 7);
template <class T>
constexpr int sz(const T &a) { return (int)a.size(); }
template <class T>
constexpr T pow2(const T a) { return a * a; }
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class A, int N, class T>
void fillArray(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

int n;
pair<ll, int> a[2005];
ll dp[2005][2005];
void solve() {
    cin >> n;
    rep(i, n) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(a, a + n, greater<>());
    rep(i, n) {
        rep(l, i + 1) {
            auto r = i - l;
            maxs(dp[l + 1][r], dp[l][r] + a[i].first * abs(a[i].second - l));
            maxs(dp[l][r + 1], dp[l][r] + a[i].first * abs(a[i].second - (n - 1 - r)));
        }
    }

    ll ans = 0;
    rep(i, n + 1) maxs(ans, dp[i][n - i]);
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 26332
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
#define FI first
#define SE second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))

int N;
vector<int> a;

constexpr int INF = 10000000;

bool is_eq_greater(int val)
{
    {
        bool flg = true;
        REP(i, N) if (a[i * 2] < val) flg = false;
        if (flg) return true;
    }
    if (a[N - 1] < val and a[N] < val) return false;
    if (a[N - 1] < val and a[N - 2] < val) return false;

    int r2 = -1, l2 = -1, r1 = N - 1, l1 = N - 1;
    REP(k, N - 1)
    {
        if (a[N - 1 + k] < val and  a[N - 1 + k + 1]  < val) break;
        r1 = N - 1 + k;
        if (a[N - 1 + k] >= val and a[N - 1 + k + 1] >= val) { r2 = N - 1 + k + 1; break; }
    }
    REP(k, N - 1)
    {
        if (a[N - 1 - k] < val and  a[N - 1 - k - 1]  < val) break;
        l1 = N - 1 - k;
        if (a[N - 1 - k] >= val and a[N - 1 - k - 1] >= val) { l2 = N - 1 - k - 1; break; }
    }
    if (l2 >= 0 and r2 >= 0) return true;
    if (l2 < 0 and r2 >= 0 and (l1 + r1) / 2 <= N - 1) return true;
    if (r2 < 0 and l2 >= 0 and (l1 + r1) / 2 >= N - 1) return true;
    return false;
}


int main()
{
    cin >> N;
    a.resize(2 * N - 1);
    cin >> a;

    int L = 1, R = N * 2 + 1; // [L, R)
    while (R - L > 1)
    {
        int C = (L + R) / 2;
        (is_eq_greater(C) ? L : R) = C;
    }
    cout << L << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
 string S;
  cin>>S;
  int N=S.size();
  vector<int> A(N);
  for(int i=0;i<N;i++){
  int sum=0;
    for(int j=i;j<N;j++){
    char c=S.at(j);
      if(c=='A'||c=='C'||c=='G'||c=='T')
        sum++;
      else break;
    
    } A.at(i)=sum;
  
   }int Max=A.at(0);
  for(int i=1;i<N;i++)
    if(Max<=A.at(i))
       Max=A.at(i);
       
       cout<<Max<<endl;
      
      
      
      
      
      
      
      
      
  
  return 0;
}

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

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> A;
	A.resize(N);
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ans += (long long)A[i];
	}
	int Q;
	cin >> Q;
	vector<int> B, C;
	B.resize(Q);
	C.resize(Q);
	for (int i = 0; i < Q; i++)
		cin >> B[i] >> C[i];

	map<int, int> m;
	for (int i = 0; i < A.size(); i++)
		m[A[i]]++;

	for (int i = 0; i < B.size(); i++) {
		auto itr = m.find(B[i]);
		// B[i]が存在すれば
		if (itr != m.end()) {
			int add = itr->second;
			m[C[i]] += add;
			m.erase(itr);

			ans += (long long)((C[i] - B[i]) * add);
		}

		cout << ans << endl;
	}

	return 0;
}

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

namespace ConsoleApp5
{
    class Program
    {

        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] line = S.Split(' ');
            long N = long.Parse(line[0]);
            long K = long.Parse(line[1]);
            
            if(N % K < Math.Abs(K - (N % K)))
            {
                Console.WriteLine(N % K);
            }
            else
            {
                Console.WriteLine(Math.Abs(K - N % K));
            }


        }
    }
}

Measured memory_bytes: 13140
import java.io.*;
import java.util.StringTokenizer;


public class Main {

    public static void main(String[] args) throws IOException {

        Scanner s = new Scanner(System.in);
        String word = s.next();
        int max=0,cnt=0;
        for(int i=0;i<word.length();i++){
            if(word.charAt(i)=='S'){
                max = Math.max(max,cnt);
                cnt=0;
            }
            else cnt++;
        }
        max = Math.max(max,cnt);

        System.out.println(max);

    }

}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

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

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

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

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

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


}

Measured memory_bytes: 25380
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            solve(sc);
        }
    }

    public static void solve(Scanner sc) {
        int n = sc.nextInt();
        int ans = 1;
        for (int i = 0; i <= 100; i++) {
            if (ans > n) {
                System.out.println(ans / 2);
                return;
            }
            ans *= 2;
        }
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

string s, t;

int dp[3010][3010];

string construct(int i, int j) {
    if (i == 0 || j == 0) return "";
    if (s[i-1] == t[j-1]) return construct(i-1, j-1) + s[i-1];
    if (dp[i][j] == dp[i][j-1]) return construct(i, j-1);
    return construct(i-1, j);
}

string solve() {
    int len_s = (int)s.size();
    int len_t = (int)t.size();

    for (int i = 1; i <= len_s; i++) {
        for (int j = 1; j <= len_t; j++) {
            if (s[i-1] == t[j-1]) {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    return construct(len_s, len_t);
}

void input() {
    cin >> s >> t;
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 35968
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	final long MOD = (long) (1e9 + 7);
	long[] inv = new long[100002];
	{
		inv[0] = inv[1] = 1;
		for (int i = 2; i < inv.length; ++i) {
			inv[i] = MOD - inv[(int) MOD % i] * (MOD / i) % MOD;
		}
	}

	void run() {
		PrintWriter pw = new PrintWriter(System.out);
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for (int i = 0; i < N; ++i) {
			A[i] = sc.nextLong();
		}
		long sum = 0;
		for (int i = 1; i <= N; ++i) {
			sum = (sum + inv[i]) % MOD;
		}
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			ans = (ans + sum * A[i] % MOD) % MOD;
			sum = (sum - inv[N - i] + inv[i + 2] + MOD) % MOD;
		}
		for (int i = 1; i <= N; ++i)
			ans = ans * i % MOD;
		System.out.println(ans);

	}

	long pow(long a, long n) {
		long ret = 1;
		for (; n > 0; n >>= 1, a = a * a % MOD) {
			if (n % 2 == 1) {
				ret = ret * a % MOD;
			}
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		public boolean hasNext() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}

		public int nextInt() {
			long nl = nextLong();
			if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
				throw new NumberFormatException();
			return (int) nl;
		}

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

}


Measured memory_bytes: 62904
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a;
	string s;
	cin>>a>>s;

	if(a>=3200){
		cout<<s;
	}
	else{
		cout<<"red";
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define int long long

int N, Q;
vector<int> G[200200];
int cnt[200200];

void dfs(int v, int pa) {
    int res = cnt[v];
    for(auto u : G[v]) {
        if(u == pa) continue;
        cnt[u] += res;
        dfs(u, v);
    }
}

void solve() {
    cin >> N >> Q;
    rep(i, N - 1) {
        int a, b; cin >> a >> b; a --; b --;
        G[a].pb(b); G[b].pb(a);
    }
    rep(i, N) {
        cnt[i] = 0;
    }
    rep(i, Q) {
        int p, x; cin >> p >> x;
        p --; cnt[p] += x;
    }
    dfs(0, -1);
    rep(i, N) {
        cout << cnt[i] << " ";
    }
    cout << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}


Measured memory_bytes: 24320
/*
 * 	Roses are red
 * 		Violets are blue
 * 			I cried
 * 				And so did you
 */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=2e18;
const int infi=1e9;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

int a[1005];
void solve() {
	int n;
	cin>>n;
	bool ne=1;
	fr(i,1,n) {
		cin>>a[i];
		if(a[i]>0)
			ne=0;
	}
	if(ne) {
		int mi=1;
		fr(i,1,n)
			if(a[mi]<a[i])
				mi=i;
		cout<<a[mi]<<endl<<n-1<<endl;
		int last=n;
		fr(i,1,mi-1) {
			cout<<1<<endl;
			last--;
		}
		for(int i=mi+1; i<=n; i++) {
			cout<<last<<endl;
			last--;
		}
		return;
	}
	int esum=0,osum=0,par=0;
	for(int i=2; i<=n; i+=2)
		esum+=max(0LL,a[i]);
	for(int i=1; i<=n; i+=2)
		osum+=max(0LL,a[i]);
	if(osum>esum)
		par=1;
	cout<<max(osum,esum)<<endl;
	vi ans;
	while(n%2!=par||a[n]<=0) {
		ans.pb(n);
		n--;
	}
	a[0]=infi;
	while(n!=par) {
		trace(n);
		if(a[n-2]<=0) {
			ans.pb(n-2);
			if(n==3) {
				ans.pb(1);
			}
			n-=2;
		} else {
			ans.pb(n-1);
			n-=2;
		}
	}
	cout<<sz(ans)<<endl;
	trav(i,ans)
		cout<<i<<endl;
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int w, a, b;
  cin >> w >> a >> b;
  if(b < a) swap(a,b);
  int ans = max(0,b - (a+w));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3552
import time
import random


class Problem:

    def __init__(self, D, s, c):
        self.last_days = [0] * 26
        self.D = D
        self.s = s
        self.c = c
        self.answer = [0] * self.D
        self.best_answer = [0] * self.D

    def scoring(self, day, ind):
        day_score = self.s[day][ind]
        minus_score = 0
        for i in range(26):
            if i != ind:
                minus_score += self.c[i] * (day + 1 - self.last_days[i])
        day_score -= minus_score
        return day_score

    def get_all_scores(self, day):
        """全ての選択肢のscoreを返す"""
        minus_score = 0
        all_scores = [0] * 26
        for i in range(26):
            if i == 0:
                for j in range(1, 26):
                    minus_score += self.c[j] * (day + 1 - self.last_days[j])
                all_scores[0] = self.s[day][0] - minus_score

            else:
                minus_score += self.c[i - 1] * (day + 1 - self.last_days[i - 1])
                minus_score -= self.c[i] * (day + 1 - self.last_days[i])
                all_scores[i] = self.s[day][i] - minus_score
        return all_scores

    def _strategy_greedy(self, day):
        all_scores = self.get_all_scores(day)

        ind = random.randint(0, 25)
        score = self.scoring(day, ind)
        return score, ind

    def solve(self):
        self.init()

        sum_score = 0
        for i in range(self.D):
            score, ind = self._strategy_greedy(i)
            self.last_days[ind] = i + 1
            self.answer[i] = ind
            sum_score += score
        return sum_score, self.answer

    def _strategy_perturbation(self):
        # ランダムに１日を取り出し、一番その日の期待コストが大きくなるよう変化させる
        # 貪欲法に摂動を加えてみる
        day = random.randint(0, 3)

        # scores = [self.scoring()]

        random.randint(0, 3)

    def solve_greed(self):
        self.init()

    def init(self):
        self.last_days = [0] * 26
        self.answer = [0] * self.D


def main():
    time_start = time.time()
    DO_TIME = 2 * 0.90
    D = int(input())
    c = list(map(int, input().split()))
    s = []

    for _ in range(D):
        s.append(list(map(int, input().split())))

    max_score = 0

    problem = Problem(D, s, c)
    ite = 0
    while time.time() - time_start < DO_TIME:
        ite += 1
        score, answer = problem.solve()

        if score > max_score:
            # print("hit")
            # print(max_score)
            max_score = score
            problem.best_answer = answer

    for i in range(D):
        # problem.best_answer[i] += 1
        # print(problem.best_answer[i])
        print(1)
    # print(ite)
    # print(max_answer)
    # print(max_score)
    # print(problem.get_all_scores(1))


main()


Measured memory_bytes: 9768
a,b=map(int, input().split())
#print(a,b)
# list(map(int, input().split()))
alist=list(map(int, input().split()))
#print(alist)

ans=0
for i in alist:
  ans+=i
#print(ans)
if ans>a:
  print(-1)
else:
  print(a-ans)

Measured memory_bytes: 10052
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <cstring>
#include <string>
#include <sstream>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()

using namespace std;

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

vector<int> in(10);
string res;

void dfs(int, int, int);

int main(void){
    int n; cin >> n;
    while(n --){
        res = "NO";
        rep(i, 10) cin >> in[i];

        dfs(0, 0, 0);
        cout << res << endl;
    }

    return 0;
}

void dfs(int left, int right, int cur){
    if(cur == in.size()) res = "YES";
    if(res == "YES") return;

    if(left < in[cur]) dfs(in[cur], right, cur + 1);
    if(right < in[cur]) dfs(left, in[cur], cur + 1);
}

Measured memory_bytes: 1200
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define REP(i,m,n) for(i=(m);i<((int)(n));i++)
#define rep(i,n) REP(i,0,n)
#define INFTY (1<<21)
#define LLINFTY (1LL<<53)
typedef long long ll;
typedef unsigned long long ull;
int n,a[20],res;
int s1[111111],s2[111111],s3[111111];
int ab(int n){return n<0?-n:n;}
inline int min(int a,int b)
{
  return a<b?a:b;
}
void solve()
{
  int x,y,c; x=y=c=0;
  int sp=0;
  s1[sp]=s2[sp]=s3[sp]=0; sp++;
  while(sp){
    sp--;
    x=s1[sp];
    y=s2[sp];
    c=s3[sp];
    if(c==n){
      res=min(res,ab(x-y));
      continue;
    }
    s1[sp]=x+a[c];
    s2[sp]=y;
    s3[sp]=c+1;
    sp++;
    s1[sp]=x;
    s2[sp]=y+a[c];
    s3[sp]=c+1;
    sp++;
  }
}
int main(void)
{
  int i;
  for(;;){
    scanf("%d",&n); if(!n)break;
    rep(i,n) scanf("%d",a+i);
    res=INFTY;
    solve();
    printf("%d\n",res);
  }
  return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;

int main() {

    int n;
    cin >> n;

    vector<vector<ll>> vecs = vector<vector<ll>>(n, vector<ll>(3));

    rep(i, n) {
        ll x, y;
        ll h;
        cin >> x >> y >> h;

        vecs[i][0] = x;
        vecs[i][1] = y;
        vecs[i][2] = h;

    }

    for (ll x = 0; x <= 100; x++) {
        for (ll y = 0; y <= 100; y++) {

            if (x == 100 && y == 100) {
                cout << ' ';
            }

            ll check = [&] {
                ll before = INF;
                ll border = INF;
                for (ll i = 0; i < n; i++) {
                    ll vx = vecs[i][0];
                    ll vy = vecs[i][1];
                    ll vh = vecs[i][2];
                    if (vh == 0) {
                        ll diff = abs(vx - x) + abs(vy - y);
                        // 頂点がx , yだったとすると、vx, vz地点の高さはph のはず
                        ll ph = diff + vh;
                        border = min(border, ph);
                    }
                }

                for (ll i = 0; i < n; i++) {
                    ll vx = vecs[i][0];
                    ll vy = vecs[i][1];
                    ll vh = vecs[i][2];

                    ll diff = abs(vx - x) + abs(vy - y);
                    // 頂点がx , yだったとすると、vx, vz地点の高さはph のはず
                    ll ph = diff + vh;
                    if (vh == 0) {
                        continue;
                    }

                    if (ph > border) {
                        return -1ll;
                    }

                    if (before == INF) {
                        before = ph;
                    } else {
                        if (before != ph) {
                            return -1ll;
                        }
                    }
                }
                return before;
            }();

            if (check != -1) {
                cout << x << ' ' << y << ' ' << check << endl;
                return 0;
            }
        }
    }

}

//55 80 79

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

int main(){
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    if(A >= K){
        cout << K << endl;
    }
    else if(A + B >= K){
        cout << A << endl;
    }
    else{
        cout << A - (K - A - B) << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
def main():
    import sys
    input = sys.stdin.readline
    from bisect import bisect_left, bisect_right
    sys.setrecursionlimit(10**9)

    N, M = map(int, input().split())
    AB = []
    for i in [0]*N:
        A, B = map(int, input().split())
        AB.append((A, B))
    AB.sort(key=lambda x:x[0])

    POWER = 1
    x = [0] * (N+1)
    x[0] = AB[0][POWER]
    for i in range(N-1):
        x[i+1] = AB[i][POWER] ^ AB[i+1][POWER]
    x[N] = AB[N-1][POWER]

    graph = [ [] for _ in [0]*(N+1) ]
    for i in range(1, M+1):
        L, R = map(int, input().split())
        L = bisect_left(AB, (L, 0))
        R = bisect_right(AB, (R, 1))
        graph[L].append((R, i))
        graph[R].append((L, i))

    ans = []
    POS = 0
    ID = 1
    def dfs(v):
        used[v] = True
        res = x[v]
        for edge in graph[v]:
            if used[edge[POS]]: continue
            r = dfs(edge[POS])
            if r: ans.append(edge[ID])
            res ^= r
        return res

    used = [False] * (N+1)
    for i in range(N+1):
        if used[i]: continue
        if dfs(i):
            print(-1)
            return

    print(len(ans))
    ans.sort()
    print(*ans)


main()

Measured memory_bytes: 149104