akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;


int N;
vector<char> op;
vector<ll> A;
char ops[2] = {'+', '-'};

ll memo[100000][3];


ll dfs(int p, int c){
    // clip c
    c = min(2, c);
    if(p == N) return 0;
    if(memo[p][c] != -1) return memo[p][c];
    ll ret = 0;
    if(c % 2 == 0){
        if(op[p] == '+'){
            ret = max(ret, A[p] + dfs(p+1, c));
        }else{
            ret = max(ret, -A[p] + dfs(p+1, c+1));
            if(c >= 1) ret = max(ret, A[p] + dfs(p+1, c));
        }
    }else{
        if(op[p] == '+'){
            ret = max(ret, -A[p] + dfs(p+1, c));
            ret = max(ret, A[p] + dfs(p+1, c-1));
        }else{
            ret = max(ret, A[p] + dfs(p+1, c+1));
        }
    }
    memo[p][c] = ret;
    return ret;
}


int main(){
    cin >> N;

    ll start;
    cin >> start;

    N--;
    op.resize(N);
    A.resize(N);
    for(int i=0;i<N;i++){
        cin >> op[i] >> A[i];
    }
    memset(memo, -1, sizeof(memo));
    cout << start + dfs(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 9728
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int n = ni();
		int k = ni();
		char[] s = next().toCharArray();
		int op = 0;
		int result = 0;
		for(int i = 1; i < n; i++) {
			if(s[i] == s[i - 1]) {
				result++;
			} else {
				if(s[i] != s[0]) {
					op++;
				}				
			}
		}
		if(op > k) {
			result += k * 2;
		} else {
			if(s[n - 1] != s[0]) {
				result += op * 2 - 1;
			}else {
				result += op * 2;
			}
		}		
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25172
N = int(input())
x,y = [],[]
for i in range(N):
    X,Y = [float(e) for e in input().split()]
    x.append(X)
    y.append(Y)

import itertools

ans = []
for order in itertools.permutations([i for i in range(N)]):
    r = 0.0
    for i in range(1,N):
        r += ((x[order[i]]-x[order[i-1]])**2 + (y[order[i]]-y[order[i-1]])**2) ** 0.5
    ans.append(r)

import numpy as np
print(np.mean(ans))



Measured memory_bytes: 22560
m, k = map(int, input().split())
if not (0<=k<2**m):
  print(-1)
  exit()
if m == 1:
  if k == 0:
    print(0, 0, 1, 1)
  else:
    print(-1)
else:
  L = []
  for i in range(2**m):
    if i != k:
      L.append(i)
  L.append(k)
  for i in range(2**m-1, -1, -1):
    if i != k:
      L.append(i)
  L.append(k)
  print(*L)

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> p(n+1);
    p[1] = k;
    for (int i=0; i<q; i++){
        int a;
        cin >> a;
        if (a == 1) p[2]--;
        else if (a == n) {
            p[1]--; p[n]++;
        }
        else {
            p[1]--; p[a]++; p[a+1]--;
        }
    }
    int sum = 0;
    for (int i=1; i<=n; i++) {
        sum += p[i];
        if (sum > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
	const int mod=1000000007;
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		int m=1<<n;
		long[] dp=new long[m];
		dp[0]=1;
		for(int i=0;i<n;i++){
			int[] a=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			for(int j=m-1;j>0;j--){
				if(bits(j)==i+1){
					for(int k=0;(1<<k)<=j;k++){
						if((j&(1<<k))!=0&&a[k]==1){dp[j]=(dp[j]+dp[j^(1<<k)])%mod;}
					}
				}
			}
		}
		Console.WriteLine("{0}",dp[m-1]);
	}
	static int bits(long bits){
		bits=(bits&0x55555555)+(bits>>1&0x55555555);
		bits=(bits&0x33333333)+(bits>>2&0x33333333);
		bits=(bits&0x0f0f0f0f)+(bits>>4&0x0f0f0f0f);
		bits=(bits&0x00ff00ff)+(bits>>8&0x00ff00ff);
		return (int)((bits&0x0000ffff)+(bits>>16&0x0000ffff));
	}
}

Measured memory_bytes: 29408
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;
using mpint = mp::cpp_int; // 多倍長整数（任意精度）

/*
 * 定数
 */
const long double PI = (acos(-1));
const long double EPS = 1e-10;
const long long INF = 1e18;

/*
 * データ変換 
 */
/* char -> int */
int ctoi(char c) { return (int)(c - '0'); }

/*
 * 数学的な計算
 */
/* 階乗 */
int factorial(int n){ int ret = 1; for(int i = 1; i < n + 1; ++i) { ret = ret * i; } return ret; }

/* 最大公約数 */
template <typename T>T gcd(T x, T y){ return x % y == 0 ? y : gcd(y, x % y); }

/* 最小公倍数 */
template <typename T>T lcm(T a, T b) { return a * b / gcd(a, b); }

/* n個の整数の最小公倍数 */
template <typename T>T lcm_n(vector<T> &numbers) { T l; l = numbers[0]; for(int i = 1; i < numbers.size(); ++i) { l = lcm(l, numbers[i]); } return l; }

/*
 * DP向け
 */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/*
 * グラフ
 */
class Graph {
   public:
    vector<vector<int>> G;
    vector<int> Trans;
    vector<int> inDeg;
    int numV;
 
    Graph(int numV) {
        this->numV = numV;
        inDeg.assign(numV, 0);
        Trans.assign(numV, 0);
        G.assign(numV, vector<int>());
    }
 
    int topologicalSort(int v, vector<int> &dp) {
        if (dp[v] != -1) {
            return dp[v];
        }
 
        int res = 0;
 
        for (auto to : G[v]) {
            chmax(res, topologicalSort(to, dp) + 1);
        }
 
        return dp[v] = res;
    }
};

int main(){
  long double a, b, n;

  cin >> a >> b >> n;

  if(n < b){
    cout << (ll)(floor((a*n)/b) - a*floor(n/b)) << endl;
  }else{
    cout << (ll)(floor((a*(b-1))/b) - a*floor((b-1)/b)) << endl;
  }

  return 0;
}


Measured memory_bytes: 3712
# Acceptance of input

import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

adj_mat = [[0] * V for i in range(V)]

for line in file_input:
    u, v, c = map(int, line.split())
    adj_mat[u][v] = c

# Ford???Fulkerson algorithm

import collections

# BFS for residual capacity network
def bfs(start, goal, parent):
    flow = [0] * V
    queue = collections.deque()
    queue.append(start)
    flow[start] = 10000
    while queue:
        u = queue.popleft()
        for v, r_capacity in enumerate(adj_mat[u]):
            if not flow[v] and (r_capacity > 0):
                queue.append(v)
                flow[v] = min(flow[u], r_capacity)
                parent[v] = u
    return flow[goal]

def ford_fulkerson(source, sink):
    max_flow = 0
    while True:
        parent = [None] * V
        aug_path_flow = bfs(source, sink, parent)
        if aug_path_flow:
            max_flow += aug_path_flow
            v = sink
            while (v != source):
                u = parent[v]
                adj_mat[u][v] -= aug_path_flow
                adj_mat[v][u] += aug_path_flow
                v = u
        else:
            break
    return max_flow

# output
print(ford_fulkerson(0, V - 1))

Measured memory_bytes: 8176
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int X; cin >> X;
  int v = lcm(360, X);
  cout << v / X << endl;
}


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

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	long long a, b = 2, c = 1, d = 1, e;
	cin >> a;
	for (int k = 1; k <= a / 2; k++) {
		while (c <= a) {
			c = c * b;
		}
		c = c / b;
		b++;
		d = max(c, d);
		c = 1;
	}
	cout << d << endl;
	cin >> e;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[100];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A + i);
	for (int i = 0; i < N; ++i) A[i] *= N;

	int sum = 0;
	for (int i = 0; i < N; ++i) sum += A[i];
	sum /= N;
	int ave = sum;

	pair<int, int> best = make_pair(1001001001, -1);
	for (int i = 0; i < N; ++i) {
		best = min(best, { abs(A[i] - ave), i });
	}
	printf("%d\n", best.second);

	return 0;
}


Measured memory_bytes: 256
var sample_input = require('fs').readFileSync('/dev/stdin', 'utf8');
var coefficient_sets = (sample_input.trim()).split("\n");
coefficient_sets.forEach(function(coefficient_set){
  var coefficients = coefficient_set.split(" ").map(Number);
  var a = coefficients[0];
  var b = coefficients[1];
  var c = coefficients[2];
  var d = coefficients[3];
  var e = coefficients[4];
  var f = coefficients[5];
  var x;
  var y;
  // (e*a x + -(d*b) )x = c*e - f*b
  var x = ( c*e - f*b ) / (e*a - d*b);
  var y = (c-a*x) / b;
  console.log([x.toFixed(3),y.toFixed(3)].join(" "));
});

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

#define vi vector<int>
#define vp vector<pair<int, int>>

int main() {

    int N, M;
    cin >> N >> M;

    vp pt;
    int A, B;
    for (int i = 0; i < N; i++) {
        cin >> A >> B;
        pt.push_back(make_pair(A, B));
    }

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

    int count = 0;
    // cout << endl;
    // for (int i = 0; i < N; i++) {
    //     cout << pt[i].first << " " << pt[i].second << endl;
    // }

    multiset<int> s;
    int itr = 0;
    for (int d = 1; d <= M; d++) {
        if (itr != N) {
            while (pt[itr].first <= d) {
                s.insert(pt[itr].second);
                itr++;
                if (itr == N) break;
            }
        }

        if (!s.empty()) {
            count += *s.rbegin();
            auto p = s.rbegin();
            s.erase(prev(s.end()), s.end());
        }
    }

    cout << count << endl;


    return 0;
}


Measured memory_bytes: 5620
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f
#define pi 3.1415926535898
using namespace std;
const int mod=998244353;
int n,s;
int a[200020];
ll dp[3030][3030];
int main()
{
    cin>>n>>s;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }
    dp[0][0]=1;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<=s; j++)
        {
            dp[i][j]=(dp[i-1][j]*2)%mod;
            if(j>=a[i])
                dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%mod;
        }
    }
    cout<<dp[n][s];
    return 0;
}


Measured memory_bytes: 74652
#include <bits/stdc++.h>
#define ll long long
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

using namespace std;

int main() {
  INIT;
  
  int a,b;
  cin>> a>>b;
  if(a<=8 && b <=8){
  cout << "Yay!"<< endl;
}else{
  cout << ":("<< endl;
}
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+50,mod=1e9+7,inv2=5e8+4;
int n,ver[N*2],nxt[N*2],head[N],tot,sz[N],pw[N],ans;
int read(){
    int x=0,c;
    while(!isdigit(c=getchar()));
    while(isdigit(c))x=x*10+c-48,c=getchar();
    return x;
}
void add(int x,int y){ver[++tot]=y;nxt[tot]=head[x];head[x]=tot;}
void dfs(int x,int ff){
    sz[x]=1;int dat=pw[n-1];
    for(int i=head[x],y;i;i=nxt[i]){
        if((y=ver[i])==ff)continue;
        dfs(y,x);(dat-=pw[sz[y]]-1)%=mod;
        sz[x]+=sz[y];
    }
    (dat-=pw[n-sz[x]])%=mod;
    (ans+=dat)%=mod;
}
int main(){
    n=read();pw[0]=1;
    for(int i=1;i<=n;i++)pw[i]=2*pw[i-1]%mod;
    for(int i=1,x,y;i<n;i++){
        x=read(),y=read();
        add(x,y);add(y,x);
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)ans=1ll*ans*inv2%mod;
    printf("%d\n",(ans+mod)%mod);
    return 0;
}

Measured memory_bytes: 17152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define END(a) {cout << (a) << "\n"; return 0;}
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long 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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    VI h = {0};
    FOR(i, 0, n) {
        int in; cin >> in;
        if (in != h.back())h.push_back(in);
    }
    if (h.back())h.push_back(0);
    n = h.size();

    map<int, VI> map;
    FOR(i, 0, n)map[h[i]].push_back(i);
    int ans = 0, cnt = 1, bef = 0;
    for (auto p : map) {
        ans += cnt * (p.first - bef);
        for (auto i : p.second) {
            if ((i && h[i - 1] < h[i]) && (i < n - 1 && h[i] > h[i + 1])) {
                --cnt;
            }
            else if ((i && h[i - 1] > h[i]) && (i < n - 1 && h[i] < h[i + 1])) {
                ++cnt;
            }
        }
        bef = p.first;
    }
    cout << ans << "\n";
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1e9;

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

int dfs(vector<string> &s) {
  vector< vector<int> > dist(h, vector<int>(w, INF));
  queue<P> q;
  q.push(P(0, 0));
  dist[0][0] = 0;

  while (!q.empty()) {
    P cur = q.front(); q.pop();
    int cx = cur.second, cy = cur.first;

    for (int i = 0; i < 4; ++i) {
      int nx = cx + dx[i];
      int ny = cy + dy[i];
      if (nx >= 0 && nx < w && ny >= 0 && ny < h && dist[ny][nx] == INF && s[ny][nx] == '.') {
	dist[ny][nx] = dist[cy][cx] + 1;
	q.push(P(ny, nx));
      }
    }
  }
  return dist[h - 1][w - 1];
}

int main() {
  cin >> h >> w;
  vector<string> s(h);
  int n = 0;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
    for (int j = 0; j < w; ++j) if (s[i][j] == '.') n++;
  }

  int dist = dfs(s);
  if (dist == INF) puts("-1");
  else cout << (n - (dist + 1)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <queue>
#include <sstream>
#include <unordered_map>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF=1e9+7;

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

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

int main(){
    string S;
    cin>>S;
    int A[S.length()],min=99999999,leng=S.length();
    rep(i,leng){
        A[i]=stoi(S.substr(i,1));
    }
    rep(i,leng-2){
        int b=A[i]*100+A[i+1]*10+A[i+2];
        int a=abs(753-b);
        if(min>a) min=a;
    }
    cout<<min<<endl<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int 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 {
  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];
  }
};

int main(){
	int x, y;
	cin >> x >> y;
	if((x+y) % 3 != 0){
		cout << 0 << endl;
		return 0;
	}
	int xd, yd;
	xd = (2*x - y)/3;
	yd = x - 2*xd;
	mint ans;
	if(xd < 0 || yd < 0) ans = 0;
	else{
		combination c(xd+yd);
		ans = c(xd+yd, xd);
	}
	cout << ans.x << endl;
	return 0;
}

Measured memory_bytes: 10624
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a) for(int i = 0; i < (a);i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using Graph = vector < vector<int>>;
long int sum[200020] = {};
int main() {
	int M, D;
	cin >> M >> D;
	int count = 0;
	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= D; j++) {
			if ((j % 10 >= 2) && (j / 10 >= 2)) {
				if ((j % 10) * (j / 10) == i) {
					count++;
				}
			}
		}
	}
	cout << count;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

i64 dp[310][310];

void solve() {
  int n, k;
  cin >> n >> k;
  vi64 h(n + 1);
  reps(i, n) cin >> h[i];

  rep(i, 310) rep(j, 310) dp[i][j] = 1e18;
  dp[0][0] = 0;

  reps(i, n) reps(j, n) {
    i64 mi = 1e18;
    rep(l, i) {
      amin(mi, dp[l][j - 1] + max(h[i] - h[l], 0ll));
    }
    dp[i][j] = mi;
  }

  i64 ans = 1e18;
  repc(i, n) amin(ans, dp[i][n - k]);
  cout << ans << endl;
}


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


int main()
{
    string s1,s2;
    int count=0;
    cin>>s1>>s2;
    for(int i=0;i<s1.length();i++)
    {
    	if(s1[i]!=s2[i])
    	count++;
	}
	cout<<count;
    return 0;
}

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

int sx, sy, gx, gy;
int dx[5][1111], dy[5][1111], dn[5];
int memo[5][5][1111];

int solve(int k, int t, int q){

  if(k == 4) return abs(dx[t][q]-gx) + abs(dy[t][q]-gy);
  if(memo[k][t][q]) return memo[k][t][q];

  int ans = 1<<28, s, d = (t+1)%5;

  for(int i=0;i<dn[d];i++){
    if(!k) s = abs(sx-dx[d][i]) + abs(sy-dy[d][i]);
    else s = abs(dx[t][q]-dx[d][i]) + abs(dy[t][q]-dy[d][i]);
    ans = min(ans, solve(k+1, d, i) + s);
  }

  return memo[k][t][q] = ans;
}

int main(){

  int w, h, i, j, a, b, u;
  char c;

  while(true){
    scanf("%d %d", &w, &h);
    if(!w && !h) break;

    memset(dn, 0, sizeof(dn));

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf(" %c", &c);
	if(c == 'S') sx = j, sy = i;
	else if(c == 'G') gx = j, gy = i;
	else if(c != '.') u = c-'1', dx[u][dn[u]] = j, dy[u][dn[u]] = i, dn[u]++;
      }
    }
    
    h = -1;
    for(i=0;i<5;i++) if(!dn[i]) h++;

    b = 1<<28;
    for(i=0;i<5&&h<1;i++){
      memset(memo, 0, sizeof(memo));
      if(b > solve(0,i,0)) a = i, b = memo[0][i][0];
    }

    if(b == 1<<28) printf("NA\n");
    else printf("%d %d\n", a+1, b);

  }
}

Measured memory_bytes: 1188
#define rep(i,n) for (int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
 
 
int main(){
  
  unsigned long long l,r;
  cin >> l >> r;
  
unsigned long long mi=INT_MAX,i=0,j=0;
  
 if(r/2019-l/2019!=0)
    cout << 0 << endl;
 else{
   l%=2019;
   r%=2019;
   while(l+i!=r){
     j=l+i;
     while(j!=r){
       j++;
       mi=min((l+i)%2019*j%2019%2019,mi);
       
     }
     i++;
   }
 
   
  cout << mi << endl;
}
 
    
  
}



Measured memory_bytes: 3596
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    a_x,a_y, b_x,b_y = map(int,input().strip().split())
    e1=b_x - a_x
    e2=b_y-a_y
    c_x=b_x-e2
    c_y=b_y+e1
    d_x=c_x-e1
    d_y=c_y-e2
    print(c_x,c_y,d_x,d_y)
    #c=2a-b


if __name__ == '__main__':
    main()

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

int main() {
  long n,m,q;
  cin >> n >> m >> q;
  map<vector<long>,long> a;
  map<vector<long>,long> b;
  vector<vector<long>> pq(q,vector<long>(2));
  for(long i=0;i<m;i++) {
    long l,r;
    cin >> l >> r;
    a[{l,r}]++;
  }
  for(long i=0;i<q;i++) cin >> pq[i][0] >> pq[i][1];
  for(long i=0;i<n;i++) {
    for(long j=1;i+j<=n;j++) {
      b[{j,i+j}]=a[{j,i+j}];
      if(i>0) b[{j,i+j}]+=b[{j,i+j-1}]+b[{j+1,i+j}];
      if(i>1) b[{j,i+j}]-=b[{j+1,i+j-1}];
    }
  }
  for(long i=0;i<q;i++) cout << b[pq[i]] << endl;
}

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

#define MAX (1<<24)
#define MIN (-1)

class State
{
public:
	string n,t;
	char c;
	int p,r;
	State(string n, string t, char c, int p, int r)
		:n(n),t(t),c(c),p(p),r(r)
	{}

	bool operator<(const State& s) const
	{
		if(t!=s.t) return t<s.t;
		if(t=="SELL" && p!=s.p) return p<s.p;
		if(t=="BUY" && p!=s.p) return p>s.p;

		return r<s.r;
	}
};

class Dealer
{
public:
	string n;
	int s,b;
	Dealer(string n, int s, int b)
		:n(n),s(s),b(b)
	{}

	bool operator<(const Dealer& d) const
	{
		return n<d.n;
	}
};

int main()
{
	int N;
	while(cin >> N, N)
	{
		int mi[30], ma[30], tt[30], nm[30];
		for(int i=0; i<30; i++)
		{
			mi[i]=MAX;
			ma[i]=MIN;
			tt[i]=0;
			nm[i]=0;
		}

		int n=0;
		map<string, int> d;
		vector<State> st;
		vector<Dealer> dr;
		for(int i=0; i<N; i++)
		{
			bool dealed=0;
			string a,b;
			char c;
			int p;
			
			cin >> a >> b >> c >> p;
			if(!d.count(a))
			{
				d[a]=dr.size();
				dr.push_back(Dealer(a,0,0));
			}

			for(int j=0; j<st.size(); j++)
			{
				if(st[j].t==b) continue;
				if(st[j].c!=c) continue;

				if(st[j].n==a) continue;

				if(b=="SELL")
				{
					if(p<=st[j].p)
					{
						int np=(p+st[j].p)/2;
						int z=st[j].c-'A';
						mi[z]=min(mi[z], np);
						ma[z]=max(ma[z], np);
						tt[z]+=np;
						nm[z]++;

						dr[d[a]].s+=np;
						dr[d[st[j].n]].b+=np;

						dealed=true;
						st.erase(st.begin()+j);
					}

					
				}
				else
				{
					if(p>=st[j].p)
					{
						int np=(p+st[j].p)/2;
						int z=st[j].c-'A';
						mi[z]=min(mi[z], np);
						ma[z]=max(ma[z], np);
						tt[z]+=np;
						nm[z]++;

						dr[d[a]].b+=np;
						dr[d[st[j].n]].s+=np;

						dealed=true;
						st.erase(st.begin()+j);
					}
				}

				break;
			}

			if(!dealed) st.push_back(State(a,b,c,p,i));
			sort(st.begin(), st.end());
		}

		for(int i=0; i<26; i++)
		{
			if(nm[i]==0) continue;
			cout << (char)(i+'A') << " " << mi[i] << " "  << (int)(tt[i]/nm[i]) << " "<< ma[i] << endl;
		}
		cout << "--" << endl;

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

		for(int i=0; i<dr.size(); i++)
		{
			cout << dr[i].n << " " << dr[i].b << " " << dr[i].s << endl;
		}
		cout << "----------" << endl;
	}

}

Measured memory_bytes: 992
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        i: usize,
    }
    println!("{}", n - i + 1);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public	static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] dice = new int[7];
		int tmp;
		for (int i = 0; i < 6; i++) {
			dice[i] = sc.nextInt();
		}
		String s = sc.next();
		for(int i = 0; i < s.length(); i++) {
			char c = s.charAt(i);
			switch(c){
				case 'E':
					tmp = dice[0];
					dice[0] = dice[3];
					dice[3] = dice[5];
					dice[5] = dice[2];
					dice[2] = tmp;
					break;
				case 'W':
					tmp = dice[0];
					dice[0] = dice[2];
					dice[2] = dice[5];
					dice[5] = dice[3];
					dice[3] = tmp;
					break;
				case 'N':
					tmp = dice[0];
					dice[0] = dice[1];
					dice[1] = dice[5];
					dice[5] = dice[4];
					dice[4] = tmp;
				break;				
				case 'S':
					tmp = dice[0];
					dice[0] = dice[4];
					dice[4] = dice[5];
					dice[5] = dice[1];
					dice[1] = tmp;
					break;
			}
		}
		System.out.println(dice[0]);
	}
}



Measured memory_bytes: 26292
#include "bits/stdc++.h"
using namespace std;
#define LL long long
int ar[100010];
char s[100010];
long long cnt[26][26];
long long tot[26];
const int maxn = 400010;
const int logn = 19;
vector <int> v[maxn];
set<int>st;
list<int>li;
map<string,int>mp;
pair<int,int>p;
bool mark[maxn];
int d[maxn];
int n, k;

void join() {
    int x;
    cin>>x;
    
    vector<int> vc;
    for(int i=0;i<1;i++){
        vc.push_back(1);
        vc.push_back(1);
        vc.push_back(1);
        vc.push_back(2);
        vc.push_back(1);
        vc.push_back(2);
        vc.push_back(1);
        vc.push_back(5);
        vc.push_back(2);
        vc.push_back(2);
         vc.push_back(1);
         vc.push_back(5);
         vc.push_back(1);
          vc.push_back(2);
          vc.push_back(1);
          vc.push_back(14);
           vc.push_back(1);
            vc.push_back(5);
             vc.push_back(1);
             vc.push_back(5);
             vc.push_back(2);
             vc.push_back(2);
             vc.push_back(1);
             vc.push_back(15);
              vc.push_back(2);
               vc.push_back(2);
                vc.push_back(5);
                 vc.push_back(4);
                  vc.push_back(1);
                  vc.push_back(4);
                   vc.push_back(1);
                    vc.push_back(51);
    }
    cout<<vc[x-1];
}

void solve() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++) {
	     cin >> a[i];
     }
    for(int i = 0; i < n; i++) {
	     cout<< a[i];
     }
}

int main()
{
    //int tc;
//	scanf("%d", &tc);
	//while(tc--) {
	    //solve();
	    join();
//	}
    return 0; 
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N,x;
  cin>>N>>x;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  sort(A.begin(),A.end());
  int ans=0;
  for(int i=0;i<N;i++){
    x-=A[i];
    if(x<0)break;
    ans++;
  }
  if(ans==N && x!=0)cout<<N-1<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;

int main(){
    int A,B;
    cin >> A >> B;
    if(A>=13){
        cout << B << endl;
    }else if(A<=5){
        cout << 0 << endl;
    }else{
        cout << B/2 << endl;
    }
    return 0;
}


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

const int maxn = 1e6+5;

bool check(ll y, ll x) {
   while(y%x==0) y/=x;
   if(y == 1) return true;
   else if(y%x == 1) return true;
   else return false;
}
int main()
{
   ll sum = 1;
   ll a; cin >> a;
   ll b = a-1ll;
   if(b != 1ll) sum++;
   for(ll i = 2; i <= sqrt(b); i++) {
    if(b%i==0ll) {
        if(i != b/i) sum += 2ll;
        else sum++;
    }
   }
   for(ll i = 2; i <= sqrt(a); i++) {
    if(a%i==0ll) {
        if(check(a, a/i)||check(a, i)) sum++;
    }
   }
   cout << sum << endl;
}


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

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

    int ans = 1;

    while (ans * 2 <= N)
    {
        ans *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3596
/* ex7_1
   masaaki52	*/
#include <stdio.h>
#include <math.h>

typedef struct point{//xy座標の導入
  int x_elem;
  int y_elem;
}point;

point shift_point(point a,point b);//プロトタイプ宣言

int main(void){
  point vertice1,vertice2,vertice3,vertice4;
  scanf("%d %d ",&vertice1.x_elem,&vertice1.y_elem);
  scanf("%d %d",&vertice2.x_elem,&vertice2.y_elem);
  //vertice1,vertice2からvertice3の座標を求める
  vertice3 = shift_point(vertice1,vertice2);
  printf("%d %d ",vertice3.x_elem,vertice3.y_elem);
  //vertice2,vertice3からvertice4の座標を求める
  vertice4 = shift_point(vertice2,vertice3);
  printf("%d %d",vertice4.x_elem,vertice4.y_elem);
  return 0;
}

point shift_point(point a,point b){//正方形の点a,bの座標からcの座標を求める
  point c;
  c.x_elem = b.x_elem - b.y_elem + a.y_elem;
  c.y_elem = b.y_elem + b.x_elem - a.x_elem;
  return(c);
}

Measured memory_bytes: 1712
class UnionFind():

    def __init__(self, n):
        # 頂点の値が0から始まる前提なので注意
        self.par = [i for i in range(n)]

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)

        if x == y:
            return
        
        self.par[x] = y
        return


def main():
    N, M = map(int, input().split())
    p = list(map(lambda x: int(x)-1, input().split()))

    uf = UnionFind(N)
    for i in range(M):
        x, y = map(int, input().split())
        uf.unite(x-1, y-1)
    
    ans = 0
    for i in range(N):
        if uf.same(i, p[i]):
            ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()


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

template <class T>
inline void read(T &x) {
	static char ch; 
	static bool opt; 
	while (!isdigit(ch = getchar()) && ch != '-'); 
	x = (opt = ch == '-') ? 0 : ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
	if (opt)
		x = ~x + 1; 
}

template <class T>
inline void putint(T x) {
	static char buf[45], *tail = buf; 
	if (!x)
		putchar('0'); 
	else {
		if (x < 0)
			putchar('-'), x = ~x + 1; 
		for (; x; x /= 10) *++tail = x % 10 + '0'; 
		for (; tail != buf; --tail) putchar(*tail); 
	}
}

template <class T>
inline bool tense(T &x, const T &y) {
	return y < x ? x = y, true : false; 
}

template <class T>
inline bool relax(T &x, const T &y) {
	return x < y ? x = y, true : false; 
}

template <class T>
inline T getAbs(const T &x) {
	return x < 0 ? -x : x; 
}

typedef long long s64; 
typedef long double ld; 
typedef std::vector<int> vi; 
typedef std::pair<int, int> pii; 
#define mp(x, y) std::make_pair(x, y)

const int MaxN = 2e5 + 5; 

int n; 
s64 a[MaxN], b[MaxN], ans; 
std::vector<int> divisor, son[110], par[110]; 

ld t[MaxN]; 
int cnt[110][110];  

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

int main() {
#ifdef orzczk
	freopen("a.in", "r", stdin); 
#endif

	std::ios::sync_with_stdio(false);
	std::cin.tie(0);

	s64 M = 1e9; 
	for (int i = 1; i * i <= M; ++i)
		if (M % i == 0) {
			divisor.push_back(i); 
			divisor.push_back(M / i); 
		}
	
	int S = divisor.size(); 
	for (int i = 0; i < S; ++i)
		for (int j = 0; j < S; ++j)
			if (divisor[i] % divisor[j] == 0) {
				son[i].push_back(j); 
				par[j].push_back(i); 
			}
	
	// std::cerr << divisor.size() << '\n'; 
	
	std::cin >> n; 
	for (int i = 1; i <= n; ++i) {
		std::cin >> t[i]; 

		a[i] = (s64)(t[i] * (ld)M + 1e-3); 
		s64 g = gcd(a[i], M), m = M / g; 

		// std::cout << a[i] << ' ' << g << '\n'; 

		int posM = 0, posA = 0; 
		s64 tg = gcd(a[i] / g, M); 
		for (int i = 0; i < S; ++i) {
			if (divisor[i] == m) {
				posM = i; 
			}
			if (divisor[i] == tg) {
				posA = i; 
			}
		}

		// std::cerr << '>' << posA << ' ' << posM << '\n'; 

		for (int x : son[posA])
			for (int y : par[posM]) {
				// std::cout << ':' << x << ' ' << y << '\n'; 
				ans += cnt[y][x]; 
			}

		++cnt[posA][posM]; 
	}

	std::cout << ans << '\n'; 

	return 0; 
}

Measured memory_bytes: 8492
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

int main() {
    int N, L;
    cin >> N >> L;

    int T = 0;
    for (int i = 0; i < N; i++) {
        T += L + i;
    }

    int ansI = -1;
    int minT = INF;
    for (int i = 0; i < N; i++) {
        if (minT > abs(L + i)) {
            minT = abs(L + i);
            ansI = i;
        }
    }

    cout << T - (L + ansI) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};



int main() {
    ll H; cin>>H;
    ll ans;
    int i=0;
    while(H>=2){
        H/=2;
        i++;
    }
    cout<<(ll)pow(2ll,(ll)i+1)-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n;
    cin >> n;
    vll a(n + 1);
    a[0] = 1, a[1] = 1;
    REP(i, n - 1){
        a[i + 2] = a[i] + a[i + 1];
    }
    cout << a[n] << endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        double[] p = new double[N];
        for (int i = 0 ; i < N; i++) p[i] = scanner.nextDouble();
        double dp[][] = new double[N+1][N];
        dp[0][0] = (1-p[0]);
        dp[1][0] = p[0];
        for (int i = 1; i < N; i++) {
            dp[0][i] = (1-p[i]) * ((i-1>=0)?dp[0][i-1]:1.0);
            for (int j = 1; j <= i+1; j++) {
                dp[j][i] = ((i-1 >=0 && j-1 >= 0)?dp[j - 1][i - 1]:1.0) * p[i];
                dp[j][i] = dp[j][i] + ((i-1 >= 0)? dp[j][i-1]:1.0) * (1-p[i]);
            }
        }
        double result = 0;
        for (int j = N/2+1; j <= N; j++) {
            result += dp[j][N-1];
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 125076
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,m;
  cin>>A>>B>>m;
  int a[A],b[B],x[m],y[m],c[m];
  int mina=100005,minb=100005;
  for(int i=0;i<A;i++){
    cin>>a[i];
    mina=min(a[i],mina);
  }
  for(int i=0;i<B;i++){
    cin>>b[i];
    minb=min(b[i],minb);
  }
  for(int i=0;i<m;i++) cin>>x[i]>>y[i]>>c[i];
  
  int ans=1000100;
  for(int i=0;i<m;i++){
  	ans=min(a[x[i]-1]+b[y[i]-1]-c[i],ans);
  }
  ans=min(ans,mina+minb);
  cout<<ans<<endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    ll a;
    double b;
    cin >> a >> b;
    ll bb = (ll)(b*100+0.1);
    cout << a * bb/100 << endl;
    return 0;
}


Measured memory_bytes: 3708
#include <stdio.h>

int main(void) {
	int n,a,b,sum=0,i,rem,num,dig_sum;
	scanf("%d %d %d",&n,&a,&b);
	for(i=1;i<=n;i++)
	{
		if(i<10){
			if(i>=a && i<=b)
			{
				sum=sum+i;
			}
		}
		else if(i>=10)
		{
			num=i;
			dig_sum=0;
	     while(num)

        {
	        rem=num%10;
	        num /= 10;
	        dig_sum+=rem;
        }
        if(dig_sum>=a && dig_sum<=b)
        	sum=sum+i;
		}
	}


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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)  for(long long i=0;i<n;++i)
#define rep1(i,n) for(long long i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
const ld PI = acos(-1);

ld Coseno(ld angle){
    return cos ( angle * M_PI / 180.0 );
}

int main(){
    ios;


    ld a, b, h, m;
    cin >> a >> b >> h >> m;
    ld a2 = a*a;
    ld b2 = b*b;
    ld angle = 180 - abs(180 -  abs( m * 6 - (h * 30 + m * 0.5) ) );
    //deb(angle);
   // deb(a2); deb(b2);
    ld ans = sqrt( (a2 + b2) - ( (2 * a * b) * Coseno(angle)) );
    cout << setprecision(20); cout << fixed;
    //cout << M_PI << '\n';
    //cout << cos(90);
    cout << ans;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

set<char> vowel{'a', 'i', 'u', 'e', 'o'};
string s[50], c[50];

void makeCode(int i) {
    string tmp(1, s[i][0]);
    rep(j, s[i].length() - 1) {
        if (vowel.count(s[i][j])) tmp += s[i][j + 1];
    }
    c[i] = tmp;
}

int main(){
    cin.sync_with_stdio(false);
    int n;
    while(cin >> n, n) {
        int maxi = 0;
        rep(i, n) {
            cin >> s[i];
            makeCode(i);
            maxch(maxi, (int)c[i].length());
        }

        int ok = -1;
        repl(i, 1, maxi + 1) {
            set<string> dif;
            rep(j, n) {
                dif.insert(c[j].substr(0, min(i, (int)c[j].length())));
            }
            if (dif.size() == n) {
                ok = i;
                break;
            }
        }

        cout << ok << endl;
    }

    return 0;
}

Measured memory_bytes: 3192