akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc119d
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABC = ReadIntList();
            var ans = 0;
            if (ABC[0] * ABC[2] <= ABC[1])
            {
                ans = ABC[2];
            }
            else
            {
                ans = ABC[1] / ABC[0];
            }
            Console.WriteLine(ans);
#if DEBUG
            Console.ReadKey();
#endif
        }

        private static bool IsRange(int a, int from, int to) => (from <= a && a <= to);
        private static int ReadInt() => int.Parse(Console.ReadLine());
        private static List<int> ReadIntList() => Console.ReadLine().Split().Select(int.Parse).ToList();
        private static double ReadDouble() => double.Parse(Console.ReadLine());
        private static List<double> ReadDoubleList() => Console.ReadLine().Split().Select(double.Parse).ToList();
        private static long ReadLong() => long.Parse(Console.ReadLine());
        private static List<long> ReadLongList() => Console.ReadLine().Split().Select(long.Parse).ToList();
        private static List<int> Int2Digits(int a) => a.ToString().ToCharArray().Select(_ => int.Parse(_.ToString())).ToList();
        private static int BinarySearch<Type>(IReadOnlyList<Type> s, Type target) // target 以下の最大要素のインデックスを返す
            where Type : IComparable
        {
            var lower = 0;
            var upper = s.Count - 1;
            while (upper - lower > 1)
            {
                var mid = lower + (upper - lower) / 2;
                if (s[mid].CompareTo(target) <= 0)
                {
                    lower = mid;
                }
                else
                {
                    upper = mid;
                }

            }
            return lower;
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<int>> next(n+1, vector<int>(26,n));	//i文字目以降の最初に文字cが登場するindex
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<26; j++){ next[i][j] = next[i+1][j]; }
    next[i][s[i]-'a'] = i;
  }
  
  vector<int> dp(n+1, inf);
  vector<pair<char,int>> recon(n+1,{'?',n});
  dp[n]=1;
  
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<26; j++){
      if(next[i][j]==n){
        if(dp[i]>1){ dp[i]=1; recon[i]={'a'+j,n};}	//次の文字がない時
      } else if(dp[i]>dp[next[i][j]+1]+1){
        dp[i] = dp[next[i][j]+1]+1;
        recon[i] = {'a'+j, next[i][j]+1};
      }
    }
  }
  
  string ans="";
  int index=0;
  while(index<n){
    auto p = recon[index];
    ans += p.F;
    index = p.S;
  }
  cout << ans << endl;
  return 0;
}

/*
https://qiita.com/drken/items/a207e5ae3ea2cf17f4bd
長さ nn の文字列 SS が与えられる。
SS の部分文字列 (空文字含む) として考えられるものの個数を数え上げよ。
ただし答えがとても大きくなることがあるので、個数を 1,000,000,007 で割ったあまりを求めよ。
SS = "abcde" のとき、32 通り (全文字が異なるので 25=3225=32 通り)
SS = "aaaaa" のとき、6 通り ("", "a", "aa", "aaa", "aaaa", "aaaaa")
SS = "aba" のとき、7 通り ("", "a", "b", "aa", "ab", "ba", "aba")

int main(){
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<int>> next(n+1, vector<int>(26,n));	//i文字目以降の最初に文字cが登場するindex
  for(int i=n-1; i>=0; i--){
    for(int j=0; j<26; j++){ next[i][j] = next[i+1][j]; }
    next[i][s[i]-'a'] = i;
  }
  
  vector<ll> dp(n+1,0);
  dp[0]=1;	//reset 空文字列""にあたる
  for(int i=0; i<n; i++){
    for (int j=0; j<26; j++){
      if (next[i][j] >= n) continue; // 次の文字 j がもうない場合はスルー
      dp[next[i][j] + 1] += dp[i];
      dp[next[i][j] + 1] %= mod;
    } 
  }
  ll ans=0;
  for(int i=0; i<=n; i++){
    ans += dp[i];
    ans %= mod;
  }
  cout << ans << endl;
*/


Measured memory_bytes: 29316
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	int n,k;
	cin>>n>>k;
	ll arr[n];
	for ( int i=0;i<n;i++)
		cin>>arr[i];
	sort( arr,arr+n);
	if ( k>=n){
		cout<<0<<'\n';
	}
	else{
		ll total=0;
		for ( int i=0;i<n-k;i++)
			total+=arr[i];
		cout<<total<<'\n';
	}

}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<cmath>

int main(){
    
    long long n, m;
    std::cin >> n >> m;

    std::vector<std::pair<long long, long long>> ab(n);
    std::vector<std::pair<long long, long long>> cd(m);

    for(auto&& e : ab){
        long long a, b;
        std::cin >> a >> b;
        e = {a, b};
    }

    for(auto&& e : cd){
        long long c, d;
        std::cin >> c >> d;
        e = {c, d};
    }

    for(long long i = 0; i < n; i++){
        std::pair<long long, long long> min = {std::abs(ab[i].first - cd[m - 1].first) + std::abs(ab[i].second - cd[m - 1].second), m - 1};
        for(long long j = m - 1; j >= 0; j--){
            long long dis = std::abs(ab[i].first - cd[j].first) + std::abs(ab[i].second - cd[j].second);
            if(min.first >= dis) min = {std::min(min.first, dis), j};
        }
        std::cout << min.second + 1 << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
s = input()
for i in range(len(s)):
    if i % 2 == 0:
        if not (s[i] == 'R' or s[i] == 'U' or s[i] == 'D'):
            print('No')
            break
    else:
        if not (s[i] == 'L' or s[i] == 'U' or s[i] == 'D'):
            print('No')
            break
else:
    print('Yes')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define INF (1LL << 30)
#define int long long
#define pii pair<long long, long long>
#define MOD 1000000007
#define print(x) cout << (x) << endl
using namespace std;
typedef long long ll;

signed main()
{
    int N, K;
    cin >> N >> K;

    bool even = (K % 2 == 0);
    int ans1 = 0;
    int ans2 = 0;
    

    // mod K  == 0
    for (int i = K; i <= N; i += K)
    {
        ++ans1;
    }

    if (even)
    {
        for (int i = K/2; i <= N; i += K){
            ++ans2;
        }
    }

    ans1 = ans1*ans1*ans1;
    ans2 = ans2*ans2*ans2;

    cout << ans1 + ans2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

    long count = 0;
    for (int i = 0; i < 1 << N; i++) {
      List<Character> a = new ArrayList<>();
      List<Character> b = new ArrayList<>();
      int num = i;
      for (int j = 0; j < N; j++) {
        int bit = num & 1;
        if (bit == 0) {
          a.add(S[j]);
        } else {
          b.add(S[j]);
        }
        num >>= 1;
      }

      Collections.reverse(a);
      Collections.reverse(b);
      char[] aa = toCharArray(a);
      char[] bb = toCharArray(b);
      count += count(S, aa, bb);
    }

    System.out.println(count);
  }

  private static char[] toCharArray(List<Character> list) {
    char[] res = new char[list.size()];
    for (int i = 0; i < list.size(); i++) {
      res[i] = list.get(i);
    }
    return res;
  }

  private static long count(char[] s, char[] a, char[] b) {
    int n = s.length / 2;
    long[][] dp = new long[a.length + 1][b.length + 1];
    dp[0][0] = 1;
    for (int j = 0; j < b.length + 1; j++) {
      for (int i = 0; i < a.length + 1; i++) {
        if (i > 0 && s[n + i + j - 1] == a[i - 1]) {
          dp[i][j] += dp[i - 1][j];
        }
        if (j > 0 && s[n + i + j - 1] == b[j - 1]) {
          dp[i][j] += dp[i][j - 1];
        }
      }
    }
    return dp[a.length][b.length];
  }
}


Measured memory_bytes: 107308
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;

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

int func(long long n) {
	if (n < 10)return 1;
	return func(n/10)+1;
}
int a[4];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	string input;
	cin >> input;
	REP(i,4)a[i] = input[i] - '0';
	REP(x, 8) {
		int sum = a[0];
		string s;
		s += (char)('0' + a[0]);
		REP(i, 3) {
			if (x & (1 << i)) {
				sum += a[i+1];
				s += '+';
			}
			else {
				sum -= a[i + 1];
				s += '-';
			}
			s += (char)('0' + a[i + 1]);
		}
		if (sum == 7) {
			cout << s << "=7" << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
use std::io::{self, BufRead};

fn main() {
    let stdin = io::stdin();
    let mut handle = stdin.lock();
    let mut buf = String::new();
    handle.read_line(&mut buf).unwrap();
    let (N, M) = {
        let t = buf.trim()
    .split_whitespace()
    .map(|x| x.parse::<usize>().unwrap()).collect::<Vec<_>>();
        (t[0], t[1])
    };
    buf.clear();

    let mut prices = Vec::with_capacity(M);
    let mut cs = Vec::with_capacity(M);
    for _ in 0..M {
        handle.read_line(&mut buf).unwrap();
        let (a, b) = {
            let t = buf.trim()
                .split_whitespace()
                .map(|x| x.parse::<usize>().unwrap()).collect::<Vec<_>>();
            buf.clear();
            (t[0], t[1])
        };
        prices.push(a);

        handle.read_line(&mut buf).unwrap();
        cs.push(buf.trim().split_whitespace().map(|x| {
            let num = x.parse::<usize>().unwrap();
            1 << (num - 1)
        }).fold(0, |acc, cur| acc | cur));
        buf.clear();
    }

    let inf = 1 << 60;
    let mut dp = vec![vec![inf; 1 << N]; M + 1];
    dp[0][0] = 0;

    use std::cmp::min;
    for i in 0..M {
        for j in 0..(1 << N) {
            if dp[i][j] == inf {
                continue;
            }
            // 鍵 i を使う場合
            dp[i + 1][cs[i] | j] = min(dp[i + 1][cs[i] | j], dp[i][j] + prices[i]);
            // 使わない場合
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    let mut ans = inf;
    for i in 0..(M+1) {
        ans = min(ans, dp[i][(1 << N) - 1]);
    }

    if ans == inf {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


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

int fact(int i)
{
    int ans = 1;
    for (auto j = 1; j <= i ;j++)
    {
        ans *= j;
    }
    return ans;
}

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

    int p[n];
    int q[n];
    for (auto i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (auto i = 0; i < n; i++)
    {
        cin >> q[i];
    }

    bool index[n];
    for (auto i = 0; i < n; i++)
    {
        index[i] = false;
    }

    int pAns = 0;
    for (auto i = 0; i < n; i++)
    {
        // check order
        int id = 0;
        for (auto j = 0; j < n; j++)
        {
            if (index[j])
            {
                continue;
            }
            if (j == p[i] - 1)
            {
                break;
            }
            id++;
        }
        pAns += id * fact(n-i-1);
        index[p[i]-1] = true;
    }

    for (auto i = 0; i < n; i++)
    {
        index[i] = false;
    }
    int qAns = 0;
    for (auto i = 0; i < n; i++)
    {
        // check order
        int id = 0;
        for (auto j = 0; j < n; j++)
        {
            if (index[j])
            {
                continue;
            }
            if (j == q[i] - 1)
            {
                break;
            }
            id++;
        }
        qAns += id * fact(n-i-1);
        index[q[i]-1] = true;
    }
    int ans = abs(pAns - qAns);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] T = new int[N];
		for(int i = 0;i < N;++i)
			T[i] = sc.nextInt();
		int M = sc.nextInt();
		int[][] drink = new int[M][2];
		for(int i = 0;i < M;++i) {
			drink[i][0] = sc.nextInt();
			drink[i][1] = sc.nextInt();
		}
		sc.close();
		
		int sum = 0;
		for(int i = 0;i < N;++i)
			sum += T[i];
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < M;++i)
			sb.append((sum + (drink[i][1] - T[drink[i][0]-1])) + "\n");
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
int arr[106];
int main()
{
	ios;
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
	{
		cin>>arr[i];
	}
	sort(arr+1,arr+1+n);
	int sum=0,f=1;
	for(int i=n;i>=1;--i)
	{
		sum+=arr[i]*f;
		f*=-1;
	}
	cout<<sum<<'\n';
} 

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
    int h,w;

    while (true) {
        cin >> h >> w;

        if (h == 0 && w == 0)
            break;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if ((i+j) % 2 == 1){
                    cout << ".";
                } else {
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long

using namespace std;

typedef pair<int, int> td;

int n, w;
ll op[100010];

int main(){
    #ifdef ZERBRA
        freopen("code.inp", "r", stdin);
        //freopen("code.out", "w", stdout);
    #endif // ONLINE_JUDGE
    scanf("%d%d", &n, &w);
    for (int i = 0; i < n; ++i){
        int weight, value;
        scanf("%d%d", &weight, &value);
        for (int j = w; j >= weight; --j)
            op[j] = max(op[j], op[j-weight]+value);
    }
    printf("%lld", op[w]);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6 + 5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
ll qpow(ll a, ll b) { ll s = 1; while (b > 0) { if (b & 1)s = s * a % mod; a = a * a % mod; b >>= 1; }return s; }


int main(){
    int n;
    cin>>n;
    bool flag=true;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x%2==0){
            if(x%3!=0&&x%5!=0) flag=false;
        }
    }
    if(flag) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    long long n;
    cin >> n;
    if (n==1) cout << 0 << endl;
    else {
        unordered_map<long long, int> nums;
        while (n%2==0) {
            if (nums.find(2)!=nums.end()) nums[2]++;
            else nums[2] = 1;
            n /= 2;
        }
        for (int i=3; i<=sqrt(n); i+=2) {
            while (n%i==0) {
                if (nums.find(i)!=nums.end()) nums[i]++;
                else nums[i] = 1;
                n /= i;
            }
        }
        if (n > 2) nums[n] = 1;
        long long ans = 0;
        for (auto key : nums) {
            int last = 1;
            while (last <= key.second) {
                key.second -= last;
                last++;
                ans++;
            }
        }
        cout << ans << endl;
    }

}
// 1 2 3 4 5 6

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
vector <long long> l,q[100005];
long long n,m,x,y,ans,tot,w[100005],f[100005],cnt[100005];
long long find(long long x)
{
	return f[x]==x?f[x]:f[x]=find(f[x]);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
		cin>>w[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		f[find(x+1)]=f[find(x+1)]==find(y+1)?f[find(x+1)]:f[find(x+1)]=find(y+1);
	}
	for(int i=1;i<=n;i++)
	{
		q[(cnt[find(i)]=cnt[find(i)]?cnt[find(i)]:++tot)].push_back(w[i]);
	}
	if(tot==1)
	{
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=tot;i++)
	{
		sort(q[i].begin(),q[i].end());
		ans+=q[i][0];
		for(int j=1;j<q[i].size();j++)
		{
			l.push_back(q[i][j]);
		}
	}
	sort(l.begin(),l.end());
	if(l.size()<tot-2)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	for(int i=0;i<tot-2;i++)
	{
		ans+=l[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 11380
#!/usr/bin/env python3
class SegTree:
    def __init__(self, segfunc, e, v, init_val = None):
        """
        segfunc: function 区間にしたい操作\n
        e: Any 単位元\n
        v: int or List 要素数か格納する配列\n
        init_val: Any 初期値
        """
        self.segfunc = segfunc
        self.e = e
        self.init_val = init_val if init_val != None else e
        if isinstance(v, int):
            v = [self.init_val] * v
        self.n = len(v)
        self.log = (self.n).bit_length()
        self.size = 1 << self.log
        self.tree = [e] * 2 * self.size
        # 1-indexedなのでtree[1:self.size]がN-1要素
        # tree[self.size:self.size + N]が配列
        for i in range(self.n):
            self.tree[self.size + i] = v[i]
        for i in range(self.size - 1, 0, -1):
            self._update(i)

    def set(self, k, x) -> None:
        """
        k番目の値をxに更新\n
        k: index(0-indexed)\n
        x: update value
        """
        k += self.size
        self.tree[k] = x
        for i in range(1, self.log + 1):
            self._update(k >> i)

    def get(self, k):
        """
        a[k]を返す\n
        k: index(0-indexed)
        """
        assert 0 <= k < self.size
        return self.tree[k + self.size]

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る\n
        l: index(0-indexed)\n
        r: index(0-indexed)
        """
        res = self.e
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

    def all_query(self):
        """
        全範囲にsegfuncしたものを得る
        """
        return self.tree[1]

    # 二分探索実装、いる？

    def _update(self, k):
        self.tree[k] = self.segfunc(self.tree[k * 2], self.tree[k * 2 + 1])

#import
#import math
#import numpy as np
#= int(input())
#= input()
def main():
    N, K = map(int, input().split())
    A = [int(input()) for _ in range(N)]

    MAX_A = 300005

    dp = SegTree(max, 0, MAX_A, 0)
    for i in range(N):
        x = A[i]
        now = dp.query(max(0, x - K), min(x + K + 1, MAX_A)) + 1
        dp.set(x, now)

    ans = dp.all_query()
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 102904
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string.h>
using namespace std;
long int A, B, M;
long int a[100005], b[100005], x[100005], y[100005],c[100005];
int main()
{
	cin >> A >> B >> M;
	long a_m = 10000000;
	long b_m = 10000000;

	for (long int i = 1; i <= A; i++)
	{
		cin >> a[i];
		a_m = min(a_m, a[i]);
	}
	for (long int i = 1; i <= B; i++)
	{
		cin >> b[i];
		b_m = min(b_m, b[i]);
	}
	for (long int i = 1; i <= M; i++)
	{
		cin >> x[i]>>y[i]>>c[i];
	}
	long int ans = 10000000;
	for (long int i = 1; i <= M; i++)
	{
		ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
	}
	ans = min(ans, a_m + b_m);

	cout << ans << endl;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
using namespace std;
int dat[262145], n, q, _size;
void update(int x, int y) {
	x += _size; dat[x] = y;
	while (x > 1) {
		x /= 2;
		dat[x] = min(dat[x * 2], dat[x * 2 + 1]);
	}
}
int query(int l, int r, int a, int b, int pos) {
	if (l <= a && b <= r) { return dat[pos]; }
	if (l > b)return 2147483647; if (r < a)return 2147483647;
	int D1 = query(l, r, a, (a + b + 1) / 2 - 1, pos * 2);
	int D2 = query(l, r, (a + b + 1) / 2, b, pos * 2 + 1);
	return min(D1, D2);
}
int main() {
	cin >> n >> q; _size = 1; while (_size < n)_size *= 2;
	for (int i = 0; i < 262145; i++)dat[i] = 2147483647;
	for (int i = 0; i < q; i++) {
		int a, b, c; cin >> a >> b >> c;
		if (a == 0)update(b, c);
		if (a == 1)cout << query(b, c, 0, _size - 1, 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 4112
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(void) {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = min(a, b); i > 0; i--) {
		if (a % i == 0 && b % i == 0)
			k--;
		if (k == 0) {
			cout << i << "\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

int intceil(int a, int b) {
    return (a + (b - 1)) / b;
}

signed main() {
    cin >> N;
    cout << N * (N - 1) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    cin >> len;
    int ans = 0;
    set<string> seen;
    while(len--) {
        string s;
        cin >> s;
        if(!seen.count(s)) {
            ans += 1;
            seen.insert(s);
        }
    }
    cout << ans;
}



Measured memory_bytes: 19208
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,count=0;
  cin>>n;
  char j[n];
  for(int i=0;i<n;i++){
  cin>>j[i];
  }
  for(int i=0;i<n;i++){
    if(j[i]=='A'){
       if(j[i+1]=='B'){
       if(j[i+2]=='C'){
      count++;
    }
    }
    }
  }
  cout<<count;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    string s, t;
    scan(s, t);
    int a, b;
    scan(a, b);
    string u;
    scan(u);
    writefln("%d %d", a - (s == u), b - (t == u));
}










void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	string s;
	cin >> s;

	if(s.front() == s.back()){
		if((s.size() - 2) % 2){
			cout << "Second" << endl;
		}else{
			cout << "First" << endl;
		}
	}else{
		if((s.size() - 2) % 2){
			cout << "First" << endl;
		}else{
			cout << "Second" << endl;
		}
	}
}


Measured memory_bytes: 512
from heapq import heappush,heappop,heapify
rep=range;R=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in R(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found

mo=10**9+7
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
import sys
read=sys.stdin.buffer.read;readline=sys.stdin.buffer.readline;input=lambda:sys.stdin.readline().rstrip()

inf=1<<20
def dijkstra(edge,st):
    n=len(edge)
    d=[(0 if st==i else inf) for i in range(n)]
    q=[(0,st)]
    heapify(q)
    v=[False]*n
    while q:
        dist,cur=heappop(q)
        if v[cur]:
            continue
        v[cur]=True
        for dst,dist in edge[cur]:
            alt=d[cur]+dist
            if alt<d[dst]:
                d[dst]=alt
                heappush(q,(alt,dst))
    return d


show_flg=False
show_flg=True

ans=0

h,w=LI()
sh,sw=LI()
gh,gw=LI()

w+=2
m=[1]*w
for i in range(h):
    s=input()
    m+=[1]+[i=='#'for i in s]+[1]
m+=[1]*w
h+=2
n=h*w
v=[-1]*w*h


nbw=[-2*w+1,-2*w+2,-w+1,-w+2,2,2*w+1,2*w+2,w+1,w+2,+2*w,-2*w,-2*w-1,-2*w-2,-w-1,-w-2,-2,2*w-1,2*w-2,w-1,w-2]
nbw=[2,2*w+1,2*w+2,w+1,w+2,+2*w,2*w-1,2*w-2,w-1,w-2]
nb=[1,-1,w,-w]
nb=[1,w]
d=[-1]*n
g=[[]for i in range(n)]
for i in range(n):
    if m[i]==1:
      continue
    for di in nbw:
        nx=i+di
        if 0<=nx<n and m[nx]!=1:
            g[i]+=(nx,1),
            g[nx]+=(i,1),
    for di in nb:
        nx=i+di
        if 0<=nx<n and m[nx]!=1:
            g[i]+=(nx,0),
            g[nx]+=(i,0),
            
d=dijkstra(g,sh*w+sw)
ans=d[gh*w+gw]
if ans==inf:
    ans=-1
print(ans)


Measured memory_bytes: 441988
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s,x,k;
int len;
int main()
{
	cin>>s;
	x=s;
	len=s.length();
	for(int i=0;i<=(len/2)-1;i++)
	{
		swap(s[i],s[len-1-i]);
	}

	for(int i=0;i<len;i++)
	{
		if(s[i]=='b')
		{
			s[i]='d';
			continue;
		}
		if(s[i]=='d')
		{
			s[i]='b';
			continue;
		}
		if(s[i]=='p')
		{
			s[i]='q';
			continue;
		}
		if(s[i]=='q')
		{
			s[i]='p';
			continue;
		}
	}
	if(x==s)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

int main() {
    int  t,s,k;
    cin >> t >> s >> k;
    for(int i=0;i<k;i++){
        if(i%2==0){
            s+=t/2;
            t/=2;
        }
        else{
            t+=s/2;
            s/=2;
        }
    }
    cout << t << " " <<  s << endl;
}

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

#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define vll vector<ll>
#define pll pair<ll , ll>
#define vpll vector<pair<ll, ll> >
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define N 100001
#define HOLE 1000000007

ll fn(ll x,ll rn[])
{
    if(rn[x]==x) return x;
    else return rn[x]=fn(rn[x],rn);
}

void un(ll x,ll y,ll rn[],ll sz[])
{
    x=fn(x,rn);
    y=fn(y,rn);
    if(x==y) return;
    if(sz[x]<sz[y]) swap(x,y);
    sz[x]+=sz[y];
    rn[y]=x;
    return;
}

ll power(ll x,ll y)
{
    ll res = 1; // Initialize result

    while (y > 0) {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res * x)%HOLE;

        // n must be even now
        y = y >> 1; // y = y/2
        x = (x * x)%HOLE; // Change x to x^2
    }
    return res;
}

vector <ll> adjl[N];
ll marked[N]={0};
vector <ll> order;

void dfs (ll x){

    if(marked[x])
        return;
    marked[x]=1;

    REP(i,0,adjl[x].size()){

    }

    return;
}

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

    ll q=1;
    //cin>>q;
    while(q--){

        ll n;
        cin>>n;

        ll a[n];
        ll reps[n+1]={0};

        int flag=0;

        REP(i,0,n){
            cin>>a[i];
            reps[a[i]]++;
        }

        ll sum=0;

        REP(i,1,n+1){

            if(reps[i]>0){
                sum+=(reps[i]*(reps[i]-1))/2;
            }

        }

        REP(i,0,n){

            if(reps[a[i]]>1){
                cout<<sum+1-reps[a[i]]<<endl;;
            }
            else{
                cout<<sum<<endl;
            }

        }

    }

return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    string s[n];
    string ans;
    for(size_t i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s, s+n);
    
    for(size_t i = 0; i < n; i++)
    {
        ans += s[i];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0; i < m; i++)
        cin >> b[i];
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        int sum = c;
        for (int j = 0; j < m; j++)
        {
            int a;
            cin >> a;
            sum += a * b[j];
        }
        if (sum > 0)
            cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
import java.lang.Math.*

private fun readln() = readLine()!!.trim()
private fun readlnInt() = readln().toInt()
private fun readlnStrings() = readln().split(' ')
private fun readlnInts() = readlnStrings().map { it.toInt() }
private fun readlnLongs() = readlnStrings().map { it.toLong() }


fun solve() {
    val s = readln()
    if (s.length<=1){
        print(1)
        return
    }
    val N = s.length
    val dp1 = IntArray(N+1){0}
    val dp2 = IntArray(N+1){0}
    dp1[0] = 1
    dp2[1] = 1
    if (s[0]!=s[1]){
        dp1[1] = 2
    } else {
        dp1[1] = 1
    }
    for (i in 2 until N){
        if (s[i] != s[i-1]){
            dp1[i] = max(dp1[i], dp1[i-1])
        }
        dp1[i] = max(dp1[i], dp2[i-1])
        dp1[i] += 1
        if (i>3){
            if (s.substring(i-3..i-2) != s.substring(i-1..i)){
                dp2[i] = max(dp2[i], dp2[i-2])
            }
        } else {
            dp2[i] = max(dp2[i], dp2[i-2])
        }
        dp2[i] = max(dp2[i], dp1[i-2])
        dp2[i] += 1
    }
//    println(dp1.toList())
//    println(dp2.toList())
    println(max(dp1[N-1], dp2[N-1]))
}


fun main(args: Array<String>) {
//    val queryNum = readlnInt()
//    for (queryIdx in 1..queryNum) {
//        println("Case #$queryIdx:")
        solve()
//    }
}


Measured memory_bytes: 51112
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <inttypes.h>
#include <time.h>

using namespace std;

typedef long long tnum;

#define loop(i, num) for(int i = 0; i < num; i++)

tnum* tnumAlloc(int num);
tnum scanNum();
int scanInt();
tnum* scanNums(int);
char* scanChars(int maxlength);
string scanString();
void printlnNums(int count, tnum* nums);
void printlnNum(tnum num);
void printString(string str);

#define min(a,b) (a <= b ? a : b)
#define max(a,b) (a >= n ? a : b)

#define concatVectors(dest, src) dest.insert(dest.end(), src.begin(), src.end());

int main() {
    int a = scanInt();
    if(a == 1) {
        printf("0");
    }
    else {
        printf("1");
    }
    return 0;
}

//have to be free()
tnum* tnumAlloc(int num) {
	return (tnum*)calloc(num,sizeof(tnum));
}

tnum scanNum() {
	tnum ret;
    cin >> ret;

    return ret;
}

int scanInt() {
	tnum ret;
    cin >> ret;

    return ret;
}

//have to be free()
tnum* scanNums(int num) {
	tnum* buf;
	tnum* tmp;
	buf = tnumAlloc(num);
	for (int i = 0; i < num; i++) {
		cin >> buf[i];
	}

	return buf;
}

//have to be free()
char* scanChars(int maxlength) {
	char* ret = (char*)malloc(maxlength+1);
	scanf("%s", ret);

	return ret;
}

//have to be free()
string scanString() {
	string ret;
	cin >> ret;
	return ret;
}

void printlnNum(tnum num) {
    cout << num << endl;
}

// can be used for debugging
void printlnNums(int count, tnum *nums) {
	loop(i, count) {
		cout << nums[i];
		if (i != count - 1) printf(" ");
	}
	printf("\n");
}

void printString(string str) {
	cout << str;
}


Measured memory_bytes: 3544
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <algorithm>

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

using namespace std;

vector<string> split(string &str,char delim)
{
	vector<string> res;
	size_t current = 0,found;
	while((found = str.find_first_of(delim,current)) != string::npos)
	{
		res.push_back(string(str,current,found  - current));
		current = found + 1;
	}
	res.push_back(string(str,current,str.size() - current));
	return res;
}

int main()
{
	int n,m,cost[21][21];
	rep(i,21)
	{
		rep(j,21)
		{
			cost[i][j] = 1000000;
		}
	}

	cin >> n >> m;

	rep(i,m)
	{
		string s;
		cin >> s;
		vector<string> _s = split(s,',');
		int a = atoi(_s[0].c_str());
		int b = atoi(_s[1].c_str());
		int c = atoi(_s[2].c_str());
		int d = atoi(_s[3].c_str());

		cost[a][b] = c;
		cost[b][a] = d;
	}


	REP(k,1,n+1)
	{
		REP(i,1,n+1)
		{
			REP(j,1,n+1)
			{
				cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
			}
		}
	}

	string s;
	cin >> s;
	vector<string> _s = split(s,',');
	int x1 = atoi(_s[0].c_str());
	int x2 = atoi(_s[1].c_str());
	int y1 = atoi(_s[2].c_str());
	int y2 = atoi(_s[3].c_str());

	int ans = y1 - y2;
	ans -= cost[x1][x2] + cost[x2][x1];

	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int N = 100010;
int _w;

struct Triple {
	int i, l, r;
	Triple() {}
	Triple( int i, int l, int r ):
		i(i), l(l), r(r) {}
};

struct Cmp1 {
	bool operator()( Triple a, Triple b ) const {
		if( a.r == b.r ) return a.i < b.i;
		else return a.r < b.r;
	}
};

struct Cmp2 {
	bool operator()( Triple a, Triple b ) const {
		if( a.l == b.l ) return a.i < b.i;
		else return a.l > b.l;
	}
};

int n, L[N], R[N];
set<Triple,Cmp1> s1;
set<Triple,Cmp2> s2;

void init() {
	s1.clear();
	s2.clear();
	for( int i = 1; i <= n; ++i ) {
		Triple tmp(i, L[i], R[i]);
		s1.insert(tmp);
		s2.insert(tmp);
	}
}

ll move( ll &p, Triple t ) {
	int l = t.l;
	int r = t.r;
	if( p >= l && p <= r ) return 0;
	else if( p < l ) {
		ll d = l-p;
		p += d;
		return d;
	}
	else {
		ll d = p-r;
		p -= d;
		return d;
	}
}

ll solve( int type ) {
	init();
	ll p = 0, s = 0;
	int begin = type == 1 ? 0 : 1;
	int end = type == 1 ? n-1 : n;
	for( int i = begin; i <= end; ++i )
		if( i & 1 ) {
			Triple tmp = *s1.begin();
			s1.erase(tmp);
			s2.erase(tmp);
			s += move(p, tmp);
		} else {
			Triple tmp = *s2.begin();
			s1.erase(tmp);
			s2.erase(tmp);
			s += move(p, tmp);
		}
	s += abs(p);
	return s;
}

int main() {
	_w = scanf( "%d", &n );
	for( int i = 1; i <= n; ++i )
		_w = scanf( "%d%d", L+i, R+i );
	printf( "%lld\n", max(solve(1), solve(2)) );
	return 0;
}


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

int main(){
 
  long long K, X, i, Min, Max;
  cin >> K >> X;
  
  Min = max(X - K, -1000000ll);
  Max = min(X + K, 1000000ll);
    
  for(i = Min + 1; i < Max; i++){
    cout << i << " ";
  }
  cout << endl;
  return 0;
}

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

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define ps(s) printf("%s",s.c_str())
#define	inf (ll)1e15
#define mod 1000000007
#define mem(x,val) memset(x,val,sizeof x)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string getString(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string getLine(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=100100;

ll bigMod(ll b, ll p, ll m)
{
    ll ret=1,cur=b%m;
    while(p)
    {
    	if(p&1)ret=(ret*cur)%mod;
    	cur=(cur*cur)%mod;
    	p>>=1;
    }
    return ret;
}

int main()
{
    //#ifndef ONLINE_JUDGE
    //	freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //#endif
	ll n,k;
	while(~sf("%lld %lld",&n,&k))
	{
		ll ans=0;
		ll cnt[k+5];
		for(ll i=k;i>=1;i--)
		{
			ll tot=bigMod(k/i,n,mod);
			ll sub=0;
			for(int mul=2*i;mul<=k;mul+=i)
			{
				sub=(sub+cnt[mul])%mod;
			}
			tot=(tot-sub+mod)%mod;
			cnt[i]=tot;

			tot=(tot*i)%mod;
			ans=(ans+tot)%mod;
		}
		pf("%lld\n",ans);
	}
    return 0;
}



































Measured memory_bytes: 4580
#include<bits/stdc++.h>
#define re register
using namespace std;

inline int read(){
	re int ans = 0;re bool f = 1;re char ch = getchar();
	while(ch<'0'||ch>'9'){if (ch=='-')f = 0;ch = getchar();}
	while(ch>='0'&&ch<='9'){
		ans = (ans<<3)+(ans<<1)+(ch^48);
		ch = getchar();
	}
	return f?ans:~(ans-1);
}
const int N = 1e6;
int num[N];
signed main(void){
	int n = read();
	for(re int i=1;i<n;++i){
		num[read()]++;
	}
	for(re int i=1;i<=n;++i){
		printf("%d\n",num[i]);
	}
	return 0;
}

Measured memory_bytes: 4368
#include<stdio.h>
int main(void){
  int k,a,b;
  int sum=0;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
  for(int i=a;i<=b;i++){
    if(i%k==0){
      sum+=1;
    }
  }
  if(sum>=1){
    printf("OK\n");
  }else{
    printf("NG\n");
  }
  return 0;
}

Measured memory_bytes: 1620
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
      return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
     n= int(sys.stdin.readline())
     a= list(map(int, sys.stdin.readline().split()))
     b= list(map(int, sys.stdin.readline().split()))

     ans = 0
     for i in range(n):
          ans += min(a[i]+a[i+1],b[i])
          if a[i] < b[i]:
               a[i+1] = a[i+1] - (b[i]-a[i])
               a[i+1] = max(0, a[i+1])
     print(ans)


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

#define int long long
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<pi>
#define ps(x,y) fixed<<setprecision(y)<<x
#define w(t) int t;cin>>t;while(t--)solve()
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
//debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);

int gcd(int a , int b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
}

void solve(){
	
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	//clock_t z = clock();
	int n,x,t;
	cin>>n>>x>>t;
	if (n%x==0)cout<<t*n/x;
	else cout<<t*(n/x+1);

}


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

int b[2000][1000];
int s[2001][1001];

#define calc(x, y, w, h) (s[(x)+(w)][(y)+(h)] - s[(x)+(w)][(y)] - s[(x)][(y)+(h)] + s[(x)][(y)])

int main(void){
    long n, k;
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    for(long i=0; i<n; i++){
        long x, y;
        char c;
        cin >> x >> y >> c;
        y %= 2*k;
        if(c=='W'){
            x += k;
        }
        if(y>=k){
            y-=k;
            x+=k;
        }
        x %= 2*k;
        b[x][y]++;
    }
    for(long x=0; x<2*k; x++){
        for(long y=0; y<k; y++){
            s[x+1][y+1] = b[x][y] + s[x][y+1] + s[x+1][y] - s[x][y];
        }
    }
    long max = 0;
    for(long x=0; x<k; x++){
        for(long y=0; y<k; y++){
            long t = calc(x, y, k, k-y)+calc(0, 0, x, y)+calc(x+k, 0, k-x, y);
            t = t<n/2 ? n-t : t;
            max = t>max ? t : max;
        }
    }
    cout << max;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

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

void solve()
{
	string S;
	cin >> S;
	int w;
	cin >> w;
	for (int i = 0; i < S.size(); i += w)
	{
		cout << S[i];
	}
	cout << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
H,W = map(int,input().split())
Grid = [[1 if g == "." else 0 for g in input()] for _ in range(H)]
dp = [[10**5]*(W) for _ in range(H)]
dp[0][0] = 0
black = 0
flag = Grid[0][0]

for g in Grid:
    for gg in g:
        if not(gg):
            black += 1

a = [-1,1]

import sys
sys.setrecursionlimit(10**4)
def bfs(grid,h,w,Q):
    if h == H - 1 and w == W - 1:
        return dp[h][w]
    for aa in a:
        if 0 <= h + aa <= H -1:
            if grid[h+aa][w]:
                grid[h+aa][w] = 0
                dp[h+aa][w] = dp[h][w] + 1
                Q.append([h+aa,w])
        if 0 <= w + aa <= W - 1:
            if grid[h][w+aa]:
                grid[h][w+aa] = 0
                dp[h][w+aa] = dp[h][w] + 1
                Q.append([h,w + aa])
    if len(Q) == 0:
        return -1
    else:
        nexth,nextw = Q.pop(0)
        return bfs(grid,nexth,nextw,Q)
queue = []
Grid[0][0] = 0
if  flag:
    ans = bfs(Grid,0,0,queue)
    if ans == -1:
        print(-1)
    else:
        print(H*W - ans - 1 - black)
else:
    print(-1)


Measured memory_bytes: 4980