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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 15;
const int MB = 1 << MN;
const ll inf = -1e9;

int e[MN][MN];
int ct[MB];
int dp[MN][MB];

int main() {
	int N, M; cin >> N >> M;
	int sum = 0;
	rep(i, M) {
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		e[a][b] = e[b][a] = c;
		sum += c;
	}

	rep(i, N) rep(j, 1 << N) {
		dp[i][j] = inf;
	} 

	rep(j, 1 << N) {
		rep(u, N) rep(v, u) {
			if (((j >> u) & 1) && ((j >> v) & 1)) {
				ct[j] += e[u][v];
			}
		}
	}

	rep(j, 1 << N) {
		if (j & 1) {
			dp[0][j] = ct[j];
		}
	}

	rep(j, 1 << N) {
		for (int k = j; k > 0; k = (k - 1) & j) {
			rep(i, N) if (((j ^ k) >> i) & 1) {
				rep(p, N) if (((k >> p) & 1) && dp[p][k] != inf && e[p][i] > 0) {
					dp[i][j] = max(dp[i][j], dp[p][k] + ct[j ^ k] + e[p][i]);
				}
			}
		}
	}

	int ans = sum - dp[N-1][(1 << N) - 1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2432
function main()
    parse_int(x) = parse(Int, x)
    readline()
    line = parse_int.(split(readline()))
    steps = 0
    current_max = 0
    for n in line
        if n > current_max
            current_max = n
        end
        steps += current_max - n
    end
    return steps
end

println(main())


Measured memory_bytes: 195012
N = int(input())

ans = [0]*N

for i in range(1,101,1):
  for j in range(1,101,1):
    for k in range(1,101,1):
      n = i**2+j**2+k**2+i*j+j*k+k*i
      if n > N:
        continue
      ans[n-1]+=1
      
for i in range(N):
  print(ans[i])
                           

Measured memory_bytes: 9140
N=int(input())
A=list(map(int,input().split()))
count=0
ans=1
A.sort()
if(N%2==0):
  flag=True
  for i in range(N):
    if(i%2==0):
      if(A[i]!=i+1):
        flag=False
        break
    else:
      if(A[i]!=i):
        flag=False
        break
      else:
        ans=(ans*2)%(10**9+7)
else:
  flag=True
  if(A[0]!=0):
    flag=False
  for i in range(N):
    if(i%2==1):
      if(A[i]!=i+1):
        flag=False
        break
    else:
      if(A[i]!=i):
        flag=False
        break
      else:
        if(i>0):
          ans=(ans*2)%(10**9+7)
if(flag==True):
  print(ans)
else:
  print(0)
    

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define pb push_back
#define ld long double
#define mod 1000000007
#define mk make_pair
#define ull unsigned long long
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
void factor(ll n,vector<pair<ll,ll>>&p)
{
    ll i=1;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            p.pb(mk(i,n/i));
        }
    }
}
int main()
{
    fastIO;
    ll n;
    cin>>n;
    vector<pair<ll,ll>>p;
    factor(n,p);
    ll flag=0,x,y,val,val1;
    ll ans=inf;
    for(ll i=0;i<p.size();i++)
    {
        x=p[i].first;
        y=p[i].second;
        val=abs(x-1)+abs(y-1);
        if(ans>val)
        {
            ans=val;
        }
    }
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio() ios_base::sync_with_stdio(false);
#define rmod(x, y) ((((x)%(y))+(y))%(y))
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
template<typename T, typename R = null_type, typename C = less<T>>
tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update> ordered_set(){
	return tree<T, R, C, rb_tree_tag, tree_order_statistics_node_update>();
}

const int maxn = 3005;
bool vis[maxn][maxn][2];
int n;
ll a[maxn], dp[maxn][maxn][2];

ll solve(int l, int r, bool taro){
	if (l == r) {
		if (taro) return a[l];
		return -a[l];
	}
	ll &ret = dp[l][r][taro];
	if(vis[l][r][taro]) return ret;
	if (taro) ret = max(a[l]+solve(l+1, r, 0), a[r]+solve(l, r-1, 0));
	else ret = min(solve(l+1, r, 1)-a[l], solve(l,r-1, 1)-a[r]);
	vis[l][r][taro] = 1;
	return ret;
}


int main(){
	scanf("%d", &n);
	for(int i = 1; i<=n; i++) scanf("%lld", &a[i]);
	printf("%lld\n", solve(1, n, 1));
	return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];

    REP(i, n) {
        if(i==0 || h[i-1] < h[i]) {
            h[i]--;
        }
    }

    bool flag = true;
    FOR(i, 1, n) {
        if(h[i-1] > h[i]) flag = false;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;    

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <vector>
#include <stack>
using namespace std;

int main(){
    int a; cin >> a;
    if(a == 1) printf("0\n");
    else printf("1\n");
    return 0;
}


Measured memory_bytes: 3556
#include <iostream>

using namespace std;

typedef long long LL;

void set_bit(LL &n, int position)
{
    n |= (1LL << position);
}

LL no_of_set_bits(LL n, int position)
{
    LL set_bits = 0; //cout << "At n = " << n << " p = " << position << endl;

    LL weight = (1LL << position);

    if(position == 0)
    {
        return (n/2 + n%2);
    }
        LL no_of_blocks = (n)/weight; //cout << "W = " << weight << " B = " << no_of_blocks << " ";

        set_bits += (no_of_blocks/2)*weight;

        LL total_reached = no_of_blocks*weight; //cout << "T = " << total_reached << " Increase = " << (no_of_blocks/2)*weight;// << endl;

        if(no_of_blocks%2 == 1)
            set_bits += n - total_reached + 1;

            //cout << " ans = " << set_bits << endl;

    return set_bits;
}

int main()
{
    LL left, right;
    cin >> left >> right;

    LL xor_answer = 0;

    const int MAX_BITS = 63;
    for(int i = 0; i < MAX_BITS; i++)
    {
        LL no_of_set_bits_here = no_of_set_bits(right, i);// - no_of_set_bits(left - 1, i);

      	if(left != 0) no_of_set_bits_here -= no_of_set_bits(left - 1, i);
      
        if(no_of_set_bits_here%2 == 1)
            set_bit(xor_answer, i);
    }

    cout << xor_answer;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int N, M, A[30][30], K[30], i, j, k, cnt = 0, cntA = 0;
	scanf("%d %d",&N,&M);
	for (i = 0; i < N; i++) {
		scanf("%d ",&K[i]);
		for (j = 0; j < K[i]; j++) {
			scanf("%d",&A[i][j]);
		}
	}
	for (i = 0; i < K[0]; i++) {
		for (k = 1; k < N; k++) {
			for (j = 0; j < K[k]; j++) {
				if (A[0][i] == A[k][j])
					cnt++;
			}
		}
		if (cnt == N - 1)
			cntA++;
		cnt = 0;
	}
	if (N == 1)
		cntA = K[0];
	printf("%d", cntA);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n;
    cin >> n;
    ll ans = 1e18;
    for (ll i = 1; i <= sqrt(n); ++i)
    {
        if(n%i == 0)
        {
            ans = min(ans,i + n/i - 2);
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 10 03:26:19 2018

@author: Yuki
"""

s = input()
A = int(s[0])
B = int(s[1])
C = int(s[2])
D = int(s[3])

def calc(num1, num2, op):
    if op=='+':
        return num1 + num2
    else:
        return num1 - num2
flag = False
for op1 in ['+', '-']:
    for op2 in ['+', '-']:
        for op3 in ['+', '-']:
            if calc(calc(calc(A, B, op1), C, op2), D, op3)==7:
                flag = True
            if flag:
                break
        if flag:
            break
    if flag:
        break
print(s[0]+op1+s[1]+op2+s[2]+op3+s[3]+'=7')





Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,m,ans;
int edge[105][105];
void rec(int nx,vector<int>vec,vector<int>val){
	if(nx == n+1) return;
	rec(nx+1,vec,val);
	
	int x = INF;
	for(int i=0;i<vec.size();i++){
		if(edge[nx][vec[i]] == -1) return;
		val[i] = min(val[i],edge[nx][vec[i]]);
		x = min(x,edge[nx][vec[i]]);
	}
	vec.pb(nx); val.pb(x);
	if(val.size() >= 2){
		int S = 0; for(int i=0;i<val.size();i++) S += val[i];
		ans = max(ans,S);
	}
	rec(nx+1,vec,val);
}
int main(){
	cin >> n >> m;
	memset(edge,-1,sizeof(edge));
	rep(i,m){
		int a,b,c; cin >> a >> b >> c;
		edge[a][b] = edge[b][a] = c;
	}
	rec(1,vector<int>(0),vector<int>(0)); cout << ans << endl;
}

Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, s;
    cin >> n >> s;
    for(long long i = 2; i <= sqrt(n); i++){
        long long cnt = 0, p = n;
        while(p > 0){
            cnt += p % i;
            p = p/i;
        }
        if(cnt == s){
            cout << i;
            return 0;
        }
    }
    long long ans = 1e18;
    for(long long i = 1; i <= sqrt(n - s); i++){
        if((n - s) % i == 0){
            long long k = (n - s)/i + 1;
            if(k > sqrt(n)){
                long long r = n/k + n % k;
                if(r == s){
                    ans = min(ans, k);
                }
            }
        }
    }
    if(s == n){
        ans = min(ans, n + 1);
    }
    if(ans == 1e18){
        cout << "-1";
    }
    else{
        cout << ans;
    }
    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

// Union-Find木
template<class Abel>//加減可能のアーベル群
class UnionFind{
protected:
    vector<int> par;//親ノード
    vector<Abel> pod;//ポテンシャル
    Abel O=0;
public:
    UnionFind(int n,Abel zero=0) : par(n,-1),pod(n,zero){
        O=zero;
    }

    //根を求める（同時に経路圧縮）
    int root(int x){
        if(par[x]<0) return x;
        int r = root(par[x]);
        pod[x] +=pod[par[x]];
        return par[x]=r;
    }

    //根が等しいか判定
    bool issame(int x,int y){
        return root(x)==root(y);
    }

    //マージ
    bool unite(int base,int x){
        unite(base,x,O);
    }
    bool unite(int base,int x,Abel pd){
        pd -=p(x) - p(base);
        base=root(base);x=root(x);
        if(base==x)return false;
        if(par[base]>par[x]) std::swap(base,x),pd=-pd;
        //baseがxの親になる
        par[base] +=par[x];//根は-(size)
        par[x]=base;
        pod[x]=pd;
        return true;
    }

    //属す根のサイズ
    int size(int x){
        return -par[root(x)];
    }
    //要素のポテンシャル
    Abel p(int x){
        root(x);//経路圧縮
        return pod[x];
    }
    //要素の相対ポテンシャル
    Abel diff(int base,int x){
        if(issame(base,x)) return pod[x]-pod[base];
        return 0;//同箇所にない場合は未定義
    }
};


int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,M,K,L;
    cin >>N>>M;
    
    UnionFind<int> COMU(N+M,0);
    rep(i,N){
        cin>>K;
        rep(k,K){
            cin>>L;
            COMU.unite(i,N+L-1);
        }
    }
    bool is=true;
    repd(i,1,N){
      is=(is &&COMU.issame(i-1,i));
    }

    cout << ((is) ? "YES" : "NO") <<endl;
    return (0);
}

Measured memory_bytes: 1792
N,M = map(int,input().split())
H = list(map(int,input().split()))

miti = []
for i in range(M):
    miti.append(list(map(int,input().split())))

count = []
for i in range(N):
    count.append(1)

for i in range(M):
    if H[miti[i][0]-1] < H[miti[i][1]-1]:
        count[miti[i][0]-1]=0

    if H[miti[i][0]-1] > H[miti[i][1]-1]:
        count[miti[i][1]-1]=0

    if H[miti[i][0]-1] == H[miti[i][1]-1]:
        count[miti[i][0]-1]=0
        count[miti[i][1]-1]=0

ans = 0
for i in range(N):
    ans += count[i]

print(ans)

Measured memory_bytes: 31968
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

/*

A ~ B => 0 ~ B - 0 ~ (A - 1)
累積和とかと同じ考え方
ex)
4 ~ 8 -> (0 ~ 8) - (0 ~ 3)

A xor B = C
=>    C    xor    A    =    B
    0 ~ 8       0 ~ 3     4 ~ 8

こう考えると
問題は，0 ~ A のxorの値を求める．

*/

ll calc (ll A) {

    if (A <= 0) return 0;
    A++;
    // 10 ^ 12 <= 2進数 40桁ぐらい

    ll ans = 0;
    /*
    i桁目の偶奇を調べる
    0000
    0001
    0010
    0011
     .
     .
    0桁目 -> 周期 2
    1桁目 -> 周期 4
    2桁目 -> 周期 8
    */
    for (int i = 0; i < 50; i++) {

        ll loop = (1LL << ( i + 1));
        ll cnt = (A / loop) * (loop / 2);
        cnt += max(0LL, (A % loop) - (loop / 2));
        // その桁の1の位が奇数ならans++;
        if (cnt % 2 == 1) {
            ans += 1LL << i;
        }
    }
    return ans;
}

int main() {

    ll A, B;
    cin >> A >> B;
    ll ans = calc(B) ^ calc(A-1);
    cout << ans << '\n';
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val input = readLine()?.split(" ")
    val a = input?.get(0)?.toInt() ?: 0
    val b = input?.get(1)?.toInt() ?: 0

    when {
        a > b -> println("a > b")
        a < b -> println("a < b")
        else -> println("a == b")
    }
}


Measured memory_bytes: 31988
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int q = sc.nextInt();
		
		int[] a = new int[n+1];
		//for (int i = 1; i <= n; i++) a[i] = 0;
		//HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		
		for (int i = 0; i < q; i++) {
			int aa = sc.nextInt();
			a[aa]++;
		}
		//for (int i = 1; i <= n; i++) System.out.println(a[i]);
		
		for (int i = 1; i <= n; i++) {
			if(k-q+a[i] > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
	
		
	/*	for (int i = 1; i <= n; i++) a[i] = k;
		
		for(int i = 0; i < q; i++) {
			int aa = sc.nextInt();
			//System.out.println(aa);
			for(int j = 1; j <= n; j++) {
				if(j != aa) a[j]--;
				//System.out.println(a[i]);
			}
		}
		
		for (int i = 1; i <= n; i++) {
			if(a[i] > 0) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		}
		*/
		
		
	}

}


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

int main() {
	
	int x, y;
	cin >> x >> y;
	int ans = 0;
	if(x==1&&y==1){
		ans = 400000;
	}
	switch(x){
		case 1: ans += 300000;
		break;
		case 2: ans += 200000;
		break;
		case 3: ans += 100000;
		break;
	}
	switch(y){
		case 1: ans += 300000;
		break;
		case 2: ans += 200000;
		break;
		case 3: ans += 100000;
		break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int K = s.nextInt();
		int[] d = new int[K];
		int[][] A;
		A = new int[K][];
		
		for(int i=0; i<K; i++) {
		    d[i] = s.nextInt();
		    A[i] = new int[d[i]];
			for(int k=0; k<d[i]; k++) {
				A[i][k] = s.nextInt();
			}
			
		}
		ArrayList<Integer> sunukes = new ArrayList<Integer>();
		for(int i=0; i<K; i++) {
			for(int k=0; k<d[i]; k++) {
				if(sunukes.contains(A[i][k])) {}
				else {sunukes.add(A[i][k]);}
			}
		}
		int ans = N - sunukes.size();
		System.out.println(ans);
	}

}


Measured memory_bytes: 46516
import java.util.Scanner;



public class Main {

    static int mod = (int) 1e9 + 7;
    public static final long pow(long x, long n) {
        long sum = 1;
        while (n > 0) {
            if ((n & 1) == 1) {  //ビットが立っていたら
                sum *= x;        //x^2^k1 * x^2^k2 * x^2^k3 * ・・・
            }
            x *= x;              //((x^2)^2)^2・・・
            n >>= 1;
        }
        return sum;
    }

    public static final long modPow(long a,long n,long p) {
        if (n == 1) return a % p;
        if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
        long t = modPow(a, n / 2, p);
        return (t * t) % p;
    }

    static long fermatComb(long a, long b) {
        if (b > a - b)
            return fermatComb(a, a - b);
        long mul = 1; //分子
        long div = 1; //分母
        for (int i = 0; i < b; i++) {
            mul *= (a - i);
            mul %= mod;
            div *= (i + 1);
            div %= mod;
        }
        long ans = mul * modpow(div, mod - 2) % mod; //フェルマーの小定理を利用して掛け算で計算
        return ans;
    }

    //mod条件下の高速pow
    static long modpow(long a, long p) {
        if (p == 0)
            return 1;
        if (p % 2 == 0) {
            long root = modpow(a, p / 2);
            return root * root % mod;
        } else
            return a * modpow(a, p - 1) % mod;
    }

    static long calc(long a, long b, long p) {
        if (b == 0) {
            return 1;
        } else if (b % 2 == 0) {
            long d = calc(a, b / 2, p);
            return (d * d) % p;
        } else {
            return (a * calc(a, b - 1, p)) % p;
        }
    }

    public static void main(String[] args) {
	// write your code here
        Scanner sc= new Scanner(System.in);
        long a=sc.nextLong(),b=sc.nextLong(),c=sc.nextLong();
        long result=modPow(2,a,mod)-1;
        long bresult=fermatComb(a,b);
        long cresult=fermatComb(a,c);
        long ans=result-bresult-cresult;
        while(ans<0){
            ans+=mod;
        }

        System.out.println(ans);
    }
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

int N, M;
VI2 path;

int cnt;
std::bitset<8> visited;
std::bitset<8> mask;

void dfs(int i) {
    if(visited[i]) {
        return;
    }

    visited.set(i);
    if( (visited & mask) == mask) {
        ++cnt;
    } else {
        for(auto next: path[i]) {
            dfs(next);
        }
    }
    visited.reset(i);
    
    return;
}
int main() {
    std::cin >> N >> M;
    path.resize(N);
    REP(i, M) {
        int a, b;
        std::cin >> a >> b;
        --a, --b;
        path[a].pb(b);
        path[b].pb(a);
    }

    cnt = 0;
    visited = std::bitset<8>(0);
    mask    = std::bitset<8>(std::pow(2, N) - 1);
    dfs(0);

    std::cout << cnt << std::endl;
}

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

int main() {
    int H,W;
    cin >> H >> W;
    string in,out;
    for(int i = 0;i < H;i++) {
        cin >> in;
        for(int t = 0;t < 2;t++) {
            out += in + "\n";
        }
    }
    cout << out;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	long long int n;
	cin>>n;
	long long int sum;
	sum=n/11*2;
	n%=11;
	if(0<n&&n<7){
		sum++;
	}else if(n>=7){
		sum+=2;
	}
	cout<<sum<<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 m = sc.nextInt();
		int[][] queue = new int[n][m];
		int[] vector = new int[m];
		int[] vectorAns = new int[n];

		for(int i = 0; i < queue.length; i++){
			for(int j = 0; j < queue[i].length; j++){
				queue[i][j] = sc.nextInt();
			}
		}
		for(int i = 0; i < vector.length; i++){
			vector[i] = sc.nextInt();
		}
		for(int i = 0; i < vectorAns.length; i++){
			for(int j = 0; j < queue[i].length; j++){
				vectorAns[i] += queue[i][j] * vector[j];
			}
		}
		for(int data: vectorAns){
			System.out.println(data);
		}
	}
}




Measured memory_bytes: 40560
program sample
	implicit none
    integer :: count,i
    character(len=3) :: a,b
    read(*,*) a,b
    
    do i=1,3
    	if (a(i:i)==b(i:i)) then
        	count = count+1
        end if
    end do
    write(*,*) count
    stop
end program sample



Measured memory_bytes: 2860
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

#define REP(i, n) for (auto i = 0; i < n; i++)

using namespace std;

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vector<int> A(N);
  vector<int> B(M);

  for (auto i = 0; i < N; ++i) {
    cin >> A[i];
  }

  for (auto i = 0; i < M; ++i) {
    cin >> B[i];
  }
  vector<long> a(N + 1, 0);
  vector<long> b(M + 1, 0);

  for (auto i = 0; i < A.size(); ++i) {
    a[i + 1] = a[i] + A[i];
  }
  for (auto i = 0; i < B.size(); ++i) {
    b[i + 1] = b[i] + B[i];
  }

  int ans = 0;
  int j = M;
  REP(i, N + 1) {
    if (a[i] > K) break;
    while (b[j] > K - a[i]) {
      --j;
    }
    ans = max(ans, i + j);
  }
  cout << ans << endl;
}


Measured memory_bytes: 7536
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

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

const double PI=(acos(-1));



int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n)cin>>h[i];
    int now=0;  //present height
    int ans=0;  //count of watering
    rep(i,n){
        if(now<h[i])ans+=h[i]-now;
        now=h[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3564
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    double ans = 0;
    rep(i, N)
    {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY")
        {
            ans += x;
        }
        else
        {
            ans += x * 380000.0;
        }
    }
    outD(ans);


    //
    return 0;
}

Measured memory_bytes: 3764
#include<iostream>
#include<cstring>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="SUN")cout<<7;
  if(s=="MON")cout<<6;
  if(s=="TUE")cout<<5;
  if(s=="WED")cout<<4;
  if(s=="THU")cout<<3;
  if(s=="FRI")cout<<2;
  if(s=="SAT")cout<<1;
  return 0;
}

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

using namespace std;

#define vi vector<int>
#define all(v) v.begin(),v.end()
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D1(x) {cerr<<" [" <<#x<<": "<<x<<"]";cout << endl;}
#define D2(x) {cerr<<" [" <<#x<<": ";for(auto it:x)cerr<<it<< " ";cerr<<"] ";cout << endl;}

const ll MOD = 1e9 + 7;
const ll maxn = 2e5 + 5;

void solve(){
	char a;
	cin >> a;
	if(a>='A' && a<='Z')cout << 'A';
	else cout << 'a';
}

int main() {
    IOS
        
        solve();
    cerr << endl << "[ Time : " << (float) clock() / CLOCKS_PER_SEC << " secs ]" << endl;

}
// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3796
from collections import deque,defaultdict
import sys
def bfs(s,g,n):
    bfs_map = [-1]*n
    bfs_map[s] = 0
    q = deque([s])
    while q:
        x = q.popleft()
        for y in v[x]:
            if c[x][y] > 0 and bfs_map[y] < 0:
                bfs_map[y] = bfs_map[x]+1
                q.append(y)
    return bfs_map

def update(s,g,bfs_map):
    f = float("inf")
    p = [[None]*2 for i in range(bfs_map[g])]
    y = g
    for i in range(bfs_map[g])[::-1]:
        p[i][1] = y
        for x in v[y]:
            if c[x][y] > 0 and bfs_map[x] == i:
                if c[x][y] < f:
                    f = c[x][y]
                y = x
                p[i][0] = x
                break
        else:
            return 0

    for x,y in p:
        c[x][y] -= f
        c[y][x] += f
    return f

def dinic(s,g,n):
    f = 0
    while 1:
        bfs_map = bfs(s,g,n)
        if bfs_map[g] < 0:
            return f
        cap = update(s,g,bfs_map)
        while cap > 0:
            f += cap
            cap = update(s,g,bfs_map)
if __name__ == "__main__":
    n,e = map(int, sys.stdin.readline()[:-1].split())
    v = [[] for i in range(n)]
    c = [[0]*n for i in range(n)]
    for i in range(e):
        a,b,w = map(int,sys.stdin.readline()[:-1].split())
        v[a].append(b)
        v[b].append(a)
        c[a][b] = w
    print(dinic(0,n-1,n))



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

int main() {
  int n;
  cin >> n;
  string S;
  bool flag = false; //Three
  
  for (int i = 0; i < n; i++) {
    cin >> S;
    if (S == "Y") {
      flag = true;
      break;
    }
  }
  
  if (flag)
  	cout << "Four" << endl;
  else
  	cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P; typedef unsigned long long int ull;
const ll mod = 1000000007;
const int inf = 1e9 + 7;
const ll linf = 1LL << 60;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,m,n) for(int i=(m);i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
#define vec vector<int>
#define vecb vector<bool>
#define vecd vector<double>
using str = string;
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
	if (firstItr < 0 || secondItr>int(str.size() - 1))return str;
	while (firstItr < secondItr) {
		swap(str[firstItr], str[secondItr]);
		firstItr++; secondItr--;
	}
	return str;
}
std::string RunLengthEncoding(std::string str) {
	int itr = 0; std::string res;
	while (itr < int(str.size())) {
		char tmp = str[itr++];
		int length = 1;
		while (itr <int(str.size()) && str[itr] == tmp) { ++itr; ++length; }
		res.push_back(tmp);
		res += to_string(length);
	}
	return res;
}
std::string split(std::string str, size_t first_itr, size_t second_itr) {
	std::string tmp;
	for (size_t i = first_itr; i < second_itr + 1; i++) {
		tmp.push_back(str.at(i));
	}
	return tmp;
}


int main() {
	double a; cin >> a;
	cout << d10 << 2 * a * PI << endl;
	return 0;
}

Measured memory_bytes: 3824
import heapq
N, M = map(int, input().split())
A_array = map(int, input().split())

h = []
for a in A_array:
    heapq.heappush(h, -a)

for i in range(M):
    p = heapq.heappop(h)
    p = p / 2
    heapq.heappush(h, p)

ans = 0
for i in range(N):
    p = heapq.heappop(h)
    ans += int(-p)

print(ans)

Measured memory_bytes: 99224
#include<stdio.h>
#define free 5
#define harf 12

int main(void)
{
      int A=0;
      int B=0;
      scanf("%d%d",&A,&B);

      if(free>=A){
            printf("%d\n",0);
      }
      else{
            if(harf>=A){
                  printf("%d\n",B/2);
            }
            else{
                  printf("%d\n",B);
            }
      }
      return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=a;i<b;i++)
#define reset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define pi acos(-1)
#define eps 0.00000001
#define pb push_back
#define off 250555

int n,lis[111],avg,ans;

int f(int x)
{
    int ret=0;
    For(i,0,n) ret+=(x-lis[i])*(x-lis[i]);
    return ret;
}

int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin>>n;
    For(i,0,n) cin>>lis[i];
    For(i,0,n) avg+=lis[i];
    avg/=n;
    int com=f(avg);
    ans=avg;
    if(f(avg+1)<com)
    {
        com=f(avg+1);
        ans=avg+1;
    }
    if(f(avg-1)<com)
    {
        ans=avg-1;
        com=f(avg-1);
    }
    cout<<com;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define tc int t; cin>>t; while(t--)
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define mod 1000000007
#define pb push_back
#define vi vector<int>
#define vc vector<char>
#define eb emplace_back
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define fo(i,x,n) for(int i=x;i<n;i++)
#define csb(x) __builtin_popcount(x)
#define tz(x) __builtin_ctz(x)
#define lsbp(x) __builtin_ffs(x)
#define msbp(x) __lg(x)
#define btoi(str,i) stoi(str,0,i)
#define ff first
#define ss second
const int inf=0x3f3f3f3f3f3f3f3f;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


map<int,vi>mp;
const int mx=1e5+5;
int m;
int dp1[mx],dp2[mx];
// void dfs2(int u,int p){
//    dp2[u]=0;
//    for(auto c:mp[u]){
//         dp2[u]=dp1[u];
//       int ans=(dp2[p])/(dp1[u]+1);
//       ans+=1;
//       dp2[u]=(dp2[u]%m*ans%m)%m;
//       if(c==p)continue;
//       dfs2(c,u);
//    }
// }
// void dfs2(int u,int p,int ans){
//    dp2[u]=dp1[u]*(1+ans);
//    vi pref,suff;
//    for(auto it:mp[u]){
//     if(it!=p){
//        pref.eb(it);
//        suff.eb(it);
    
//    }
//    }
//    reverse(all(suff));
//    int n=pref.size();
//    for(int i=0;i<n-1;i++){
//       pref[i+1]*=pref[i];
//       suff[n-i-2]*=suff[n-i-1];
//    }
//    int cnt=0;
//     for(auto it:mp[u]){
//        if(it!=p){
//           int w=(1+ans);
//           if(cnt>0)w*=pref[cnt-1];
//           if(cnt<n-1)w*=suff[cnt+1];
//           dfs2(it,u,w);
//           cnt+=1;
//        }
//     }
   
// }
void dfs2(int u,int par,int ans){
 
    //dp2[u] represents the number of ways to paint the tree if the root of the tree is u and is painted black
    
    dp2[u]=(dp1[u]*(1+ans))%m;
    vector<int> pref,suff;
    for(auto v:mp[u]){
        if(v!=par){
           pref.push_back(1+dp1[v]);
           suff.push_back(1+dp1[v]);
        }
    }
    int n=pref.size();
    for(int i=1;i<n;i++) pref[i]=(pref[i-1]*pref[i])%m;
    for(int i=n-2;i>=0;i--) suff[i]=(suff[i+1]*suff[i])%m;
 
    int cnt=0;
    for(auto v:mp[u]){
        if(v!=par){
            int ways=1+ans;
            if(cnt>0) ways=(ways*pref[cnt-1])%m;
            if(cnt<n-1) ways=(ways*suff[cnt+1])%m;
 
            dfs2(v,u,ways);
            cnt++;
        }
       
    }
 
}
void dfs(int u,int p){
   dp1[u]=1;
   for(auto c:mp[u]){
      if(c==p)continue;
         dfs(c,u);
      dp1[u]=(dp1[u]%m*(dp1[c]+1)%m)%m;
   }
   // dp1[u]+=1;
}
int32_t main(){

int n;cin>>n>>m;
if(n==1){cout<<1<<endl;return 0;}
for(int i=1;i<n;i++){
int x,y;cin>>x>>y;
mp[x].eb(y);
mp[y].eb(x);
}
dfs(1,0);
dfs2(1,0,0);
for(int i=1;i<=n;i++){
   // if(!dp2[i])cout<<dp1[1]<<endl;
    cout<<dp2[i]%m<<endl;
}
}

Measured memory_bytes: 31872
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

signed main(){
	bool f[4] = {true, true, true, true};
	int a, b;
	cin >> a >> b;
	f[a] = false;
	f[b] = false;
	for(int i = 1; i <=3; i++)if(f[i])cout << i << endl;
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

struct edge{
    ll v,cost;
};

int main(){
    ll n;
    cin>>n;
    vector<vector<edge>> adj(n);
    ll a,b,c;
    rep(i,n-1){
        cin>>a>>b>>c;
        a--,b--;
        adj[a].push_back((edge){b,c});
        adj[b].push_back((edge){a,c});
    }
    ll q,k;
    cin>>q>>k;
    k--;
    vector<ll> dist(n,-1);
    queue<ll> que;
    que.push(k);
    dist[k]=0;
    while(!que.empty()){
        ll now=que.front();
        que.pop();
        rep(i,adj[now].size()){
            if(dist[adj[now][i].v]==-1){
                dist[adj[now][i].v]=dist[now]+adj[now][i].cost;
                que.push(adj[now][i].v);
            }
        }
    }
    ll x,y;
    rep(i,q){
        cin>>x>>y;
        x--,y--;
        cout<<dist[x]+dist[y]<<endl;
    }
    return 0;
}

Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
int k,j,l,xh,cnt,nt[5010000];
bool bl[5010000];
string s;
int main(){
	cin >> s;
	nt[0]=-1,k=-1;
	l=s.size();
	while(j<l){
		if(k==-1 or s[j]==s[k]){
			j++,k++,xh=j-k;
			bl[j-1]=(xh!=j and j%xh==0);
			if(s[j]!=s[k])nt[j]=k;
			else nt[j]=nt[k];
		}
		else k=nt[k];
	}
	xh=l-nt[l];
	if(xh==1)
		return printf("%d\n1",l),0;
	if(xh==l or l%xh!=0)
		return puts("1\n1"),0;
	for(int i=0;i<l/2;i++)
		swap(s[i],s[l-1-i]);
	memset(nt,-1,sizeof(nt));
	k=-1,j=0;
	while(j<l){
		if(k==-1 or s[j]==s[k]){
			j++,k++,xh=j-k;
			bool y=(xh!=j and j%xh==0);
			if(y==0 and bl[l-1-j]==0)
				cnt++;
			if(s[j]!=s[k])nt[j]=k;
			else nt[j]=nt[k];
		}
		else k=nt[k];
	}
	printf("2\n%d",cnt);
	return 0;
}

Measured memory_bytes: 21764
#include <iostream>
#include <sstream>
#include <vector> 
#include <algorithm>
#include <string>
#include <map>
using namespace std;

int main() {
    int N;
    int Q;
    int count = 0;
    
    cin >> N;

    vector<int> n_vec(N);
    

    for (int i = 0; i < N; i++) {
        cin >> n_vec.at(i);
    }

    cin >> Q;

    vector<int> q_vec(Q);

    for (int i = 0; i < Q; i++) {
        cin >> q_vec.at(i);
    }

    
    for (int i = 0; i < Q; i++) {
        int q = q_vec.at(i);

        for (int k = 0; k < N; k++) {
            int n = n_vec.at(k);

            if(n == q) {
                count++;
                break;
            }
        }
    }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define pss pair<short,short>
#define piii  pair<pii,int>
#define vii vector<pair<int,int> >
#define st first
#define nd second
const int mod=1000000007;
const int inf=1000000009;
const long long int INF=1000000000000000009;
using namespace std;
int P[100001],T[100001],S[100001];
int pow(ll a,int b)
{
    ll wynik=1;
    if(b==0)
        return 1;
    while(b!=0)
    {
        if(b&1)
        {
            wynik*=a;
            wynik%=mod;
        }
        a*=a;
        a%=mod;
        b/=2;
    }
    return wynik;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&T[i]);
    for(int i=1;i<=n;i++)
        P[i]=pow((ll)i,mod-2);
    for(int i=1;i<=n;i++)
    {
        S[i]=S[i-1]+P[i];
        S[i]%=mod;
    }
    ll wynik=0;
    for(int i=1;i<=n;i++)
    {
        wynik+=(ll)S[i]*T[i]+(ll)(S[n-i+1]-S[1])*T[i];
        wynik+=(ll)mod*mod;
        wynik%=mod;
    }
    for(int i=2;i<=n;i++)
    {
        wynik*=i;
        wynik%=mod;
    }
    printf("%lld",wynik);
    return 0;
}


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

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define all(x) (x).begin(),(x).end()
#define IN(type,a) type a;cin >> a
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

using ll = long long;

int main() {
    IN(int, n);
    int sum = 0;
    int ans = 0;
    int k;
    REP(i, n){
        cin >> k;
        sum += k;
        ans -= k*k;
    }
    ans += sum*sum;
    ans /= 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("C:\\Users\\BOG\\Desktop\\path.txt");ofstream out("C:\\Users\\BOG\\Desktop\\crd.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main(){
    fast;
    ll x,y; cin>>x>>y;
    cout<<x*y/__gcd(x,y);
}

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

using namespace std;
int n,i,j;
double p[3001],a[3001][3001],ans;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>p[i];
    }
    a[0][0]=1.0;
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=i;j++)
        {
            if(j==0)
            {
                a[i][j]=a[i-1][0]*(1-p[i]);
            }
            else{
               a[i][j]=(a[i-1][j]*(1.0-p[i]))+a[i-1][j-1]*p[i];
            }
        }
    }
    ans=0.0;
    for(j=n/2+1;j<=n;j++)
        ans+=a[n][j];
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}


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

using ll=long long;
const ll MOD=1000000007;

int main() {
  int a,b;
  cin >> a >> b;
  if(b%a==0){
    cout << a+b << endl;
  }
  else
    cout << b-a << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

int main() 
{
	int n,m;
	while(cin>>n>>m&&!(n==0&&m==0))
	{
		pair<int,int> a[20000],b[20000];
		REP(i,m)
		{
			int x,y,z;
			cin>>x>>y>>z;
			y-=1;z-=1;
			a[i] = make_pair(x,y);
			b[i] = make_pair(x,z);
		}
		sort(a,a+m);
		sort(b,b+m);
		
		bool inf[20000]={};
		inf[0]=true;
		//REP(i,n)cout<<inf[i];cout<<endl;
		REP(i,m){if(inf[a[i].second]){inf[b[i].second]=true;}}
		//REP(i,n)cout<<inf[i];cout<<endl;
		int ans(0);
		REP(i,n)ans+=inf[i];
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1504
import Control.Applicative ((<$>), (<*>))
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Char (isSpace)

main :: IO ()
main = do
  B.getLine
  solve <$> getl (readil B.readInt) >>= print

solve :: [Int] -> Int
solve = f 0 . sortBy (flip compare)
  where
    f d []  = d
    f d [x] = d + x
    f d (x:y:ys) = f (d + x - y) ys
      
getl :: (ByteString -> a) -> IO a
getl f = f <$> B.getLine

readil :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a]
readil f = unfoldr g
  where
    g s = do
      (n, s') <- f s
      return (n, B.dropWhile isSpace s')


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

using namespace std;

int main() {
  int n;
  cin >> n;

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

  long long cnt1 = 0, sum = 0;
  for (int i = 0; i < n; ++i) {
    long long _sum = sum + a[i], su = (i & 1 ? _sum : -_sum);
    if (su >= 0) {
      cnt1 += su + 1;
      sum = (i & 1 ? -1 : 1);
    } else sum = _sum;
  }

  long long cnt2 = 0;
  sum = 0;
  for (int i = 0; i < n; ++i) {
    long long _sum = sum + a[i], su = (i & 1 ? -_sum : _sum);
    if (su >= 0) {
      cnt2 += su + 1;
      sum = (i & 1 ? 1 : -1);
    } else sum = _sum;
  }

  cout << min(cnt1, cnt2) << endl;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
using namespace std;
 
 
int main() {
    int n; cin >> n;
    vector<int> a(n), b(n);
    vector<int> aa(n,0), bb(n,0);
    rep(i,n) { cin >> a[i]; aa[ --a[i] ]++; }
    rep(i,n) { cin >> b[i]; bb[ --b[i] ]++; }
    rep(i,n) if (aa[i] + bb[i] > n) { cout << "No" << endl; return 0; }
 
  	cout << "Yes" << endl;
    queue<pair<int,int>> que;
 
    rep(i,n) {
        if (a[i] != b[i]) {
            if (!que.empty()) {
                auto p = que.front();
                if (a[i] != p.first && b[i] != p.first) {
                    que.pop();
                    swap(b[p.second], b[i]);
                }
            }
        }
        else {
            if (que.empty()) que.push({a[i],i});
            else {
                auto p = que.front();
                if (a[i] == p.first) que.push(make_pair(a[i],i));
                else {
                    que.pop();
                    swap(b[p.second], b[i]);
                }
            }
        }
    }
    rrep(i,n) {
        if (a[i] != b[i]) {
            if (!que.empty()) {
                auto p = que.front();
                if (i != p.second && a[i] != p.first && b[i] != p.first) {
                    que.pop();
                    swap(b[p.second], b[i]);
                }
            }
        }
        else {
            auto p = que.front();
            if (i != p.second && a[i] != p.first) {
                que.pop();
                swap(b[p.second], b[i]);
            }
        }
    }

    rep(i,n) cout << b[i] + 1 << (i == n - 1 ? "\n" : " ");
    return 0;
}

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

int main(void)
{
    int N;
    scanf("%d", &N);

    long a;
    int i;
    int c = 0;
    for (i = 0; i < N; i++) {
        scanf("%ld", &a);
        while (1) {
            if (a % 2 == 0) {
                a /= 2;
                c++;
            }
            else
                break;
        }
    }
    printf("%d\n", c);
    return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<int>fac;
	for(int i=1;i*i<=m;++i){
		if(m%i)continue;
		fac.emplace_back(i);
		fac.emplace_back(m/i);
	}
	sort(fac.begin(),fac.end());
	int L=0,R=fac.size(),val=m/n;
	while(R-L>1){
		int M=(L+R)/2;
		if(fac.at(M)>val)R=M;
		else L=M;
	}
	cout<<fac.at(L)<<"\n"s;
}


Measured memory_bytes: 3656
import collections
n = int(input())
S = []
A = collections.Counter(input())
for i in range(n-1):
    B = collections.Counter(input())
    A &= B
ans = ""
for i in A:
    if A[i] > 0:
        ans += i*A[i]
ans = list(ans)
ans.sort()
print("".join(ans))

Measured memory_bytes: 3444