akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

struct summ{ll flag;string s;};

bool comp(summ x,summ y){
    if(x.flag>y.flag){
        return true;
    }
    if(x.flag==y.flag){
        return x.s<y.s;
    }
    return false;
}

int main(){
    ll n;cin>>n;
    string s[n];
    ll c=0;
    unordered_map<string,ll> mp;
    summ sum[n];
    rep(i,0,n-1){
        sum[i].flag=0;
        sum[i].s="";
    }
    rep(i,0,n-1){
        cin>>s[i];
        auto itr=mp.find(s[i]);
        if(itr==mp.end()){
            mp[s[i]]=c;
            sum[c].flag++;
            sum[c].s=s[i];
            c++;
        }else{
            sum[mp[s[i]]].flag++;
        }
    }
    /*
    rep(i,0,c-1){
        cout<<sum[i].flag<<' '<<sum[i].s<<endl;
    }
     */
    sort(sum,sum+c,comp);
    cout<<sum[0].s<<endl;
    if(n>1){
        rep(i,1,n-1){
            if(sum[i].flag!=sum[0].flag){
                break;
            }
            cout<<sum[i].s<<endl;
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 28744
#include<iostream>
#include<algorithm>
#include<numeric>
using namespace std;

int main(){
    int n;
    while(cin >> n){
        int a[n];
        for(int i = 0; i < n; i++)  cin >> a[i];
        sort(a, a+n);

        for(int i = 1; i < n; i++)  a[i] += a[i-1];
        
        cout << accumulate(a, a+n, 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 3056
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N;
    scan(N);
    long ans = 1;
    foreach (i; 0 .. N)
    {
        ans *= i + 1;
        ans %= MOD;
    }
    writeln(ans);
}


Measured memory_bytes: 256
#include<stdio.h>

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

  int hd = b-a;
  int i,h = hd;
  for(i=0;i<hd;i++)
    h += i;

  printf("%d\n",h-b);
  return 0;
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;//vertex, cnt
int main(int argc, char *argv[]){
  int n, m;
  while(cin >> n >> m){
    if(n == 0 && m == 0)break;
    vector<vector<int> > g(n, vector<int>());
    bool used[n];
    memset(used, 0, sizeof(used));
    for (int i = 0; i < m; i++) {
      int to, from;
      cin >> to >> from;
      to--;from--;
      g[to].push_back(from);
      g[from].push_back(to);
    }
    queue<pii> que;
    que.push(pii(0, 0));
    int ans = -1;
    used[0] = true;
    while(!que.empty()){
      int v = que.front().first;
      int cnt = que.front().second;
      que.pop();
      if(cnt > 2)break;
      ans++;
      for (int i = 0; i < g[v].size(); i++) {
        int next = g[v][i];
        if(used[next] == false){
          used[next] = true;
          que.push(pii(next, cnt + 1));
        }
      }
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1368
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = III()

d = abs(A[0])
for i in range(N-1):
    d += abs(A[i]-A[i+1])
d += abs(A[N-1])

for i in range(N):
    if 1<=i<=N-2:
        print(d-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]))
    elif i==0:
        print(d-abs(-A[i])-abs(A[i]-A[i+1])+abs(-A[i+1]))
    else:
        print(d-abs(A[i-1]-A[i])-abs(A[i])+abs(A[i-1]))

Measured memory_bytes: 63852
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	int n, m; cin >> n >> m;

	if (m%n == 0) {
		cout << m + n << endl;
	}
	else {
		cout << m - n << endl;
	}

	return 0;
}

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

using ll = long long;

int N;

vector<pair<int, int>> edges;

int main() {
    cin >> N;

    if (N % 2 == 0) {
        for (int i = 1; i <= N/2; ++i) {
            for (int j = i+1; j <= N/2; ++j) {
                edges.emplace_back(i, j);
                edges.emplace_back(i, N+1-j);

                edges.emplace_back(N+1-i, j);
                edges.emplace_back(N+1-i, N+1-j);
            }
        }
    } else {
        for (int i = 1; i <= N/2; ++i) {
            for (int j = i+1; j <= N/2; ++j) {
                edges.emplace_back(i, j);
                edges.emplace_back(i, N-j);

                edges.emplace_back(N-i, j);
                edges.emplace_back(N-i, N-j);
            }

            edges.emplace_back(N, i);
            edges.emplace_back(N, N-i);
        }
    }

    cout << edges.size() << endl;
    for (pair<int, int> e : edges) {
        cout << e.first << " " << e.second << endl;
    }

    return 0;
}


Measured memory_bytes: 384
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    sl = [input() for i in range(n)]

    m = int(input())
    tl = [input() for i in range(m)]

    maxcount = 0
    for s in set(sl+tl):
        count = sl.count(s) - tl.count(s)
        if count > maxcount:
            maxcount = count

    print(maxcount)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
  // Your code here!
  int n,i,a[1000];
  scanf("%d",&n);
  for(i=1; i<=n; i++){
  scanf("%d",&a[i]);
  }
  for(i=n ; i>=1 ; i--){
  printf("%d",a[i]);
  
  if(i==1) break;
  printf(" ");
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long ll;



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

  for(int i=0; i<n; i++){
    cin >> p[i];
  }
  for(int i=0; i<n; i++){
    cin >> q[i];
  }

  int count = 0;
  int nump = 0, numq = 0;
  bool eq = true;

  do{
    count += 1;
    eq = true;
    for(int i=0; i<n; i++){
      if(x[i] != p[i]){
        eq = false;
      }
    }
    if(eq){
      nump = count;
    }
    eq = true;
    for(int i=0; i<n; i++){
      if(x[i] != q[i]){
        eq = false;
      }
    }
    if(eq){
      numq = count;
    }
  }while(next_permutation(x.begin(), x.end()));
  cout << abs(nump-numq) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e15;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e15;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h1, m1, h2, m2;
    cin >> h1 >> m1 >> h2 >> m2;
    int k;
    cin >> k;
    m2 += h2 * 60;
    m1 += h1 * 60;
    m2 -= k;
    cout << max(m2 - m1, 0ll);
}
/*

*/  

Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_map>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int const MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-12;
int INF = INT_MAX / 10;

struct union_find {
	vector<int> v;
	union_find(int n) : v(n, -1) {}
	int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if (-v[x] < -v[y]) swap(x, y);
		v[x] += v[y]; v[y] = x;
	}
	bool root(int x) { return v[x] < 0; }
	bool same(int x, int y) { return find(x) == find(y); }
	int size(int x) { return -v[find(x)]; }
};

i_i f(int x, int y) {
	if (x > y) swap(x, y);
	return i_i(x, y);
}

int main() {
	int N; cin >> N;
	vector<int> a(N - 1), b(N - 1), c(N - 1), d(N - 1);
	rep(i, N - 1) scanf("%d%d", &a[i], &b[i]), a[i]--, b[i]--;
	rep(i, N - 1) scanf("%d%d", &c[i], &d[i]), c[i]--, d[i]--;
	map<i_i, int> mp;
	rep(i, N - 1) {
		mp[f(a[i], b[i])]++;
		mp[f(c[i], d[i])]++;
	}
	queue<i_i> q;
	for (auto z: mp) if (z.second == 2) {
		mp[z.first] = 0;
		q.push(z.first);
	}
	vector<set<int> > st(N);
	rep(i, N - 1) {
		st[a[i]].insert(i);
		st[b[i]].insert(i);
		st[c[i]].insert(~i);
		st[d[i]].insert(~i);
	}
	union_find uf(N);
	while (q.size()) {
		i_i uv = q.front(); q.pop();
		int u = uv.first, v = uv.second;
		u = uf.find(u); v = uf.find(v);
		uf.unite(u, v);
		int w = uf.find(u);
		if (u == w) swap(u, v);
		for (int i: st[u]) {
			st[v].insert(i);
			if (i >= 0) {
				if (!mp[f(a[i], b[i])]) continue;
				mp[f(a[i], b[i])]--;
				if (a[i] == u) a[i] = w;
				if (b[i] == u) b[i] = w;
				mp[f(a[i], b[i])]++;
				if (mp[f(a[i], b[i])] == 2) {
					mp[f(a[i], b[i])] = 0;
					q.push(f(a[i], b[i]));
				}
			}
			else {
				i = ~i;
				if (!mp[f(c[i], d[i])]) continue;
				mp[f(c[i], d[i])]--;
				if (c[i] == u) c[i] = w;
				if (d[i] == u) d[i] = w;
				mp[f(c[i], d[i])]++;
				if (mp[f(c[i], d[i])] == 2) {
					mp[f(c[i], d[i])] = 0;
					q.push(f(c[i], d[i]));
				}
			}
		}
	}
	cout << (uf.size(0) == N ? "YES" : "NO") << endl;
}


Measured memory_bytes: 75904
import java.util.*

fun main(args : Array<String>) {
    val (x, y, a, b, c) = readLine()!!.split(" ").map { it.toInt() }

    val rr = readLine()!!.split(" ").map { it.toInt() }.sortedDescending()
    val gg = readLine()!!.split(" ").map { it.toInt() }.sortedDescending()
    val tt = readLine()!!.split(" ").map { it.toInt() }.sortedDescending()

    val tNum = Math.min(x+y, tt.size)
    val aa = PriorityQueue<Int>(x+y+tNum){ i1, i2 ->
        return@PriorityQueue i2-i1
    }
    aa.addAll(rr.take(x))
    aa.addAll(gg.take(y))
    aa.addAll(tt.take(tNum))

    var sum = 0L
    repeat(x+y) {
        sum += aa.poll()
    }

    println(sum)
}

Measured memory_bytes: 110040
#include <stdio.h>
#include <ctype.h>
#include <string.h>

void check(int A,int B,char* S){
    if(strlen(S) != A+B+1){
        printf("No");
        return;
    }
    for(int i = 0; i < A; i++){
        if(!isdigit(S[i])){
            printf("No");
            return;
        }
    }
    if(S[A] != '-'){
        printf("No");
        return;
    }
    for(int i = A+1; i < A+B+1; i++){
        if(!isdigit(S[i])){
            printf("No");
            return;
        }
    }
    printf("Yes");
    return;
}

int main(int argc, char const *argv[]) {
    int A,B;
    char S[11];
    scanf("%d %d",&A,&B);
    scanf("%s",S);
    check(A,B,S);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  ll N, T;
  cin >> N >> T;
  vector<ll> t(N);
  rep(i, 0, N) cin >> t[i];
  ll ans = N * T;
  rep(i, 1, N) {
    ll d = t[i] - t[i-1];
    if(d < T) ans -= T - d;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>                                                                              
using namespace std;                                                                                  
using ll = long long;                                                                                 
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }               
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }               
int dp[200005];                                                                                       
                                                                                                      
int main() {                                                                                          
  int n, k;                                                                                           
  cin >> n >> k;                                                                                      
  vector<int> a(n);                                                                                   
  for (int i=0; i<n; i++) {                                                                           
    cin >> a[i];                                                                                      
  }                                                                                                   
  for (int i=1; i<=k; i++) {                                                                          
    for (int j=0; j<n; j++) {                                                                         
      if (i-a[j] >= 0) {                                                                              
        dp[i] |= !dp[i-a[j]];                                                                         
      }                                                                                               
    }                                                                                                 
  }                                                                                                   
  if (dp[k]) {                                                                                        
    cout << "First" << endl;                                                                          
  } else {                                                                                            
    cout << "Second" << endl;                                                                         
  }                                                                                                   
  return 0;                                                                                           
}                                                                                                     
                                     

Measured memory_bytes: 640
#!python3

iim = lambda: map(int, input().rstrip().split())

def resolve():
    N, M, Q = iim()
    A = [list(iim()) for i in range(Q)]

    def f(aa, i):
        ans = 0
        if i < N:
            for j in range(aa[i], M+1):
                aa[i+1] = j
                ans = max(ans, f(aa, i+1))
            return ans

        for ai, bi, ci, di in A:
            if aa[bi] - aa[ai] == ci:
                ans += di
        return ans

    print(f([1]*(N+1), 0))

if __name__ == "__main__":
    resolve()


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

struct BipartiteMatching{
  vector<vector<int> > G;
  int V;
  vector<int> match,used;
  
  BipartiteMatching(){}
  BipartiteMatching(int V):V(V){init();}
  
  void init(){
    for(int i=0;i<(int)G.size();i++) G[i].clear();
    G.clear();
    match.clear();
    used.clear();
    G.resize(V);
    match.resize(V,-1);
    used.resize(V,0);
  }
  
  void add_edge(int u,int v){
    G[u].push_back(v);
    G[v].push_back(u);
  }

  bool dfs(int v){
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
      int u=G[v][i],w=match[u];
      if(w<0||(!used[w]&&dfs(w))){
	match[v]=u;
	match[u]=v;
	return true;
      }
    }
    return false;
  }

  int calc(int v){
    int res=0;
    //fill(match.begin(),match.end(),-1);
    fill(used.begin(),used.end(),0);
    if(dfs(v)){
      res++;
    }
    return res;
  }
};


signed main(){
  int n;
  cin>>n;
  BipartiteMatching bm(n+1);
  int ans=0;
  for(int i=1;i<=n;i++){
    int p;
    cin>>p;
    bm.add_edge(p,i);
    ans+=bm.calc(i);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CBoxesAndCandies solver = new CBoxesAndCandies();
        solver.solve(1, in, out);
        out.close();
    }

    static class CBoxesAndCandies {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), x = in.nextInt();
            long sum = 0;
            int prev = 0;
            long ans = 0;
            for (int i = 0; i < n; i++) {
                int a = in.nextInt();
                sum += a;
                if (sum > x) {
                    //System.out.println(sum - x + " " + sum);
                    a -= sum - x;
                    ans += sum - x;
                    sum = x;
                } else {
                    //System.out.println(0 + " " + sum);
                }
                sum -= prev;
                prev = a;
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 50952
'use strict';
// JavaScript Array permutation generator
// (optimized from CoffeeScript output: see ArrayPermutation.coffee)
(function() {
  var generatePermutation = function(perm, pre, post, n) {
    var elem, i, rest, len;
    if (n > 0)
      for (i = 0, len = post.length; i < len; ++i) {
        rest = post.slice(0);
        elem = rest.splice(i, 1);
        generatePermutation(perm, pre.concat(elem), rest, n - 1);
      }
    else
      perm.push(pre);
  };

  /*
  extend Array.prototype
  e.g. [0, 1, 2].permutation(2)
  => [[0, 1], [0, 2], [1, 0], [1, 2], [2, 0], [2, 1]]
  */
  Array.prototype.permutation = function(n) {
    if (n == null) n = this.length;
    var perm = [];
    generatePermutation(perm, [], this, n);
    return perm;
  };
})();
const main = input => {
  const n = parseInt(input[0]);
  const p = input[1].split(' ').map(val => parseInt(val));
  const q = input[2].split(' ').map(val => parseInt(val));
  let pStr = p.join('');
  let qStr = q.join('');
  // console.log(pStr, qStr);
  // console.log(p.permutation());
  let str = p.permutation().map(val => val.join(''));
  // console.log(str);
  str.sort();
  // console.log(str);
  let pId, qId;
  for(let i=0; i<str.length; i++) {
    if (pStr == str[i]) pId = i;
    if (qStr == str[i]) qId = i;
  }
  console.log(Math.abs(pId-qId));
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 30140
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,ans=0;
    cin>>n;
    for (int i=0;i<n-1;i++) 
    {
        int a,b;
        cin>>a>>b;
        if (a>b) swap(a,b);
        ans-=a*(n-b+1);
    }
    for (int i=0;i<n;i++)
    {
        ans+=(n-i)*(i+1);
    }
    cout<<ans;
    return 0;
}

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

int main() {
	long long n;

	std::cin >> n;

	std::vector<long long> v(n);
	for (int i = 0; i < n; i++) {
		std::cin >> v[i];
	}

	std::cout << *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()) << std::endl;
	return 0;
}

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

//{ SFT
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
//gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bit(n) (1LL << (n))
#define bits(n) bitset(n)
#define pcnt(x) __builitin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end());
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
#define F first
#define S second
#define cauto (const auto &)
template <class A, class B>
using pii = vector<pair<A, B>>;
template <class T> //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) //最大値更新 返り値はbool
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) //最小値更新 返り値はbool
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod1 = 1e9 + 7;
constexpr long long mod2 = 998244353;
//} END

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

    int n, m, a, b;
    cin >> n >> m;
    pii<int, int> p;
    pii<int, int> q;

    rep(i, 0, n)
    {
        cin >> a >> b;
        p.emplace_back(a, b);
    }
    rep(i, 0, m)
    {
        cin >> a >> b;
        q.emplace_back(a, b);
    }

    rep(i, 0, n)
    {
        int point, cnt, ans;
        rep(j, 0, m)
        {
            point = abs(p[i].first - q[j].first) + abs(p[i].second - q[j].second);
            //cout<<point<<' ';
            if (j == 0)
            {
                cnt = point;
                ans = j + 1;
            }
            if (cnt > point)
            {
                ans = j + 1;
            }
            chmin(cnt, point);
        }
        cout << ans << '\n';
    }
}

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

int main(){
  int H,W,K;
  cin >> H >> W >> K;
  vector<vector<int>> c(H,vector<int>(W,0)); 
  for(int i=0; i<H; i++){
    string s;
    cin >> s;
    for(int j=0; j<W; j++){
      if(s[j] == '#') c[i][j] = 1;
    }
  }
  int ans = 0;
  for (int i=0; i<(1 << H); i++) {
    bitset<6> h(i);
    for (int j = 0; j<(1 << W); j++) {
      bitset<6> w(j);
      int bl=0;
      for(int k=0; k<H; k++){
        for(int l=0; l<W; l++){
          if(c[k][l]==1 && h[k]==0 && w[l]==0) bl++;
        }
      }
      if(bl == K) ans++;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimization ("O2")
#pragma GCC target("popcnt")
#pragma GCC target ("avx2")
using namespace std;

int main(){
	string s,t;
	cin >> s >> t;
	t.pop_back();
	if(s == t){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();


        Array.Sort(a);
        Array.Reverse(a);

        long index = 1;
        long ans = 0 + a[0];
        long count = 0;
        for (long i = 2; i < n; i++)
        {
            if (count > 1)
            {
                count = 0;
                index++;
            }
            ans += a[index];
            count++;
        }



        // 出力
        Console.WriteLine(ans);
    }
}

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

int main() {
    int a, b; cin >> a >> b;
    const int k = (a + b) / 2;
    if(abs(a - k) == abs(b - k)) {
        cout << k << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
    cin>>a>>b;
    if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  rep(i,0,n-2){
      if(s.at(i)=='A'){
          if(s.at(i+1)=='B'&&s.at(i+2)=='C'){
              count ++;
          }
      }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 256
// --------------
// Tejas Pandey  |
// 13 - 08 - 20  |
// Atcoder BC 175|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;
     
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2] && s[0] == 'R') cout << '3';
  else if(s[0] == s[1] && s[0] == 'R') cout << '2';
  else if(s[1] == s[2] && s[2] == 'R') cout << '2';
  else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << '1';
  else cout << '0';
  return 0;
}


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

using namespace std;

int main(void) {
  int num, i;
  string S, T;
  cin >> S >> T;
  
  num = 0;
  for(i = 0; i < 3; i++) {
    if(S[i] == T[i]) {
      num++;
    }
  }
  
  cout << num << endl;
  return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<bool> to(N + 1);
	vector<bool> from(N + 1);
	fill(to.begin(), to.end(), false);
	fill(from.begin(), from.end(), false);
	for (int i = 0; i < M; i++) {
		int a, b; cin >> a >> b;
		if (a == 1) to[b] = true;
		if (b == N) from[a] = true;
	}
	for (int i = 1; i <= N; i++) {
		if (to[i] && from[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    int n;cin>>n;
    int a;
    for(int i=1;i<=n;i++){
        cin>>a;
        if(a&1){cout<<"first";
            return 0;}
    }
    cout<<"second";
}



Measured memory_bytes: 256
import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math
#import sympy

#N = int(input())
#N,K,d= map(int,input().split())
#A = list(map(int,input().split()))
s = str(input())
#T = str(input())
c,C=0,0

for i in s:
    if i=='R':
        c+=1

    else:
        C=max(c,C)
        c=0

print(max(C,c))


Measured memory_bytes: 27136
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), greater<int>());
    int now = 0;
    long long ans = 0;
    priority_queue<int> pq;
    pq.push(a[now++]);
    for (; now < n; now++) {
        ans += pq.top();
        pq.pop();
        pq.push(a[now]);
        pq.push(a[now]);
    } 
    cout << ans << endl;
}

Measured memory_bytes: 5016
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using ll = long long;
int main(){
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        d.merge(a - 1, b - 1);
    }
    vector<vector<int>> c;
    c = d.groups();
    cout << c.size() - 1 << endl;
}

Measured memory_bytes: 8972
def bell(edges, n):
    count = 0
    dist = [float('inf') for i in range(n)]
    dist[0] = 0

 
    for i in range(n):
        for edge in edges:
            if dist[edge[1]] > dist[edge[0]] + edge[2] and edge[0] != float('inf'):
                dist[edge[1]] = dist[edge[0]] + edge[2]
                if (i == n - 1) & (edge[1] == n - 1):
                    print('inf')
                    exit()
                
    return dist
 
 
n,m = map(int,input().split())
edges = []
for _ in range(m):
    a, b, c = (int(x) for x in input().split())
    edges.append([a-1, b-1, -c])
 
res = bell(edges, n)
 
print(-res[n-1])

Measured memory_bytes: 3396
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Sum of Large Numbers
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int sum = 0;
  for (int i = k - 1; i <= n; i++) {
    ll s0 = (ll)i * (i + 1) / 2;
    ll s1 = (ll)(n + (n - i)) * (i + 1) / 2;
    sum = (sum + (s1 - s0 + 1) % MOD) % MOD;
  }

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 3236
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

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

    solve();
}

void solve() {
    ll n, m;
    std::cin >> n >> m;

    vstr a(n), b(m);
    for (ll i = 0; i < n; i++) std::cin >> a[i];
    for (ll i = 0; i < m; i++) std::cin >> b[i];

    for (ll i = 0; i < n - m + 1; i++) for (ll j = 0; j < n - m + 1; j++) {
        bool flg = true;
        for (ll k = 0; k < m; k++) for (ll l = 0; l < m; l++)
            if (a[i + k][j + l] != b[k][l]) { flg = false; break; }
        if (flg) { std::cout << "Yes" << '\n'; return; }
    }

    std::cout << "No" << '\n';
}


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

int main(void){
    ll n;
    string s;

    cin >> n >> s;

    ll count = 1;
    rep(i, n-1){
        if(s[i] != s[i+1]){
            count++;
        }
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 512
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// ll lmax(ll o , ll w) {if(o>w)return o; return w;}
// ll lmin(ll o , ll w) {if(o<w)return o; return w;}
#define LNF 3999999999999999999
#define INF 999999999
#define N 3000003
#define PI 3.14159265359
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (ll)(c).size()
#define mkp(a,b) make_pair(a,b)
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
ll n , a[N] , sum , ans , mod = 1e9 + 7;
int main(){
fcin;
    cin >> n;
    for(ll i = 0 ; i < n ; i++) cin >> a[i] , sum += a[i];
    for(ll i = 0 ; i < n ; i++){
        sum -= a[i];
        a[i] %= mod;
        ans += (sum + mod )%mod * a[i];
        ans%=mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5180
#include<iostream>

using namespace std;

int main()
{
	int m, n, d, f, x;
	while (cin>>n)
	{
		f = m = d = 0;
		for (int i = 0; i < n; i++)
		{
			cin >> x;
			if (x % 4 == 0) f++;
			if (x % 2 == 0) d++;
			else m++;
		}
		if (d - f >= 1 && f >= m) cout << "Yes" << endl;
		else if (d - f == 0 && (m - 1) <= f) cout << "Yes" << endl;
		else
		{
			cout << "No" << endl;
		}
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int X = 0;
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    if (S == "Y") {
      X++;
      break;
    }
  }
  
  if (X == 0) {
    cout << "Three" << endl;
  }
  else if (X == 1) {
    cout << "Four" << endl;
  }
  else {
    cout << "error" << endl;
  }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }

    val ballCnt = IntArray(N) { 1 }

    val redContains = BooleanArray(N)
    redContains[0] = true

    for (i in 1..M) {
        val (x, y) = readInputLine().split(" ").map { it.toInt() - 1}
        ballCnt[x]--
        ballCnt[y]++

        if (redContains[x]) {
            redContains[y] = true
        }
        if (ballCnt[x] == 0) {
            redContains[x] = false
        }
    }

    println(redContains.count { it })
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 56004
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N];
int main()
{
	int n;
	cin >> n;
	a[0]=-1;
	int sum=0,max=-1;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]<=a[i-1]){
			sum++;
			if(sum>max) max=sum;
		}
		else if(a[i]>a[i-1]){
			sum=0;
			if(sum>max) max=sum;
		}	
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 640
//Ace
#include <bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in, in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i, k, n) for (in i = k; i < n; ++i)
#define repr(i, k, n) for (in i = k; i >= n; --i)
#define sz(x) (in) x.size()
#define all(x) begin(x), end(x)
const in MOD = 1e9 + 7;
const in N = 1e6 + 1;

in fact[N];

void seive()
{
    rep(i, 2, N)
    {
        if (fact[i] == 0)
        {
            for (in j = i * i; j < N; j += i)
                fact[j] = i;
        }
    }
}

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

    in n;
    cin >> n;
    in a[n];
    in gc = 0;
    rep(i, 0, n)
    {
        cin >> a[i];
        gc = __gcd(a[i], gc);
    }

    if (gc != 1)
    {
        cout << "not coprime";
    }
    else
    {
        seive();
        map<in, in> vis;
        rep(i, 0, n)
        {
            map<in, in> tvis;
            while (fact[a[i]] != 0)
            {
                if (vis[fact[a[i]]] == 1)
                {
                    cout << "setwise coprime";
                    return 0;
                }
                tvis[fact[a[i]]] += 1;
                a[i] /= fact[a[i]];
            }
            if (a[i] != 1 && vis[a[i]] == 1)
            {
                cout << "setwise coprime";
                return 0;
            }
            tvis[a[i]] = 1;
            for (auto j : tvis)
                vis[j.first] += j.second;
        }
        cout << "pairwise coprime";
    }

    return 0;
}

Measured memory_bytes: 19276
#include <iostream>
#include <vector>
#include <string>
#include <map>
using namespace std;
int dx[8] = {0,1,1,1,0,-1,-1,-1};
int dy[8] = {1,1,0,-1,-1,-1,0,1};
int main(){
  int h,w;
  while(cin>>h>>w,h){
    vector<string> s(h);
    for(int i = 0;i < h;i++){
      cin>>s[i];
    }
    map<string,int> mp;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
	for(int d = 0;d < 8;d++){
	  int y = i, x = j;
	  string tmps = "";
	  tmps += s[i][j];
	  while(true){
	    int ny = (y+dy[d] + h)%h, nx = (x+dx[d] + w)%w;
	    if(ny == i && nx == j){
	      break;
	    }else{
	      tmps+=s[ny][nx];
	      mp[tmps]++;
	      x=nx,y=ny;
	    }
	  }
	}
      }
    }
    string ans;
    int maxsize = 0;
    for(auto itr = mp.begin();itr!=mp.end();itr++){
      if(itr->second >= 2 && itr->first.size() > maxsize){
	ans = itr->first;
	maxsize = itr->first.size();
      }
    }
    if(maxsize)cout << ans << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 38024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<int> div(int n) {
    vector<int> ans;
    for(int i = 1; i*i <= n; i++) {
        if(n%i == 0) {
            ans.push_back(i);
            ans.push_back(n/i);
        }
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(1e6+2,0);
    rep(i,n) {
        cin >> a[i];
        b[a[i]]++;
    }
    int ans = 0;
    for(int x: a) {
        vector<int> divisor = div(x);
        bool ok = true;
        for(int y: divisor) {
            if(b[y] > 0) {
                if(y != x) {
                    ok = false;
                    break;
                } else if(b[y] > 1){
                    ok = false;
                    break;
                }
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 8004
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int, A: "List[int]"):
    ans = 0

    B = [sum(A[1:])]
    for i, a in enumerate(A[1:-1]):
        B.append(B[i] - a)

    for i, ai in enumerate(A[:-1]):
        ans += (ai * B[i])
    
    print(ans % MOD)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

char A[4];

int write(int i, int j){
    for(int p=0; p<i-1; ++p) cout << A[0];
    for(int p=0; p<j; ++p) cout << A[1];
    for(int p=0; p<i; ++p) cout << A[2];
    for(int p=0; p<j; ++p) cout << A[3];
    cout << A[0];
    return 0;
}

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x=tx-sx+1, y=ty-sy+1;
	A[0]='R'; A[1]='U'; A[2]='L'; A[3]='D';
	int P=write(x, y);
	A[0]='U'; A[1]='R'; A[2]='D'; A[3]='L';
	int Q=write(y, x);
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
<?php

fscanf(STDIN, "%d", $n);
if ($n === 1) {
    echo 0;
    return;
}

$res = [];
for ($i = 2; $i <= sqrt($n); ++$i) {
    if ($n % $i != 0) continue;
    $ex = 0;

    while ($n % $i == 0) {
        ++$ex;
        $n /= $i;
    }
    $res[] = [$i, $ex];
}
if ($n != 1) $res[] = [$n, 1];

$total = 0;
foreach ($res as $arr) {
    $a = $arr[0];
    $ex = $arr[1];

    $i = 1;
    while ($ex >= 0) {
        $ex -= $i;

        if ($ex < 0) break;

        ++$i;
    }

    $total += $i - 1;

    /* echo "a: $a, ex: $ex, i: $i", PHP_EOL; */
}
echo $total;


Measured memory_bytes: 16120
#include<stdio.h>
int main(void)
{
  int a,b;
  scanf("%d %d",&a,&b);
  for(int c=0;c<3;c++){
    if(a*b*c%2==1){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define rg register
using namespace std;
const int MAXN=1e5+10;
int n,T1[MAXN],T2[MAXN];
int M1,S1,M2,S2,M3,S3,M4,S4;
inline int Read()
{   rg int a=0,c=1;   rg char b=getchar();
	while(b!='-'&&(b<'0'||b>'9'))b=getchar();
	if(b=='-')c=-1,b=getchar();
	while(b>='0'&&b<='9')a=a*10+b-48,b=getchar();
	return a*c;
}
inline int Min(rg int A,rg int B){   return A<B?A:B;   }
int main()
{   n=Read();
	for(rg int i=1;i<=n;i+=2)
	{   int A=Read(),B=Read();
		T1[A]++,T2[B]++;
	}
	for(rg int i=1;i<=1e5;i++)
	{	if(T1[i]>M1) M3=M1,S3=S1,M1=T1[i],S1=i;
		else if(T1[i]>M3) M3=T1[i],S3=i;
		if(T2[i]>M2) M4=M2,S4=S2,M2=T2[i],S2=i;
		else if(T2[i]>M4) M4=T2[i],S4=i;
	}
	if(S1!=S2) printf("%d\n",n-M1-M2);
	else printf("%d\n",Min(n-M1-M4,n-M2-M3));
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

bool hantei(long long x){
  for(long long i=2; i*i<=x; i++){
    if(x%i==0) return 0;
  }
  return x>1;
}

int main(){
  
  int n; cin>>n;
  ll ans{};
  for(int i=1; i<=n; i++){
    ll k = n/i;
    ans += i*k*(k+1)/2;
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] l = new int[n];
			int sum = IntStream.range(0, n).map(i -> l[i] = scanner.nextInt()).sum();
			int max = Arrays.stream(l).max().getAsInt();
			System.out.println(((sum - max) > max) ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 36176
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg


int main()
{
	string s, t;
	cin >> s >> t;
	ll ans = 0;
	REP(i, s.length()) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3860
N=int(input())
l=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
S=list(input())
l2=l[N:]+l[:N]
for i in range(len(S)):
  j=l.index(S[i])
  S[i]=l2[j]
ans="".join(S)
print(ans)

Measured memory_bytes: 3064