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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};


int solve(int a,int b){
    if(a>b)swap(a,b);
    if(b%a==0)return (2*(b/a)-1)*a;
    else return 2*(b/a)*a+solve(a,b%a);
}

int n,x;
 
signed main(){
	cin>>n>>x;
	cout<<n+solve(x,n-x)<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#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() {
  string s;
  cin >> s;
  int n = s.size() - 1;
  ll ans = 0;
  rep(bit, 1<<n) {
    ll now = s[0] - '0';
    rep(i, n) {
      if (bit & 1<<i) {
        ans += now;
        now = 0;
      }
      now = 10 * now + (s[i+1] - '0');
    }
    ans += now;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repf(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define repr(i, a, b) for (int i = (int)a; i > (int)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 4e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vii a(n), b(n), c(n - 1);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n - 1) cin >> c[i];
    int ans = 0;
    rep(i, n) ans += b[i];
    rep(i,n-1){
        if (a[i]+1==a[i+1]){
            ans += c[a[i] - 1];
        }
    }
    cout << ans << ENDL;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    char c;
    cin >> c;
    if(c=='A')cout<<'T';
    if(c=='C')cout<<'G';
    if(c=='G')cout<<'C';
    if(c=='T')cout<<'A';
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int N = reader.nextInt();
		int M = reader.nextInt();
		boolean[] A = new boolean[N];
		boolean[] B = new boolean[N];
		for(int i=0; i<M; i++) {
		    int a = reader.nextInt();
		    int b = reader.nextInt();
		    if (a == 1) A[b] = true;
		    if (b == N) B[a] = true;
		}
		for(int i=0; i<N; i++) {
		    if(A[i] && B[i]) {
		        System.out.println("POSSIBLE");
		        return;
		    }
		}
		System.out.println("IMPOSSIBLE");
	}
	
	public static void solver(String S) {
		// write logic
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}


Measured memory_bytes: 25140
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll n,m,k; cin>>n>>m>>k;
	vector<ll> a(n);
	vector<ll> b(m);
	rep(i,0,n) cin>>a[i];
	rep(i,0,m) cin>>b[i];
	ll ans=0;
	vector<ll> acum(n+1,0);
	vector<ll> bcum(m+1,0);
	acum[1]=a[0]; bcum[1]=b[0];
	rep(i,1,n+1) acum[i]=acum[i-1]+a[i-1];
	rep(i,1,m+1) bcum[i]=bcum[i-1]+b[i-1];
	rep(abooks,0,n+1){
		ll res=abooks;
		// debug(abooks);
		ll nokori=k-acum[abooks];
		if(nokori>=0){
			// debug(nokori);
			ll bbooks=distance(bcum.begin(), upper_bound(all(bcum), nokori))-1;
			// debug(bbooks);
			res+=bbooks;
		}else{
			res=0;
		}
		// cout<<res<<endl;
		ans=max(ans,res);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 9588
#include<bits/stdc++.h>
using namespace std;
typedef  long long  ll;
ll inf=LLONG_MAX,mod=1000000007,BS,k;
ll prime[1000005];
ll seive(){
    for(ll i=0;i<1000005;i++)prime[i]=i;
    for(ll i=2;i<1000005;i++){
        if(prime[i]==i)
        for(ll j=i*i;j<1000005;j+=i)
        prime[j]=i;
    }
    return 0;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        #ifndef ONLINE_JUDGE
            freopen("input.txt","r",stdin);
            freopen("output.txt","w",stdout);
        #endif
        map<ll,ll> mp;
        seive();
        ll n;cin>>n;
        ll arr[n];
        for(ll i=0;i<n;i++)cin>>arr[i];
        ll flg=0,temp;vector<ll>ans;
        for(ll i=n-1;i>=0;i--){
            temp=arr[i];ans.clear();
            while(1){
                if(temp==1)break;
                if(mp.find(prime[temp])!=mp.end())
                flg=1;
                ans.push_back(prime[temp]);
                temp/=prime[temp];
            }
            if(temp!=1)
            mp[temp]++;
            for(auto it:ans)
            mp[it]++;
        }
        if(!flg)
        {
            cout<<"pairwise coprime";return 0;
        }
        ll g=0;
        for(ll i=0;i<n;i++){
            g=__gcd(g,arr[i]);
        }
        if(g==1){
            cout<<"setwise coprime";return 0;
        }
        cout<<"not coprime";

}


Measured memory_bytes: 24140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vl x(n);
  rep(i, n) cin >> x[i];
  ll ans = 1e18;
  rep(i, n - k + 1) {
    ll now = min(abs(x[i]), abs(x[i + k - 1])) + x[i + k - 1] - x[i];
    ans = min(ans, now);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rep2(i,a,b) for (ll i = (a); i < (b); ++i)

#define INF 1E18



int main(){
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;

    vector<int> nums;

    int now = 1;
    int cnt = 0;
    rep(i,n){
        if(s[i] == (char)('0' + now)) ++cnt;
        else{
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) nums.push_back(cnt);

    if(nums.size() % 2 == 0) nums.push_back(0);


    int add = 2*k + 1;
    int ans = -1;
    for(int i=0; i<nums.size(); i+=2){
        int left = i;
        int right = min(i+add, (int)nums.size());
        int temp = 0;
        for(int j=left; j<right; j++){
            temp += nums[j];
        }
        ans = max(ans, temp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1020
#include <cstdio>
#include <algorithm>

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

using namespace std;

int h, w;
char x[100][101];
bool u[100][100];

void dfs(int a, int b){
	u[a][b] = true;
	int dx[4] = {0, 0, 1, -1};
	int dy[4] = {-1, 1, 0, 0};
	rep(i, 4){
		int c = a + dx[i];
		int d = b + dy[i];
		if(0 <= c && c < h && 0 <= d && d < w && !u[c][d] && x[c][d] == x[a][b]){
			dfs(c, d);
		}
	}
}

int main(){
	while(scanf("%d%d", &h, &w), h){
		rep(i, h){
			scanf("%s", x[i]);
			fill_n(u[i], w, false);
		}
		int ans = 0;
		rep(i, h){
			rep(j, w){
				if(!u[i][j]){
					++ans;
					dfs(i, j);
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1988
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    n, k = LI()
    g = [[] for i in range(n+1)]
    for i in range(n-1):
        a, b = LI()
        g[a].append(b)
        g[b].append(a)

    s = 1
    Q = [s]
    ans = k
    Qappend = Q.append
    searched = [0] * (n+1)
    searched[s] = 1
    while len(Q) != 0:
        temp = 1
        v = Q.pop()
        if v == s:
            cand = k - 1
        else:
            cand = k - 2
        for i in g[v]:
            if searched[i] == 1:
                continue
            searched[i] = 1
            temp = temp * cand % MOD
            cand -= 1
            Qappend(i)
        ans = ans * temp % MOD
    print(ans % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65212
#include <cstdio>
#include <algorithm>
using namespace std;
long long v[200005],k[200005];
int main() {
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&v[i]);
        k[i]=k[i-1]+v[i];
    }
    long long p[5]={0,0,0,0,0},mmin=0x7fffffff;
    int l=1,r=3;
    for(int i=2;i<n-1;i++){
        while (l<i&&abs(k[l]-k[0]-(k[i]-k[l]))>=abs(k[l+1]-k[0]-(k[i]-k[l+1]))) {
            l++;
        }
        while (r<n&&abs(k[r]-k[i]-(k[n]-k[r]))>=abs(k[r+1]-k[i]-(k[n]-k[r+1]))) {
            r++;
        }
        p[1]=k[l]-k[0];
        p[2]=k[i]-k[l];
        p[3]=k[r]-k[i];
        p[4]=k[n]-k[r];
        mmin=min(mmin,max(p[1],max(p[2], max(p[3],p[4])))-min(p[1], min(p[2], min(p[3], p[4]))));
    }
    printf("%lld\n",mmin);
    return 0;
}


Measured memory_bytes: 3328
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy

def main():
  n = int(input())
  xs = numpy.array(list(map(int, input().strip().split())))
  min = 10**9
  for p in range(1, 101):
    cost = numpy.sum((xs - p) ** 2)
    if min > cost:
      min = cost
  print(int(min))

if __name__=='__main__':
  main()

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> P(n);
    copy_n(istream_iterator<int>(cin), n, P.begin());

    int ans = 0;
    int mi = 1e9;
    for (const auto &p: P){
        if (p < mi){
            ans++;
            mi = p;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <cmath>
#define ll long long
#define ull unsigned long long
using namespace std;
vector<vector<int>> g;
vector<int> len;
vector<vector<int>> col(2);
vector<int> ans;
vector<int> s;
void yn(bool a){
    if(a){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}

int main(){
 

        int a,ans;
        for(int i=0;i<5;i++){
            cin>>a;
            if(a==0){
                ans=i+1;
            }
        }
        cout<<ans<<endl;
    
    
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>
#include <stack>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    map<int,vector<int>> xindex;
    map<int,vector<int>> yindex;

    int n = get<int>();
    vector<int> a(n), b(n);
    vector<bool> visited(n);
    for (int i = 0; i < n; i++) {
        a[i] = get<int>(), b[i] = get<int>();
        xindex[a[i]].push_back(i);
        yindex[b[i]].push_back(i);
    }
    long ans = 0;
    for (int i = 0; i < n; i++) {
        if (visited[i]) continue;

        set<int> xset;
        set<int> yset;
        function<long(int)> dfs = [&](int j) {
            if (visited[j]) return 0L;
            xset.insert(a[j]);
            yset.insert(b[j]);
            visited[j] = true;
            long r = 1;
            for (int k : xindex[a[j]])
                r += dfs(k);
            for (int k : yindex[b[j]])
                r += dfs(k);
            return r;
        };
        long r = dfs(i);
        ans += xset.size() * yset.size() - r;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int a,b;
  cin >> a >> b;
  int ans = (a+b+1)/2;
  cout << ans << endl;
}


Measured memory_bytes: 256
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s.begin(),s.end());
    long long a=1;
    long long sum=0;
    for(int i=1; i<n; i++){
        if(s[i]==s[i-1]) a++;
        else{
            sum+=a*(a-1);
            a=1;
        }
    }
    sum+=a*(a-1);
    cout << sum/2 << endl;
}

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

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

using namespace std;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n), b(n);
  std::map<int, int> map;
  rep(i, n) {
    int ta, tb;
    std::cin >> ta >> tb;
    map[tb] += ta;
    a[i] = ta;
    b[i] = tb;
  }

  sort(b.begin(), b.end());
  b.erase(unique(b.begin(), b.end()), b.end());

  int sum = 0;
  for (auto i : b) {
    sum += map[i];
    if (sum > i) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  std::cout << "Yes" << std::endl;
  return 0;
}


Measured memory_bytes: 14348
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 200010;
int a[N];
int n, s;

int main()
{
	int n;
	long long res = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
		scanf("%d",&a[i]);
	int j = 0;
	long long tmp = 0, sum = 0;
	for(int i = 1; i <= n; i++)
	{
		while(j + 1 <= n && (tmp ^ a[j + 1]) == sum + a[j + 1])
		//找到最右边满足条件的右端点 
		{
			sum += a[j + 1];
			tmp ^= a[j + 1];
			j++;
		}
		if(tmp == sum)
			res += j - i + 1;
		sum -= a[i];
		tmp ^= a[i];
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 1024
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
P = list(map(int, input().split()))
ans = 0
for i in range(M):
    A, B = list(map(int, input().split()))
    uf.union(A-1,B-1)
for i in range(N):
    if uf.same(P[i]-1,i):
        ans += 1
print(ans)

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

const int lim = 1'000'000'000;

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

  int x1 = 0, y1 = 0;
  int x2 = lim, y2 = 1;
  int x3 = (n % lim == 0 ? 0 : lim) - n % lim;
  int y3 = (n % lim == 0 ? 0 : 1) + n / lim;

  printf("%d %d %d %d %d %d\n", x1, y1, x2, y2, x3, y3);
}

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

const int mod = 998244353;

int main(){
  int n; cin >> n;
  vector<int> a(n); int k = 0;
  for (int i = 0; i < n; i++){
    cin >> a.at(i);
    k += a.at(i);
  }
  int64_t p = 1;
  for (int i = 0; i < n; i++){
    p *= 3;
    p %= mod;
  }
  int h = (k+1)/2;
  int64_t dp1[310][45010], dp2[310][45010];
  for (int i = 0; i <= n; i++){
    for (int j = 0; j <= h; j++){
      dp1[i][j] = dp2[i][j] = 0;
    }
  }
  dp1[0][0] = dp2[0][0] = 1;
  for (int i = 0; i < n; i++){
    for (int j = 0; j <= h; j++){
      dp1[i+1][j] = (dp1[i+1][j] + 2 * dp1[i][j]) % mod;
      int m = min(j + a.at(i), h);
      dp1[i+1][m] = (dp1[i+1][m] + dp1[i][j]) % mod;
    }
  }
  for (int i = 0; i < n; i++){
    for (int j = 0; j <= h; j++){
      dp2[i+1][j] = (dp2[i+1][j] + dp2[i][j]) % mod;
      if (j + a.at(i) <= h) dp2[i+1][j + a.at(i)] = (dp2[i+1][j + a.at(i)] + dp2[i][j]) % mod;
    }
  }
  int64_t ans = p - 3 * dp1[n][h] + 3 * (k%2==0 ? dp2[n][h] : 0);
  while (ans < 0) ans += mod;
  ans %= mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 213888
#include<iostream>
#include<algorithm>
#include<functional>
#include<cstdint>
using namespace std;

const int MAX = 1000;

int main() {
	int N, M;
	int64_t x, y, z;
	cin >> N >> M;
	int64_t ans[8][MAX];
	for (int i = 0;i < N;i ++) {
		cin >> x >> y >> z;
		for (int j = 0;j < 8;j ++) {
			ans[j][i] = ((j & 4) == 0 ? x : -x) + ((j & 2) == 0 ? y : -y) + ((j & 1) == 0 ? z : -z);
			
		}
	}
	for (int i = 0;i < 8;i ++) sort(ans[i], ans[i] + N, greater<int64_t>());
	for (int i = 0;i < 8;i ++) for (int j = 1;j < M;j ++) ans[i][0] += ans[i][j];
	int64_t maximum = 0;
	for (int i = 0;i < 8;i ++) maximum = max(maximum, ans[i][0]);
	cout << (M == 0 ? 0 : maximum);
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

絶対値を聞かれた時は場合分けして符号を外すのは常識よね
ということで、8通りに場合分けするよ
とりあえず、全部正の時で考えると、当然だけどx+y+zがそのまま合計になる訳だ
ということはx+y+zが0以上になるやつ全部取ればおｋね
これを、後はxの符号を反転させたり以下略で試せば終わるよ
なおオーバーフローには注意ね！
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
    ios_base::sync_with_stdio(0);

    ld a, b, x;
    cin >> a >> b >> x;
    x /= a;

    ld res;
    if (x >= a * b / 2.)
    {
        ld h = (a * b - x) / a;
        h *= 2;
        res = atan (h / a);
    }
    else
    {
        ld h = x / b;
        h *= 2;
        res = acos (-1.0) / 2. - atan (h / b);
    }
    res = res * 180 / acos (-1.0);
    cout << fixed << setprecision(8);
    cout << res << "\n";
}

Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()
S3 = input()

ans = 0
for i in range(N):
    youso = set()
    youso.add(S1[i])
    youso.add(S2[i])
    youso.add(S3[i])
    ans += len(youso) - 1

print(ans)

Measured memory_bytes: 3060
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		String S = fs.next();
		if(S.equals("ABC")) System.out.println("ARC");
		else System.out.println("ABC");
	}

}


Measured memory_bytes: 25332
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque
inf = 10 ** 15
mod = 10 ** 9 + 7

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n = int(input())
judge = [1 for i in range(10**3)] # 素数が何個あるか
for i in range(n,1,-1):
    tmp = factorization(i)
    for v,num in tmp:
        judge[v]+=num
ans = 1
for num in judge[2:]:
    ans = (ans*num)%mod
print(ans)

Measured memory_bytes: 42092
#include <bits/stdc++.h>
using namespace std;
const int N = 3e3+5;

double p[N], dp[N][N], sum;

int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> p[i];
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			dp[i][j] = dp[i-1][j] * (1 - p[i]);
			if (j)	dp[i][j] += dp[i-1][j-1] * p[i];
		}
	}
	int cs = (n + 1) / 2;
	for (int i = cs; i <= n; i++)
		sum += dp[n][i]; 
	printf("%.10f\n", sum);
	return 0;
}

Measured memory_bytes: 68992
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		while(true){
		  int n = Integer.parseInt(input.readLine());
		  if(n == 0) break;
		  String line = input.readLine();
		  String[] str = line.split(" ");
		  double[] data = new double[n];
		  
		  double avg = 0 , sum = 0 , scat = 0 , dev = 0;
		  for(int i = 0 ; i < n ; i ++){
			  data[i] = Double.parseDouble(str[i]);
			  sum += data[i];
			  avg = sum / (double)n ;
		  }
		  for(int j = 0 ; j < n ; j++){
			  scat += Math.pow(avg - data[j], 2); 
		  }
		  
		  dev = Math.sqrt(scat/(double)n);
		  sb.append(dev + "\n");
		  
		}
		System.out.print(sb);
		
	}

}

Measured memory_bytes: 19392
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 1000000;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){ 
    string s;
    cin >> s;
    cout << (s[0] == s[2] ? "Yes" : "No") << '\n';
    return 0;
}   

Measured memory_bytes: 256
n = int(input())
string = input().rstrip("\n")

facing_west_in_west = 0
facing_east_in_east = string.count("E") - (string[0] == "E")
list_ = [facing_east_in_east]
for i in range(1, n):
    if string[i - 1] == "W":
        facing_west_in_west += 1
    if string[i] == "E":
        facing_east_in_east -= 1
    list_.append(facing_east_in_east + facing_west_in_west)
print(min(list_))


Measured memory_bytes: 15520
n=int(input())
btcprice=380000
jpysum=0
btcsum=0

for i in range(n):
  num,coin=input().split()
  num=float(num)
  if coin=='JPY':
    jpysum+=num
  else:
    btcsum+=num

print(jpysum+btcsum*btcprice)

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a==1) a+=13;
    if(b==1) b+=13;
    if(a>b)cout << "Alice" << endl;
    else if(a<b)cout << "Bob" << endl;
    else cout << "Draw" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int H[] = new int[9999];
    int W[] = new int[9999];
    int i=0;

    H[0]=1;
    W[0]=1;
    do{
      H[i] = scanner.nextInt();
      W[i] = scanner.nextInt();
      i++;
    }while((!(H[i-1]==0&&W[i-1]==0)));

    for (int j=0;j<i-1;j++){
      for(int k=0;k<H[j];k++){
        for(int l=0;l<W[j];l++){
          System.out.print("#");
        }
        System.out.print("\n");
      }
      System.out.print("\n");
    }

  }
}


Measured memory_bytes: 37712
from math import pi as PI, sin, cos, sqrt


def main():
  a, b, h, m = map(int, input().split())
  
  ar = PI/2 - 2 * PI / 12 * h - 2 * PI / 60 / 12 * m 
  br = PI/2 - 2 * PI / 60 * m
  
  ax, ay = a * cos(ar), a * sin(ar)
  bx, by = b * cos(br), b * sin(br)
  
  c = sqrt((ax - bx) ** 2 + (ay - by) ** 2)
  
  print(c)
  
  
  
if __name__ == '__main__':
  main()


Measured memory_bytes: 62492
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    int ans=1;
    for(int i=0;i<a;i++){
        if(ans*2>=ans+b)ans+=b;
        else ans*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int sum = 0;
    int i = a;
    while (i <= N)
    {
        sum += b;
        i += a;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
from itertools import combinations
from itertools import permutations


def f(x, lst, rem):
    d = abs(x - min(lst))
    min_lst = min(lst)
    tpl = None
    for v in range(1, len(lst) - rem + 2):
        for t in combinations(lst, v):
            if abs(x - sum(t)) + 10 * (v - 1) < d:
                d = abs(x - sum(t)) + 10 * (v - 1)
                tpl = t
    if tpl is None:
        lst.remove(min_lst)
    else:
        for v in tpl:
            lst.remove(v)
    return d, lst


def main():
    N, A, B, C = map(int, input().split())
    L = [int(input()) for i in range(N)]

    ans = int(1e9+7)
    for ABC in permutations((A, B, C), 3):
        lst = L[:]
        accum = 0
        for i, v in enumerate(ABC):
            d, lst = f(v, lst, 3 - i)
            accum += d
        ans = min(ans, accum)
    print(ans)


main()

Measured memory_bytes: 3064
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def calc_div(i):
        num = 0
        for j in range(1, i + 1, 2):
            if i % j == 0:
                num += 1
        return num

    n = ii()
    cnt = 0
    for i in range(1, n + 1, 2):
        if calc_div(i) == 8:
            cnt += 1
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)
/*
long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[200001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}
*/
lld p1=1000000007,p2=998244353;
lld l,r,mid,ans=0;
lld n,i,j,k;
lld x,y,n1,b=0,a,n2,h,z,c;
lld p=1000000000;
double pi=3.1415926535;
    
void solve()
{
    string s;
    cin>>k;
    cin>>s;
    n=s.size();
    if(k>=n)
    {
        cout<<s;
    }
    else
    {
        for(i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"...";
    }
}   

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    // cin>>t;
    //cout<<t;
    //getfac(p2);
    for(int i=0;i<t;i++)
    {
       //cout<<"Case #"<<i+1<<": ";
            solve();
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int f(int n){
    if(n % 2 == 0){
        return n / 2;
    }
    else{
        return 3 * n + 1;
    }
}
int main(void){

  int s,k,i=1;
  cin >> s;
  vector<int> vec;
  vec.push_back(s);
  
  while(1){
      k = f(s);
      i++;
      if(count(vec.begin(),vec.end(),k) != 0) break;
      vec.push_back(k);
      s = k;
      
  }
  
  cout << i << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int lli;
vector<lli> h;

int main(void) {
    lli N,A,B;
    cin >> N >> A >> B;
 
    for(int i=0; i<N; i++) {
        lli hh;
        cin >> hh;
        h.push_back(hh);
    }
 
    lli start=0, stop=0x7FFFFFFF;
    while(stop-start > 1) {
        lli m = (start+stop)/2;
 
        lli sum = 0;
        for(lli t : h) {
            if(t-(m*B) > 0)
                sum += (t-(m*B)+(A-B-1))/(A-B);
            if(sum > m)
                break;
        }
 
        if(sum > m)
            start = m;
        else
            stop = m;
    }
    cout << stop << endl;

    return 0;
}


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

using namespace std;

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

vector<int> uni(100000, -1);

int root(int a)
{
  if (uni[a] < 0) return a;
  else return uni[a] = root(uni[a]);
}

bool connect(int a, int b)
{
  a = root(a);
  b = root(b);
  if(a == b) return false;

  if(abs(uni[a]) < abs(uni[b]))
  {
    int tmp = a;
    a = b;
    b = tmp;
  }

  uni[a] += uni[b];
  uni[b] = a;
  return true;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> nums(n, 0);
  vector<p> v(m, {0,0});
  for (int i = 0; i < n; i++)
  {
    cin >> nums[i];
  }

  for (int i = 0; i < m; i++)
  {
    cin >> v[i].first >> v[i].second;
    connect(v[i].first, v[i].second);
  }

  int res = 0;
  for (int i = 0; i < n; i++)
  {
    if (root(nums[i]) == root(i+1) || nums[i] == i+1)
    {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n - 1; i >= 0; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int main()
{
    string s;
    cin >> s;
    rep(i, s.size())
    {
        if (i % 2 == 0 && s[i] == 'L')
        {
            cout << "No" << endl;
            return 0;
        }
        else if (i % 2 == 1 && s[i] == 'R')
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define lb(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define ub(c, x) distance((c).begin(), upper_bound(all(c), (x)))
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
#define vv(type, name, h, ...) vector<vector<type>> name(h, vector<type>(__VA_ARGS__))
#define vvv(type, name, h, w, ...) vector<vector<vector<type>>> name(h, vector<vector<type>>(w, vector<type>(__VA_ARGS__)))
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<ii> vii;

#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3;
const lli INF = 1e18;
const lli MOD = 1e9+7;
const ld EPS = 1e-4;

vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	vi m(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}


lli SUM(lli a, lli b, lli mod=MOD){
	return (a+b+mod)%mod;
}

lli PROD(lli a, lli b, lli mod=MOD){
	a%=mod; b%=mod;
	return a*b % mod;
}

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

vvi graph(int n, int m){
	vv(int,v,n+1,0);
	fore(i,0,m){
		int a,b; cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	return v;
}

// ---- コーディングはここから！ ('-')7

void solve(){
	int n; cin>>n;
	vi v(n-1);fore(i,0,n-1)cin>>v[i];
	lli sum = 0;
	fore(i,0,n-2)sum+=min(v[i+1],v[i]);
	sum+=v[0]+v.back();
	cout<<sum<<ENDL;

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


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b ? a:b;}
ll min(ll a, ll b) {return a<b ? a:b;}

ll moP(ll x, ll n) {
    ll res=1;
    while(n>0) {
        if(n&1) moC(res, *, x);
        moC(x, *, x);
        n>>=1;
    }
    return res;
}

ll dp[222][MAX];
int main() {
    ll N, X;
    cin >> N >> X;
    ll a[222];
    ll i, x;
    
    for(i=0; i<N; i++)
        cin >> a[i];
    sort(a, a+N);
    reverse(a, a+N);
    
    dp[0][X]=1;
    for(i=0; i<N; i++) {
        for(x=0; x<=X; x++) {
            moC(dp[i+1][x], +, dp[i][x]*(N-i-1)%MOD);
            moC(dp[i+1][x%a[i]], +, dp[i][x]);
        }
    }
    
    ll ans=0;
    for(i=0; i<=X; i++)
        moC(ans, +, dp[N][i]*i%MOD);
    
    pt(ans);
    
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
map<P,ll> memo;

ll f(ll s, ll x) {
  P m(s,x);
  if(memo.count(m))return memo[m];
  if(s == 0)return 1;
  memo[m] = f(s/2, x/2) + f((s-1)/2, (x^1)/2) % MOD;
  if(s >= 2) memo[m] += f((s-2)/2, x/2);
  return memo[m] %= MOD;
}

int main() {
  cin.sync_with_stdio(false);
  ll n;
  cin >> n;
  cout << f(n, n) << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	set := make(map[int]struct{})
	for i := 0; i < n; i++ {
		if _, ok := set[a[i]]; ok {
			delete(set, a[i])
		} else {
			set[a[i]] = struct{}{}
		}
	}
	fmt.Println(len(set))
	return
}

Measured memory_bytes: 7528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  string s;
  cin >> s;
  if (s.at(2)==s.at(3) && s.at(4)==s.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
long long R=1,C=1,H[2000010],N[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
  long long n,m,a[3],i,j,x,d[3][100010],r[300010],ans=0,c[3]={};
int main(){
  scanf("%lld %lld %lld %lld %lld",&n,&m,&a[0],&a[1],&a[2]);
  for(j=0;j<3;j++){
    for(i=0;i<a[j];i++){
      r[R]=j;
      scanf("%lld",&x);
      hin(x);
    }
  }
  for(i=0;1;i++){//printf("%d\n",i);
    j=hout();//printf("%d %d\n",r[j],N[j]);
    if(r[j]==0&&c[0]==n)continue;
    if(r[j]==1&&c[1]==m)continue;
    ans+=N[j];
    c[r[j]]++;
    if(c[0]+c[1]+c[2]==n+m){
      printf("%lld\n",ans);
      return 0;
    }
  }
}


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

signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin >> n;
    vector<pair<string, int> > a;
    for(int i = 0; i < n; ++i) {
    	string r1; int r2;
    	cin >> r1 >> r2;
    	a.push_back({r1, r2});
    }
    string use;
    cin >> use;
    int ans = 0, fl = 0;
    for(int i = 0; i < n; ++i) {
    	if(fl == 0 && a[i].first != use) continue;
    	if(fl == 0 && a[i].first == use) {
    		fl = 1;
    		continue;
    	}		
    	ans += a[i].second;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256