akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

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

const int MAXN = 1e3 + 5;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const char smjer[4] = {'R', 'U', 'L', 'D'};

int n;
ll X[MAXN], Y[MAXN], pot[MAXN];

void done(){
  cout << -1;
  exit(0);
}

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

  pot[0] = 1;
  FOR(i, 1, 35)
    pot[i] = pot[i - 1] * 2;

  cin >> n;
  REP(i, n)
    cin >> X[i] >> Y[i];

  int par = (abs(X[0]) + abs(Y[0])) % 2;
  FOR(i, 1, n){
    if( (abs(X[i]) + abs(Y[i])) % 2 != par )
      done();
  }

  if(par == 0){
    REP(i, n)
      X[i] ++;
  }
  par = !par;

  cout << 31 + par << "\n";
  for(int i = 30; i >= 0; --i)
    cout << pot[i] << " ";
  if(par)
    cout << 1;
  cout << "\n";

  REP(i, n){
    int x = 0, y = 0;
    for(int j = 30; j >= 0; --j){
      REP(k, 4){
        ll nx = x + dx[k] * pot[j];
        ll ny = y + dy[k] * pot[j];
        //TRACE(nx); TRACE(ny);
        //TRACE( abs(nx - X[i]) + abs(ny - Y[i]) ); TRACE(pot[j]);
        if( abs(nx - X[i]) + abs(ny - Y[i]) < pot[j] ){
          x = nx;
          y = ny;
          cout << smjer[k];
          break;
        }
      }
    }

    if(par) cout << 'L';
    cout << "\n";
  }
}


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


int main() {
    int  a[3];
    cin >> a[0]>>a[1]>>a[2];
    sort(a, a + 3);
    cout << a[0] + a[1] << endl;
    
 
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

long long int A, B, C, K;

int main(void){

    scanf("%lld%lld%lld%lld", &A,&B,&C,&K);

    if(A>=K){
        printf("%lld\n", K);
    }else if(A+B>=K){
        printf("%lld\n", A);
    }else{
        printf("%lld\n", 2*A+B-K);
    }

}

Measured memory_bytes: 1728
import sys

def input(): return sys.stdin.readline().rstrip("\r\n")
def List(): return list(map(int, input().split()))
def Num(): return int(input())


n = Num()
s = input()
r, w = s.count('R'), s.count('W')
t = 'R' * r + 'W' * w
f, ss = 0, 0
for i in range(r):
    if t[i] != s[i]:
        f += 1
print(f)



Measured memory_bytes: 9668
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
dis1 = []
dis2 = []

for i in range(0,len(a)-1):
    dis1.append(abs(a[i+1]-a[i]))
s = sum(dis1)
for i in range(0,len(a)-2):
    dis2.append(abs(a[i+2]-a[i]))

for i in range(n):
    print(s-dis1[i]-dis1[i+1]+dis2[i])



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

int main(int argc, char *argv[], char *envp[]){
	int N;
	int KAI = 0;
	cin >> N;
	for(int i=1; i<N/2 + 1; ++i){
		if(i != N-i){
			KAI += 1;
		}
	}
	cout << KAI << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c; cin >> a >> b >> c;
  cout << ((a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
package main

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


func solveFromFile() string{
    var nu int
    scanner := bufio.NewScanner(os.Stdin)
    file, err := os.Open(os.Args[1])
    if err != nil {
      log.Fatalf("failed opening file: %s", err)
    }
    scanner = bufio.NewScanner(file)
    scanner.Scan()

	  n, err2 := strconv.Atoi(scanner.Text())
    nu = n
    if err2 != nil {
      log.Fatalf("failed opening file: %s", err2)
      
    }
    
    defer file.Close()
    scanner.Scan()
    return solution(scanner.Text(),nu)
}

//========== Implement Algorithm =======================
func solution(s string, num int) string{
  if len(s)<=num{
    return s
  }else {
    s = s[0:num]+"..."
    return s
  }
  
}

func main() {

//================== Variables used ====================
  var num int
  var s, ret string
//======================================================

  if len(os.Args) >=2{
//============== Get return value from File ============
    ret = solveFromFile()


  }else{
//============== Get return value from STDIN ===========
    size,_ := fmt.Fscan(os.Stdin, &num)
    size++
    size2,_ := fmt.Fscan(os.Stdin, &s)
    size2++
    //fmt.Scan(&num)
    ret = solution(s,num)
  }

//================== OUTPUT ============================
  fmt.Println(ret)
}


Measured memory_bytes: 1884
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
using namespace std;

string abcgene(string anss){
	string c;
	string s=anss;
	string tmp="a";
	while(1){
		if(s=="ABC") return "Yes";
		if(tmp==s||s.size()<5) return "No";
		if(s.substr(0,3)=="ABC") c="A";
		else if(s.substr(s.size()-3,3)=="ABC") c="C";
		else c="B";
		tmp=s;
		int cnt=0;
		REP(i,0,(int) s.size()-2){
			if(s.substr(i,3)=="ABC"){
				s.replace(i,3,c);
				cnt++;
			}
		}
		if(cnt != count(s.begin(),s.end(),c[0])) return "No";
	}
}

int main(){
	string ans;
	cin>>ans;
	p(abcgene(ans));
	return 0;
}

Measured memory_bytes: 3240
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <math.h>
using namespace std;
using s64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{
    int H,W,h,w;
    cin >> H >> W >> h >> w;
    int ret = (H-h)*(W-w);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, x;
  cin >> N >> x;
  vector<long> data(N);
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  long count = 0, a;
  for(int i = 0; i < N - 1; i++) {
    a = data.at(i) + data.at(i + 1) - x;
    if(a > 0) {
      count += a;
      if(data.at(i + 1) > a) data.at(i + 1) -= a;
      else {
        a -= data.at(i + 1);
        data.at(i + 1) = 0;
        data.at(i) -= a;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n,m;
	cin >> n>>m;
	int k[31], a[31][31];
	REP(i, n) {
		cin >> k[i];
		REP1(j, k[i]) {
			cin >> a[i][j];
		}
	}
	int t[35] = { 0 };
	REP(i, n) {
		REP1(j, k[i]) {
			t[a[i][j]]++;
		}
	}
	int c = 0;
	for (int i = 0; i <= m;i++) {
		if (t[i] == n) c++;
	}
	cout << c << endl;
	return 0;
}

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

using namespace std;

bool array_next(int *begin, int *end, int num_max);

int main(void)
{
    int *num_array;
    int array_len;
    int num_max;
    int score_len;

    vector<int> as;
    vector<int> bs;
    vector<int> cs;
    vector<int> ds;

    cin >> array_len >> num_max >> score_len;

    for(int i = 0; i < score_len; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        as.push_back(a - 1);
        bs.push_back(b - 1);
        cs.push_back(c);
        ds.push_back(d);
    }

    num_array = new int[array_len];

    for(int i = 0; i < array_len; i++){
        num_array[i] = 1;
    }
    num_array[array_len - 1] = 0;

    int max_score = 0;
    while(array_next(num_array, num_array + array_len, num_max)){
        bool ascend = true;
        for(int i = 0; i < array_len - 1; i++){
            if(num_array[i] > num_array[i + 1]){
                ascend = false;
                break;
            }
        }

        if(ascend){
            int current_sum = 0;
            for(int i = 0; i < score_len; i++){
                if(num_array[bs[i]] - num_array[as[i]] == cs[i]){
                    current_sum += ds[i];
                }
            }

            if(current_sum > max_score){
                max_score = current_sum;
            }
        }
    }

    cout << max_score << endl;

    return 0;
}

bool array_next(int *begin, int *end, int num_max)
{
    int *last = end - 1;
    if(*last == num_max){
        if(last == begin){
            return false;
        }
        bool cont = array_next(begin, last, num_max);
        if(cont){
            *last = *(last - 1);
        }
        return cont;
    }

    *last += 1;
    return true;
}

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

int main() {
	// your code goes here
	int a,b;
	cin>>a>>b;
	for(int i=b-a+1;i<b+a;i++){
		if(i>=-1000000&&i<=1000000)cout<<i<<" ";
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define x first
#define y second

#ifdef LOCAL
#include "debug.h"
#endif

const int N = int(1e5) + 10;
const int SQRTN = 500;
const int MOD = 998244353;

int n;
int m[3];
vector<int> adj[3][N];
int g[3][N];
int ans_g[4][SQRTN];
int mod[N];

int main() {
	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif

	scanf("%d", &n);
	for (int i = 0; i < 3; i++) {
		scanf("%d", &m[i]);
		for (int j = 0; j < m[i]; j++) {
			int u, v;
			scanf("%d %d", &u, &v);
			adj[i][u].push_back(v);
			adj[i][v].push_back(u);
		}
	}

	for (int i = 0; i < 3; i++) {
		for (int j = n; j >= 1; j--) {
			vector<int> gs;
			for (int to : adj[i][j]) if (to > j) gs.push_back(g[i][to]);
			sort(gs.begin(), gs.end());
			gs.resize(unique(gs.begin(), gs.end()) - gs.begin());
			g[i][j] = 0;
			while (g[i][j] < gs.size() && gs[g[i][j]] == g[i][j]) g[i][j]++;
		}
	}

	int p = 1;
	for (int i = 0; i < 18; i++) p = p * 10LL % MOD;
	mod[0] = 1;
	for (int i = 1; i < N; i++) mod[i] = mod[i - 1] * 1LL * p % MOD;

	ans_g[3][0] = 1;
	for (int i = 2; i >= 0; i--) {
		for (int j = 1; j <= n; j++) {
			for (int _g = 0; _g < SQRTN; _g++) {
				int ig = _g ^ g[i][j];
				if (ig < SQRTN) {
					(ans_g[i][_g] += mod[j] * 1LL * ans_g[i + 1][ig] % MOD) %= MOD;
				}
			}
		}
	}

	cout << ans_g[0][0] << endl;

	return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;

	cin>> n;
	string s;
	cin>> s;
	if(s.size() <= n){
		cout<< s<< endl;
	}
	else{
		for(int i = 0; i<n; ++i) cout<< s[i];
		cout<< "...";
	}
	cout<< endl;
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
#define MOD 1000000007

#define ARRAY_MAX 1005


int main(){

    ll n,mini = LLONG_MAX/2;
    cin >> n;
    vector<ll> a(n);
    ll cnt = 0;
    bool flag = true;
    REP(i,n){
        cin >> a[i];
        if(a[i] % 2 == 1){
            flag = false;
        }
    }

    if(!flag){
        cout << "first" << endl;
    }else{
        cout << "second" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
using namespace std;

int main() {
  int n;
  while(cin >>n, n) {
    int x[n];
    int a = 0;
    for(int i=0; i<n; i++) {
      cin >> x[i];
      if(i>0){
        if (x[i]-1!=x[i-1]) {
          if (a != i-1) {
            printf("%d-%d ",x[a],x[i-1]);
          } else {
            cout << x[i-1] << " ";
          }
          a = i;
        }
      }
    }
    if (a != n-1) {
      printf("%d-%d",x[a],x[n-1]);
    } else {
      cout << x[n-1];
    }    
    cout << endl;
    
  }
}

Measured memory_bytes: 0
n, m = map(int, input().split())
data = [[0] * 2 for i in range(n)]
ac = 0
wa = 0
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if data[p-1][0] == 0:
        if s == 'AC':
            data[p-1][0] = 1
            ac += 1
            wa += data[p-1][1]
        elif s == 'WA':
            data[p-1][1] += 1

print(str(ac)+' '+str(wa))


Measured memory_bytes: 14580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    ll n;
    cin>>n;
    ll ai;
    ll aii=0;
    ll max=0;
    vector<ll> k;
    rep(i,n){
        cin>>ai;
        k.pb(ai);
        if(ai>max){
            max=ai;
            aii=i;
        }
    }
    sort(k.begin(),k.end(),greater<ll>());

    rep(i,n){
        if(i!=aii)cout<<k[0]<<endl;
        else cout<<k[1]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3312
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc054/tasks/abc054_c

int ab[15][15];

int main() {
    int N, M; cin >> N >> M;
    REP(i, M) {
        int a, b; cin >> a >> b;
        ab[a][b] = 1;
        ab[b][a] = 1;
    }

    vector<int> perm(N-1);
    REP(i, N-1) {
        perm[i] = i+2;
    }
    sort(perm.begin(), perm.end());

    int cnt = 0;
    do {
        int now = 1;
        for (int i = 0; i < perm.size(); i++) {
            if (!ab[now][perm[i]]) break;
            now = perm[i];
            if (i == perm.size()-1) cnt++;
        }
    } while(next_permutation(perm.begin(), perm.end()));

    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
const int sep = 64;
typedef unsigned long long ulint;
typedef pair<int, int> Pr;
typedef tuple<int, int, int> Tp;

int n, m, A, B, Q;
vector<vector<Pr>> g;
int qs[40000], qt[40000];

vector<vector<int>> mg;
vector<vector<int>> rmg;
vector<vector<int>> pre;
vector<vector<int>> rpre;
vector<int> tps, pos;
bool visit[100000];
ulint dp[100000];
bool ans[40000];

void dijkstra()
{
	mg = rmg = vector<vector<int>>(n);
	
	vector<int> dist(n, INF);
	dist[A] = 0;
	
	priority_queue<Pr, vector<Pr>, greater<Pr>> pq;
	pq.push(Pr(0, A));
	while (pq.size()){
		Pr p = pq.top(); pq.pop();
		int pos = p.second, sum = p.first;
		if (dist[pos] < sum) continue;
		
		for (auto &e : g[pos]){
			int to = e.first, cost = e.second;
			if (dist[to] > sum + cost){
				dist[to] = sum + cost;
				pq.push(Pr(sum + cost, to));
			}
		}
	}
	
	for (int v = 0; v < n; v++){
		for (auto &e : g[v]){
			int to = e.first, cost = e.second;
			if (dist[to] == dist[v] + cost){
				mg[v].push_back(to);
				rmg[to].push_back(v);
			}
		}
	}
}

void toposort(int v)
{
	visit[v] = true;
	
	for (int to : rmg[v]){
		if (!visit[to]) toposort(to);
	}
	
	pos[v] = tps.size();
	tps.push_back(v);
}

void doDp(int qs[], int qt[], bool ans[])
{
	fill_n(dp, 100000, 0);
	
	for (int i = 0; i < sep; i++){
		dp[pos[qs[i]]] |= 1ull << i;
	}
	
	for (int i = 0; i < tps.size(); i++){
		for (int to : mg[tps[i]]){
			if (pos[to] == -1) continue;
			//printf("%d -> %d\n", tps[i], to);
			dp[pos[to]] |= dp[i];
		}
	}
	
	for (int i = 0; i < sep; i++){
		if (pos[qt[i]] == -1) ans[i] = false;
		else {
			ans[i] = (dp[pos[qt[i]]] & (1ull << i)) ? true : false;
		}
	}
}

void solve()
{
	dijkstra();
	
	fill_n(visit, n, false);
	tps = vector<int>();
	pos = vector<int>(n, -1);
	toposort(B);
	
	for (int i = 0; i < Q; i += sep){
		doDp(qs + i, qt + i, ans + i);
	}
	
	for (int i = 0; i < Q; i++){
		puts(ans[i] ? "Yes" : "No");
	}
}

int main()
{
	scanf("%d %d", &n, &m);
	
	g = vector<vector<Pr>>(n);
	
	for (int i = 0; i < m; i++){
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		g[--u].push_back(Pr(--v, w));
		g[v].push_back(Pr(u, w));
	}
	scanf("%d %d %d", &A, &B, &Q);
	--A; --B;
	for (int i = 0; i < Q; i++){
		scanf("%d %d", &qs[i], &qt[i]);
		qs[i]--; qt[i]--;
	}
	
	solve();
}

Measured memory_bytes: 27364
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
//#define lli long long int
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define pci pair<char,int
#define mii map<int,int>
#define mll map<long long int,long long int>
#define mci map<char,int>
#define umii unordered_map<int,int>
#define umll unordered_map<long long int,long long int>
#define umci unordered_map<char,int>
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define mod 1000000007
using namespace std;
ll visit[100001]={0};
vector<ll> adj[1000001];

bool sortinrev(const pair<ll,ll> &a,  
               const pair<ll,ll> &b) 
{
       if(a.first!=b.first) return(a.first > b.first);
       else return (a.second<b.second);
} 
ll power(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)%m;
        n=n/2;
    }
    return result%m;
}
bool isPrime(ll k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    ll i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}
 
ll bin(ll n)
{
    int di= 0;
    while(n)
    {   di=di+n%10;
        n=n/10;
        
    }
    return di;
}
ll coun(auto v, vector<ll> a, ll x)
{
	ll ans1 = 0;
	for(auto i=v;i!=a.end();i++)
	{
		while(1)
		{
			ans1++;
			if(x>=*i)
			{
				x = *i;
				break;
			}
			x*=2;
		}
		x*=2;
	}
	ans1=ans1+v-a.begin();
	return ans1;
}
int main(){
   IOS;
ll t1;t1=1;
while(t1--){
ll n;cin>>n;
ll ans[n+1]={0};
for(ll i=1;i<=100;i++){
    for(ll j=1;j<=100;j++){
        for(ll k=1;k<=100;k++){ll z=i*i+j*j+k*k+i*j+j*k+k*i;
            if(i*i+j*j+k*k+i*j+j*k+k*i<=n) {
                ans[z]++;
            }
        }
    }
}
for(ll i=1;i<=n;i++) cout<<ans[i]<<"\n";
}



return 0;}

Measured memory_bytes: 27088
#include <cstdio>
#include <algorithm>
using namespace std;

void bubbleSort(int A[],int N){
	bool flag=false;
	int cnt=0;
	do{
		flag=false;
		for(int i=0;i<N-1;++i){
			if(A[i]>A[i+1]){
				swap(A[i],A[i+1]);
				cnt++;
				flag=true;
			}
		}
	} while(flag);
	for(int i=0;i<N;++i){
		if(i==0) printf("%d",A[i]);
		else printf(" %d",A[i]);
	}
	puts("");
	printf("%d\n",cnt);
}

int main(){
	int N;scanf("%d",&N);
	int A[100];
	for(int i=0;i<N;++i) scanf("%d",&A[i]);
	bubbleSort(A,N);
}



Measured memory_bytes: 2736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int r;
    cin >> r;
    cout << r*r << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a, b, c, x;

int main(void)
{
	cin >> a >> b >> c >> x;
	
	int ans = 0;
	for(int i = 0; i <=  a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if(500*i + 100*j + 50*k == x) ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define loop(i,start, stop) for(int i = start; i < (stop); i++)
using namespace std;

int main(){
  
  string S;
  cin >> S;

  int ans = 0;

  if (S[0] == 'R' && S[1] == 'R' && S[2] == 'R') {cout << 3 << endl;}
  else if (S[0] == 'R' && S[1] == 'R') {cout << 2 << endl;}
  else if (S[1] == 'R' && S[2] == 'R') {cout << 2 << endl;}
  else if (S[0] == 'R' || S[1] == 'R' || S[2] == 'R') {cout << 1 << endl;}
  else {cout << 0 << endl;}

  return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans = 0;
    if (a <= k){
        ans += a;
        k -= a;
    }else{
        ans += k;
        cout << ans << endl;
        return 0;
    }

    if (k <= 0){
        cout << ans << endl;
        return 0;
    }

    if (b <= k){
        k -= b;
    }else{
        cout << ans << endl;
        return 0;
    }

    if (k <= 0){
        cout << ans << endl;
        return 0;
    }

    if (c <= k){
        ans -= c;
        k -= c;
    }else{
        ans -= k;
        cout << ans << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define MAX_N 500000
#define dat 7368800
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
int table[500001];
int main() {
	int M,N;
	vector<int> v;
	
	//?´???°??¨
	v.pb(2);
	for(int i=3; i <= dat; i+=2) {
		bool add = true;
		rep(j,0,v.size()) {
			if(v[j] * v[j] > i) break;
			if(i % v[j] == 0) {
				add = false;
				break;
			}
		}
		if(add) v.pb(i);
	}
	
	while(cin >> M >> N) {
		bool n[dat];
		
		//cout << "A" << endl;
		memset(n, false, sizeof(n));
		memset(table, 0, sizeof(table));
		
		
		if(M == 0 && N == 0) break;
		
		if(M > N) {
			cout << M+N << endl;
			continue;
		}
		
		
		int cnt = 0; //??\??????????????°???????????????
		int i = M;
		while(cnt != N) {
			if(!n[i]) { //??\??????????????°???????????????
				table[cnt] = i;
				cnt++;
				
				//n?????????????????´??°
				int num = 1;
				while(i * num <= dat) {
					n[i * num] = true;
					num++;
					//cout << "while " << endl;
				}
			}
			i++;
			//cout << "test  " << i << endl;
		}
		//rep(j,0,cnt) cout << table[j] << endl;
		cout << *upper_bound(v.begin(), v.end(), table[cnt-1]) << endl;
	}
	return 0;
}

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

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = max({(A + B), (A - B), (A * B)});
  cout << ans << endl;
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input! {
        s: chars
    }

    let mut cnt = count(&s);
    *cnt.entry('o').or_insert(0) += 15 - s.len();
    println!("{}", if cnt[&'o'] >= 8  {"YES"} else {"NO"});
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

Measured memory_bytes: 4352
h, w = map(int, input().split())
l = [input() for i in range(h)]
idh=[]
idw=[]

for i in range(w):
    fl = True
    for j in range(h):
        if l[j][i]=='#':
            fl=False
    if fl:
        idw.append(i)
for i in range(h):
    if l[i].count('#')==0:
        idh.append(i)
for i in range(h):
    if i in idh:
        continue
    for j in range(w):
        if j in idw:
            continue
        print(l[i][j], end='')
    print('')

Measured memory_bytes: 42600
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int a = sc.nextInt();
		
		while(n >= 0) {
			n = n-500;
		}
		
		if(n == 0) {
			System.out.println("Yes");
		}else {
			n = n + 500;
			if(n <= a) {
				System.out.println("Yes");
			}else {
				System.out.print("No");
			}
		}
		
		sc.close();
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 1e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________

int main()
{
       speed;
       int a[3];
       arrin(a,3);
       cout<<a[2]<<" "<<a[0]<<" "<<a[1]<<endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#define pb push_back
std::map<int, int> mem[200005];
std::vector<int> adj[200005];
int ans[200005];
int calc(int u, int fa, int lim, bool force = false)
{
	if (!force && u > lim)
		return 0;
	if (mem[u].count(lim))
		return mem[u][lim];
	int &res = mem[u][lim];
	res = 1;
	for (int v : adj[u])
	{
		if (v != fa)
			res += calc(v, u, lim);
	}
	return res;
}
void dfs(int u, int fa = -1, int mx = -1, int lst = -1)
{
	if (u)
		ans[u] += calc(u, fa, mx, true) - calc(u, fa, lst);
	for (int v : adj[u])
	{
		if (v == fa)
			continue;
		ans[v] = ans[u];
		dfs(v, u, std::max(mx, u), mx);
	}
}
int main()
{
	// freopen("AGC029-E.in", "r", stdin);
	int n;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[--u].pb(--v);
		adj[v].pb(u);
	}
	dfs(0);
	for (int i = 1; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}


Measured memory_bytes: 50816
import sys
sys.setrecursionlimit(10 ** 6)

def solve():
    S = input()
    # print(S, len(S))

    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    def recur(i):
        if i >= len(S):
            return True

        for word in words:
            if S[i:i + len(word)] == word:
                if recur(i + len(word)):
                    return True
        return False

    ans = recur(0)

    return ans


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 58480
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <tuple>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for (int i=0;i<n;i++)

ll mod = 1e9+7;

// 階乗
ll factorial(ll a){
    if (a==1){
        return 1;
    }
    return a * (factorial(a-1));
}

//組み合わせの数
ll nCr(ll n,ll r){
    return factorial(n)/factorial(r);
}

//重複する組み合わせの数
ll nHr(ll n,ll r){
    return factorial(n+r-1)/factorial(r);
}

int main(){
    int a,b;
    cin >> a >> b;
    int ans = a + b;
    if (a - b > ans){
        ans = a - b;
    }
    if (a*b>ans){
        ans = a * b;
    }
    cout << ans << endl;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

using int64 = long long;

map< int64, int > prime_factor(int64 n)
{
  map< int64, int > ret;
  for(int64 i = 2; i * i <= n; i++){
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return(ret);
}


void solve(long long X){
    for(i64 i = -3100; i < 6100; ++i){
        // A^5 = X + B^5
        i64 B = i * i * i * i * i;
        if(X + B < 0) continue;
        if(X + B == 0){
            cout << 0 << " " << i << endl;
            return;
        }
        auto factors = prime_factor(X + B);
        i64 a = 1;
        bool flag = true;
        for(auto factor : factors){
            if(factor.second % 5 != 0) flag = false;
            rep(j, factor.second / 5) a *= factor.first;
        }
        if(flag){
            cout << a << " " << i << endl;
            return;
        }
    }
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[] an = new String[h];
        for (int i = 0; i < h; i++) {
            an[i] = sc.next();
        }

        String sh = "";
        for (int i = 0 ; i < w + 2; i++) { // edge width edge
            sh += "#";
        }

        System.out.println(sh);
        for (int i = 0; i < h; i++) {
            System.out.print("#");
            System.out.print(an[i]);
            System.out.print("#");
            System.out.println();
        }
        System.out.println(sh);
    }

}

Measured memory_bytes: 22228
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
int w[N_], n,C[N_][2], even;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &w[i]);
		C[w[i]][i % 2]++;
	}
	int odd = 0;
	for (i = 1; i <= 100000; i++) {
		even = max(even, odd + C[i][1]);
		odd = max(odd, C[i][0]);
	}
	odd = 0;

	for (i = 1; i <= 100000; i++) {
		even = max(even, odd + C[i][0]);
		odd = max(odd, C[i][1]);
	}
	printf("%d\n", n - even);
}

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

void solve(){
  int n;
  cin>>n;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  string s;
  cin>>s;
  if(s[n-1]=='1'){
    cout<<1<<endl;
    return;
  }
  reverse(vec,vec+n);
  reverse(s.begin(),s.end());
  vector<ll> bases;
  for(int i=0;i<n;i++){
    for(ll base:bases){
      vec[i]=min(vec[i],vec[i]^base);
    }
    if(vec[i]){
      if(s[i]=='0'){
        bases.push_back(vec[i]);
      }
      else{
        cout<<1<<endl;
        return;
      }
    }
  }
  cout<<0<<endl;
}

int main(){
  int t;
  cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

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

    // 初期化は既に 0 に初期化される
    // 初期条件も既に 0 で OK

    // ループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == k) continue;
                chmax(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }

    // 答え
    long long res = 0;
    for (int j = 0; j < 3; ++j) chmax(res, dp[N][j]);
    cout << res << endl;
}


Measured memory_bytes: 4992
package main

import (
	"fmt"
)

func abs(n int) (m int) {
	if n < 0 {
		m = -n
	} else {
		m = n
	}
	return
}

func rune2int(r rune) int {
	return int(r) - 48
}

func main() {
	var s string
	fmt.Scan(&s)
	var diff int = 753
	for i := 0; i < len(s)-2; i++ {
		var tmp int = rune2int(rune(s[i]))*100 + rune2int(rune(s[i+1]))*10 + rune2int(rune(s[i+2]))*1
		if y := abs(753 - tmp); y < diff {
			diff = y
		}
	}
	fmt.Println(diff)
}


Measured memory_bytes: 512
#関数リスト
import sys
input = sys.stdin.readline
 
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

num = I()
result = ""
alphabet = [chr(ord('a') + i) for i in range(26)]

while True:
    num -= 1
    result = alphabet[num % 26] + result
    num //= 26
    if num == 0:
        break
print(result)

Measured memory_bytes: 9196
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
  ll N, K, a, b, ans = 0;
  cin >> N >> K;
  if (K == 0) {
    cout << N*N << endl;
    return 0;
  }
  for (int i = 1; i <= N - K; i++) {
    b = K + i;
    ans += N/b*i + max(0LL, N%b - K + 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace A___Tenki
{
    class Program
    {
        static void Main (string[] args)
        {
            var s = Console.ReadLine ();
            var t = Console.ReadLine ();
            var ans = 0;
            for (var i = 0; i < 3; i++)
            {
                if (s[i] == t[i])
                {
                    ans++;
                }
            }
            Console.WriteLine (ans);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

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

    int n; cin >> n;
    vi a(n),s(n+1,0); 
    rep(i,n){
        cin >> a[i];
        s[i+1]=s[i]+a[i];
        s[i+1]%=MOD;
    }
    int res=0;
    rep(i,n){
        int sum=s[n]-s[i+1];
        if(sum<0) sum+=MOD;
        res+=a[i]*sum%MOD;
        res%=MOD;
    }
    cout<<res<<endl;
    
}

Measured memory_bytes: 6356
N, A, B = list(map(int, input().split()))

# 各桁の和を計算する関数
def find_sum_of_digits(n):
    sum_num = 0
    while (n>0):
        sum_num += n % 10
        n = n // 10
    return sum_num

total = 0
for i in range(N+1):
    sum_num = find_sum_of_digits(i)
    if A <= sum_num <= B:
        total += i
print(total)

Measured memory_bytes: 39408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(all(a)); reverse(all(a));
	ll ans = a[0];
	for (int i = 2; i < n; i++) ans += a[i / 2];
	cout << ans << '\n';
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};



int main(){
    ll N, M; cin >> N >> M;
    vector<ll> a(M), b(M);
    for(int i=0; i<M; i++) cin >> a[i] >> b[i];

    ll tmp = N*(N-1)/2;
    vector<ll> ans(M);
    ans[M-1] = tmp;

    UnionFind uni(N);
    for(int i=M-1; i>=1; i--){
        if(uni.root(a[i]-1) != uni.root(b[i]-1)){
            tmp -= uni.size(a[i]-1)*uni.size(b[i]-1);
            uni.connect(a[i]-1, b[i]-1);
        }
        ans[i-1] = tmp;
    }

    for(int i=0; i<M; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
int main(){
  double a,b,x;
  cin>>a>>b>>x;
  double V=a*a*b/2;
  if(x==V){
    cout<<fixed<<setprecision(10)<<180*atan(1)/M_PI<<endl;
  }
  else if(x>V){
    double c=2*(a*a*b-x)/(a*a*a);
    cout<<fixed<<setprecision(10)<<180*atan(c)/M_PI<<endl;
  }
  else{
    double d=a*b*b/(2*x);
    cout<<fixed<<setprecision(10)<<180*atan(d)/M_PI<<endl;
  }
}

Measured memory_bytes: 256
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
a = lmp()
mod = int(1e9+7)
ans = 0
num = sum(a)
for i in range(n-1):
    u = num - a[i]
    ans += a[i] * u
    ans %= mod
    num = u
print(ans)



Measured memory_bytes: 94216
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<
pair<int,int>,
null_type,
less<pair<int,int> >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int n, t;
vector<int> a;
long long ans;
ordered_set sl, sr;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	a.resize(3*n);
	for(int i = 0; i < 3*n; i++) cin >> a[i];
	long long suml = 0, sumr = 0;
	for(int i = 0; i < n; i++) sl.insert(make_pair(a[i], ++t)), suml += a[i];
	for(int i = n; i < 3*n; i++) sr.insert(make_pair(a[i], ++t));
	for(int i = 0; i < n; i++) sumr += sr.find_by_order(i)->first;
	ans = suml - sumr;
	for(int i = n; i < 2*n; i++) {
		if(a[i] > sl.begin()->first) {
			suml = suml - sl.begin()->first + a[i];
			sl.erase(*sl.begin());
			sl.insert(make_pair(a[i], ++t));
		}
		int idx = sr.order_of_key(make_pair(a[i], INT_MAX));
		assert(sr.find_by_order(idx-1)->first == a[i]);
		sr.erase(*sr.find_by_order(idx-1));
		if(idx <= n) sumr = sumr - a[i] + sr.find_by_order(n-1)->first;
		ans = max(suml - sumr, ans);
	}
	cout << ans;
}


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


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

  if (a % 3 == 0 ||
      b % 3 == 0 ||
      (a + b) % 3 == 0) {
    cout << "Possible" << endl;
  } else {
    cout << "Impossible" << endl;
  }
  
  return 0;
}

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

int main(){
  string s;
  int flag_a = 0;
  int flag_b = 0;
  int flag_c = 0;
  
  cin >> s;
  for(int i = 0; i< s.length(); i++){
      if(s[i] == 'a'){
          flag_a = 1;
      } else if(s[i] == 'b'){
          flag_b = 1;
      } else if(s[i] == 'c'){
          flag_c = 1;
      }
  }

  
  if(flag_a == 1 && flag_b == 1 && flag_c == 1){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}
    

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
using namespace std;

map<int, int>a;

int main()
{
	int n, tmp;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> tmp;
		a.insert(pair<int, int>(tmp, i));
	}

	map<int, int>::iterator start = a.begin();
	for (; start != a.end(); start++)
		cout << start->second << ' ';

	return 0;
}

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

int n;
int L[100003];

inline int read(){
	int X=0,w=0;
	char ch=0;
	while (ch<'0' || ch>'9')
	  w|=ch=='-',ch=getchar();
	while (ch>='0' && ch<='9')
	  X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
	return w ? -X : X;
}

int main(){
	n=read();
	for (int i=1;i<=n;i++)
	  L[i]=read();
	sort(L+1,L+1+n);
	int sum=0;
	for (int i=1;i<=n-1;i++)
	  sum+=L[i];
	if (sum>L[n]) printf("Yes");
	  else puts("No"); 
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
    int n;
    string str;
    cin>>n;
    cin>>str;
    int len=str.length();
    for(int i=0;i<len;i++)
    {
        int ch=str[i]-'A';
        ch=(ch+n)%26;
        cout<<char(ch+'A');
    }
    cout<<endl;
}


Measured memory_bytes: 256