akhauriyash/Code-Regression huggingface dataset:
class UnionFind():#たのんnote
 def __init__(self,n):
   self.n=n
   self.root=[-1]*(n+1)
   self.rank=[0]*(n+1)
 def FindRoot(self,x):
   if self.root[x]<0:
     return x
   else:
     self.root[x]=self.FindRoot(self.root[x])
     return self.root[x]
 def Unite(self,x,y):
   x=self.FindRoot(x)
   y=self.FindRoot(y)
   if x==y:
     return
   else:
     if self.rank[x]>self.rank[y]:
       self.root[x]+=self.root[y]
       self.root[y]=x
     elif self.rank[x]<=self.rank[y]:
       self.root[y]+=self.root[x]
       self.root[x]=y
       if self.rank[x]==self.rank[y]:
         self.rank[y]+=1
 def isSameGroup(self,x,y):
   return self.FindRoot(x)==self.FindRoot(y)
 def Count(self,x):
   return -self.root[self.FindRoot(x)]
 
n,m,k=map(int,input().split())
t=UnionFind(n+1)
cnt=[0]*(n+1) #各iについて、iと同一の連結成分に属する友達関係の人、ブロック関係の人の数を数える
for _ in range(m):
 a,b=map(int,input().split())
 cnt[a]+=1 #各iについて、iと同一の連結成分に属する友達関係の人の数を数える
 cnt[b]+=1
 t.Unite(a,b)
for _ in range(k):
 a,b=map(int,input().split())
 if t.isSameGroup(a,b)==True:
   cnt[a]+=1 #各iについて、iと同一の連結成分に属するブロック関係の人の数を数える
   cnt[b]+=1
ans=[0]*(n+1)
for i in range(1,n+1):
 ans[i]=(t.Count(i)-1)-cnt[i] #答えは(各iが属する連結成分のサイズ)-1-((iと同一の連結成分に含まれているiと友達関係にある人の数)+(iと同一の連結成分に含まれているiとブロック関係にある人の数)となる
print(*ans[1:])

Measured memory_bytes: 11828
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    public static boolean debug = true;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        HashMap<String,Long> map = new HashMap<>();
        for(int i=0; i< n;i++){
            char[] array = sc.next().toCharArray();
            Arrays.sort(array);

            String result = new String(array);

            long temp =0;
            if(map.containsKey(result)){
                temp = map.get(result);
            }
            map.put(result,temp+1);

        }

        long count =0;
        for(long c:map.values()){
            count += c * (c-1) / 2;
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 53604
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll s[3];
string ss;
int main() {
	cin >> ss;
	REP(i, ss.size()) {
		if (ss[i] == 'a')s[0]++;
		else if (ss[i] == 'b')s[1]++;
		else s[2]++;
	}
	sort(s, s + 3);
	cout << (abs(s[2] - s[0]) <= 1 ? "YES" : "NO") << endl;
}

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

int main(void){
    int r, g, b, x;
    cin >> r >> g >> b >> x;
    while(r >= g) g *= 2, --x;
    while(g >= b) b *= 2, --x;
    if(x >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int sx, sy, tx, ty;

int main(void){
	cin>>sx>>sy>>tx>>ty;

	const int dx = tx - sx, dy = ty - sy;

	cout<< string(dy, 'U') << string(dx, 'R');

	cout<< string(dy, 'D') << string(dx, 'L');

	cout<< 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';

	cout<< 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

	cout<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,q,a[100010],x[100010];
    cin>>n>>q;
    rep(i,n){
        cin>>a[i];
    }
    rep(Q,q){
        ll x;
        cin>>x;
        ll ans=0;
        ll right=0;
        ll sum=0;
        rep(left,n){
            while(sum+a[right]<=x&&right<n){
                sum+=a[right];
                right++;                
            }
            ans+=(right-left);
            if(left==right) right++;
            else sum-=a[left];
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	ll n,a,b;cin>>n>>a>>b;
	ll d=n%(a+b);
	cout<<n/(a+b)*a+min(d,a)<<endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

vector<vector<int>> adj;

int dfs(int n, int p=-1) {
  int result = 0, zero = 0;
  for (auto x: adj[n]) {
    if (x==p) continue;
    int num = dfs(x,n);
    if (!num) zero++;
    else result += num;
  }
  if (zero) result += zero-1;
  // cout << n << "->" << result << " " << zero << endl;
  return result;
}

int main() {
  int N; cin >> N;
  adj.resize(N);
  rep(i,N-1) {
    int a, b; cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int s = 0; while(adj[s].size()<=2&&s!=N) s++;
  int result = s==N ? 1 : dfs(s);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 9088
function main(a){
	a = a.split(" ");
	a=stn(a);
	if(a[0]+a[1]==a[2]||a[1]+a[2]==a[0]||a[0]+a[2]==a[1]){
		op("Yes");
	}else{
		op("No");
	}
}
function op(a){
	console.log(a);
}
function stn(a){
		return a.map(function(x){return parseInt(x,10);});
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()

print((N * (N - 1)) // 2)


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

namespace AtCoder.Question
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var t = Console.ReadLine();
            var result = new Char[t.Length];
            for (int i = 0; i < t.Length; i++)
            {
                if (t[i] == '?')
                {
                    result[i] = 'D';
                }
                else
                {
                    result[i] = t[i];
                }
            }
            Console.WriteLine(new String(result));
        }
        static T ReadValue<T>()
        {
            return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
        }
        static (T1, T2) ReadValue<T1, T2>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
        }
        static (T1, T2, T3) ReadValue<T1, T2, T3>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
        }
        static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
        {
            var input = Console.ReadLine().Split(' ');
            return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
        }
        static T[] ReadValues<T>()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
        }
    }
}


Measured memory_bytes: 27268
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define NL << endl

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

using namespace std;

signed main() {
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (auto& e : h) cin >> e;
	sort(h.begin(), h.end());

	int ans = INTMAX;
	int l = 0;
	for (int r = k - 1; r < n; r++, l++) {
		if (ans > h[r] - h[l]) ans = h[r] - h[l];
	}

	cout << ans NL;

	return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#define qmax(x,y) (x=max(x,y));
using namespace std;

typedef long long ll;
const int Maxn=210000;
const ll mod=1000000007;

int to[Maxn],nxt[Maxn],first[Maxn],tot=1;
ll f[Maxn],g[Maxn],pr[Maxn],su[Maxn],p[Maxn],ans[Maxn],m;
int n,u,v;

inline void add(int u,int v) {
	to[tot]=v;
	nxt[tot]=first[u];
	first[u]=tot++;
	to[tot]=u;
	nxt[tot]=first[v];
	first[v]=tot++;
}

void dfs(int root,int fa) {
	int tot=0;
	f[root]++;
	for(int i=first[root];i;i=nxt[i])
		if(to[i]!=fa) {
			dfs(to[i],root);
			f[root]=f[root]*f[to[i]]%m;
		}
	for(int i=first[root];i;i=nxt[i]) if(to[i]!=fa) p[++tot]=to[i];
	f[root]++;f[root]%=m;
	pr[0]=su[tot+1]=1;
	for(int i=1;i<=tot;i++) pr[i]=pr[i-1]*f[p[i]]%m;
	for(int i=tot;i>=1;i--) su[i]=su[i+1]*f[p[i]]%m;
	for(int i=1;i<=tot;i++) g[p[i]]=pr[i-1]*su[i+1]%m;
}

void dfs2(int root,int fa) {
	if(root==1) ans[root]=1;
	else ans[root]=(g[root]*ans[fa]+1)%m;
	for(int i=first[root];i;i=nxt[i])
		if(to[i]!=fa) dfs2(to[i],root);
}

int main() {
	scanf("%d%lld",&n,&m);
	for(int i=1;i<n;i++) {
		scanf("%d%d",&u,&v);
		add(u,v);
	}
	dfs(1,1);
	dfs2(1,1);
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]*(m+f[i]-1)%m);
	return 0;
}


Measured memory_bytes: 15488
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    int a[2][n],sum=0;
    rep(i,2){
        rep(j,n) cin>>a[i][j];
    }
    rep(i,n){
        int maxi=0;
        rep(j,n-i){
            maxi+=a[0][j];
        }
        repi(j,n-i-1,n){
            maxi+=a[1][j];
        }
        sum=max(maxi,sum);
    }
    cout<<sum;
}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

const int MAX_N = 100000;

int main () {
    int n, k;
    int h;

    cin >> n >> k;

    int ans = 0;

    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) {
            ans++;
        }
    }

    cout << ans << endl;
}

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

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

using namespace std;

int main(){
  string s1,s2,s3;
  cin>>s1;
  cin>>s2;
  cin>>s3;
  
  cout<<s1.at(0)<<s2.at(1)<<s3.at(2);
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

//繰り返し二乗法
ll mod_pow(ll x,ll n){
	ll res = 1;
	while(n > 0){
		if(n & 1){
			res = res * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

int main(){
	ll n;cin>>n;
	ll k;cin>>k;
	vector<ll> a(k + 1);
	for(ll i = 1; i <= k; i++) {
		a[i] = mod_pow((k / i),n);
	}
	ll ans = 0;
	vector<ll> cnt(k + 1);
	for(ll i = k; i >= 1; i--) {
		ll tmp = a[i];
		ll x = 2;
		while(x * i<= k){
			tmp -= cnt[x * i];
			x++;
		}
		cnt[i] = tmp;
	}
	for(ll i = 1; i <= k; i++) {
		ans += (i * cnt[i]);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4844
x1, y1, x2, y2 = map(int, input().split())

x3, y3 = x2 - (y2-y1), y2 + (x2-x1)
x4, y4 = x3 - (x2-x1), y3 - (y2-y1)

print(x3, y3, x4, y4)

Measured memory_bytes: 38256
END { load __FILE__ unless $stdin.eof? }

require 'prime'

n = gets.to_i
a = gets.split.map!(&:to_i)
b = a.dup

result = true
while b.size > 1
  b = b.each_slice(2).map do |s, t|
    t ||= 1
    break if s.gcd(t) != 1
    s * t
  end

  unless b
    result = false
    break
  end
end

if result
  puts "pairwise coprime"
elsif a.inject(0, :gcd) == 1
  puts "setwise coprime"
else
  puts "not coprime"
end


Measured memory_bytes: 78520
n,m=map(int,input().split())
A=set(int(input()) for i in range(m))
dp=[0]*(n+1)
dp[0]=1
for i in range(1,n+1):
    dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
    if i in A:dp[i]=0
print(dp[n])


Measured memory_bytes: 11884
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

A,B,m = inpl()
a = inpl()
b = inpl()
xyc = [inpl() for i in range(m)]
res = INF
for i in range(m):
    x,y,c = xyc[i]
    x -= 1; y -= 1
    tmp = a[x] + b[y] - c
    res = min(res, tmp)
res = min(res, min(a)+min(b))
print(res)

Measured memory_bytes: 101804
#include <stdio.h>

int search(int A[], int n, int key) {
    int i = 0;
    A[n] = key;
    while(A[i] != key) i++;
    return i != n;
}

int main(void) {
    int i,A[10001],key,sum=0,n,m;

    scanf("%d",&n);
    for(i = 0; i < n; i++) {
        scanf("%d",&A[i]);
    }

    scanf("%d",&m);

    for(i = 0; i < m; i++) {
        scanf("%d",&key);
        if(search(A ,n ,key)) sum ++;
    }
    printf("%d\n",sum);
    return 0;

}

Measured memory_bytes: 636
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

typedef uint16_t bitmask;

const int N = 20, K = 1 << 16;
int n, a[N][N];
ll dp[K], score[K];

ll rec(bitmask cur) {
	ll& memo = dp[cur];
	if(memo != -1) return memo;
	// DEBUG(cur);
	ll res = 0;
	vector<int> have;
	REP(i, n) if(cur & (1 << i)) have.push_back(i);
	int num_have = have.size();
	bitmask hi = (1 << num_have)-1;
	for(bitmask i = 1; i && i <= hi; ++i) {
		bitmask next_mask = 0;
		REP(j, num_have) if(i & (1 << j)) next_mask |= (1 << have[j]);
		res = max(res, score[next_mask] + rec(cur & ~next_mask));
	}
	return memo = res;
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    memset(dp, -1, sizeof(dp));
    cin >> n;
    REP(i, n) REP(j, n) cin >> a[i][j];
    int tot = 1 << n;
    REP(i, tot) {
    	vector<int> have;
		REP(j, n) if(i & (1 << j)) have.push_back(j);
		REP(j, have.size()) FOR(k, j+1, have.size()-1) score[i] += a[have[j]][have[k]];
    }
    // REP(i, tot) cout << score[i] << endl;
    cout << rec(tot - 1) << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


Measured memory_bytes: 1280
n = int(input())
h = list(map(int, input().split()))
dp = [None]*n
dp[0], dp[1] = 0, abs(h[0]-h[1])
for i in range(2, n):
    dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]))
print(dp[-1])

Measured memory_bytes: 13980
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  vector<ll> C(N); rep(i,N) cin >> C[i];
  sort(rall(C));
  ll ans = 0;
  if(N==1){
    cout << 2*C[0]%mod << endl;
    return 0;
  }
  vector<ll> mpow(200020,1);
  mpow[1] = 2;
  for(int i=2; i<=200000; i++){
    mpow[i] = mpow[i-1]*2%mod;
  }
  rep(i,N){
    ans += (2+i)*C[i]%mod;
    ans %= mod;
  }
  cerr << ans << endl;
  ans = ans * mpow[N-1] % mod;
  cout << ans*mpow[N-1]%mod << endl;
  return 0;
}


Measured memory_bytes: 3328
n=int(input())
a=list(map(int, input().split()))
cnt=[0]*((10**6)+1)
unique=[]

for num in a:
    cnt[num]+=1

for i in range(10**6 +1):
    if cnt[i]==1:
        unique.append(i)

table=[0]*((10**6)+1)
a=list(set(a))

for elem in a:
    for i in range(2*elem, 10**6 +1, elem):
        table[i]=1

ans=0

for elem in unique:
    if table[elem]==0:
        ans+=1

print(ans)

Measured memory_bytes: 53916
import sys
import itertools
import collections

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N, P = [int(x) for x in input().split()]
    S = input().strip()

    if P == 2 or P == 5:
        ans = 0
        for i, s in enumerate(S[::-1]):
            if int(s) % P == 0:
                ans += N - i
        print(ans)
        return

    M = [0] * N
    for i, s in enumerate(S[::-1]):
        M[i] = (int(s) * pow(10, i, P)) % P

    MA = []
    MA.append(M[0])
    c = collections.Counter()
    ans = 0
    c[0] += 1
    ans += c[MA[0]]
    c[M[0]] += 1
    for i in range(1, N):
        MA.append((MA[i - 1] + M[i]) % P)
        ans += c[MA[i]]
        c[MA[i]] += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18976
using System;
using System.Collections.Generic;

class A{
	public static void Main(){

		List<string> student = new List<string> ();

		while (true) {
			string[] s = Console.ReadLine ().Split (' ');

			int m = int.Parse (s [0]);
			int f = int.Parse (s [1]);
			int r = int.Parse (s [2]);
			int ad = m + f;
			string decision;

			if (m == f && f == r && m == -1) {
				break;
			} else {
				if (m == -1 || f == -1) {
					decision = "F";
				} else if (ad >= 80) {
					decision = "A";
				} else if (ad >= 65) {
					decision = "B";
				} else if (ad >= 50 || r >= 50) {
					decision = "C";
				} else if (ad >= 30) {
					decision = "D";
				} else {
					decision = "F";
				}

				student.Add (decision);
			}
		}
		for (int i = 0; i<student.Count; i++) {
			Console.WriteLine (student [i]);
		}
	}
}

Measured memory_bytes: 8976
n = gets.chomp.to_i
arr = Array.new(4,0)
n.times do 
  result = gets.chomp
  arr[0] += 1 if result == 'AC'
  arr[1] += 1 if result == 'WA'
  arr[2] += 1 if result == 'TLE'
  arr[3] += 1 if result == 'RE'
end

arr.each_with_index do |a,idx|
  puts "AC x #{a}" if idx == 0
  puts "WA x #{a}" if idx == 1
  puts "TLE x #{a}" if idx == 2
  puts "RE x #{a}" if idx == 3
end


Measured memory_bytes: 14364
// AOJ 2781: Help the Princess!
// 2018.1.31 bal4u

#include <stdio.h>

#define QMAX 40000
typedef struct { int t, r, c; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int r, int c, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].r = r, que[i].c = c, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

int H, W;
char map[203][203];
char mk[203][203];
int mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int dijkstra(int sr, int sc)
{
	int i, r, c, nr, nc, d;
	int princess = 0x7fffff;

	qsize = 0;
	enq(sr, sc, 0);
	while (qsize) {
		r = que[0].r, c = que[0].c, d = que[0].t, deq();
		if (mk[r][c]) continue;
		mk[r][c] = 1;

		if      (map[r][c] == '@') princess = d;
		else if (map[r][c] == '$') return d > princess;

		for (i = 0; i < 4; i++) {
			nr = r + mv[i][0], nc = c + mv[i][1];
			if (nr < 0 || nr >= H || nc < 0 || nc >= W ||
				map[nr][nc] == '#') continue;
			if (mk[nr][nc]) continue;
			enq(nr, nc, d+1);
		}
	}
	return 1;
}

int main()
{
	int r, c, sr, sc;
	char buf[10];

	fgets(buf, 10, stdin), sscanf(buf, "%d%d", &H, &W);
	sr = -1;
	for (r = 0; r < H; r++) {
		fgets(map[r], 203, stdin);
		if (sr >= 0) continue;
		for (c = 0; c < W; c++) if (map[r][c] == '%') sr = r, sc = c;
	}

	puts(dijkstra(sr, sc)? "Yes": "No");
	return 0;
}


Measured memory_bytes: 2080
a,b,c,d,e,f=map(int,input().split())
ans=-1
sugarwater=0
sugar=0
for i in range(101):
    for j in range(101):
        for k in range(101):
            for l in range(101):
                if (c*k+d*l) > e*(a*i+b*j):
                    break
                if (100 * a * i + 100 * b * j == 0 or 100 * a * i + 100 * b * j + c * k + d * l > f):
                    break
                if ans < 100*(c*k+d*l)/(100 * a * i + 100 * b * j + c*k + d*l):
                    ans=100*(c*k+d*l)/(100 * a * i + 100 * b * j + c*k + d*l)
                    sugarwater = 100 * a * i + 100 * b * j + c*k + d*l
                    sugar = c*k+d*l
print("{} {}".format(sugarwater,sugar))

Measured memory_bytes: 44140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int a,b;
    cin >> a >> b;
    if(a<b) cout << 'a' sp '<' sp 'b' << endl;
    else if(a>b) cout << 'a' sp '>' sp 'b' << endl;
    else cout << 'a' sp "==" sp 'b' << endl;
    return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
typedef vector<int>vi;
typedef pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vi>vvi;
#define double long double
#define pow powl
#define sqrt sqrtl
#define cbrt cbrtl
#define floor floorl
#define ceil ceill
#define pb push_back
#define ep emplace_back
#define PB pop_back
#define pf push_front
#define ef emplace_front
#define PF pop_front
#define mp make_pair
#define ub(a,b) upper_bound(all(a),b)-a.begin()
#define lb(a,b) lower_bound(all(a),b)-a.begin()
#define bs(a,b) binary_search(all(a),b)
#define mem(a,b) memset(a,b,sizeof(a))
#define in(a,n) FOR(i,0,n-1) cin>>a[i]
#define in1(a,n) FOR(i,1,n) cin>>a[i]
#define ff first
#define ss second
#define out(a,n) FOR(i,0,n-1) cout<<a[i]<<" ";cout<<endl;
#define out1(a,n) FOR(i,1,n) cout<<a[i]<<" ";cout<<endl;
#define clr(a) a.clear()
#define pow2(a) (1LL<<a)
#define all(a) a.begin(),a.end()
#define all1(a) a.begin()+1,a.end()
#define rall(a) a.rbegin(),a.rend()
#define rall1(a) a.rbegin(),a.rend()
#define sz(a) ((int)a.size())
#define FOR(i,a,b) for(auto i=a;i<=b;i++)
#define NFOR(i,a,b) for(auto i=a;i>=b;i--)
const int mod=1e9+7;

inline int add(int a,int b){return (a%mod + b%mod)%mod;}
inline int sub(int a ,int b){return (a%mod - b%mod + mod)%mod;}
inline int mul(int a,int b){return (a%mod * b%mod)%mod;}
inline int power(int a,int b,int MOD){int res=1;while(b){if(b&1){res*=a;res%=MOD;}a=a*a;a%=MOD;b>>=1;}return res;}

#define trace(x) cout<<#x<<" :: "<<x<<endl;
#define trace2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define trace3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define trace4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}
signed main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 int n;
	 cin>>n;
	 vector<int>v(26,1e9);
	 for(int i=0;i<n;i++)
	 {
	 	   string s;
	 	   cin>>s;
	 	   vector<int>f(26,0);
	 	   for(auto &x:s)
	 	   	f[x-'a']++;
	 	   for(int j=0;j<26;j++)
	 	   	v[j]=min(v[j],f[j]);
	 }
	 string ans;
	 for(int i=0;i<26;i++)
	 {
	 	  for(int j=0;j<v[i];j++)
	 	  	 ans+=(char)('a'+i);
	 }
	 cout<<ans<<endl;
	 time();
	 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <cmath>
#include <map>
#include <set>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> a;
    int b;
    for(int i=0;i<3;i++){
        cin >> b;
        a.emplace_back(b);
    }
    sort(a.begin(),a.end());
    int ans=0;
    for(int i=0;i<2;i++){
        ans+=abs(a[i]-a[i+1]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    long ans = 0;
    long tmp = 0;
    for(int i=s.length()-1;i>=0;i--){
        if(i!=0 && s[i] == 'C'){
            i--;
            if(s[i]== 'B')tmp++;
            else if(s[i]=='C'){
                i++;
                tmp = 0;
            }else{
                tmp = 0;
            }
        }else if(s[i]=='A'){
            ans += tmp;
        }else{
            tmp = 0;
        }
    }
    cout << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  
  string S;
  cin >> S;
  
  vector<int> res(N + 1);
  
  int left = 0;
  int right = count(S.begin(), S.end(), '.');
  res.at(0) = left + right;
  
  for(int i = 0; i < N; i++){
    if(S.at(i) == '#')
      left++;
    else
      right--;
    
    res.at(i + 1) = left + right;
  }
  
  cout << *min_element(res.begin(), res.end()) << endl;
}


Measured memory_bytes: 1412
#include<iostream>
using namespace std;
int main(){
  int N, M, C;
  cin >> N >> M >> C;
  int B[M+1]={};
  for(int i = 1; i <= M; i++) cin >> B[i];
  int A[N+1][M+1]={};
  for(int i = 1; i <= N; i++ )for(int j = 1; j <= M; j++)cin >> A[i][j];

  int ans = 0;
  for(int i = 1; i <= N; i++){
    int sum = 0;
    for(int j = 1; j <= M; j++){
      sum += A[i][j]*B[j];
    }
    if(sum + C > 0)ans++;
  }
  cout << ans <<endl;
}



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

int main(){
    int sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;

    for(int i=0; i < abs(sy - gy); i++) cout << "U";
    for(int i=0; i < abs(sx - gx); i++) cout << "R";
    for(int i=0; i < abs(sy - gy); i++) cout << "D";
    for(int i=0; i < abs(sx - gx); i++) cout << "L";

    cout << "L";
    for(int i=0; i < abs(sy - gy); i++) cout << "U";
    cout << "UR";
    for(int i=0; i < abs(sx - gx); i++) cout << "R";
    cout << "D";

    cout << "R";
    for(int i=0; i < abs(sy - gy); i++) cout << "D";
    cout << "DL";
    for(int i=0; i < abs(sx - gx); i++) cout << "L";
    cout << "U" << endl;


    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> pll;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(make_pair(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
const int mod = 1000000007;

int main() {
    ll n, a;
    cin >> n;
    ll ans[100005];
    for(ll i = 0; i < n; i++) {
        cin >> a;
        ans[a - 1] = i + 1;
    }
    for(ll i = 0; i < n; i++) {
        cout << (i == 0 ? "" : " ") << ans[i];
    }
    cout << endl;
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> x_sort(n);
    rep(i, n) {
        cin >> x[i];
        x_sort[i] = x[i];
    }
    sort(x_sort.begin(), x_sort.end());

    int c_r = x_sort[(int)x_sort.size()/2];
    int c_l = x_sort[(int)x_sort.size()/2 - 1];

    rep(i, n) {
        if(x[i] >= c_r) printf("%d\n", c_l);
        else printf("%d\n", c_r);
    }

    return 0;
}

Measured memory_bytes: 4736
n,m,l=map(int,raw_input().split())
matA=[map(int,raw_input().split()) for i in range(n)]
matB=[map(int,raw_input().split()) for j in range(m)]
for i in range(n):
	for j in range(l):
		 print sum([matA[i][k]*matB[k][j] for k in range(m)]),
	print	

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

const int N = 1000005;
const int mod = (int) 998244353;

int n, mx;
int a[N];
int cnt[N];
int ans[N];
long long inv[N];

void init() {
   inv[0] = inv[1] = 1;
   for (int i = 2; i < N; i++) {
      inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
   }
}

int solve(int g) {
   long long sum = 0, res = 0;
   for (int i = g; i <= mx; i += g) {
      (sum += cnt[i] * 1LL * i % mod) %= mod;
   }
   for (int i = g; i <= mx; i += g) {
      (res += cnt[i] * 1LL * i % mod * sum % mod) %= mod;
   }
   (res *= inv[g]) %= mod;
   for (int i = 2 * g; i <= mx; i += g) {
      res -= ans[i] * 1LL * i % mod * inv[g] % mod;
      if (res < 0)
         res += mod;
   }
   return ans[g] = res;
}

int main() {
   init();
   scanf("%d", &n);
   memset(cnt, 0, sizeof cnt);
   memset(ans, 0, sizeof ans);
   mx = 0;
   for (int i = 0; i < n; i++) {
      scanf("%d", a + i);
      cnt[a[i]]++;
      mx = max(mx, a[i]);
   }
   int res = 0;
   for (int g = mx; g > 0; g--) {
      (res += solve(g)) %= mod;
   }
   for(int i = 0 ; i < n ; ++i){
      res = (res - a[i] + mod) % mod;
   }
   res = (1ll * res * inv[2]) % mod;
   printf("%d\n", res);
   return 0;
}

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

int main(){
    int N;
    cin >>N;
    char S[N];
    long long r=0;long long g=0;long long b=0;
    for(int i=0;i<N;i++){
        cin >>S[i];
        if(S[i]=='R') r++;
        else if(S[i]=='G') g++;
        else if(S[i]=='B') b++;
    }
    long long  ans = r*g*b;
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            if(j+j-i<N){
                if((S[j+j-i]!=S[j])&&(S[i]!=S[j])&&(S[i]!=S[j+j-i])) ans --;
            }
        }
    }
    cout <<ans<<endl;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int a[1000][1000];
vector<pint> ans;
int main() {
  int N; cin>>N;
  int M	= N/2*2;
  for(int i = 1; i <= M; i++) {
    for(int j =	i+1; j <=	M; j++) {
      if(i+j ==	M+1) continue;
      ans.push_back(make_pair(i,j));
    }
    if(N != M) {
      ans.push_back(make_pair(i,M+1));
    }
  }
  cout << ans.size() <<	endl;
  REP(i,ans.size()) {
    cout << ans[i].first << " "	<< ans[i].second << endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <deque>
#include <iostream>
#include <vector>

#include <set>

#define FOR(i, b, e) for(int i=(b);i<(e);i++)
#define REP(i, n) FOR(i,0,n)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

set<int> s;

int N;

int main() {
    cin >> N;
    REP(i, N) {
        int tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    if (s.size() == N)
        cout << "YES";
    else
        cout << "NO";
    cout << endl;
    return 0;
}


Measured memory_bytes: 9600
s = list(input())
t = list(input())
s.sort()
t.sort(reverse=-True)
S = ''.join(s)
T = ''.join(t)
chk = [S,T]
if S == T:
  print('No')
  exit()
else:
  chk.sort()
  if chk[0] == S:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <deque>
#include <string>
#include <vector>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdio>
#include <cmath>
#include<list>
#include <cstdlib>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 8;
int n,q,x,num;
int s[maxn];

bool is_find(int x)
{
    int left,right,mid;
    left = 0; right = n;
    while(left < right)
    {
        mid = (left + right) / 2;
        if(s[mid] == x) return true;
        else if(s[mid] > x){
            right = mid;
        }else if(s[mid] < x){
            left = mid + 1;
        }
    }
    return false;
}
int main()
{
    scanf("%d",&n);
    num = 0;
    for(int i = 0; i < n; ++i) scanf("%d", &s[i]);
    sort(s,s+n);
    scanf("%d",&q);
    for(int i = 0; i < q; ++i) {
        scanf("%d", &x);
        if(is_find(x)) num++;
    }
    printf("%d\n",num);
    return 0;
}

Measured memory_bytes: 3532
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.math.BigInteger
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlin.math.sqrt

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val A = nal(N)
    if (A.contains(0L)) {
      out.println(0)
      return
    }

    val B = A.filter { it > 1 }
    if (B.size >= 60) {
      out.println(-1)
      return
    }

    var ans = BigInteger.valueOf(1)
    for (a in A) {
      ans = ans.multiply(BigInteger.valueOf(a))
    }
    debug{ans.toString()}
    if (ans.compareTo(BigInteger.valueOf(1e18.toLong())) == 1) {
      out.println(-1)
    } else {
      out.println(ans)
    }
  }













































  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}

Measured memory_bytes: 58648
#include<iostream>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;

int main(void) {
	int n;
	int a[101];
	cin >> n;
	FOR(i, 0, n) {
		cin >> a[i];
	}
	sort(a, a+n);
	cout << a[n-1] - a[0] << endl;
}

Measured memory_bytes: 256
n=int(input())
a=[]
b=[]
c=[0]
for i in range(n):
    a.append(input())
m=int(input())
for i in range(m):
    b.append(input())
for d in a:
    ans=a.count(d)-b.count(d)
    c.append(ans)
print(max(c))

Measured memory_bytes: 3064
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 101;
const i64 P = 1000000000 + 7;
i64 dp[maxn][maxn * maxn];

void add(i64 &x, i64 y) {
    (x += y) %= P;
    if (x < 0) x += P;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, k;
    cin >> n >> k;
    dp[n][0] = 1;
    for (int i = n; i >= 1; --i) forn(j, maxn * maxn) {
        if (!dp[i][j]) continue;
        forn(x, k + 1) {
            if (x > i) {
                add(dp[i - 1][j], dp[i][j]);
                continue;
            }
            int t = i - x;
            if (j >= t) {
                int jj = j + 1 + (j - t) / i;
                assert(jj < maxn * maxn);
                add(dp[i - 1][jj], dp[i][j]);
            } else add(dp[i - 1][j], dp[i][j]);
        }
    }

    i64 total = n * k * (k + 1) / 2;
    forn(i, n - 1) (total *= (k + 1)) %= P;
    forn(j, maxn * maxn) {
//        if (dp[0][j]) cerr << j << ' ' << dp[0][j] << '\n';
        add(total, -j * dp[0][j]);
    }
    cout << total << '\n';
    
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

using namespace std;
typedef long long ll;

ll n, a, b, c;
ll ans=0;
vector<ll> A, B, C;

int main(){
	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> a;
	    A.push_back(a);
	}

	for(int i = 0; i < n; i++){
		cin >> b;
	    B.push_back(b);
	}

	for(int i = 0; i < n; i++){
		cin >> c;
	    C.push_back(c);
	}


	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());

	for(int i = 0; i < n; i++){
		ll ab = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
		ll bc = C.end() - upper_bound(C.begin(), C.end(), B[i]);

		ans += ab*bc;
	}

	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 3316
// Believe in yourself...
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) (c).size()
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)

#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=1e5+10;
const ll mod=1e9+7;

#pragma GCC Optimize("Ofast")

ll a[maxn],b[maxn];
ll n;

void equall(){
	REP(i,n)
		if(a[i]!=b[i])
			return;
	cout<<0;
	exit(0);
}
int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i]>>b[i];
	equall();
	ll sum=0,m=inf;
	REP(i,n){
		if(b[i]<a[i])
			m=min(m,b[i]);
		sum+=b[i]+a[i];
	}
	sum-=2*m;
	ll ans=sum/2;
	cout<<ans;
}

Measured memory_bytes: 512
import Prelude hiding (abs)
import Control.Monad
import Control.Arrow ((&&&))
import Data.List (nub, sort, group)
import Data.Maybe (fromMaybe)
import qualified Data.IntMap as M

main :: IO ()
main = do
    [h,w] <- (map read . words) <$> getLine
    as <- replicateM h getLine
    mapM_ putStrLn $ solve as w

-- |
solve :: [String] -> Int -> [String]
solve as w = [wall] ++ body ++ [wall]
  where
    wall = replicate (w + 2) '#'
    body = map sand as

sand :: String -> String
sand s = "#" ++ s ++ "#"


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

int main() {
	int P, Q, R,s;
	cin >> P >> Q >> R;
	if (P > Q ) {
		s = Q;
		if (P > R) {
			s = s + R;
		}
		else {
			s = s + P;
		}
		
	}
	else {
		s = P;
		if (Q > R) {
			s = s + R;
		}
		else
		{
			s = s + Q;
		}
	}
	cout << s << endl;
	return 0;
}


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

using namespace std;
//using ll = long long;

int main() {
	int N;
	long long A, B;
	int pre, now;
	long long ans = 0;

	cin >> N >> A >> B;
	cin >> now;
	for (int i = 1; i < N; i++) {
		pre = now;
		cin >> now;
		ans += min((now - pre) * A, B);
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
    string s;
    cin >> s;
    size_t n = s.length();

    for (int i = 0; i < n; ++i){
        if(s[i]=='7'){
            cout << "Yes" << endl;
            break;
        }
        if (i==n-1){
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(){
    int N, i;
    long long int ans[86];

    scanf("%d", &N);

    ans[0] = 2;
    ans[1] = 1;

    for(i=2; i<=N; i++){
        ans[i] = ans[i-2] + ans[i-1];
    }

    printf("%lld\n", ans[N]);

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int next_seq(int *seq, const int len, const int m)
{
    int carry = 0, last, last_value;
    for (int i = len - 1; i >= 0; i--)
    {
        if (seq[i] >= m && i > 0)
        {
            seq[i] = seq[i - 1] + 1;
        }
        else if (seq[i] >= m)
        {
            carry = 1;
        }
        else
        {
            seq[i]++;
            last = i;
            last_value = seq[i];
            break;
        }
    }

    for (int i = last + 1; i < len; i++)
    {
        seq[i] = last_value;
    }

    return carry;
}

int main()
{
    int n, m, q, max = 0;
    int a[50] = {
        0,
    };
    int b[50] = {
        0,
    };
    int c[50] = {
        0,
    };
    int d[50] = {
        0,
    };

    int seq[11] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
    }

    seq[n - 1] = 0;

    while (!next_seq(seq, n, m))
    {
        int sum = 0;

        for (int i = 1; i <= q; i++)
        {
            if (seq[b[i - 1] - 1] - seq[a[i - 1] - 1] == c[i - 1])
                sum += d[i - 1];
        }
        /*
        for (int i = 0; i < n; i++)
        {
            printf("%02d ", seq[i]);
        }
        */
        max = max < sum ? sum : max;
        //printf(" %d\n", sum);
    }

    printf("%d", max);

    return 0;
}

Measured memory_bytes: 1732
N = int(input())
*A, = map(int, input().split())
t = (N & 1)
S = [0]*(N+1)
for l in range(1, N+1):
    S = [min(S[i+1] - A[i], S[i] - A[i+l-1]) for i in range(N-l+1)] if (l ^ N) & 1 else [max(S[i+1] + A[i], S[i] + A[i+l-1]) for i in range(N-l+1)]
print(S[0])

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

int main(){
	string s;cin >> s;
 	for(int i=0;i<3;i++){
    	if(s[i]==s[i+1]){
        	cout << "Bad";
          	return 0;
        }
    }
  	cout << "Good";
  	return 0;
}

Measured memory_bytes: 256