akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int a, b, c, d, e, f;
int dp[3010][3010];

int main(int argc, char *argv[]){
    cin >> a >> b >> c >> d >> e >> f;
    double ma = 0;
    int res1 = 100 * a; int res2 = 0;
    dp[0][0] = 1;
    rfor(i, 1, f + 1) rfor(j, 0, i + 1){
        // i : 水溶液の質量
        // j : 砂糖の質量
        int water = i - j;
        int sugar = j;

        if(100 * a <= i) if(dp[i - 100 * a][j]) dp[i][j] = 1;
        if(100 * b <= i) if(dp[i - 100 * b][j]) dp[i][j] = 1;
        if(c <= i && c <= j) if(dp[i - c][j - c]) dp[i][j] = 1;
        if(d <= i && d <= j) if(dp[i - d][j - d]) dp[i][j] = 1;

        if(sugar * 100 <= water * e && dp[i][j] && j > 0){
            double E = 1.0 * 100 * j / i;
            if(ma < E){
                ma = E;
                res1 = i;
                res2 = j;
            }
        }
    }
    cout << res1 << " " << res2 << endl;
    return 0;
}

Measured memory_bytes: 33536
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


n = int(input())
d = set()
for i in range(n):
    command,s = input().split()
    if command == "insert":
        d.add(s)
    else:
        if s in d:
            print("yes")
        else:
            print("no")



Measured memory_bytes: 31808
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    x -= a;
    x -= (x/b)*b;
    System.out.println(x);
  }
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

int main(void){
    long long MOD = 1000000007LL;
    int n, m;
    cin >> n >> m;
    vector<int> s(n, 0);
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    vector<int> t(m, 0);
    for(int i = 0; i < m; i++){
        cin >> t[i];
    }

    vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 0));
    vector<vector<long long>> sumdp(n + 1, vector<long long>(m + 1, 0));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(s[i] == t[j]){
                dp[i + 1][j + 1] = (sumdp[i][j] + 1) % MOD;
            }
            sumdp[i + 1][j + 1] = (sumdp[i + 1][j] + sumdp[i][j + 1] + MOD - sumdp[i][j] + dp[i + 1][j + 1]) % MOD;
        }
    }
    long long ans = (sumdp[n][m] + 1) % MOD;
    cout << ans << endl;
}


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

#define ll long long int
#define tinput int t; cin>>t; while(t--)
#define rep(i,n,s) for((i)=(s); (i)<(n); (i)++)

int main(){
   // freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	if(n==0) cout<<"1";
	else cout<<"0";
	
	return 0;
}

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

int main(){

    int purchase_num;
    int max_cap;

    while(std::cin >> purchase_num >> max_cap){
        if(purchase_num == 0 && max_cap == 0) break;
        std::vector<int> price;
        std::string str;
        int input_data;
        int min_price = 0;
        std::cin.ignore();
        std::getline(std::cin, str);
        std::istringstream iss(str);
        while(!iss.eof()){
            iss >> input_data;
            price.push_back(input_data);
        }
        std::sort(price.begin(),price.end(),std::greater<int>());
        for(int i = 0; i < price.size(); ++i){
            if((i+1)%max_cap != 0){
                min_price += price[i];
            }
        }
        std::cout << min_price << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3184
#include "bits/stdc++.h"
using namespace std;
int main(void){
    int N,Q,R[100000],QQ[100000],QQQ[100000];
    char S[100000];
    cin >> N >> Q >> S;
    for (int i = 0;i < N;i++){
        if (S[i]=='A' && S[i+1]=='C'){
            R[i+1] = R[i] + 1;
        }else {
            R[i+1] = R[i];
        }
    }
    
    for (int i = 0;i < Q;i++){
        cin >> QQ[i] >> QQQ[i];
        cout << R[QQQ[i] - 1] - R [QQ[i] - 1] << endl;
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n, s) for (int i = (s); i < (n); i++)
#define MOD 1000000007
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

int calc_num(string S,char c1,char c2){
    int N=S.size();
    int _N;
    int ans=0;
    if(N%2==0){
        _N=N;
    }
    else{
        _N=N-1;
    }
    for(int i=0;i<_N;i+=2){
        if(S[i]!=c1){
            ans++;
        }
        if(S[i+1]!=c2){
            ans++;
        }
    }
    if(N!=_N && S[N-1]!=c1){
        ans++;
    }
    return ans;

}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> S;
    N = S.size();
    int ans = calc_num(S,'0','1');
    ans = min(calc_num(S,'1','0'),ans);
    cout << ans << endl;
 //   system("pause");
    return 0;
}


Measured memory_bytes: 512
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function abmp(a,b,p);if b==0;1;elseif b%2==0;k=abmp(a,div(b,2),p);(k*k)%p;else;(a*abmp(a,b-1,p))%p;end;end;;

function binarr(n,p);z=1;for i in 1:n;z=z*i%p;end;fac=Array{Int}(n+1);inv=Array{Int}(n+1);inv[n+1]=abmp(z,p-2,p)
for i in 0:n-1;inv[n-i]=(inv[n+1-i]*(n-i))%p;end;for i in 0:n;fac[i+1]=(((z*inv[i+1])%p)*inv[n+1-i])%p;end;fac;end;

function main()
    mod=10^9+7
    x,y = readline() |> split |> parseMap
    if (2*x-y)%3==0&&2*x>=y&&2*y>=x
        p = div(2*x-y,3)
        q = div(2*y-x,3)
        ba = binarr(p+q,mod)
        println(ba[p+1])
    else
        println(0)
    end
end
main()

Measured memory_bytes: 166808
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N;
  while (cin >> N) {
    vec<ll, 2> a = make_v(N, N, 0ll);
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        cin >> a[i][j];
      }
    }
    vector<ll> profit(1 << N, 0);
    for (int m = 0; m < (1 << N); m++) {
      ll sum = 0;
      for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
          if (((m >> i) & 1) && ((m >> j) & 1)) {
            sum += a[i][j];
          }
        }
      }
      profit[m] = sum;
    }
    vector<ll> dp(1 << N, 0);
    for (int m = 0; m < (1 << N); m++) {
      int nouse = ((1 << N) - 1) ^ m;
      for (int bit = nouse;; bit = (bit - 1) & nouse) {
        dp[m | bit] = max(dp[m | bit], dp[m] + profit[bit]);
        if (!bit) break;
      }
    }
    cout << dp.back() << endl;
  }
  return 0;
}


Measured memory_bytes: 1280
#include <stdio.h>

int main() {
	int m, f, r, a;
	while(1) {
		scanf("%d %d %d", &m, &f, &r);
		a = m + f;
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		if(m == -1 || f == -1){
			printf("F\n");
		}
		else if (a >= 80) {
			printf("A\n");
		}
		else if ( a >= 65 && a < 80) {
			printf("B\n");
		}
		else if (a >= 50 && a < 65) {
			printf("C\n");
		}
		else if (a >= 30 && r < 50) {
			printf("D\n");
		}
		else if(a >= 30 && r >= 50){
			printf("C\n");
		}
		else if (a < 30) {
			printf("F\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2112
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n;
    cin >> n;
    int a, before = 0;
    int cnt = 1, ans = 0;
    for(int i = 0 ; i < n ; i++){
        cin >> a;
        if(before == a) cnt++; // 連続数をカウント
        else{
            before = a;
            ans += cnt / 2; // 違ったらカウントした分を反映
            cnt = 1;
        }
    }
    ans += cnt / 2; // 最後の反映されてない部分を反映
    cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define f first
#define s second
#define int long long
#define sz(x) (ll)(x.size())
using namespace std;


const int mod = 1e9+7;

int expo_pow(int x,int y){
 if(y == 0) return 1;
  y=y%(mod-1);
  x%=mod;
  if(y==0) y=mod-1;
  int res=1;
  while(y){
    if(y&1) res=(res*x)%mod;
    x=(x*x)%mod;
    y>>=1; 
  }
  return res;
}

ll add()
{
    return 0;
}

template <typename T, typename... Types>
T add(T var1, Types... var2){
    return (((((ll)(var1)) % mod + (ll)(add(var2...))) % mod) + mod) % mod;
}

ll mul(){
    return 1;
}

template <typename T, typename... Types>
T mul(T var1, Types... var2){
    return (((ll)(var1)) % mod * (ll)(mul(var2...))) % mod;
}

void solve(){
  int n;
  cin >> n;
  if (n == 1) {
    cout << 0 << "\n";
    return;
  }
  int ans = 1;
  for (int i = 0 ; i < n; ++i) ans = mul(ans,10);
  int tmp = 1;
  for (int i = 0; i < n; ++i) tmp = mul(tmp,9);
  ans = ((ans - 2*tmp)%mod + 2*mod)%mod;
  tmp = 1;
  for (int i = 0; i < n; ++i) tmp = mul(tmp,8);
  ans = (ans + tmp)%mod;
  cout << ans << "\n";
}


signed main(){
  fast;
  int test = 1;
  int i=1;
  while(test--){
    solve();
  }
}





Measured memory_bytes: 3668
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        long[] a=new long[n+1];
        for (int i = 1; i <= n; i++) {
            a[i]=sc.nextLong()+a[i-1];
        }
        long ans=Long.MAX_VALUE; 
        for (int i = 1; i < n; i++) {
            long x=a[i];
            long y=a[n]-a[i];
            ans=min(ans,abs(x-y));
        }
        out.println(ans);
    }
}

Measured memory_bytes: 84928
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums = Stream.of(sc.nextLine().split("")).mapToInt(Integer::parseInt).toArray();

        // 1000
        int n = 1 << nums.length - 1;

        for (int i = 0; i < n; i++) {
            int sum = nums[0];
            String str = String.valueOf(nums[0]);
            for (int k = 0; k < nums.length - 1; k++) {
                if ((i & (1 << k)) != 0) {
                    // 足し算
                    sum += nums[k+1];
                    str += "+" + nums[k+1];
                } else {
                    // 引き算
                    sum -= nums[k+1];
                    str += "-" + nums[k+1];
                }
            }
            if (sum == 7) {
                System.out.println(str + "=7");
                return;
            }
        }
    }
}

Measured memory_bytes: 28624
#include<bits/stdc++.h>
#define N 55
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;

int h, w;

string s[N];


bool check(int y1,int x1,int y2,int x2){
  
  queue<P> q;

  bool used[N][N];

  memset(used,0,sizeof(used));

  q.push(P(y1,x1));
  
  while(!q.empty()){

    P t=q.front(); q.pop();

    int y = t.first, x = t.second;

    if(s[y][x]=='#') continue;
    
    if(used[y][x]) continue;
    
    used[y][x] = true;
    
    if(y + 1 < h) q.push(P(y+1,x));
    
    if(x + 1 < w) q.push(P(y,x+1));
    
  }

  return used[y2][x2];
}


vector<P2> rec;

void addrec(){

  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){

      if(!('a'<=s[i][j]&&s[i][j]<='z')) continue;
      
      for(int k=i;k<h;k++)
	for(int l=j;l<w;l++)

	  if(s[k][l]=='A'+s[i][j]-'a'&&check(i,j,k,l))
	    if(check(0,0,i,j)&&check(k,l,h-1,w-1))
	      rec.push_back(P2(P(i,j),P(k,l)));
      
    }
  
}


int dp[1005][N][N];
bool used[1005][N][N];

void dfs(int num,int y,int x,bool dr){

  if(used[num][y][x]) return;
  
  used[num][y][x]=true;
  
  int y1 = rec[num].first.first, x1 = rec[num].first.second;
  
  int y2 = rec[num].second.first, x2 = rec[num].second.second;
  
  if(!check(y2,x2,y,x)) return;
  
  dp[num][y][x]=0;

  int res1=0, res2=0;
  
  for(int i=0;i<rec.size();i++){

    int sy, sx, gy, gx;

    sy = rec[i].first.first;
    sx = rec[i].first.second;
    gy = rec[i].second.first;
    gx = rec[i].second.second;

    if(num==i) continue;
    
    if(y1<=sy&&x1<=sx&&gy<=y2&&gx<=x2){
      if(!(y1==sy&&x1==sx)&&!(gy==y2&&gx==x2)){
	if(check(y1,x1,sy,sx)&&check(gy,gx,y2,x2)){
	  dfs(i,y2,x2,1);
	  res1=max(res1,dp[i][y2][x2]);
	}
      }
    }

    if(dr&&gy==y&&gx==x) continue;
    
    if(y2<=sy&&x2<=sx&&gy<=y&&gx<=x){
      if(!(y2==sy&&x2==sx)){
	if(check(y2,x2,sy,sx)&&check(gy,gx,y,x)){
	  dfs(i,y,x,0);
	  res2=max(res2,dp[i][y][x]);
	}
      }
    }
    
  }
  
  dp[num][y][x]=res1+res2+1;
  
}


int main(){
  
  
  while(1){
    
    cin>>h>>w;
    if(!h&&!w) break;
    
    for(int i=0;i<h;i++) cin>>s[i];
    
    memset(dp,-1,sizeof(dp));
    memset(used,0,sizeof(used));
    
    addrec();

    for(int i=0;i<rec.size();i++){

      if(!check(0,0,rec[i].first.first,rec[i].first.second)) continue;
      if(!check(rec[i].second.first,rec[i].second.second,h-1,w-1)) continue;
      
      dfs(i,h-1,w-1,0);
    }

    int ans=-1;
    
    for(int i=0;i<rec.size();i++) ans=max(ans,dp[i][h-1][w-1]);
    
    if(ans==-1&&check(0,0,h-1,w-1)) ans=0;
    
    cout<<ans<<endl;
    
    rec.clear();
  }
  
  return 0;
}

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

using namespace std;

int main() {
    int N, M, a, b;
    cin >> N >> M;
    vector<pair<int,int>> v;

    for (int i=0;i<M;i++)
    {
        cin >> a >> b;
        v.push_back({a, b});
    }

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

    int bridges = 0;

    int y = -1;
    for (int j=0; j<M;j++)
    {
        if (v[j].first >= y)
        {
            bridges++;
            y = v[j].second;
        }
        else
        {
            y = min(y, v[j].second);
        }
    }

    cout << bridges;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int m;
	int h;
	string s, s1, s2;
	cin >> s;
	while (s != "-"){
		cin >> m;
		rep(i, m){
			cin >> h;
			s1 = s.substr(0, h);//substract [0, h)
			s2 = s.substr(h);//substract [h
			s = s2 + s1;
		}
		cout << s << '\n';
		cin >> s;
	}

	return 0;
}


Measured memory_bytes: 3228
#include <stdio.h>
#define MAX 10000

int S[MAX], n;
int linearSearch(int);

int main(){
  int i, q, count = 0, T[MAX];

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++){
    scanf("%d",&T[i]);
    if(linearSearch(T[i]) == 1) count++;
  }
  printf("%d\n",count);

  return 0;
}

int linearSearch(int t){
  int i;
  for(i = 0; i < n; i++){
    if(S[i] == t) return 1;
  }

  return 0; 
}

Measured memory_bytes: 644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private static int count = 0;
	private static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) {

		try {
			// nを入力
			int n = Integer.parseInt(bufferedReader.readLine());

			// mergeSort対象配列
			int[] A = new int[n];

			// mergeSort対象配列の中身を入力
			String[] array = bufferedReader.readLine().split(" ");

			bufferedReader.close();

			// String配列をint配列に変換
			for (int i = 0; i < array.length; i++) {
				A[i] = Integer.parseInt(array[i]);
			}

			int left = 0;
			int right = A.length;

			mergeSort(A, left, right);

			StringBuilder message = new StringBuilder();
			message.append(A[0]);
			for (int i = 1; i < A.length; i++) {
				message.append(" ");
				message.append(A[i]);
			}
			message.append("\n");
			message.append(count);
			System.out.println(message.toString());

		} catch (Exception e) {
			e.printStackTrace();
		} finally {

		}
	}

	private static void mergeSort(int[] a, int left, int right) {

		if (left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(a, left, mid);
			mergeSort(a, mid, right);
			merge(a, left, mid, right);
		}
	}

	/**
	 * マージ処理をします。
	 *
	 * @param a     マージソート対象の配列
	 * @param left  左のindex
	 * @param mid   真ん中のindex
	 * @param right 右のindex
	 */
	private static void merge(int[] a, int left, int mid, int right) {
		// n of left
		int n1 = mid - left;
		// n of right
		int n2 = right - mid;

		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];

		int i;

		for (i = 0; i < n1; i++) {
			L[i] = a[left + i];
		}
		for (i = 0; i < n2; i++) {
			R[i] = a[mid + i];
		}
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;

		i = 0;
		int j = 0;
		for (int k = left; k < right; k++) {
			// Aに小さい方を入れる
			count++;
			if (L[i] <= R[j]) {
				a[k] = L[i++];
			} else {
				a[k] = R[j++];
			}
		}
	}
}



Measured memory_bytes: 166432
N = int(input())
S = input()
ans = 0
for i in range(1,N):
    bef = list(set(S[:i]))
    aft = list(set(S[i:]))
    cnt = 0
    for j in bef:
        if j in aft:
            cnt += 1
    else:
        ans = max(cnt, ans)

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

 class Vector {
	private double pointX;
	private double pointY;

	Vector(double pointX, double pointY) {
		this.pointX = pointX;
		this.pointY = pointY;
	}

	public double getPointX() {
		return pointX;
	}
	public double getPointY() {
		return pointY;
	}
	public void setPointX(int pointX) {
		this.pointX = pointX;
	}
	public void setPointY(int pointY) {
		this.pointY = pointY;
	}


 }

public class Main {


	static Scanner sc = new Scanner(System.in);


	public static void main(String[] args) {
		while(sc.hasNext()) {
			Vector a = new Vector(sc.nextDouble(), sc.nextDouble());
			Vector b = new Vector(sc.nextDouble(), sc.nextDouble());
			Vector c = new Vector(sc.nextDouble(), sc.nextDouble());
			Vector p = new Vector(sc.nextDouble(), sc.nextDouble());

			judgePoint(a, b, c, p);
		}

	}

	private static void judgePoint(Vector a, Vector b, Vector c, Vector p) {
		Vector pa = new Vector(a.getPointX() - p.getPointX(), a.getPointY() - p.getPointY());
		Vector pb = new Vector(b.getPointX() - p.getPointX(), b.getPointY() - p.getPointY());
		Vector pc = new Vector(c.getPointX() - p.getPointX(), c.getPointY() - p.getPointY());

		double op_pa_pb = pa.getPointX() * pb.getPointY() - pb.getPointX() * pa.getPointY();
		double op_pb_pc = pb.getPointX() * pc.getPointY() - pc.getPointX() * pb.getPointY();
		double op_pc_pa = pc.getPointX() * pa.getPointY() - pa.getPointX() * pc.getPointY();

			if (  ( op_pa_pb > 0 && op_pb_pc > 0 && op_pc_pa > 0 ) ||
					( op_pa_pb < 0 && op_pb_pc < 0 && op_pc_pa < 0 ) ) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}

	}

}


Measured memory_bytes: 32508
import sys, math
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    N, K = map(int, input().split())

    """
    gcd(a1,...,aN) = dになる時を考える。もしこの個数がわかれば\sum_dして答えを得る。
    （決め打ち二分探索的な発想として出てくるのか？？？）
    これはa1,...,aNがすべてdの倍数のときと予想が立つが、すぐにgcd=2d, 3d,...の場合もありうると気づく。
    しかしこの考察から
            gcd(a1,...,aN)がdの倍数になる(a1,...,aN)の個数 = (K // d)^N
    という式を得る。

    同様にgcd(a1,...,aN)=(2dの倍数), gcd(a1,...,aN)=(3dの倍数)なる(a1,...aN)の個数もすぐ求まるので、
    kd <= Nなるなるべく大きなkを考えて（そうするとgcd(a1,...,aN)=mdなる(a1,...aN)の個数がばっちり求まる）、
    あとはkを小さくしていきながら適当な引き算を施すことで答えが求まる。
    """

    count = [0] * (K + 1) # count[i] = (gcd(a1,...,aN) = iとなる(a1,...,aN)の組の数)
    for d in range(1, K + 1):
        count[d] = pow(K // d, N, mod)
    for d in range(K // 2 + 1, 0, -1):
        for m in range(2, K // d + 1):
            count[d] -= count[m * d]
            count[d] %= mod
    #print(count)
    ans = 0
    for i in range(1, K + 1):
        ans += count[i] * i
        ans %= mod
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 72860
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

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; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

int main() {
	int n;
	cin >> n;
	VL v(n);
	REP(i, n) { cin >> v[i]; }

	vector<bool> dp(n * 100 + 1, false);
	dp[0] = true;
	REPC(x, v) {
		RREP(i, n * 100 - x + 1) {
			if (dp[i]) {
				dp[i + x] = true;
			}
		}
	}
	RREP(i, n * 100 + 1) {
		if (dp[i] && i % 10 != 0) {
			cout << i << endl;
			return 0;
		}
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
using namespace std;

int main()
{
  int d1,d2,m1,m2;
  cin >> m1 >> d1 >> m2 >>d2;
  int a = 0;
  if(d2 == 1) a=1;
  printf("%d\n", a);

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std;

using ll = long long;

int n, k;
ll minValue = LLONG_MAX;

vector<ll> b;

void Calc(int index, int kCount, ll prevHeight, ll value) {
    if(kCount == k) {
        minValue = min(value, minValue);
        return;
        
    }

    ll maxHeight = -1;

    for(int i = index; i >= 0; --i)
        maxHeight = max(maxHeight, b[i]);

    if(maxHeight > prevHeight)
        prevHeight = maxHeight;

    for(int i = index + 1; i < n; ++i) {

        if(b[i] > prevHeight) {
            Calc(i, kCount + 1, b[i], value);
        }
        else {
            Calc(i, kCount + 1, prevHeight + 1, value + prevHeight - b[i] + 1);
        }
    }
}
int main() {

    cin >> n >> k;

    b.resize(n);

    for(int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    
    Calc(0, 1, b[0], 0);
    cout << minValue << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<int> T(N);
  for(int i=0;i<N;i++){
    cin>>T.at(i);
  }
  sort(T.begin(),T.end());
  reverse(T.begin(),T.end());
  int A=0;
  int B=0;
  for(int i=0;i<N;i++){
    if(i%2==0){
      A+=T.at(i);
    }
    else{
      B+=T.at(i);
    }
  }
  cout<<A-B<<endl;
}
  

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

signed main(){
  int N;
  cin>>N;
  std::vector<int> T(N);
  for(int i=0;i<N;i++)cin>>T[i];
  std::vector<int> v(N,0);
  for(int i=1;i<N;i++)if(T[i]>T[i-1])v[i]=1;
  std::vector<int> A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  std::vector<int> w(N,0);
  for(int i=N-2;i>=0;i--)if(A[i]>A[i+1])w[i]=1;
  int ans=1;
  v[0]=1;
  w[N-1]=1;
  int out=0;
  for(int i=0;i<N;i++){
    if(v[i]==1&&w[i]==1){
      if(A[i]!=T[i])out++;
    }
    if(v[i]==1&&w[i]==0){
      if(T[i]>A[i])out++;
    }
    if(v[i]==0&&w[i]==1){
      if(T[i]<A[i])out++;
    }
    if(v[i]==0&&w[i]==0){
      ans*=min(T[i],A[i]);
      ans%=1000000007;
    }
  }
  if(out)cout<<0<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int a[200];
int n,l;
int main()
{
    n=read();l=read();
    for(int i=1;i<=n;i++)  a[i]=l+i-1;
    int sum=0;
    for(int i=1;i<=n;i++)  sum+=a[i];
    int ans;
    int res=1e9;
    for(int i=1;i<=n;i++)
    {
        int tmp=sum-a[i];
        if(abs(tmp-sum)<res)  res=abs(tmp-sum),ans=tmp;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var a = line.split(' ');
  var b = Number(a);
  var c = b*b*Math.PI;
  var d = b*2*Math.PI;
  console.log(c.toFixed(6)+" "+d.toFixed(6));
  process.exit();
});
process.stdin.on('end', function () {
});

Measured memory_bytes: 16356
import math

N = int(input())
a = list(map(int,input().split()))
b = []
x = math.ceil(N/2)
check = 0

for i in reversed(range(N-x)):
    flag = a[i]
    mul = i + 1
    for j in range(mul + mul -1,N,mul):
        check += a[j]
    if (check % 2 == 0 and flag == 0) or (check % 2 == 1 and flag == 1):
        a[i] = 0
    else:
        a[i] = 1
    check = 0

ans = a.count(1)
print(ans)
if ans == 0:
    exit()

for i in range(N):
    if a[i] == 1:
        b.append(i+1)

print(*b)

Measured memory_bytes: 17104
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T>
using ordered_set =
       tree <T,null_type,less <T>,rb_tree_tag,tree_order_statistics_node_update> ;
///find_by_order()
///order_of_key()

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x=y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}
template <class T>
T safe_sqrt(T x){
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD){
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD){
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD){
    return ( (x % MOD) * (y % MOD) ) % MOD;
}

#define ll long long
#define pll pair <ll,ll>
#define pii pair <int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)((c).size())
#define fn "test"    ///FILE_NAME_HERE

/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

    void solve(){
    	int n,k;
    	double ans = 0.0;
    	cin>>n>>k;
    	for(int i = 1;i <= n;++i){
    		int j = 0;
    		while(i * MASK(j) < k){
    			++j;
    		}
    		ans += pow((double)n,-1) * pow(2,-j);
    	}
    	cout<<setprecision(20)<<fixed;
    	cout<<ans;
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    task::solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=55;
const int maxm=2466;
const ll inf=0x3f3f3f3f3f3f3f3f;//long long最大值，8个3f
#define tp tuple<ll,ll,ll>

vector<tp> G[maxn];//存每个点所能到达的点
ll c[maxn],d[maxn];//此点换钱的钱数和花费时间
ll dp[maxn][maxm];

int main(){
	int n,m,s;
	scanf("%d%d%d",&n,&m,&s);
	s=min(2450,s);//防止越界，取2450（最大容量）以下。
	for(int i=1;i<=m;i++){
		ll u,v,a,b;
		scanf("%lld%lld%lld%lld",&u,&v,&a,&b);
		G[u].push_back(tp(v,a,b)); //点 钱 时间 
		G[v].push_back(tp(u,a,b));
	}
	for(int i=1;i<=n;i++)
		scanf("%d%d",&c[i],&d[i]);
	fill(dp[0],dp[0]+54*2465,inf);//全部初始化为inf的骚操作
	dp[1][s]=0;//初始化起点
	//优先队列，按照tuple三个值（从前往后）升序
	priority_queue<tp,vector<tp>,greater<tp>> pq;
	pq.push(tp(0,1,s));
	
	while(!pq.empty()){
		tp cur;
		cur=pq.top();
		pq.pop();
		ll t=get<0>(cur),u=get<1>(cur),w=get<2>(cur);//取tuple值
		if(dp[u][w]>t) continue; //可有可无的判重
		for(auto i:G[u]){//遍历vector
			ll v=get<0>(i),toa=get<1>(i),tob=get<2>(i);
			if(dp[v][w-toa]>t+tob&&w>=toa){//如果有足够钱可达且这样走比原有dp更快
				dp[v][w-toa]=t+tob;
				pq.push(tp(t+tob,v,w-toa));//存入状态
			}
		}
		if(dp[u][min(2450LL,w+c[u])]>t+d[u]){//如果充1次钱后比原有dp更快
			dp[u][min(2450LL,w+c[u])]=t+d[u];
			pq.push(tp(t+d[u],u,min(2450LL,w+c[u])));//存入状态
		}
		//这里只充一次钱，因为接下来会有下一次充钱的状态到来~
	}
	for(int i=2;i<=n;i++){
		ll ans=inf;
		for(int j=0;j<=2450;j++)
			ans=min(ans,dp[i][j]);//取到达时剩下的不同钱中最快的
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 7372
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 610000
ll n,m,k;
ll dp[N];
int a[N];
ll b[N];
int main(){
    n=in();
    int w=in();
    rep(i,n){
        a[i]=in();b[i]=lin();
    }
    rep(i,n){
        rep3(j,w,a[i]){
            dp[j]=max(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    cout<<dp[w];
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    string s;
    cin >> s >> K;
    int n = s.size();
    s += s;
    ll tmp1 = 0;
    REP(i,n-1){
        if(s[i] == s[i+1]) tmp1++, i++;
    }
    if(K==1){
        cout << tmp1 << endl;
        return 0;
    }
    ll tmp2 = 0;
    for(int i=0;i<2*n-1;i++){
        if(s[i] == s[i+1]) tmp2++, i++;
    }
    ll cnt = 0;
    if(s[0] == s[n-1]){
        for(int i=1;i<n;i++){
            if(s[i] == s[0]) cnt++;
            else break;
        }
        for(int i=n-1;i>=0;i--){
            if(s[i] == s[0]) cnt++;
        }
    }
    //cout << tmp1 << " " << tmp2 << endl;
    if(2 * tmp1 == tmp2) cout << tmp1 * K << endl;
    else{
        //cout << ans << endl;
        if(cnt % 2 == 0) cout << tmp1 + (tmp2 - tmp1) * (K - 1) << endl;
        else cout << tmp2 * (K / 2) + tmp1 << endl;
        /*
        if(cnt % 2 == 0) cout << (tmp2) * (K / 2) + (tmp2 - tmp1) * (K%2) << endl;
        else cout << (tmp2) * (K / 2) +  tmp1 * (K%2) << endl;
        */
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   int d,n;
    cin>>d>>n;
    if(d==0)
    {
        if(n==100)
        {
            cout<<101<<"\n";
        }
        else{
        cout<<n<<"\n";}
    }
    if(d==1)
    {
       if(n==100)
       {
           cout<<101*100<<"\n";
       }
       else{
         cout<<n*100<<"\n";
       }
    }
    if(d==2)
    {
       if(n==100)
       {
           cout<<101*100*100<<"\n";
       }
       else{
         cout<<n*100*100<<"\n";
       }
    }
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
#include <stdlib.h>
using namespace std;
long long h[100005];
long long dp[100005];
int main() {
	int N, K; cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> h[i];
	dp[1] = 0;
	for (int i = 2; i <= N; i++) {
		dp[i] = 1LL << 50;
		for (int j = 1; j <= K and i - j >= 1; j++) {
			dp[i] = min(dp[i], dp[i - j] + llabs(h[i] - h[i - j]));
		}
	}
	cout << dp[N] << endl;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = max(min(B, D) - max(A, C), 0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
using namespace std;
long long dp[109][5509], N, K, mod = 1000000007;
int main() {
	cin >> N >> K; dp[N][0] = 1;
	for (int i = N; i >= 1; i--) {
		for (int j = 0; j <= N*(N + 1) / 2; j++) {
			if (dp[i][j] == 0)continue;
			for (int k = 0; k <= K; k++) {
				if (i < k) {
					dp[i - 1][j] += dp[i][j];
					dp[i - 1][j] %= mod;
				}
				else {
					int Z = j + k; Z /= i;
					dp[i - 1][j + Z] += dp[i][j];
					dp[i - 1][j + Z] %= mod;
				}
			}
		}
	}
	long long R = 1;
	for (int i = 0; i < N; i++) { R *= (K + 1); R %= mod; }
	R *= K*N; R %= mod; if (R % 2 == 1)R += mod; R /= 2;
	for (int i = 0; i <= N*(N + 1) / 2; i++) {
		R -= dp[0][i] * i; R = (R + mod*mod) % mod;
	}
	cout << R << endl;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  vector<ll> a(n),b(n);
  rep(i,n){
    cin>>a[i];
  }
  rep(i,n){
    cin>>b[i];
  }
  vector<ll> c(n+1),d(n+1);
  c[0]=a[0];
  rep(i,n-1){
    c[i+1]=c[i]+a[i+1];
  }
  d[n-1]=b[n-1];
  rep(i,n-1){
    d[n-i-2]=d[n-i-1]+b[n-i-2];
  }
  ll ans=d[0];

  rep(i,n){
    ans=max(ans,c[i]+d[i]);
  }
  cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 256
import numpy as np
N, M =  map(int, input().split())


high = list(map(int, input().split()))
good = [0 for i in range(N)]



for i in range(M):
    A, B =map(int, input().split())
    if (high[A - 1] > high[B - 1]):
        good[B - 1] += 1
    elif (high[A - 1] == high[B - 1]):
        good[A - 1] += 1
        good[B - 1] += 1
    else:
        good[A - 1] += 1

        
print(good.count(0))


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

int n;
char buf[114514];

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf(" %s", buf);

    string s(buf);
    set<string> dic;
    for (int i=1; i<=s.size()-1; i++) {
      string s1 = s.substr(0, i);
      string s2 = s.substr(i);

      dic.insert(s1+s2);
      dic.insert(s2+s1);
      reverse(s1.begin(), s1.end());
      dic.insert(s1+s2);
      dic.insert(s2+s1);
      reverse(s2.begin(), s2.end());
      dic.insert(s1+s2);
      dic.insert(s2+s1);
      reverse(s1.begin(), s1.end());
      dic.insert(s1+s2);
      dic.insert(s2+s1);
    }

    printf("%d\n", (int)dic.size());
  }
}

Measured memory_bytes: 3312
# -*- coding: utf-8 -*-


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)
    return sorted(divisors, reverse=True)


if __name__ == '__main__':
    n, k = map(int, input().split(' '))
    A = list(map(int, input().split(' ')))
    divisors = make_divisors(sum(A))
    for divisor in divisors:
        remainders = sorted(map(lambda x: x % divisor, A))
        idx = n - sum(remainders) // divisor
        ope_num = sum(remainders[:idx])
        if ope_num <= k:
            print(divisor)
            break


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define SORT(obj) sort(obj.begin(),obj.end())
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;
using ll = long long;

int main(){
  ll n;
  cin>>n;
  vector<int> data(n);
  REP(i,n-1){
    int a;
    cin>>a;
    data[a-1]++;
  }
  REP(i,n){
    cout<<data.at(i)<<endl;
  }
}


Measured memory_bytes: 4056
import sys

N=999999
a=[ 1 for i in range(N+1)]
a[0]=0
a[1]=0
for i in range(2, N+1):
	for j in range(i*i,N+1,i):
		a[j]=0


b=[ 0 for i in range(N+1)]
t=0
for i in range(2,N+1):
	t+=a[i]
	b[i]=t


for line in sys.stdin:
	n=int(line)
	print b[n]


Measured memory_bytes: 76008
import java.util.Scanner;
import java.util.Stack;

public class Main {

	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		Stack<Integer> b = new Stack<Integer>();
		while(a.hasNext()){
			int c = a.nextInt();
			if(c==0){
				System.out.println(b.pop());
			}
			else{
				b.push(c);
			}
		}
	}
}

Measured memory_bytes: 12000
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;

signed main() {
	int a, b, c;
	char s, d;
	cin >> a >> s >> b >> d >> c;
	if (b >= 5)cout << "TBD" << endl;
	else cout << "Heisei" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int n; cin >> n;
    ll a, b;
    vector<ll> v;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        cin >> a >> b;
        v.push_back(a+b);
        ans -= b;
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for(ll i = 0; i < n; i++){
        if(i % 2 == 0){
            ans += v[i];
        }
    }
    cout << ans << endl;
}

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

int main() {
    double a, b;
    while (cin >> a >> b) {
        if (a < 35.50 && b < 71.00) cout << "AAA" << endl;
        else if (a < 37.50 && b < 77.00) cout << "AA" << endl;
        else if (a < 40.00 && b < 83.00) cout << "A" << endl;
        else if (a < 43.00 && b < 89.00) cout << "B" << endl;
        else if (a < 50.00 && b < 105.00) cout << "C" << endl;
        else if (a < 55.00 && b < 116.00) cout << "D" << endl;
        else if (a < 70.00 && b < 148.00) cout << "E" << endl;
        else cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 3072
import java.util.Scanner;


public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long k = (a + b) / 2;
        if ((a + b) % 2 == 1) {
            System.out.println("IMPOSSIBLE");
        } else {
            System.out.println(k);
        }
    }
}


Measured memory_bytes: 21588
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: i32 = read();
    let v: Vec<(i32,i32,i32)> = (0..n).map(|_| {
        (read(),read(),read())
    }).collect();

    let mut p = (0,0,0);
    for (t,x,y) in v {
        let tp = t-p.0;
        let xp = (x-p.1).abs();
        let yp = (y-p.2).abs();
        if xp + yp <= (t-p.0) && (tp + xp + yp) % 2 ==0  {
            p = (t,x,y);
        } else {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
/*
  Fuad Ashraful Islam
  University of Asia Pacific,Bangladesh
  Date:23th April 2020
  TODO:
  https://vjudge.net/contest/338714
  http://lightoj.com/volume_showproblem.php?problem=1149
 */
#include<bits/stdc++.h>
#define dbg(x) cerr <<__LINE__<<" where "<< #x << " = " << x << endl
#define all(x) (x).begin(),(x).end()

using namespace std;
template <class T>
inline void read(T &res)
{
  res = 0; bool bo = 0; char c;
  while (((c = getchar()) < '0' || c > '9') && c != '-');
  if (c == '-') bo = 1; else res = c - 48;
  while ((c = getchar()) >= '0' && c <= '9')
    res = (res << 3) + (res << 1) + (c - 48);
  if (bo) res = ~res + 1;
}
template<typename T> T Abs(T x){ return x<0?-x:x; }
template<typename T>T Max(T a,T b){return a>b?a:b;}
const int N=2222;
typedef long long ll;
int len,_,n,d,k,m,l,c,cs=1;
string s;
int fre[N];
const int mod=2019;

int main()
{
 cin>>s;
 len=(int)s.size();
 ll num=0;
 ll ten=1;
 ll ans=0;
 fre[0]=1;
 // cout<<s<<endl;
 for(int i=len-1;i>=0;--i)
 {
   num=num+(s[i]-'0')*ten;
   num%=mod;
   ans+=fre[num];
   fre[num]++;
   ten=(ten*10)%mod;
 }
 cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 3672
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)
	
	for (let i = 1; i <= 9; i++) {
		if (i * 111 >= n) {
			console.log(i * 111)
			break
		}
	}
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
fun main(args: Array<String>) {
    val N = nextInt()
    val S = Array(N) { next() }
    val a = LongArray(26)
    repeat(N) { a[S[it][0] - 'A'] += 1 }
    val c = "MARCH".map { a[it - 'A'] }
    var ans = 0L
    for (i in 0 until 3)
    for (j in i + 1 until 4)
    for (k in j + 1 until 5)
        ans += c[i] * c[j] * c[k]
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun nextLong(offset: Long = 0L) = nextLong() + offset
fun nextDouble() = next().toDouble()
fun listOfString() = next().split(" ")

Measured memory_bytes: 41368
#include<bits/stdc++.h>
using namespace std;
int min(int a,int b){
  if(a>b){
    return(b);
  }else{
    return(a);
  }
}
int max(int a,int b){
  if(a>b){
    return(a);
  }else{
    return(b);
  }
}
int main(){
  int n;
  cin>>n;
  int x[n],xx[n];
  for(int i=0;i<n;i++){
    cin>>x[i];
    xx[i]=x[i];
  }
  sort(xx,xx+n);
  int m;
  m=(n)/2-1;
  for(int i=0;i<n;i++){
    if(x[i]<=xx[m]){
      cout<<xx[min(n-1,m+1)]<<endl;
    }else{
      cout<<xx[min(n-1,m)]<<endl;
    }
  }
  return(0);
}


Measured memory_bytes: 3712
import sys
import numpy as np

h, w = map(int, sys.stdin.readline().split())
grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(h)], dtype='U1')
grid = np.pad(grid, 1, 'constant')
grid = grid == '#'

def main():
    res = grid[1:-1, 1:-1]
    l = grid[1:-1, :-2]
    r = grid[1:-1, 2:]
    u = grid[:-2, 1:-1]
    d = grid[2:, 1:-1]
    ans = 'No' if np.any(res & ~(l | r | u | d)) else 'Yes'
    print(ans)

if __name__ ==  '__main__':
    main()

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

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

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    int A, B;
    cin >> A >> B;
    for (int i = 1; i <= 1000; i++) {
        if (floor(i * 0.08) == A && floor(i * 0.1) == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,a[21],b,c,d=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b>>c;
		a[b]=c;
		if(d<c)
			d=c;
	}
	int i=1;
	while(true){
		if(a[i]==d){
			cout<<i<<" "<<a[i]<<endl;
			break;
		}
		i++;
	}
    return 0;
}
 

Measured memory_bytes: 1164