akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

using namespace atcoder;

int main(void)
{
    IOS
    int n, q;
    cin >> n >> q;
    dsu d(n);
    REP(i,q) {
        int x; cin >> x;
        if (x == 1) {
            int a, b;
            cin >> a >> b;
            OUT(d.same(a,b) ? 1:0)
        } else {
            int a, b;
            cin >> a >> b;
            d.merge(a,b);
        }
    }

    return 0;
}

Measured memory_bytes: 3996
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>

using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
// istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
// ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main()
{
	int N, K;
	cin >> N >> K;
	
	mint Sum[200002];
	
	for(int i=0; i <= N+1; i++){
		Sum[i] = 0;
	}
	
	for(int i = 1; i <= N+1; i++){
		Sum[i] = Sum[i-1] + i;
	}
	
	mint ans = 0;
	
	for(int i = K; i <= N+1; i++){
		ans += (Sum[N+1]-Sum[N+1-i]) - (Sum[i]) + 1;
	}
	
	cout << ans.x << endl;
	
	return 0;
}


Measured memory_bytes: 5148
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
#include<vector>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)

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


int main() {

	string n;

	cin >> n;
	rep(i, 0, n.size()) {
		if (n[i] != n[n.size() - i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}

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

vector<int> buf;
int array[] = { 3, 5, 7 };
int allsum;
int n;

void dfs(int i, int size, int range_start, int range_end){
  if ( i == size ){
    bool flag[] = {false, false, false};
    int sum = 0;
    int d = 1;
    for (int j = 0; j < size; j++) {
      flag[buf[j]] = true;
      sum += array[buf[j]] * d;
      d *= 10;
    }

    if (sum <= n && flag[0] && flag[1] && flag[2]) 
    {
      // for(int j = 0; j < size; j++) {
      //   cout << array[buf[j]] << " ";
      // }
      // cout << endl;

      allsum++;
    }
  }
  else {
    for (int j = range_start; j < range_end; ++j) {
      buf[i] = j;
      dfs(i + 1, size, range_start, range_end);
    }
  }
}

int main(void) {
  int range_start = 0;
  int range_end = 3;
  
  cin >> n;
  int d = log10(n) + 1;

  // cout << n << " " << d << endl;

  buf.resize(d);

  allsum = 0;
  for (int i = 3; i < d; i++) {
    dfs(0, i, range_start, range_end);
  }
  dfs(0, d, range_start, range_end);

  cout << allsum << endl;

  return 0;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
cumA = [0]
for i in range(N):
  cumA.append(cumA[-1] + A[i])

ans = 0
M = 10**9 + 7
for i in range(N-1):
  ans += (A[i]*(cumA[N]-cumA[i+1]))
  ans %= M
print(ans)

Measured memory_bytes: 110128
#include <iostream>
#include <cstdio>
using namespace std;
int main(void) {
  int n, sum, hit;
  while(scanf("%d", &n)) {
    if(n == 0) break;
    sum = 0;
    n /= 4;
    for(int i = 0 ; i < n ; i++) {
      cin >> hit;
      sum += hit;
    }
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<math.h>
#include <stdio.h>
#include<vector>
#include<deque>
#include<stdlib.h>
//#include <algorithm>
#include<set>
#include <limits>
#include<string>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define ll long long
#define d_5 100000
int main(void){
  int N,M,Q;
  cin >> N >> M >> Q;
  int l,r;
  vector<vector<int>> d2(N,vector<int>(N,0));
  vector<vector<int>> c(N,vector<int>(N,0));
  rep(i,M){
    cin >> l>>r;
    l--;r--;
    d2[l][r] +=1;
  }
  rep(i,N){
    c[i][0]=d2[i][0];
  }
  rep(i,N){
    rep(j,N-1){
      c[i][j+1]=c[i][j]+d2[i][j+1];
    }
  }
  int p,q;
  rep(i,Q){
    int sum=0;
    cin >> p >> q;
    p--;q--;
    for(int j=p;j<=q;j++){
      if(p>=1){
        sum+=c[j][q]-c[j][p-1];
      }else{
        sum+=c[j][q];
      }
    }
    cout << sum << endl;
  }
	return 0;
}

Measured memory_bytes: 2944
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str[101];
P p[101];
bool used[101];
vector<P> data;
vector<P> data2;
int main(void){
	scanf("%d",&n);
	int sum=0;
	int msum=0;
	for(int i=0;i<n;i++){
		cin >> str[i];
		int mini=0;
		int cnt=0;
		int out=0;
		for(int j=0;j<str[i].size();j++){
			if(str[i][j]=='('){
				cnt++;
			}else{
				if(cnt==0){
					out++;
				}else cnt--;
			}
		}
		if(out==0){
			sum+=cnt;
		}else if(cnt==0){
			msum+=out;
		}else{
			if(out<=cnt)data.push_back(P(out,cnt));
			else data2.push_back(P(cnt,out));
		}
	}
	memset(used,false,sizeof(used));
	bool flag=true;
	for(int i=0;i<data.size();i++){
		int nex=-1;
		for(int j=0;j<data.size();j++){
			if(sum>=data[j].first && !used[j]){
				nex=j;
			}
		}
		if(nex>=0){
			sum-=data[nex].first;
			sum+=data[nex].second;
			used[nex]=true;
		}else{
			flag=false;
		}
	}
	memset(used,false,sizeof(used));
	sort(data2.begin(),data2.end());
	for(int i=(int)data2.size()-1;i>=0;i--){
		sum-=data2[i].second;
		if(sum<0)flag=false;
		sum+=data2[i].first;
	}
	printf("%s\n",(sum==msum && flag)?"Yes":"No");
	return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string S;
	cin >> S;
	int cb = 0;
	long long ans = 0;
	for (char c : S) {
		if (c == 'B') {
			++cb;
		} else {
			ans += cb;
		}
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    REP(i, n)
    {
        cin >> d.at(i);
    }
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());
    cout << d.size() << endl;
}


Measured memory_bytes: 3656
import sys
# sys.stdin = open('input.txt')

x = int(input())

for a in range(1000):
    a5 = a**5
    for b in range(-1000, 1000):
        b5 = b**5
        if a5 - b5 == x:
            print(a, b)
            break
    else:
        continue
    break

Measured memory_bytes: 9172
#include<iostream>
int main() {
	int n;
	std::cin >> n;
	int a[200];
	for (int i = 0; i < n; i++)
		std::cin >> a[i];
	int count = 0;
	bool flag = true;
	while (true) {
		for (int i = 0; i < n; i++)
			if ((a[i] % 2) == 1) flag = false;
		if (flag) {
			for (int i = 0; i < n; i++)
				a[i] /= 2;
			count++;
		}
		else break;
	}
	std::cout << count << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>

#define sf scanf
#define pf printf

using namespace std;

const int Maxn = 1000010;
int prime[Maxn];
int flag[Maxn];
int cnt ;
void _init()
{
    for(int i = 2;i < Maxn;i ++)
    {
        if(flag[i] == 0)
        {
            prime[cnt++] = i;
            for(int j = i * 2;j < Maxn;j += i)
                flag[j] = 1;
        }
    }
}
int Find(int n)
{
    int l = 0,r = cnt;
    while(l <= r)
    {
        int mid = (l + r) / 2;
        if(prime[mid] <= n)
            l = mid + 1;
        else
            r = mid - 1;
    }
    return l;
}
int main()
{
    _init();

    int n;
    while(~sf("%d",&n))
    {
        pf("%d\n",Find(n));
    }
    return 0;
}

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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> W(n+1),E(n+1);
    for(int i=0;i<n;++i){
        E[i] = 0;
        W[i] = 0;
    }
    for(int i=0;i<n;++i){
        if(s[i]=='E'){
            E[i+1]=E[i]+1;
            W[i+1] = W[i];
        } 
        else{
            W[i+1] = W[i]+1;
            E[i+1] = E[i];
        } 
    }
    int ans = E[n]-E[1];
    for(int i=1;i<=n;++i){
        int res = (E[n]-E[i]) + W[i-1];
        if(res<ans) ans = res;
    }
    cout << ans << endl;
    return 0;
}

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

const int mod=1000000007;
int cnt[2],n,m,a[31][31],f[2][28000010],x,y,nw[31],ma[31],ct[31],mi[1010],ans,g[31];

int main()
{
	mi[0]=1;
	for (int i=1; i<=1000; i++) mi[i]=2ll*mi[i-1]%mod;
	scanf("%d%d",&n,&m);
	if (n<=2) return printf("%d\n",m),0;
	for (int i=1; i<=m; i++) scanf("%d%d",&x,&y),a[x][y]=1;
	x=1,y=0,cnt[0]=1,f[0][1]=1;
	for (int i=n-1; i>2; i--)
	{
		x^=1,y^=1,cnt[y]=0;
		for (int j=0; j<=n-i; j++) nw[j]=ma[j]=0;
		nw[n-i]=-1;
		for (int j=1; j<=cnt[x]; j++)
		{
			int c=0;
			nw[n-i]++;
			for (int j=n-i; ; j--)
				if (nw[j]>ma[j-1]+1) nw[j]=0,nw[j-1]++; else
				{for (int k=j; k<=n-i; k++) ma[k]=max(ma[k-1],nw[k]); break;}
			for (int l=0; l<=n-i; l++) ct[l]=0;
			for (int l=i+1; l<=n; l++) if (a[i][l]) ct[nw[n-l+1]]++,c++;
			bool bo=(f[x][j]>0);
			for (int l=0,nw=0,nww=1; l<=ma[n-i]+1; l++)
			{
				if (!bo) f[y][++cnt[y]]=0; else 
				{
					if (l) nww=1ll*nww*(mi[ct[l-1]]+mod-1)%mod;
					f[y][++cnt[y]]=1ll*f[x][j]*mi[c-nw-ct[l]]%mod*nww%mod;
				}
				if (!ct[l]) bo=0;
				nw+=ct[l];
			}
		}
	}
	for (int i=0; i<=n-2; i++) nw[i]=ma[i]=0;
	nw[n-2]=-1;
	for (int i=1; i<=cnt[y]; i++)
	{
		int c=0;
		nw[n-2]++;
		for (int j=n-2; ; j--)
			if (nw[j]>ma[j-1]+1) nw[j]=0,nw[j-1]++; else
			{for (int k=j; k<=n-2; k++) ma[k]=max(ma[k-1],nw[k]); break;}
		if (!f[y][i]) continue;
		for (int j=0; j<=n-2; j++) ct[j]=0;
		for (int j=3; j<=n; j++) if (a[1][j]) ct[nw[n-j+1]]++,c++;
		bool bo=1;
		for (int j=0,nw=0,nww=1; j<=ma[n-2]+1; j++)
		{
			if (!bo) g[j]=0; else
			{
				if (j) nww=1ll*nww*(mi[ct[j-1]]+mod-1)%mod;
				g[j]=1ll*f[y][i]*mi[c-nw-ct[j]]%mod*nww%mod;
			}
			if (!ct[j]) bo=0;
			nw+=ct[j];
		}
		c=0;
		for (int j=0; j<=n-2; j++) ct[j]=0;
		for (int j=3; j<=n; j++) if (a[2][j]) ct[nw[n-j+1]]++,c++;
		for (int j=0,nw=0,nww=1; j<=ma[n-2]+1; j++)
		{
			if (j) nww=1ll*nww*(mi[ct[j-1]]+mod-1)%mod;
			ans=(ans+1ll*g[j]*mi[c-nw-ct[j]]%mod*nww)%mod;
			if (!ct[j]) break;
			nw+=ct[j];
		}
	}
	ans=(mi[m]-ans+mod)%mod;
	return printf("%d\n",ans),0;	
}

Measured memory_bytes: 127360
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int y = in.nextInt();
        int x = in.nextInt();
        for (int i = 0; i < y; i++) {
            String s = in.next();
            out.println(s);
            out.println(s);
        }
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 24660
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  string S; ll K; cin >> S >> K;
  int N = S.size();
  char ans[N];
  rep(i, N-1){
    ll tmp = 26 - (S[i]-'a');
    if(K>=tmp && S[i]!='a'){
      K-=tmp; ans[i] = (S[i] - 'a' + tmp)%26 + 'a';
    }
    else ans[i] = S[i];
  }
  ans[N-1] = (S[N-1] - 'a' + (K%26))%26 + 'a';
  rep(i, N){
    cout << ans[i];
  }
  cout << endl;
}

Measured memory_bytes: 640
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

ll MOD = 998244353;

string S;

int thres[2][2020], N, R, B;
ll dp[4040][4040];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> S;
    N = S.size();

    for (int i = 1; i <= N; ++i) {
        thres[0][i] = thres[0][i-1] + 2 - (S[i-1] - '0');
        thres[1][i] = thres[1][i-1] + (S[i-1] - '0');
    }
    R = thres[0][N]; B = thres[1][N];

    dp[0][0] = 1;
    for (int w = 1; w <= 2*N; ++w) {
        int rM = w <= N ? thres[0][w] : R;
        for (int r = 0; r <= rM; ++r) {
            int b = w - r;
            if (b > (w <= N ? thres[1][w] : B)) continue;
            if (r > 0) (dp[r][b] += dp[r-1][b]) %= MOD;
            if (b > 0) (dp[r][b] += dp[r][b-1]) %= MOD;
        }
    }

    cout << dp[R][B] << endl;

    return 0;
}


Measured memory_bytes: 125440
require 'set'
require 'bigdecimal'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

L = get_int

x = BigDecimal(L) / 3

puts (x ** 3).to_f


Measured memory_bytes: 14640
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <stdlib.h>

using namespace std;



int main()
{
  long long int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;

  bool ok = false;


  long long int gap = b-a;
  long long int up = (n-1)*d;
  long long int bot = (n-1)*c;

  for(int i=0;i<n-1 && !ok ;i++){
    if(up >= gap && gap >= bot){
      ok = true;
    }
    up = up - d - c;
    bot = bot - c - d;
  }

  if(ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    int A, B;
    cin >> A >> B;
    cout << A*B << endl;
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

const double PI = 3.141592653;
  
void Main(){
	double r;
	cin >> r;
	cout << r*2*PI << endl;
	return;
}

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


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int x,y; cin>>x>>y;
    if(x==2){
        if(y==2) cout<<"Yes"<<endl; else cout<<"No"<<endl;
        return 0;
    }
    if(x==1||x==3||x==5||x==7||x==8||x==10||x==12){
        x = y;
        if(x==1||x==3||x==5||x==7||x==8||x==10||x==12) cout<<"Yes"<<endl; else cout<<"No"<<endl;
        return 0;
    }
    if(x==4||x==6||x==9||x==11){
        x=y;
        if(x==4||x==6||x==9||x==11) cout<<"Yes"<<endl; else cout<<"No"<<endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
 
#define MAX 1000002
 
typedef unsigned char byte;
byte mask[8] = {0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01};
  
int *Lv;
int n, k;
  
bool cmp_Lv(const int i, const int j){ return Lv[i] < Lv[j]; }
  
bool cmp(const int i, const int j){
    if(Lv[i] != Lv[j]){ return Lv[i] < Lv[j]; }
    int L_i = (i + k >= n ? -1 : Lv[i + k]);
    int L_j = (j + k >= n ? -1 : Lv[j + k]);
  
    return L_i < L_j;
}
  
int main()
{
    int *A;
    char c[MAX];
    scanf("%s", c);
    std::string T = std::string(c);
    n = T.size();
 
    A = new int[n + 1], Lv = new int [n + 1];
 
    byte *t;
    t = new byte [(n >> 3) + 1];
  
    int i;
    for(i = 0; i < n; i++){ A[i] = i; }
    for(i = 0; i < n; i++){ Lv[i] = T[i]; }
  
    int bkt[129];
    for(i = 0; i < 129; i++){ bkt[i] = 0; }
    for(i = 0; i < n; i++){ bkt[Lv[i]]++; }
    int sum = 0;
    for(i = 0; i < 129; i++){ sum += bkt[i]; bkt[i] = sum; }
    for(i = 0; i < n; i++){ A[--bkt[Lv[i]]] = i; }
  
    for(i = 1; i < n; i++){
        t[i >> 3] = (Lv[A[i]] != Lv[A[i - 1]] ? t[i >> 3] | mask[i & 7] : t[i >> 3] & ~mask[i & 7]);
    }
    t[n >> 3] = t[n >> 3] | mask[n & 7];
  
    Lv[A[0]] = 0;
    for(i = 1; i < n; i++){
        Lv[A[i]] = Lv[A[i - 1]] + !!(mask[i & 7] & t[i >> 3]);
    }
  
    k = 1;
    while(1){
        if(k > n) break;
 
        std::sort(A, A + n, cmp);
  
        for(i = 1; i < n; i++){
            t[i >> 3] = (cmp(A[i - 1], A[i]) ? t[i >> 3] | mask[i & 7] : t[i >> 3] & ~mask[i & 7]);
        }
        Lv[A[0]] = 0;
        for(i = 1; i < n; i++){
            Lv[A[i]] = Lv[A[i - 1]] + !!(mask[i & 7] & t[i >> 3]);
        }
 
        if(Lv[A[n - 1]] == n - 1) break;
        k <<= 1;
    };
  
    char p[1000];
    int q, left, right, mid, crit;
    bool exist;
    scanf("%d", &q);
  
    A[n] = n;
  
    while(q){
        scanf("%s", p);
        std::string P = std::string(p);
        left = 0, right = n, exist = false;
        while(left < right){
  
            if(n < P.size()){ exist = false; break; }
  
            mid = (left + right) / 2;
            crit = T.compare(A[mid], P.size(), P);
  
            if(crit > 0){ right = mid; }
            else if(crit < 0){ left = mid + 1; }
            else{ exist = true; break; }
        };
        if(T.compare(A[right], P.size(), P) == 0) exist = true;
        if(exist){ printf("1\n"); }else{ printf("0\n"); }
        q--;
    }
    return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
    int Q;cin >> Q;
    priority_queue<ll, vector<ll>, greater<ll>> que1;
    priority_queue<ll> que2;
    ll w = 0;
    ll h = 0, l = 0;
    while (Q--) {
        int a;
        cin >> a;
        if(a == 1){
            ll b,c;cin >> b >> c;
            w += c;
            if(que1.size() == que2.size()){
                if(que2.size() == 0){
                    que2.push(b);
                    l += b;
                }else{
                    if(que2.top() >= b){
                        que2.push(b);
                        l += b;
                    }else{
                        que1.push(b);
                        h += b;
                        que2.push(que1.top());
                        h -= que1.top();
                        l += que1.top();
                        que1.pop();
                    }
                }
            }else{
                que2.push(b);
                l += b;
                que1.push(que2.top());
                h += que2.top();
                l -= que2.top();
                que2.pop();
            }
        }else{
            cout<<que2.top()<<" "<<w + h - que2.top() * (ll)que1.size() + (ll)que2.size() * que2.top() - l<<endl;
        }
    }
}


Measured memory_bytes: 3828
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0423"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
template <typename T>
vector<T> dijkstra(int s,vector< vector< pair<int, T> > > & G){
  const T INF = numeric_limits<T>::max();
  using P = pair<T, int>;
  int n=G.size();
  vector<T> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  return ds;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  int n,l;
  scanf("%d %d",&n,&l);

  using P = pair<int, Int>;
  vector<vector<P> > G(l+1);
  for(int i=0;i<n;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    G[a].emplace_back(b,c);
  }

  for(int i=0;i<l;i++)
    G[i+1].emplace_back(i,0);

  printf("%lld\n",dijkstra(0,G)[l]);
  return 0;
}
/*
  verified on 2018/01/16
  https://atcoder.jp/contests/arc026/tasks/arc026_3
*/
#endif

#undef call_from_test

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

  vector<int> ts(n),es(n);
  for(int i=0;i<n;i++) cin>>ts[i]>>es[i];

  using P = pair<int, int>;
  vector< vector<P> > G(n+1);
  for(int i=0;i<m;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;c--;
    G[b].emplace_back(a,c);
  }

  for(int i=0;i<n;i++) G[n].emplace_back(i,ts[i]);
  auto ds=dijkstra(n,G);

  long long ans=0;
  for(int i=0;i<n;i++) ans+=(long long)ds[i]*es[i];
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 12252
x, n = map(int, input().split())
p_str = input()

if n == 0:
    print(x)
    exit()

p = list(map(int, p_str.split()))

for i in range(0, 101):
    i1 = x - i
    i2 = x + i
    if i1 not in p:
        print(i1)
        break
    elif i2 not in p:
        print(i2)
        break
    else:
        continue


Measured memory_bytes: 61884
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int maxn=1e5+10;
char a[maxn];
int main()
{       int m,n;
     cin>>n>>m;
     scanf("%s",a+1);
      a[m]=a[m]+32;
    for(int i=1;i<=n;i++)
        cout<<a[i];
    cout<<endl;

return 0;
    }


Measured memory_bytes: 256
using System;

namespace AtCoder190804_B
{
    class Program
    {
        static void Main()
        {
            String input = Console.ReadLine();
            int n = int.Parse(input);

            int res = 0;

            UpdateRes(n, ref res, 1);

            Console.WriteLine($"{res}");
        }

        private static void UpdateRes(int n, ref int res, int i)
        {
            // 各偶数桁の最小(10, 1000, 100000)を表す
            int p = (int)Math.Pow(10, i);
            if (n < p)
            {
                // 奇数桁が最大桁数の場合
                res += n - ((p / 10) - 1);
            }
            else
            {
                // 偶数桁が存在する場合一つ小さい奇数桁の最小(1, 100, 1000)を1-9まで加算する
                res += 9 * (p / 10);
                if (n >= (p * 10))
                {
                    // 上位の桁が存在する場合再帰的に計算する
                    UpdateRes(n, ref res, i + 2);
                }
            }
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define INT(a) scanf("%d",&a)
#define STR(a) scanf("%s",a)
#define DBL(a) scanf("%lf",&a)
#define LNG(a) scanf("%lld",&a)
#define PI acos(-1)


int a[1005], b[1005], n;
int memo[1005][10005];

int dp(int pos, int H){
	if(H<=0) return 0;
	if(pos>n) return 100000000;
	if(memo[pos][H]!=-1) return memo[pos][H];
	int p =  dp(pos+1, H);
	return memo[pos][H]=min(b[pos]+min(dp(pos, H-a[pos]), dp(pos+1, H-a[pos])),p);
}



int main(){
	int H;
	cin>>H>>n;
	memset(memo, -1, sizeof memo);
	for(int i=1;i<=n; i++){
		cin>>a[i]>>b[i];
	}

	cout<<dp(1, H)<<endl;
	return 0;
}

Measured memory_bytes: 40320
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}

signed main()
{
   int N; cin >> N;
   V<int> a(N), b(N);
   REP(i, N) {
      cin >> a[i];
   }
   REP(i, N) {
      cin >> b[i];
   }

   const int MAX_K = 28;
   int ans = 0;
   FORE(k, 0, MAX_K+1) {
      V<int> A(N), B(N);
      REP(i, N) {
         A[i] = a[i] % (1LL<<(k+1));
         B[i] = b[i] % (1LL<<(k+1));
      }
      SORT(B);
      int cnt = 0;
      REP(i, N) {
         cnt += LB(B,2*(1LL<<k)-A[i]) - LB(B,  (1LL<<k)-A[i]);
         cnt += LB(B,4*(1LL<<k)-A[i]) - LB(B,3*(1LL<<k)-A[i]);
      }
      ans |= (cnt % 2) << k;
   }

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 6552
using System;
using System.Collections.Generic;
using System.Linq;

namespace Joyeuse
{
	class Program
	{
		#region Reserve
		static int cin() { return cin(-1); }
		static int cin(int D) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return int.Parse(s);
		}
		static long cln(long D = -1){
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return D;
			return long.Parse(s);
		}
		static int[] cins(char spliter) {
			string s = Console.ReadLine();
			if (string.IsNullOrEmpty(s))
				return new int[] { };
			string[] ss = s.Split(spliter);
			var Res = new int[ss.Length];
			for (int i = 0; i < ss.Length; i++)
				Res[i] = int.Parse(ss[i]);
			return Res;
		}
		static int[] cins() { return cins(' '); }
		static void print(object j) { Console.WriteLine(j.ToString()); }
		static void print(string j) { Console.WriteLine(j); }
		static string read() { return Console.ReadLine(); }
		#endregion
		
		static void Main(string[] args) {
			var I = cins();
			int N = I[0],M=I[1];
			var arrive = new HashSet<int>();
			var depart = new HashSet<int>();
			
			for(int i=0;i<M;i++){
				I=cins();
				if(I[0]==1||I[1]==1){
					arrive.Add(I[0]+I[1]-1);
					continue;
				}
				if(I[0]==N||I[1]==N)
					depart.Add(I[0]+I[1]-N);
			}
			var G = Enumerable.Range(1,N)
				.Select(i=>arrive.Contains(i)).ToArray();
			bool res=false;
			foreach(var d in depart)
				if(G[d-1]){res=true;break;}
			print(res?"POSSIBLE":"IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 26404
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;

int main() {
    int N;
    cin >> N;
    for (int i = 111; i <= 999; i += 111) {
        if (i >= N) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    int m=n;
    while(m>10)
        m/=10;
    if(m==10)
        puts("10");
    else{
        m=n;
        int ans=0;
        while(m){
            ans+=m%10;
            m/=10;
        }
        printf("%d\n",ans);
    }
}


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

typedef long double ld;									// XD
#define int long long
#define PB push_back
#define all(x) (x).begin(),(x).end()
#define ii pair <int,int>
#define mii map <int,int>
#define vi vector<int>
#define vii vector< ii >
#define F first
#define S second
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define sz(x) (int)((x).size())
#define mem(a,x) memset(a,x,sizeof(a))
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
inline void io(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int mod = 1e9 + 7;
const int inf = 3e16;
const int maxn = 2e5+5;
int vis[maxn], cnt = 0;
vi g[maxn];
void dfs(int x){
	++cnt; vis[x] = 1;
	for(int i : g[x]){
		if(!vis[i])
			dfs(i);
	}
}
void solve(){
	int n, m; cin>>n>>m;
	rep(i, 0, m){
		int x, y; cin>>x>>y; --x;--y;
		g[x].PB(y); g[y].PB(x);
	}
	int ans = 0;
	rep(i, 0, n){
		cnt = 0;
		if(!vis[i]){
			dfs(i); 
			ans = max(ans, cnt);
		}
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); //io();
    //cout<<setprecision(12);
    int tc=1;// cin>>tc;
    while(tc--){
        solve();cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 22392
N = gets.to_i
weight_arr = gets.split(" ").map(&:to_i)

s1 = 0
s2 = weight_arr.sum
diff = s2

weight_arr.each do |w|
  s1 += w
  s2 -= w
  c_diff = (s1 - s2).abs

  diff = c_diff if diff > c_diff
  # 差が増加する場合は以降の計算は不要
  break if diff - c_diff < 0
end
puts diff


Measured memory_bytes: 14312
package main

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

var sc = bufio.NewScanner(os.Stdin)

func rcvInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func gcd(a, b int) int {
	for b != 0 {
		c := a % b
		a, b = b, c
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	n := rcvInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = rcvInt()
	}

	y := a[0]
	for _, x := range a {
		y = gcd(x, y)
	}

	fmt.Println(y)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int dp[100010];

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

    for(int i = 0; i < 100010; i++) dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[n-1] << endl;

    return 0;
}

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

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

int main(){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    map<char,ll> mp;
    rep(i,n){
        mp[s[i]]++;
    }
    ll ans=1;
    for(auto i:mp){
        ans*=(i.second+1)%(int)(1e9+7);
        ans%=(int)(1e9+7);
    }
    
    cout << (ans-1)%(int)(1e9+7);
}

Measured memory_bytes: 512
x, y, z, k = map(int, input().split())
a = [int(m) for m in input().split()]
b = [int(m) for m in input().split()]
c = [int(m) for m in input().split()]
a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)
s = []
for i in range(x):
    for j in range(y):
        s.append(a[i] + b[j])

s.sort(reverse=True)
s1 = []
for i in range(min(x * y, k)):
    s1.append(s[i])

t = []
for i in range(min(x * y, k)):
    for j in range(z):
        t.append(s1[i] + c[j])

t.sort(reverse=True)

for i in range(k):
    print(t[i])

Measured memory_bytes: 151640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
struct Fast {Fast(){std::cin.tie(0);std::ios::sync_with_stdio(false);}} fast;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

bool vector_find(std::vector<ll> vec, ll number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) {
        return true;
    }
    else {
        return false;
    }
}

vector<string> split(const string& src, const char* delim = ":") {
    vector<string> vec;
    string::size_type len = src.length();
    
    for (string::size_type i = 0, n; i < len; i = n + 1) {
        n = src.find_first_of(delim, i);
        if (n == string::npos) {
            n = len;
        }
        vec.push_back(src.substr(i, n - i));
    }
    
    return vec;
}

int main(int argc, char *argv[]){
    ll result = 0;
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N){
        cin >> A[i];
    }
    vector<pair<ll,ll>> CBpair(M);
    rep(i, M){
        ll b, c;
        cin >> b >> c;
        CBpair.push_back(make_pair(c, b));
    }
    sort(ALL(CBpair), greater<>());

    sort(ALL(A));

    bool flag = false;
    ll pos = 0;
    rep(i, M){
        rep(j, CBpair[i].second){
            if(A[pos] < CBpair[i].first){
                result += CBpair[i].first;
                pos ++;
                if(pos == N){
                    flag = true;
                    break;
                }
            } else{
                flag = true;
                break;
            }
        }
        if(flag){
            break;
        }
    }
    
    if(pos != N){
        For(i, pos, N){
            result += A[i];
        }
    }
    
    cout << result << endl;
}


Measured memory_bytes: 5504
N = int(input())
ans = [0,0,0,0]
for i in range(N):
    S = input()
    if S == "AC":
        ans[0] += 1
    elif S == "WA":
        ans[1] += 1
    elif S == "TLE":
        ans[2] += 1
    elif S == "RE":
        ans[3] += 1

print("AC x {}".format(ans[0]))
print("WA x {}".format(ans[1]))
print("TLE x {}".format(ans[2]))
print("RE x {}".format(ans[3]))    

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
constexpr int maxn = 100000;
int A[maxn];
int main(){
    ios::sync_with_stdio(false);
    int N, ans = 0;
    cin >> N;
    map<int, int> mp;
    for(int i = 0; i < N; i += 1){
        cin >> A[i];
        mp[A[i]] = i;
    }
    sort(A, A + N);
    for(int i = 0; i < N; i += 2) ans += mp[A[i]] & 1;
    cout << ans;
    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair



int main() {
    int N; cin >> N;
    int k = 0;
    for (int i = 2; i*(i-1) <= 2*N; i++) {
        if (i*(i-1) == 2*N) {
            k = i;
            break;
        }
    }

    if (k == 0) printf("No\n");
    else {
        printf("Yes\n%d\n", k);
        vector<vector<int>> S(k, vector<int>(0));
        int a = 1;
        REP(i, k) REP2(j, i+1, k) {
            S[i].PB(a);
            S[j].PB(a);
            a++;
        }
        REP(i, k) {
            printf("%d", (int)S[i].size());
            REP(j, S[i].size()) printf(" %d", S[i][j]);
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 4304
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int d;
ll c[30];
ll s[400][30];
ll t[400];

int main() {
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) rep(j, 26) cin >> s[i][j];
    rep(i, d) cin >> t[i];

    vector<ll> last(26, 0);

    ll score = 0;
    rep(i, d) {
        score += s[i][t[i] - 1];
        last[t[i] - 1] = i + 1;
        rep(j, 26) {
            score -= c[j] * (i + 1 - last[j]);
        }
        cout << score << endl;
    }
}


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

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  vector<int> B(N);
  for( int i = 0; i < N; i++ ) cin >> B.at(i);
  
  int cnt = 0;
  for( int i = 0; i < N; i++ ){
    if( A.at(i) > B.at(i) ) cnt += A.at(i)-B.at(i);
    else if( A.at(i) < B.at(i) ) cnt -= (B.at(i)-A.at(i))/2;
  }
  
  if( cnt <= 0 ) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int a,b;
		cin>>a>>b;
		cout<<max(a*b,max(a+b,a-b));
	}
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n, m;
   cin >> n >> m;
   vector<int> a(n);
   rep(i, m) {
      int k;
      cin >> k;
      rep(j, k) {
         int s;
         cin >> s;
         s--;
         a[s] |= 1 << i;
      }
   }
   int p = 0;
   rep(i, m) {
      int x;
      cin >> x;
      p |= x << i;
   }
   int ans = 0;
   rep(s, 1 << n) {
      int t = 0;
      rep(i, n) {
         if (s >> i & 1) {
            t ^= a[i];
         }
      }
      if (t == p) {
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i=0; i<n; i++){
        cin >> x[i];
    }

    int result = pow(2, 29);
    for(int i=0; i+(k-1)<n; i++){
        int tmp = 0;
        tmp += x[i+k-1] - x[i];
        tmp += min(abs(x[i]), abs(x[i+k-1]));
        result = min(result, tmp);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;

template <typename T>
inline void output(T a, int p) {
    if(p){
        cout << fixed << setprecision(p)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
// end of template

struct Node {int p, l, r;}; // parent, left, right

class Parse{
public:
    int N;
    int root;
    vector<Node> T;
    Parse(int n){
        N = n;
        T.resize(n, Node{-1, -1, -1});
    }
    
    void make_root(){
        rep(i, N){
            if (T[i].p == -1) {
                root = i;
            }
        }
    }
    
    void add(int p, int l, int r){
        T[p].l = l;
        T[p].r = r;
        if (l != -1) T[l].p = p;
        if (r != -1) T[r].p = p;
    }
    
    void parse(int u, int op){
        if (u == -1) {
            return;
        }
        if (op == 1) cout << " " << u; // pre
        parse(T[u].l, op);
        if (op == 2) cout << " " << u; // in
        parse(T[u].r, op);
        if (op == 3) cout << " " << u; // post
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    Parse P(N);
    rep(i, N){
        int p, l, r;
        cin >> p >> l >> r;
        P.add(p, l, r);
    }
    P.make_root();
    //cout << P.root << endl;
    cout << "Preorder" << endl;
    P.parse(P.root, 1);
    cout << endl;
    cout << "Inorder" << endl;
    P.parse(P.root, 2);
    cout << endl;
    cout << "Postorder" << endl;
    P.parse(P.root, 3);
    cout << endl;
    return 0;
}

Measured memory_bytes: 3212
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

typedef pair<string,int> Psi;

map<string, int> m;

const int d[4] = { -4, 4, -1, 1 };

int main() {
  queue<Psi> que;
  que.push(Psi(string("01234567"), 0));
  while(!que.empty()) {
    Psi p = que.front();
    int cost = p.second;
    que.pop();
    if (m.count(p.first)) continue;
    m.insert(Psi(p.first, cost));
        
    int z_idx = -1;
    rep (i,8) if (p.first[i] == '0') { z_idx = i; break; }
    
    for (int i = 0; i < 4; ++i) {
      if (z_idx == 3 && i == 3) continue;
      if (z_idx == 4 && i == 2) continue;
      int t_idx = z_idx + d[i];
      if (t_idx < 0 || t_idx >= 8) continue;
      string copy = p.first;
      swap(copy[z_idx], copy[t_idx]);
      que.push(Psi(copy, cost+1));
    }
  }
    
  string a = "01234567";
  while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> a[5] >> a[6] >> a[7]) {
    cout << m[a] << endl;
  }
  return 0;
}

Measured memory_bytes: 2224
N = int(input())
primes = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47]

two = sum(p<=N//2 for p in primes) # 2
four = sum(p<=N//4 for p in primes) if N>=12 else sum([N>=9, N>=6]) # 4
ft = sum([N>=91, N>=60, N>=30, N>=16]) # 14
tf = sum([N>=100, N>=54, N>=28]) # 24
sf = N>=78 # 74

tff = four * (four-1) * (two-2) // 2 # 2,4,4
ttf = tf * (two-1) # 2,24
fft = ft * (four-1) # 4,14
sfo = sf # 74

print(tff+ttf+fft+sfo)

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll>A(X), B(Y), C(Z);
REP(i, X) cin >> A.at(i);
REP(i, Y) cin >> B.at(i);
REP(i, Z) cin >> C.at(i);

vector<ll>AB;
REP(i,X)REP(j, Y) AB.push_back(A.at(i) + B.at(j));

sort(all(AB));
reverse(all(AB));
vector<ll>ans;

REP(i, min(K, (int)AB.size()))REP(j, Z) ans.push_back(AB.at(i) + C.at(j));

sort(all(ans));
reverse(all(ans));

REP(i, K) print(ans.at(i));



}


Measured memory_bytes: 43368