akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

long long COM(long long n, long long k) {
    long long mul = 1;
    long long div = 1;
    for (long long i = 0; i < k; i++) {
        mul = (mul * (n - i));
        div = (div * (i + 1));
    }
    return mul / div;
}

//--------------------------- Solve ---------------------------//

void solve() {
    int N, M; cin >> N >> M;
    vector<long long> A(N+1);
    map<int, int> mp;
    set<int> s;

    mp[0]++;
    s.insert(0);
    for (int i = 1; i < N+1; i++) {
        cin >> A[i];
        A[i] += A[i-1];
        mp[A[i] % M]++;
        s.insert(A[i] % M);
    }

    long long ans = 0;

    for (auto e : s) {
        if (mp[e] > 1) {
            ans += COM(mp[e], 2);
        }
    }

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

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

    return 0;
}

Measured memory_bytes: 9744
#include<iostream>
#include<math.h>
#include<map>
using namespace std;

int main(){

    long long int i,l,r,j,ans=0,cnt=0,res,n,m,t=0;
    cin >> n;
    for(i=1;i<=n;i++){
        res = n/i;
        ans += res*i*(res+1)/2;
    }
    cout << ans;
}



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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};


int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int M=max(a,b);
	M=max(M,c);
	cout<<(a+b+c)-M<<endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
h=list(map(int,input().split()))
def ch_min(a,b):
    if a>b:
        return b
    
    return a
def solve():
    dp=[float('inf')]*n
    dp[0]=0

    for i in range(1,n):
    
        for j in range(1,1+k):
            if i-j>=0:
                dp[i]=ch_min(dp[i],dp[i-j]+abs(h[i]-h[i-j]))
                
                if dp[i]==0:
                    break
                
    print(dp[-1])
    

solve()

Measured memory_bytes: 54624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

signed main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	int n;
	cin >> n;
	int v[n], c[n];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	int res[n];
	for (int i = 0; i < n; i++) {
		res[i] = v[i] - c[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (res[i] > 0) ans += res[i];
	}
	cout << ans << "\n";
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
	int n, l;
	char teks[110];
	string kata;
	vector<string> hasil;
	scanf("%d %d\n", &n, &l);
	for (int i = 0; i < n; i++) {
		scanf("%s\n", teks);
		kata = teks;
		hasil.push_back(kata);
	}
	sort(hasil.begin(), hasil.end());
	for (int i = 0; i < n; i++)
		printf("%s", hasil[i].c_str());
	printf("\n");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,x,y;
	cin>>n>>x>>y;
	vl v(n);
	rep(i,n)cin>>v[i];
	if(n==1) cout<<abs(v[0]-y)<<endl;
	else cout<<max(abs(v[n-1]-y),abs(v[n-2]-v[n-1]))<<endl;
}



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

int main() {
    int H, W, D; cin >> H >> W >> D;
    int N = H * W;
    vector<P> A(N+1);
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            int a; cin >> a;
            A[a] = make_pair(i, j);
        }
    }

    vector<int> x(N+1);
    for (int i = 1; i <= D; i++){
        int now = i;
        while(now+D <= N){
            P l = A[now];
            P r = A[now+D];
            int kyori = abs(l.first - r.first) + abs(l.second - r.second);
            x[now+D] = x[now] + kyori;
            now += D;
        }
    }

    int Q; cin >> Q;
    rep(i, Q){
        int L, R; cin >> L >> R;
        int ans = x[R] - x[L];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 4240
/*input
akasaka

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ld l;
  cin >> l;
  ld a = l / 3.0;
  cout << fixed << setprecision(15) << a * a * a << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int c;
        int[] ice = new int[10];

        while((n = sc.nextInt())!=0){
            for(int i=0;i<n;i++){
                c = sc.nextInt();
                ice[c]++;
            }
            for(int i=0;i<10;i++){
                if(ice[i]==0){System.out.print("-");}
                else{
                    for(int j=0;j<ice[i];j++){
                        System.out.print("*");
                    }
                }
                System.out.println("");
                ice[i]=0;
            }
        }
        
    }
}


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

/*
提出前に確認!
- setとmultisetを間違えない
*/

long long floor_sum(int a, int b, int n, int m)
{
	long long ans = 0;
	if (a >= m)
	{
		ans += (long long)n * (n - 1) * (a / m) / 2;
		a %= m;
	}
	if (b >= m)
	{
		ans += (long long)b / m * n;
		b %= m;
	}
	long long y_max = ((long long)n * a + b) / m;
	if (y_max == 0) return (ans);
	long long x_max = m * y_max - b;
	ans += (n - (x_max + a - 1) / a) * y_max;
	ans += floor_sum(m, (a - x_max % a) % a, y_max, a);
	return (ans);
}

int	main(void)
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		int n, m, a, b;
		cin >> n >> m >> a >> b;
		cout << floor_sum(a, b, n, m) << endl; 
	}
	return (0);
}


Measured memory_bytes: 3620
<?php
fscanf(STDIN,"%d %d %d %d",$a,$b,$c,$k);
if($k>=$a+$b+$c){
    $sum=$a-$c;
}elseif($k<=$a && $k<=$a+$b){
    $sum=$k;
}else{
    $k-=$a;
    $k-=$b;
    if($k<=0){
        $sum=$a;
    }else{
        $sum=$a-$k;
    }
}
echo $sum;

Measured memory_bytes: 15964
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;
std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}
std::set<int> factor(int n, const std::vector<int>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::set<int> res;
  while (n > 1) {
    res.insert(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}
void solve()
{
	int n;
	cin>>n;
	bool pairwise=true;
	int setwise=1;
	vector<int>minf=sieve(1000001);
	set<int>used;
	rep(i,n){
		int a;
		cin>>a;
		if(!i){
			setwise=a;
		}else{
			setwise=gcd(a,setwise);
		}
		set<int>fac=factor(a,minf);
		for(auto i=fac.begin();i !=fac.end(); i++){
			if(used.count(*i) and *i!=1){
				pairwise=false;
			}else{
				used.insert(*i);
			}
		}
	}
	if(pairwise){
		cout<<"pairwise coprime"<<endl;
	}else if(setwise==1){
		cout<<"setwise coprime"<<endl;
	}else{
		cout<<"not coprime"<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 10832
import sys
import itertools
k, n = map(int, sys.stdin.buffer.readline().split())
a = list(map(int, sys.stdin.buffer.readline().split()))
a.append(a[0] + k)
b, c = itertools.tee(a)
next(c)
ans = k - max(y - x for x, y in zip(b, c))
print(ans)


Measured memory_bytes: 27980
n=int(input())
l=list(map(int,input().split()))
s=[0]*8
a=0
for i in l:
    if i<400:
        s[0]+=1
    elif i<800:
        s[1]+=1
    elif i<1200:
        s[2]+=1
    elif i<1600:
        s[3]+=1
    elif i<2000:
        s[4]+=1
    elif i<2400:
        s[5]+=1
    elif i<2800:
        s[6]+=1
    elif i<3200:
        s[7]+=1
    else:
        a+=1
#print(s)
b=0
for i in s:
    if i!=0:
        b+=1
print(max(1,b),b+a)    

Measured memory_bytes: 3064
#include<iostream>
#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;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    string s, t;
    cin >> s >> t;
    cout << t << s << "\n";
}

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

int s, d, m;
int k[302], w[302][302], p[302][302];
int f[302];

//dp1[i][j][k] : 甘味セットiの種類jまでで, 価格j分買い込んだときの, 最大体重
int dp1[102][52][302];
int dp2[102][302]; //期間iまでで, 価格jを使ったときの, 最大体重

void calcDP2(){
  memset(dp2, -1, sizeof(dp2));
  dp2[0][0] = 0;

  for(int i = 0; i < d; i++){ //期間i
    int st = f[i]; //期間iの甘味セット番号

    for(int j = 0; j <= m; j++){ //使った価格j
      if(dp2[i][j] == -1) continue;

      for(int l = 0; j + l <= m; l++){ //今から使おうとする価格l
	if(dp1[st][k[st]][l] == -1) continue;
	dp2[i + 1][j + l] = max(dp2[i + 1][j + l], dp2[i][j] + dp1[st][k[st]][l]);
      }
    }
  }
}

void calcDP1(){
  memset(dp1, -1, sizeof(dp1));

  for(int i = 0; i < s; i++){ //甘味セット番号
    dp1[i][0][0] = 0;

    for(int j = 0; j < k[i]; j++){ //甘味セットiの商品番号
      for(int l = 0; l <= m; l++){ //買い込んだ価格
	if(dp1[i][j][l] == -1) continue;
	int nj = j + 1;

	dp1[i][nj][l] = max(dp1[i][nj][l], dp1[i][j][l]);

	int nl = l + p[i][j];
	if(nl > m) continue;

	dp1[i][nj][nl] = max(dp1[i][nj][nl], dp1[i][j][l] + w[i][j]);
      }
    }
  }
}

void solve(){
  calcDP1();
  calcDP2();

  int maxEikyo = -1;
  int minCost = 0;

  for(int i = 0; i <= m; i++){
    if(maxEikyo < dp2[d][i] || maxEikyo == dp2[d][i] && minCost > i){
      maxEikyo = dp2[d][i];
      minCost = i;
    }
  }

  cout << maxEikyo << " " << minCost << endl;
}

int main(){
  while(cin >> s >> d >> m){
    for(int i = 0; i < s; i++){
      cin >> k[i];

      for(int j = 0; j < k[i]; j++){
	cin >> w[i][j] >> p[i][j];
      }
    }

    for(int i = 0; i < d; i++){
      cin >> f[i];
    }

    solve();
  }
}

Measured memory_bytes: 7788
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef complex<double> xy_t;
typedef vector<lint> poly;
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;}

const lint mod = 1e9+7;
const lint INF = mod;
const int MAX = 100010;

lint powmod(lint x, lint n){
    lint ret = 1;
    while(n > 0){
        if(n&1) ret *= x, ret %= mod, n -= 1;
        else x *= x, x %= mod, n >>= 1;
    }
    return ret;
}

int main(){
    int n;
    scanf("%d", &n);
    lint a[n];
    rep(i, n) scanf("%lld", &a[i]);
    lint cnt[62][2];
    rep(i, 62)rep(j, 2) cnt[i][j]=0;
    rep(i, n)rep(j, 62){
        ++cnt[j][(a[i]>>j)&1];
    }
    lint ans=0;
    rep(i, 62){
        (ans+=cnt[i][0]*cnt[i][1]%mod * powmod(2, i)%mod)%=mod;
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;

int g[10][10]={};


int dfs(int s,int N,vector<bool>used){
  bool flag=true;
  rep(i,N){
    if(used[i]==false){
      flag=false;
    }
  }
  if(flag)return 1;
  int sum=0;
  rep(i,N){
    if(g[s][i]==0)continue;
    if(used[i])continue;
    used[i]=true;
    sum+=dfs(i,N,used);
    used[i]=false;
  }
  return sum;
}


signed main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a][b]=1;
    g[b][a]=1;
  }
  vector<bool> used(n);
  used[0]=true;
  cout<<dfs(0,n,used)<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            int tmp = i;
            int sum = 0;
            while(tmp != 0) {
                sum += (tmp%10);
                tmp /= 10;
            }
            if(sum >= a && sum <= b) {
                ans += i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22100
import sys

N=int(input())
s=set()

w=input()
s.add(w)
tmp=w[-1]

for i in range(N-1):
    w=input()

    if w in s or tmp!=w[0]:
        print("No")
        sys.exit()
    else:
        s.add(w)
        tmp=w[-1]

print("Yes")

Measured memory_bytes: 3064
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

N,W = map(int,(input().split()))
wv = [[] for i in range(4)]


w,v = map(int,(input().split()))
min_w = w
wv[0].append(v)

for i in range(N-1):
	w,v = map(int,(input().split()))
	wv[w-min_w].append(v)

wv[0].sort(reverse=True)
wv[1].sort(reverse=True)
wv[2].sort(reverse=True)
wv[3].sort(reverse=True)
L1 = len(wv[0])
L2 = len(wv[1])
L3 = len(wv[2])
L4 = len(wv[3])

SUM = 0
sum_wv1 = [0]
for i in range(L1):
	SUM += wv[0][i]
	sum_wv1.append(SUM)

SUM = 0
sum_wv2 = [0]
for i in range(L2):
	SUM += wv[1][i]
	sum_wv2.append(SUM)

SUM = 0
sum_wv3 = [0]
for i in range(L3):
	SUM += wv[2][i]
	sum_wv3.append(SUM)

SUM = 0
sum_wv4 = [0]
for i in range(L4):
	SUM += wv[3][i]
	sum_wv4.append(SUM)

ans = 0

for n1 in range(L1+1):
	for n2 in range(L2+1):
		for n3 in range(L3+1):
			for n4 in range(L4+1):
				weight = min_w*(n1+n2+n3+n4) + n2 + 2*n3 + 3*n4
				if weight <= W:
					ans = max(ans,sum_wv1[n1]+sum_wv2[n2]+sum_wv3[n3]+sum_wv4[n4])

print(ans)

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

int main() {

	int a,i;
	i = 1;
	while (1) {
		cin >> a;
		if (a == 0) {
			break;
		}
		cout << "Case " << i << ": " << a << endl;
		i++;
	}

	return 0;
}

Measured memory_bytes: 1160
n,k=map(int,input().split())
xy=[list(map(int,input().split())) for _ in [0]*n]
xy=sorted(xy,key=lambda x:x[0])
temp=[]
for i in range(n):
    for j in range(i+k-1,n):
        temp.append([xy[j][0]-xy[i][0]]+sorted([y for x,y in xy[i:j+1]]))
m=10**19      
for t in temp:
    l=len(t)-1
    for i in range(1,l-k+2):
        m=min(m,t[0]*(t[i+k-1]-t[i]))
print(m)

Measured memory_bytes: 3316
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		String S = input.next();
		int w = input.nextInt();
		String t="";
		
		for (int i=0;i<S.length();i++)
		{
			if (i%w==0) 
				System.out.print(S.substring(i, i+1)); 
		}		
	}
}


Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            int i, j;
            if (h == 0 && w == 0) break;
            for (i = 0; i < h; i++) {
                for (j = 0; j < w; j++) {
                    System.out.print("#");
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}



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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vii;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

//constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	if ((a + b) % 2 == 1) cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n;
  ll r = 0, g = 0, b = 0;
  string s;
  cin >> n >> s;

  REP(i, n) {
    if(s[i] == 'R')
      r++;
    else if(s[i] == 'G')
      g++;
    else
      b++;
  }

  ll ans = r * g * b;

  for(int j = 1; j < n; ++j) {
    for(int i = 0; i < j; ++i) {
      int k = 2 * j - i;
      if(k < n) {
        ans -= s[i] != s[j] and s[j] != s[k] and s[k] != s[i];
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
import java.util.*;
class Main{
   static boolean solve(int n,int A[],int i,int m){
	if(m == 0)return true;
	if(i >= n)return false;
	return solve(n,A,i+1,m) || solve(n,A,i+1,m-A[i]);
    }
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int num1[] = new int[n];
	for(int i = 0; i< n; i++){
	    num1[i] = sc.nextInt();
	}
	
	int q = sc.nextInt();
	for(int i = 0; i < q; i++){
	    int m = sc.nextInt();
	    int j = 0;
	    if(solve(n,num1,j,m)){
		System.out.println("yes");
	    }
	    else System.out.println("no");
	}
	
    }
}


Measured memory_bytes: 26840
// #define CPP_IO

#pragma region

#include <bits/stdc++.h>
using namespace std;
using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
template <typename T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using maxheap = priority_queue<T>;

#define f first
#define s second

#ifdef LOCAL
#define debug cout
#define debugf(format, ...) printf(format, ##__VA_ARGS__)
#else
#define debug \
    if (0) cout
#define debugf(format, ...) 42
#endif

#define DUMP(a) debug << #a " = " << (a) << "\n";
#define DUMP2(a, b) debug << #a " = " << (a) << " " #b " = " << (b) << "\n";
#define DUMP3(a, b, c) debug << #a " = " << (a) << " " #b " = " << (b) << " " #c " = " << (c) << "\n";
#define DUMP4(a, b, c, d) debug << #a " = " << (a) << " " #b " = " << (b) << " " #c " = " << (c) << " " #d " = " << (d) << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[ ";
    for (auto e : v) os << e << " ";
    return os << "]";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, set<T, V> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V, typename S>
ostream& operator<<(ostream& os, map<T, V, S> v) {
    os << "{ ";
    for (auto e : v) os << e << " ";
    return os << "}";
}

template <typename T, typename V>
ostream& operator<<(ostream& os, pair<T, V> x) {
    return os << "( " << x.first << ", " << x.second << " )";
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& e : v) is >> e;
    return is;
}

template <typename T, typename V>
istream& operator>>(istream& is, pair<T, V>& x) {
    return is >> x.first >> x.second;
}

void solve();

int main() {
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#else
#ifdef CPP_IO
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
#endif
    solve();
}

#pragma endregion

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    cin >> a >> b >> c;
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        --a[i];
        sum += b[a[i]];
    }
    for (int i = 0; i < n - 1; ++i) {
        if (a[i + 1] == a[i] + 1) {
            DUMP(i);
            sum += c[a[i]];
        }
    }
    cout << sum << "\n";
}

Measured memory_bytes: 256
var output;
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var one = myconv(next(),4);
  var N = one[0];
  var K = one[1];
  var list = myconv(next(),4);
  var output = 0;
  for(var i = 1; i < N; i++){
    var mae = list[i - 1];
    var ato = list[i];
    if(mae + ato > K){
       var minus = (mae + ato) - K;
      output += minus;
       list[i] = Math.max(0,list[i] - minus);
       if(ato < minus){
          minus -= ato;
         list[i - 1] = Math.max(0,list[i - 1] - minus);
       }
    }
  }
  myout(output);
}


Measured memory_bytes: 17944
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

	int A = sc.nextInt();
	int B = sc.nextInt();
	int C = sc.nextInt();

	if (C >= A && B >= C) {
		System.out.println("Yes");
	}else{
		System.out.println("No");
	}

	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;

	int N, M, K;
	int Q;
	cin >> Q;
	//Q = 100000;
	const int MaxN = 100000;
	pairII q[MaxN];
	rep(i, 0, Q) {
		cin >> q[i].first >> q[i].second;
	}

	bool isPrime[MaxN + 1];

	isPrime[1] = false;
	isPrime[2] = true;
	rep(i, 3, MaxN + 1) {
		isPrime[i] = true;

		M = sqrt(i) + 1;
		rep(j, 2, M) {
			if (i % j == 0) {
				isPrime[i] = false;
				break;
			}
		}
	}

	int Sum[MaxN + 1] = { 0 };
	rep(i, 2, MaxN+1) {
		int ans = 0;
		if (isPrime[i] && isPrime[(i + 1) / 2])
				ans++;
		Sum[i] = ans + Sum[i - 1];
	}

	rep(i, 0, Q) {
		cout << Sum[q[i].second] - Sum[q[i].first-1]<< endl;
	}

	return 0;
}

Measured memory_bytes: 1920
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int A[110000];
bool used[110000] = {};

int main(){
    int N;
    cin >> N;
    long long int S = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        S = (S ^ A[i]);
    }
    bool flag[100] = {};
    for(int i = 0; i < 60; i++){
        if((S & (1LL << i)) == 0){
            flag[i] = true;
        }else{
            long long int num = (1LL << 60) - 1 - (1LL << i);
            for(int i = 0; i < N; i++){
                A[i] = (A[i] & num);
            }
        }
    }
    long long int ans = 0;
    S = 0;
    for(int i = 59; i >= 0; i--){
        if(flag[i]){
            for(int j = 0; j < N; j++){
                if(!used[j] && (A[j] & (1LL << i))){
                    used[j] = true;
                    for(int k = 0; k < N; k++){
                        if(!used[k] && (A[k] & (1LL << i))){
                            A[k] = (A[k] ^ A[j]);
                        }
                    }
                    if((S & (1LL << i)) == 0){
                        S = (S ^ A[j]);
                    }
                    break;
                }
            }
        }else{
            ans += (1LL << i);
        }
    }
    cout << ans + S * 2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  map<ll, ll> mp{};
  REP(i, N) cin >> A[i], mp[A[i]]++;
  if (mp.size() == 1) {
    if (mp[0] != 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (mp.size() == 2 && N % 3 == 0) {
    ll tmp = 0;
    for (auto s : mp) {
      if (s.first != 0) tmp = s.second;
    }
    if (mp[0] * 3 == N && tmp * 3 / 2 == N) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  if (mp.size() == 3 && N % 3 == 0) {
    vector<ll> a(0);
    for (auto s : mp) {
      a.push_back(s.first);
      if (s.second != N / 3) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (((a[0] ^ a[1]) ^ a[2]) == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int a[m],b[m];
    vector<vector<int>>pas(n);
    int root[n],check[n]={};
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
        pas[a[i]-1].push_back(b[i]-1);
        pas[b[i]-1].push_back(a[i]-1);
    }
    queue<int>q;
    check[0]=1;
    q.push(0);
    while(q.size()){
        int f=q.front();
        q.pop();
        for(int i=0;i<pas[f].size();i++){
            if(check[pas[f][i]]==0){
                check[pas[f][i]]=1;
                root[pas[f][i]]=f;
                q.push(pas[f][i]);
            }
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++)cout<<root[i]+1<<endl;
    return 0;
}

Measured memory_bytes: 12108
def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    X = [0 for _ in range(N + 1)]  # cum sum
    for i in range(N):
        X[i + 1] = X[i] + A[i]
    # split to 2 parts (X_0, ..., X_i), (X_(i+1), ..., X_N)
    ans = 10**10
    left = 0
    right = 2
    for i in range(1, N):
        while left < i:
            d = abs(X[left] - (X[i] - X[left]))
            d_next = abs(X[left + 1] - (X[i] - X[left + 1]))
            if d_next > d:
                break
            left += 1
        while right < N:
            d = abs((X[N] - X[right]) - (X[right] - X[i]))
            d_next = abs((X[N] - X[right + 1]) - (X[right + 1] - X[i]))
            if d_next > d:
                break
            right += 1
        p, q, r, s = X[left], X[i] - X[left], X[right] - X[i], X[N] - X[right]
        ans = min([ans, max([p, q, r, s]) - min([p, q, r, s])])
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 25676
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define me(a,b) memset(a,b,sizeof(a))
typedef long long ll;
using namespace std;
const int maxn=1e4+1;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int n,m;
int main(){
	scanf("%d%d",&n,&m);
	ll g=0;
	for(int i=1;i<=n;i++){
		ll x;
		scanf("%lld",&x);
		g=gcd(abs(x-m),g);
	}
	printf("%d\n",g);
    return 0;
}


Measured memory_bytes: 256
// Problem : B - Greedy Takahashi
// Contest : AtCoder - AtCoder Beginner Contest 149
// URL : https://atcoder.jp/contests/abc149/tasks/abc149_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include<set>
#define lli long long int
using namespace std;
int main()
{
	lli t,a,k,i,t1;
	cin>>t>>a>>k;
	t1=t;
	t=t-k;
	k=k-t1;
	if(k>0)
	a=a-k;
   if(t>0)
   cout<<t<<" ";
   else
   cout<<"0 ";
   if(a>0)
   cout<<a<<" ";
   else
   cout<<"0 ";
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int Min=INT_MAX,Max=INT_MIN;
	cin>>n;
	while(n--){
		int a;
		cin>>a;
		Max=max(a-Min,Max);
		Min=min(a,Min);
		
	}
	cout<<Max<<endl;
	return 0;
}


Measured memory_bytes: 3108
package main
import(
  "fmt"
)

func gcd(a int, b int)int{
	if b==0{
		return a
	}
	return gcd(b, a%b)
}
func main(){
   var k, a, b, c int
   ans:=0
   fmt.Scan(&k)
   for a=1;a<=k;a++{
     for b=1;b<=k;b++{
       for c=1;c<=k;c++{
         ans+=gcd(a, gcd(b, c))
       }
     }
   }
   fmt.Println(ans)
}


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

int main() {

int x,y;

do{
cin >> x >> y ;
if(x==0 && y==0){
break;
}
cout << min(x,y) << " " << max(x,y) << endl;
}while(x>0 || y>0);

}


Measured memory_bytes: 3096
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

const int max_nm = 200000+19;

Int N,M,K;
Int inv[max_nm];
Int invfact[max_nm];
Int fact[max_nm];

Int comb(Int n, Int r) {
    if(n < 0 || n < r)
        return 0;

    return ((fact[n]*invfact[n-r]%MOD)*invfact[r])%MOD;
}

int main(void) {
    cin>>N>>M>>K;

    fact[0] = fact[1] = 1;
    inv[1] = 1;
    invfact[0] = invfact[1] = 1;
    
    for(Int i = 2;i <= N*M;i++) {
        fact[i] = i*fact[i-1]%MOD;
        inv[i] = MOD - (MOD/i)*inv[MOD%i] % MOD;
        invfact[i] = inv[i]*invfact[i-1] % MOD;
    }

    Int ans = 0;
    
    for(Int d = 1;d < M;d++) {
        ans += (((N*N%MOD)*(M-d)%MOD)*d%MOD)*comb(N*M-2,K-2)%MOD;
        ans %= MOD;
    }

    for(Int d = 1;d < N;d++) {
        ans += (((M*M%MOD)*(N-d)%MOD)*d%MOD)*comb(N*M-2,K-2)%MOD;
        ans %= MOD;
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<string>

using namespace std;

int main(){
    int n = 'a' - 'A';
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    cout << (char)(s1[0] - n) << (char)(s2[0] - n) << (char)(s3[0] - n) << endl;
}

Measured memory_bytes: 3600
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=200010;
const double DINF=1e40;
const double EPS=1e-5;
int n;
int pre[N];
int col[N];
int bel[N];
int c[N][2];
struct Data{
	int u;
	double x;
	Data(){}
	Data(int _u,double _x):u(_u),x(_x){}
	friend bool operator < (const Data &a,const Data &b){
		return a.x<b.x;
	}
};
priority_queue<Data> q;
void readData(){
	scanf("%d",&n);
	for(int v=2;v<=n;v++)
		scanf("%d",&pre[v]);
	for(int i=1;i<=n;i++) 
		scanf("%d",&col[i]);
}
int findBel(int u){
	return bel[u]==u?u:(bel[u]=findBel(bel[u]));
}
void merge(int x,int y){
}
double getVal(int u){
	return c[u][1]?(1.0*c[u][0]/c[u][1]):DINF;
}
void init(){
	for(int i=1;i<=n;i++){
		bel[i]=i;
		c[i][0]=(col[i]==0);
		c[i][1]=(col[i]==1);
		if(i>1)
			q.push(Data(i,getVal(i)));
	}
}
bool legal(int u,double now){
	return fabs(now-getVal(u))<=EPS;
}
void solve(){
	ll ans=0;
	Data cur;
	int u,fp;
	while(!q.empty()){
		cur=q.top();
		q.pop();
		u=cur.u;
		if(findBel(u)!=u)
			continue;
		fp=findBel(pre[u]);
		ans+=1ll*c[fp][1]*c[u][0];
		c[fp][0]+=c[u][0];
		c[fp][1]+=c[u][1];
		if(fp!=1)
			q.push(Data(fp,getVal(fp)));
		bel[u]=fp;
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	init();
	solve();
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  double ans=0.0;
  for(int i=0;i<n;i++){
    double a;
    cin >> a;
    ans+=1.0/a;
  }
  cout << fixed << setprecision(50) << 1.0/ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	int N; cin >>N;
	set<string> st;
	function<void(string,int)> dfs = [&](string s,int t){
		if(s.size() == N){
			st.insert(s);return;
		}
		rep(i,t+1){
			string ns = s;
			ns += 'a'+i;
			dfs(ns,(i == t ? t+1 : t));
		}
	};
	dfs("",0);
	for(string s: st) cout << s << endl;
}


Measured memory_bytes: 12416
#include <iostream>
#include <string>
#include <stdio.h>
#include <queue>
#include <stack>
#include <string.h>
#include <algorithm>
#include <math.h>
//#include <bits/stdc++.h>
#define ll long long
#define wtcl return
using namespace std;

inline int read()
{
	ll s = 0, f = 1;
	char ch = getchar();
	for(; ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = - 1;
	for(; ch >= '0' && ch <= '9'; ch = getchar()) s = ((s << 3ll) + (s << 1ll) + (ch ^ 48ll));
	return s * f ;
}
inline void out(int x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>9) out(x/10);
	putchar(x%10+'0');
}

const int maxn = 1005;
const int inf = 999999999;

int look[maxn][maxn];
int n,m;
int dis[maxn][maxn];
int path[maxn][maxn];
void init()
{
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)
		{
			if(i==j) dis[i][j]=0;
			else
			dis[i][j]=inf;
		}

}
void floyd()
{
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
			path[i][j]= j;
	}
    for(int k=1;k<=n;k++)
    {
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=1;j<=n;j++)
    		{
    			if(dis[i][k]!=inf&&dis[k][j]!=inf&&dis[i][k]+dis[k][j]<dis[i][j])
    			{
    				dis[i][j]=dis[i][k]+dis[k][j];
          			//dis[j][i]=dis[i][k]+dis[k][j];
          			path[i][j] = path[i][k];
//          			cout<<i<<" "<<j<<" "<<k<<endl;
//          			system("pause");
				}
			}
		}
	}
}
void finde(int u, int v)
{
	while(u!=v)
	{
		//cout << u << "->";
		look[u][path[u][v]]=1;
        u = path[u][v]; 
    }
    //cout << u<<endl;;
    //look[u][v]=1; 
}
int main()
{
	while(~scanf("%d %d",&n,&m))
	{
		memset(look,-1,sizeof(look));
		init();
		for(int i=0;i<m;i++)
		{
			int u,v,val;
			u = read();
			v = read();
			val = read();
			dis[u][v]=val;
			dis[v][u]=val;
			look[u][v] = 0;
		}
		floyd();
		int ans = 0;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				if(i==j)continue;
				//printf("从 %d 到 %d 的长度是 %d 路径是：",i,j,dis[i][j]);
				finde(i,j);
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				//printf("%d ",look[i][j]);
				if(look[i][j] == 0)
				{
					ans++;
					//cout<<"+";
				}
			}
			//puts("");
		}
		cout<<ans<<endl;
	}
	wtcl 0;
}

/**
3 3
1 2 1
1 3 1
2 3 3

3 2
1 2 1
2 3 1

3 3
1 2 10
1 3 5
2 3 5

6 7
1 2 1
2 4 1
4 5 2
4 6 3
6 5 1
5 3 1
3 1 1
*/


Measured memory_bytes: 10496
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;

void solve()
{
    int n;
    scanf("%d", &n);
    vector<int> a;
    vector<ll> s0(n + 3), s1(n + 3);
    int i;
    a.push_back(0);
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp); a.push_back(tmp);
    }
    a.push_back(0);
    ll sum = 0;
    for (i = 1; i < n + 2; i++) {
        sum += abs(a[i] - a[i - 1]);
    }

    for (i = 1; i <= n; i++) {
        ll ans = sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i + 1] - a[i - 1]);
        printf("%lld\n", ans);
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

struct edge
{
    int t,w;
    edge(int t, int w) : t(t), w(w) {}
};

vector<edge> g[100005];
int dist[100005], ind[100005];

bool dijk(int st)
{
    priority_queue<pair<int,int>> pq;
    pq.emplace(0,st);
    while(!pq.empty())
    {
        int w = -pq.top().first;
        int c = pq.top().second;
        pq.pop();
        for(auto e : g[c])
        {
            int ww = w + e.w;
            if(dist[e.t]<0)
            {
                dist[e.t] = ww;
                pq.emplace(-ww,e.t);
            }
            else if(dist[e.t] != ww) return 0;
        }
    }
    return 1;
}

int main()
{
    memset(dist,-1,sizeof(dist));
    int n,m;
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        g[a].push_back(edge(b,c));
        ind[b]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(ind[i]) continue;
        for(auto e : g[i])
        {
            if(dist[e.t]<0) continue;
            int tmp = dist[e.t]-e.w;
            if(tmp<0 || (dist[i]>=0 && dist[i]!=tmp))
            {
                puts("No");
                return 0;
            }
            dist[i] = tmp;
        }
        if(dist[i]<0) dist[i] = 0;
        if(dijk(i)) continue;
        puts("No");
        return 0;
    }
    for(int i=1;i<=n;i++)
        if(dist[i]<0)
        {
            puts("No");
            return 0;
        }
    puts("Yes");
}


Measured memory_bytes: 7668
#include <cstdio>
#include <vector>
#include <map>

using namespace std;

int n;
int c[100000];
long long d[100000];
long long p[100000];
vector <int> v[100000];

int dfs(int x, int y) {
    int i;
    
    c[x] = 1;
    
    for (i = 0; i < v[x].size(); i++) {
        int t;
        
        if (v[x][i] == y) continue;
        
        t = dfs(v[x][i], x);
        c[x] += t;
        p[x] += p[v[x][i]] + t;
    }
    
    return c[x];
}

void dfs2(int x, int y, long long z) {
    int i;
    
    p[x] += z;
    
    for (i = 0; i < v[x].size(); i++) {
        if (v[x][i] == y) continue;
        
        dfs2(v[x][i], x, p[x] - p[v[x][i]] + n - c[v[x][i]] * 2);
    }
}

int main() {
    int i;
    vector <pair<int, int>> ans;
    map <long long, int> mp, mp2;
    map <long long, int>::reverse_iterator it;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%lld", &d[i]);
        
        mp[d[i]] = i;
        mp2[d[i]] = 1;
    }
    
    for (it = mp2.rbegin(); it != mp2.rend(); it++) {
        long long x = it->first, y;
        int c = it->second;
        
        if (c * 2 >= n) continue;
        
        y = x - n + c * 2;
        
        if (!mp2.count(y)) {
            puts("-1");
            
            return 0;
        }
        
        mp2[y] += c;
        v[mp[x]].push_back(mp[y]);
        v[mp[y]].push_back(mp[x]);
        ans.push_back(make_pair(mp[x], mp[y]));
    }
    
    dfs(0, -1);
    dfs2(0, -1, 0);
    
    for (i = 0; i < n; i++) {
        if (d[i] != p[i]) {
            puts("-1");
            
            return 0;
        }
    }
    
    for (i = 0; i < ans.size(); i++) printf("%d %d\n", ans[i].first + 1, ans[i].second + 1);
    
    return 0;
}


Measured memory_bytes: 28276