akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	int n; cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int k = 1, ok = 0;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (k == 2) {
			ok = 1; 
			break;
		}else {
			k = a[k-1];
		}
		cnt++;
	}
	if (ok == 1) cout << cnt;
	else cout << -1;

	cout << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin>>N;
  vector<int> L(N);
  rep(i,N) cin>>L[i];

  int ans = 0;
  for(int i=0; i<N; ++i) {
    for(int j=i+1; j<N; ++j) {
      for(int k=j+1; k<N; ++k) {
        if((L[i] != L[j]) && (L[j] != L[k]) && (L[i] !=L[k])) {
          if((abs(L[i]-L[j]) < L[k]) && (L[k] < (L[i]+L[j]))) {
            ++ans;
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

int main(){
    int A, B, C, X, counter=0;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    for (int i=0; i < A+1; i++) {
        for (int j=0; j < B+1; j++) {
            for (int k=0; k < C+1; k++) {
                if (500*i + 100*j + 50*k == X) {counter++;}
            }
        }
    }
    cout << counter << endl;
}  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <stack>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
const int mxn = 1e6+10;
int x[mxn], a[mxn];


int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n; cin>>n;
	for(int i=1; i<=n; i++) cin>>x[i];

	for(int i=1; i<=n; i++) {
		a[x[i]] = i;
	}

	bool ok = 1;
	int space = 0, cur = 1;

	while(cur<n*n and a[cur]!=0) cur++;

	for(int i=1; i<=n*n; i++) {
		if(a[i]==0) space++;
		else {
			for(int j=0; j<a[i]-1; j++) {
				while(cur<n*n and a[cur]!=0) cur++;
				a[cur] = a[i];
				space--;
				if(space<0) ok = 0;
			}
		}
		//cout << "End cur = " << cur << '\n';
	}

	if(!ok) {
		cout <<"No\n"; return 0;
	}

	int firstZero = 1;
	while(firstZero<n*n and a[firstZero]!=0) firstZero++;
	sort(x+1, x+n+1);
	for(int i=1; i<=n; i++) {
		int pos = x[i], val = a[x[i]];
		while(firstZero<n*n and a[firstZero]!=0) firstZero++;
		if(firstZero<pos and val!=n) {
			ok = 0; break;
		}
		else {
			for(int j=0; j<(n-val); j++) {
				while(firstZero<n*n and a[firstZero]!=0) firstZero++;
				a[firstZero++] = val;
			}
		}
	}

	if(!ok) {
		cout <<"No\n"; 
	}
	else {
		cout <<"Yes\n";
		for(int i=1; i<=n*n; i++)  {
			assert(a[i]!=0);
			cout << a[i] << ' ';
		}
		cout << '\n';
	}


	return 0;
}
//comparator function in sorting
//swapping arguments
//missing cases in dp
//dividing in modulo
//Beware of overflow and modulo
//Be mindful of overflow
//s is a matrix but forget
//length of ranges
//working with bit using ull

Measured memory_bytes: 4648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var lis = new List<int>();
            for (int i = 0; i < 5; i++)
                lis.Add(int.Parse(Console.ReadLine()));

            lis = lis.OrderBy(i => i % 10 == 0 ? 1000 : i % 10).ToList();
            int res = lis[0];
            for (int i = 1; i < 5; i++)
            {
                res += (lis[i] + 9) / 10 * 10;
            }
            Console.WriteLine(res);
        }

    }
}


Measured memory_bytes: 13268
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

typedef long long ll;

typedef pair<ll,ll> P;
#define X first
#define Y second

const int N = 100005;
double a[N];

void go() {
	int x,y;
	cin >> x >> y;
	if(x%y==0) cout << -1 << endl;
	else {
		for(ll t = x+x; ; t+=x) {
			if(t%y!=0) {
				cout << t << endl;
				return;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	// int t; cin >> t; for(;t--;)
	go();
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	string s[] = { 
		"0111111",
		"0000110",
		"1011011",
		"1001111",
		"1100110",
		"1101101",
		"1111101",
		"0100111",
		"1111111",
		"1101111" 
	};
	for (int n; cin >> n&&n != -1;) {
		string state = "0000000";
		rep(i, 0, n) {
			int a; cin >> a;
			string ans = "";
			rep(i, 0, 7) {
				if (s[a][i] == state[i])ans += "0";
				else ans += "1";
			}
			cout << ans << endl;
			state = s[a];
		}
	}
	return 0;
}

Measured memory_bytes: 3044
/* string */
#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
string a,ans;
void solve(){
    string date;
    for(int i = 0; i < a.size();){
        int cnt = 0;
        date = a[i];
        for(int j = i;; j++){
            if(date[0] == a[j]){
                cnt++;
            }
            else break;
        }
        if(cnt >= 10)ans+=cnt/10+48;
        i += cnt;
        ans += cnt%10+48;
        ans += date[0];
    }
}
int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(n == 0) break;
        getchar();
        cin >> a;
        for(int i = 0; i < n; i++){
            solve();
            a = ans;
            ans = "";
        }
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 1364
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int n, m, l, r, c, d[100100];
vector<pair<int,int> > e[100100];

void dijkstra(int s = 0) {
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> que;
    fill(d, d+n, linf), d[s] = 0;
    que.push({0,s});
    while(!que.empty()) {
        int v = que.top().second, dis = que.top().first; que.pop();
        if (d[v]<dis) continue;
        for (int i = 0; i < e[v].size(); ++i) {
            int to = e[v][i].first, cost = e[v][i].second;
            if (d[to] > d[v] + cost) {
                d[to] = d[v] + cost;
                que.push({d[to], to});
            }
        }
    }
}

signed main() {
    cin >> n >> m;
    rep(i,m) {
        cin >> l >> r >> c;
        l--, r--;
        e[l].push_back({r,c});
    }
    reps(i,1,n) e[i].push_back({i-1,0});
    dijkstra();
    cout << (d[n-1]==linf ? -1 : d[n-1]) << endl;
}

Measured memory_bytes: 9464
MOD=10**9+7

def Eratosthenes(N):
    """
    Eratosthenesの篩: N以下の素数のリストを返す
    """
    N+=1
    is_prime_lst = [True]*N
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_lst[i]:
            is_prime_lst[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_lst[i]]

def bpm(m,n,mod):
    """
    Bisection power method : 二分累乗法
    """
    if n==0:
        return 1
    elif n%2:
        k=bpm(m,n//2,mod)
        return k*k*m%mod
    else:
        k=bpm(m,n//2,mod)
        return k*k%mod

def main():
    N,K=map(int,input().split())
    Primes=Eratosthenes(K)
    tmp=[0]+[bpm(K//i,N,MOD) for i in range(1,K+1)]
    for p in Primes:
        for j in range(p,K+1,p):
            tmp[j//p] -= tmp[j]
    print(sum(a*b for a,b in enumerate(tmp))%MOD)

main()

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    if(n & 1){
        puts("No");
        return 0;
    }
    n /= 2;
    puts(s.substr(0, n) == s.substr(n, n) ? "Yes" : "No");
}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    fill(A, A + N, 0);
    for(int i = 0; i < N - 1; i++) {
        int a;
        cin >> a;
        A[a - 1]++;
    }
    for(int i = 0; i < N; i++){
        cout << A[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4392
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n = inp()
d = make_divisors(n)
ans = mod
for i in d:
    tmp = n//i
    ans = min(max(len(str(tmp)), len(str(i))), ans)
print(ans)


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

int solve(int n);
int dp[100];

int main(){
	int n;
	while(cin >> n , n){
		memset(dp,0,n+2);
		int ans = solve(n);
		cout << ans/365/10+1 << endl;
	}
}

int solve(int n){
	if(n == 0) return 1;
	if(dp[n] != 0) return dp[n];
	int cou=0;
	for(int i=1;i<=3;i++){
		if(n-i >= 0) cou += solve(n-i);
	}
	return dp[n] = cou;
}

Measured memory_bytes: 1168
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static long getAnswer(long[] numbers){
		int digits = numbers.length;
		if(digits==1) return numbers[0];
		
		long[] FirstExcepted = new long[digits-1];
		for(int i=0;i<digits-1;i++) FirstExcepted[i]=numbers[i+1];
		long[] FirstConnected = new long[digits -1];
		for(int i=1;i<=digits-2;i++) FirstConnected[i]=numbers[i+1];
		FirstConnected[0]=numbers[0]*10+numbers[1];
		
		long FirstPlusPart = numbers[0]*(int)Math.pow(2,digits-2) + getAnswer(FirstExcepted);
		long noFirstPlusPart = getAnswer(FirstConnected);
		
		return noFirstPlusPart + FirstPlusPart;
	}
	
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split("");
        int digits = input.length;
        long[] numbers = new long[digits];
        for(int i=0;i<digits;i++) numbers[i] = Long.parseLong(input[i]);
        
        
        System.out.println(getAnswer(numbers));
    }
}


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

int main() {
  int x, y;
  cin >> x >> y;
  bool f = false;
  for (int i = 0; i <= x; i++) {
    if (i * 2 + (x - i) * 4 == y) {
      f = true;
    }
  }
  cout << (f ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();

        int left = Integer.MIN_VALUE;
        int right = Integer.MAX_VALUE;
        for(int i = 0; i < M; i++) {
            left = Math.max(left, scanner.nextInt());
            right = Math.min(right, scanner.nextInt());
        }

        System.out.println(Math.max(0, right - left + 1));
    }
}


Measured memory_bytes: 63212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC131
{
    class D
    {
        static void Main(string[] args)
        {

            int[] a = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
            int N = a[0];

            List<int[]> taskList = new List<int[]>();
            for(int i = 0; i < N; i++)
            {
                int[] c = Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
                taskList.Add(c);
            }

            var list = taskList.OrderBy(x => x[1]);

            string r = "Yes";
            long time = 0;
            foreach(int[] task in list)
            {
                time += task[0];
                if(time>task[1])
                {
                    r = "No";
                    break;
                }

            }
            Console.WriteLine(r);
        }

    }
}


Measured memory_bytes: 34060
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
C = gets.split.map(&:to_i)

ans = 0
before = Float::INFINITY

A.each do |a|
  ans += B[a - 1]
  ans += C[before - 1] if a - before == 1
  before = a
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+10;
int n,a[maxn],cnt[20],f[1<<15],g[1<<15];

int main()
{
	scanf("%d",&n);
	int x,y,w;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d%d",&x,&y,&w);
		a[x]^=w;a[y]^=w;
	}
	for(int i=0;i<n;i++) cnt[a[i]]++;
	int res=0,s=0;
	for(int i=1;i<=15;i++)
		res+=cnt[i]>>1,s|=(cnt[i]&1)<<(i-1);
	for(int i=0;i<(1<<15);i++)
		for(int j=0;j<15;j++)
			if(i&(1<<j)) f[i]++,g[i]^=j+1;
	for(int i=1;i<(1<<15);i++) f[i]=!g[i]?f[i]-1:0;
	for(int i=1;i<(1<<15);i++)
		if(!g[i])
		{
			for(int k=(i-1)&i;k;k=(k-1)&i)
				if(!g[k]) f[i]=min(f[i],f[k]+f[i^k]);
		}
	printf("%d\n",res+f[s]);
	return 0;
}

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

int main() {
	int n, x;
	scanf("%d%d", &n, &x);
	vector<int> m(n);
	int mi = 10000;
	rep(i, n) {
		scanf("%d", &m[i]);
		x -= m[i];
		mi = min(mi, m[i]);
	}
	printf("%d\n", n + x / mi);
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
	int n, k;
	vector<int> h;

	cin >> n >> k;
	h.resize(n);
	for(auto& hi : h) {
		cin >> hi;
	}

	sort(h.begin(), h.end());

	for(int i = 0; i < min(k, n); i++) 
		h.pop_back();

	cout << accumulate(h.begin(), h.end(), 0LL);
}

Measured memory_bytes: 1024
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		HashSet<Long> first = new HashSet<>();
		HashMap<Long, Long> map = new HashMap<>();

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] array = new long[n];
		for (int i = 0; i < n; i++) {
			long a = sc.nextInt();
			array[i] = a;
			if (first.contains(a)) {
				if (map.containsKey(a)) {
					long num = map.get(a);
					map.put(a, num + 1);
				} else {
					map.put(a, 2L);
				}
			} else {
				first.add(a);
			}
		}
		sc.close();

		long answer = 0;
		for (long value : map.values()) {
			long product = (value * (value - 1)) / 2;
			answer = answer + product;
		}

		for (int i = 0; i < n; i++) {
			long a = array[i];
			if (!map.containsKey(a)) {
				print(answer);
			} else {
				long dup = map.get(a);
				long subtractAns = answer - dup + 1;
				print(subtractAns);
			}
		}

	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}

Measured memory_bytes: 133544
#include<bits/stdc++.h>
#define ll long long
#define N 5010
#define mod 1000000007
#define rep(i,l,r) for (int i=l;i<=r;++i)
using namespace std;
ll jc[N],inv[N],f[N],g[N],res;
int n,x,y,sz[N],a[N],tot,cnt;
vector<int>G[N];
ll K(ll x,int y=mod-2){
	ll t=1; for (;y;y>>=1,x=x*x%mod) if (y&1) t=t*x%mod; return t;
}
ll C(int x,int y){
	return jc[x]* inv[y]%mod *inv[x-y]%mod;
}
void U(ll &x,ll y){
	if ((x+=y)>=mod) x%=mod;
}

void dfs(int x,int fa){
	int mx=0; sz[x]=1;
	for (auto y:G[x]) if (y-fa)
		dfs(y,x), sz[x]+=sz[y], mx=max(mx,sz[y]);
	mx=max(mx,n-sz[x]);
	if (mx*2==n) exit(!(cout<<jc[mx]*jc[mx]%mod));
	if (mx*2>n) return;
	for (auto y:G[x]) if (y-fa) a[++cnt]=sz[y];
	if (x-1) a[++cnt]=n-sz[x];
	memset(f,0,sizeof f); f[tot=0]=1;
	rep(i,1,cnt){
		memset(g,0,sizeof g);
		rep(j,0,a[i]) rep(k,0,tot)
			U(g[k+j],f[k]*C(a[i],j)%mod*C(a[i],j)%mod*jc[j]%mod);
		memcpy(f,g,sizeof g);
		tot+=a[i];
	}
	rep(i,0,tot) U(res,mod+(i&1?-1:1)*f[i]*jc[n-i]%mod);
	exit(!(cout<<res));
}

int main(){
	jc[0]=1; rep(i,1,N-1) jc[i]=jc[i-1]*i%mod;
	inv[N-1]=K(jc[N-1]); for(int i=N;i--;) inv[i-1]=inv[i]*i%mod;
	cin>>n;
	rep(i,1,n-1) cin>>x>>y, G[x].push_back(y), G[y].push_back(x);
	dfs(1,0);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
ans=1
Amax=max(A)
yakusu=[[],[]]

for i in range(2):
    for j in range(2,int(A[i]**0.5)+1):
        if A[i]%j==0:
            yakusu[i].append(j)
            yakusu[i].append(A[i]//j)
    yakusu[i].append(A[i])

yakusum=yakusu[0]
yakusum.extend(yakusu[1])
yakusum=sorted(set(yakusum))

for i in yakusum:
    counter=0
    for j in range(N):
        if A[j]%i!=0:
            counter+=1
            if counter==2:
                break
    if counter<=1:
        ans=i
print(ans)


Measured memory_bytes: 14584
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
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 abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	fmt.Print("Christmas")
	if d <= 24 {
		fmt.Print(" Eve")
	}
	if d <= 23 {
		fmt.Print(" Eve")
	}
	if d <= 22 {
		fmt.Print(" Eve")
	}
	fmt.Println("")
}


Measured memory_bytes: 1768
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

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

vector <int> v[2001];
map <int,int> mp;

void bfs(int nod) {
    bitset <2001> b;
    queue <pii> q;
    q.push({nod,0});
    while(!q.empty()) {
        while(q.size() && b[q.front().first] == 1) {
            q.pop();
        }
        if(q.size()) {
            int nc = q.front().first;
            int d = q.front().second;
            mp[d]++;
            b[nc] = 1;
            q.pop();
            for(auto x : v[nc]) {
                if(b[x] == 0) {

                    q.push({x,d + 1});
                }
            }
        }
    }
}

int  main() {
    int n,i,x,y;
    cin >> n >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
    for(i = 1; i <= n - 1; i++) {
        v[i + 1].push_back(i);
        v[i].push_back(i + 1);
    }
    for(i = 1; i <= n; i++) {
        bfs(i);
    }
    for(i = 1; i <= n - 1; i++) {
        cout << mp[i] / 2 << "\n";
    }
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp_AtCoder
{

    
    class Program
    {      

        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            int sn = S.Length;
            int tn = T.Length;
            // dp[i, j] := SのsnまでとTのtnまで文字列のLCS
            int[,] dp = new int[sn + 1, tn + 1];
            

            for(int i = 1; i <= sn; i++)
            {
                for(int j = 1; j <= tn; j++)
                {
                    if(S[i - 1] == T[j - 1])
                    {
                        dp[i, j] = dp[i - 1, j - 1] + 1;
                    }
                    else
                    {
                        dp[i, j] = Math.Max(dp[i, j - 1], dp[i - 1, j]);
                    }
                }
            }

            //復元
            string lcs = "";
            int si = sn;
            int ti = tn;
            while(si > 0 && ti > 0)
            {
                if(S[si - 1] == T[ti - 1])
                {
                    lcs = S[si - 1] + lcs;
                    si--;
                    ti--;
                }
                else
                {
                    if (dp[si, ti] == dp[si - 1, ti]) si--;
                    else ti--;
                }
            }

            Console.WriteLine(lcs);
            
        }
    }
}


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

char ch[10010];
int n,m;

int main()
{
	int i,t;
	scanf("%d%s",&n,ch+1);
	m=strlen(ch+1);
	for (i=1;i<=m;i++)
	{
		t=ch[i]-'A';
		t+=n;
		t%=26;
		printf("%c",(char)('A'+t));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    String s;

    public void solve() {
        Scanner sc = new Scanner(System.in);
        s = sc.next();

        String x = s.substring(0, 2);
        String y = s.substring(2, 4);


        // case-1. month is correct in both cases
        int mm1 = Integer.parseInt(x);
        int mm2 = Integer.parseInt(y);

        if (isMonthCorrect(mm1) && isMonthCorrect(mm2)) {
            System.out.println("AMBIGUOUS");
            return;
        }

        if (!isMonthCorrect(mm1) && isMonthCorrect(mm2)) {
            System.out.println("YYMM");
            return;
        }

        if (isMonthCorrect(mm1) && !isMonthCorrect(mm2)) {
            System.out.println("MMYY");
            return;
        }

        System.out.println("NA");


    }

    boolean isYearCorrect(int year) {
        return false;
    }

    boolean isMonthCorrect(int month) {
        return month >= 1 && month <= 12;
    }

    public static void main(String[] args) {
        new Main().solve();

    }
}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  int p;
  pair<string, pair<int, int> >res[105];

  cin >> n;

  for(int i = 0;i < n;i++){
    cin >> s >> p;

    res[i] = make_pair(s, make_pair(-1 * p, i + 1));
  }

  sort(res, res + n);

  for(int i = 0;i < n;i++){
    cout << res[i].second.second << endl;
  }
  return 0;
}



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

long long  sumOfDigits(long long  a)
{
    long long  sum = 0;
    while (a)
    {
        sum += a % 10;
        a /= 10;
    }
    return sum;
}

long long  findMax(long long  x)
{

    long long  b = 1, ans = x;


    while (x)
    {


        long long  cur = (x - 1) * b + (b - 1);


        if (sumOfDigits(cur) > sumOfDigits(ans) ||
           (sumOfDigits(cur) == sumOfDigits(ans) &&
            cur > ans))
            ans = cur;

        x /= 10;
        b *= 10;
    }

    return ans;
}

int main()
{
    long long  n  ;
    cin>>n;
   long long x= findMax(n);
   int sums=0;
   //cout<<x;
   while(x){
    sums+=(x%10);
    x/=10;
   }
   cout<<sums;
    return 0;
}


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

struct Data {
  int X, id;
  ll A;
  Data(int id, int X, ll A) : id(id), X(X), A(A){}
};

int main() {
  int N, Q;
  ll T;
  cin >> N >> T >> Q;
  ll A[N];
  int D[N];
  int X[Q];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> D[i];
  }
  for (int i = 0; i < Q; i++) {
    cin >> X[i];
    X[i]--;
  }
  ll r = 0;
  ll l = 0;
  vector<ll> p;
  vector<Data> dr;
  vector<Data> dl;
  for (int i = 0; i < Q; i++) {
    if (D[X[i]] == 1) {
      dr.push_back(Data(i, X[i], A[X[i]]));
    } else {
      dl.push_back(Data(i, X[i], A[X[i]]));
    }
  }

  for (int i = 0; i < N; i++) {
    if (D[i] == 1) {
      r = A[i];
    } else {
      l = A[i];
    }
    if (r == 0 || l == 0) continue;
    if (abs(l - r) <= 2 * T && r < l) {
      p.push_back((l + r) / 2);
      l = 0;
      r = 0;
    }
  }
  
  int ir = 0;
  // for (ll i : p) {
  //   cout << "p: " << i << "\n";
  // }
  ll t[Q];
  for (int i = 0; i < dr.size(); i++) {
    int X = dr[i].X;
    t[dr[i].id] = A[X] + T;
    // if (X == 17) {
    //   cout << t[dr[i].id] << " ------------- " << p[ir] << "\n"; 
    // }
    while (ir < p.size()) {
      if (p[ir] < A[X]) {
        ir++;
      } else if (A[X] <= p[ir] && p[ir] <= t[dr[i].id]) {
        t[dr[i].id] = p[ir];
        break;
      } else {
        break;
      }
    }
    // if (X == 17) {
    //   cout << t[dr[i].id] << " ------------- " << ir << "\n";
    // }
  }
 

  int il = p.size() - 1;
  for (int i = dl.size() - 1; i >= 0; i--) {
    int X = dl[i].X;
    t[dl[i].id] = A[X] - T;
    while (il >= 0) {
      if (A[X] < p[il]) {
        il--;
      } else if (t[dl[i].id] <= p[il] && p[il] <= A[X]) {
        t[dl[i].id] = p[il];
        break;
      } else {
        break;
      }
    }
  }
  // for (int i = 0; i < p.size(); i++) {
  //   cout << i << " " << p[i] << "\n";
  // }

  for (ll i : t) {
    cout << i << "\n";
  }
  return 0;
}


Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
#define li long int
int main(){
  string s;
  cin>>s;
  vector< li > v;
  li i=0,k;
  li l=s.length();
  while(i<l){
    k=0;
    while (s[i]=='<' && i<l ){
    ++k;++i;
    }
    if(k>0)
      v.push_back(k);
    k=0;
    while (s[i]=='>' && i<l){
    ++k;++i;
    }
    if(k>0)
      v.push_back(k);
  }
  long long int sm=0;
  for(auto x:v){
  	sm+=(x*(x+1))/2;
  }
  l=v.size();
  for(i=s[0]=='<' ? 0:1;i<l-1;i+=2){
  	sm-=min(v[i],v[i+1]);
  }
  cout<<sm<<"\n";
  return 0;
}

Measured memory_bytes: 5984
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        var n = Read();
        var s = Console.ReadLine();
        var c = s.ToCharArray();
        for (int i = 0; i < s.Length; i++)
        {
            if (c[i] + n <= 'Z')
                Console.Write((char)(c[i] + n));
            if (c[i] + n > 'Z')
                Console.Write
                    ((char)(c[i] + n-26));
        }
        


        Console.Out.Flush();
    }
}


Measured memory_bytes: 13140
import heapq


def main():
    heap = []
    while True:
        order = input().split()
        if order[0] == 'insert':
            heapq.heappush(heap, -int(order[1]))
        elif order[0] == 'extract':
            print(-heapq.heappop(heap))
        elif order[0] == 'end':
            return


if __name__ == '__main__':
    main()



Measured memory_bytes: 45312
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll N, K;
    cin >> N >> K;
    vector<ll> P(N);
    REP(i, N) cin >> P[i], P[i]--;
    vector<ll> C(N);
    REP(i, N) cin >> C[i];

    ll ans = -INF;
    for(int i = 0; i < N; i++) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true) {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true) {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(ans, score);

            v = P[v];
            if (v == i) break;
        }
        
    }

    cout << ans << endl;
    

    return 0;
}  

Measured memory_bytes: 3684
<?php

while (($line = trim(fgets(STDIN)))) {
    sscanf($line, '%d %d', $H, $W);
    if ($H === 0 && $W === 0) {
        break;
    }

    for ($i = 0; $i < $H; $i++) {
        for ($j = 0; $j < $W; $j++) {
            if ($i > 0 && $i !== $H - 1 && $j > 0 && $j !== $W - 1) {
                echo '.';
            } else {
                echo '#';
            }
        }
        echo PHP_EOL;
    }
    echo PHP_EOL;
}

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

int main() {
  ll w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << fixed << setprecision(11);
  double s;
  int j = 0;
  if(x*2 == w && y*2 == h){
    j = 1;
  }
  s = w*h/2.0;
  cout << s << " " << j << endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;
const ll mod = 1e9 + 7;

int main(void)
{
	ll n, m;
	cin >> n >> m;
	set<int> sa,sb;
	rep(i, n) {
		ll a;
		cin >> a;
		sa.insert(a);
	}
	rep(i, m) {
		ll b;
		cin >> b;
		sb.insert(b);
	}
	if (sa.size() < n || sb.size() < m) {
		cout << 0 << endl;
		return 0;
	}
	ll count = 1;
	ll h = 0, w = 0, o = 0;
	for (int i = n * m; i >= 1; i--)
	{
		int a = sa.count(i);
		int b = sb.count(i);
		if (a && b) {
			h++; w++; o++;
		}
		else if (a) {
			count *= w;
			h++; o++;
		}
		else if (b) {
			count *= h;
			w++; o++;
		}
		else {
			count *= max(0LL, (w * h) - o);
			o++;
		}
		count %= mod;
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int R, C, N;

bool is_edge(int x,int y){
    if(x==0 || x==R)return true;
    if(y==0 || y==C)return true;
    return false;
}

int main(){
    cin >> R >> C >> N;
    map<pair<int, int>, int> points;
    vector<int> xs;
    vector<int> ys;
    xs.push_back(0);
    xs.push_back(R);
    ys.push_back(0);
    ys.push_back(C);
    REP(i, N){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if(!is_edge(x1, y1))continue;
        if(!is_edge(x2, y2))continue;
        points[make_pair(x1, y1)] = i;
        points[make_pair(x2, y2)] = i;
        xs.push_back(x1);
        xs.push_back(x2);
        ys.push_back(y1);
        ys.push_back(y2);
    }
    sort(ALL(xs));
    sort(ALL(ys));
    xs.erase(unique(ALL(xs)), xs.end());
    ys.erase(unique(ALL(ys)), ys.end());
    int nx = xs.size();
    int ny = ys.size();
    vector<pair<int, int> > ps;
    REP(i, xs.size())ps.push_back(make_pair(xs[i], 0));
    REP(i, ys.size())ps.push_back(make_pair(R, ys[i]));
    REP(i, xs.size())ps.push_back(make_pair(xs[nx-1-i], C));
    REP(i, ys.size())ps.push_back(make_pair(0, ys[ny-1-i]));
    ps.erase(unique(ALL(ps)), ps.end());
    while(ps.size()>1 && ps[0]==ps[ps.size()-1])ps.pop_back();
    stack<int> st;
    REP(i, ps.size()){
        if(points.count(ps[i])==0)continue;
        int idx = points[ps[i]];
        //cerr << ps[i].first << "," << ps[i].second << " " << idx << endl;
        if(st.empty()){
            st.push(idx);
        }else if(st.top() != idx){
            st.push(idx);
        }else{
            st.pop();
        }
    }
    cout << (st.empty() ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 20068
//参考https://atcoder.jp/contests/abc121/submissions/4530935

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

ll calc(ll a){
    ll ans = 0;
    a++;
    for(int i = 0; i < 50; i++)
    {
        ll loop = (1ll << (i+1));
        ll cnt = (a/loop)*(loop/2);
        cnt += max(0ll, (a%loop)-(loop/2));
        
        if(cnt%2==1){
            ans += 1ll << i;
        }
    }
    return ans;
    
}

int main(){
    ll a, b;
    cin >> a >> b;
    ll ans = calc(a-1)^calc(b);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n;
    cin >> n;
    int maxa = 0, mina = INF;
    REP(i, n) {
        int num;
        cin >> num;
        if(i == 0){
            maxa = num;
            mina = num;
        }
        else{
            maxa = max(maxa, num);
            mina = min(mina, num);
        }
    }
    cout << maxa - mina << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int main(void){
    cin>>n;
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            if(i*j==n){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


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

const int maxn = 1e7 + 10;
int divisors[maxn];

void sieve()
{
	for (int i = 1; i < maxn; i++)
	{
		for (int j = i; j < maxn; j += i)
		{
			divisors[j]++;
		}
	}
}

void solve()
{
	int n;
	cin >> n;
	sieve();
	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		ans += i * divisors[i];
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 81732
#include <iostream>
#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    double x = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1)x++;
    }

    cout << fixed << setprecision(10) << x / n << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

const ll mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  std::vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

std::string S;
mint dp[100010][15];

int main()
{
  std::cin >> S;

  ll n = S.size();

  dp[0][0] = 1;

  rep( i, n ) rep( j, 13 ) {
    if( S[i] == '?' ) {
      rep( d, 10 )
        dp[i+1][(j*10+d)%13] += dp[i][j];
    } else {
      dp[i+1][(j*10+S[i]-'0')%13] += dp[i][j];
    }
  }

  std::cout << dp[n][5].x << std::endl;

  return 0;
}

Measured memory_bytes: 12160
#include<iostream>

using namespace std;

int main(void) {

	long long int A, B, C;
	cin >> A >> B >> C;

	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) { cout << 0 << endl; }
	else {
		long long int ans = A*B;
		if (B*C < ans) { ans = B*C; }
		if (C*A < ans) { ans = C*A; }
		cout << ans << endl;
	}

	//system("pause");
	return 0;
}

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

int main(){
  int h, w;
  int dx[] = {0, 1, 0, -1, 1, -1, -1, 1};
  int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
  char s[51][51] = {};
  cin >> h >> w;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> s[i][j];
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#') continue;
      int cnt = 0;
      for(int k = 0; k < 8; k++){
        int x = i + dx[k];
        int y = j + dy[k];
        if(x < 0 || h <= x || y < 0 || w <= y) continue;
        if(s[x][y] == '#') cnt++;
      }
      s[i][j] = cnt + '0';
    }
  }
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cout << s[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
	cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	cout << head;
	if (sizeof...(tail) != 0) cout << " ";
	print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
	for (auto& a : vec) {
		cout << a;
		if (&a != &vec.back()) cout << " ";
	}
	cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
	for (auto& vec : df) {
		print(vec);
	}
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

#ifdef LOCALCODE
signed solve()
#else
signed main()
#endif
{
	auto a = IN();
	auto b = IN();
	print(a <= b ? a : a-1);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(), x.end()
#define lop(i, s, t) for (int i = s;i < (t);++i)
#define rep(i, s, t) for (int i = s;i <= (t);++i) 
#define dec(i, s, t) for (int i = s;i >= (t);--i)
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
using namespace std; 

#define Pr(f,...) printf(f,##__VA_ARGS__),fflush(stdout)

const int N=2e5+50;

typedef long long ll;

int n;
ll ans,a[N]; 
map<ll,ll> cnt;

int main() {
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout); 
#endif
	scanf("%d",&n); 
	rep(i,1,n)scanf("%lld",a+i); 
	++cnt[0];
	ll sum=0; 
	rep(i,1,n){
		sum+=a[i]; 
		ans+=cnt[sum]; 
		++cnt[sum];
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << '\n'
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define pr(s) cout << (s) << '\n'
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;
const ll INFll = 1E+18;
using mint = static_modint<mod>;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k;
    cin >> k;
    string ans = "";
    rep(i, k) ans += "ACL";
    
    pr(ans);
    return 0;
}


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

int main(){
	int n, m;
  	cin >> n >> m;
  	priority_queue<int> q;
  	rep(i, n){
    	int a;
      	cin >> a;
      	q.push(a);
    }
  
  	rep(i, m){
    	int a = q.top(); 
      	q.pop();
      	q.push(a/2);
    }
  
  	ll ans = 0;
  	rep(i, n){
      ans += q.top();
      q.pop();
    }
  	cout << ans << endl;
}

Measured memory_bytes: 3820