akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const double INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main() {
	ll N;
	cin >> N;
	vll D(N);
	for (auto& e : D)cin >> e;
	sort(D.begin(), D.end());
	ll a = D[N / 2 - 1];
	ll b = D[N / 2];
	cout << b - a << endl;

	return 0;
}


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

//??????TLE??§??? m(_)m

int w1,w2,h1,h2,sum;
int hash_a[800][800][10],hash_b[800][10];
int cumo_a[800][800][10],cumo_b[800][10];
char s[800][700],t[800][800];
 
 
void make_table(){
  rep(i,h1) rep(j,w1-w2+1) {
    rep(k,w2){
      rep(l,6)hash_a[i][j][(k*6)/60] = hash_a[i][j][(k*6)/60]*2+(((s[i][j+k]>>l)&1)?1:0);
      rep(l,6)cumo_a[i][j][(k*6)/60] = cumo_a[i][j][(k*6)/60]*2+(s[i][j+k]==63?1:0);
    }
  }
  rep(i,h2) {
    rep(j,w2){
      rep(k,6)hash_b[i][(j*6)/60] = hash_b[i][(j*6)/60]*2+(((t[i][j]>>k)&1)?1:0);
      rep(k,6)cumo_b[i][(j*6)/60] = cumo_b[i][(j*6)/60]*2+(t[i][j]==63?1:0);
    }
  }
}
 
void count_s(){
  rep(i,h1-h2+1) {
    rep(j,w1-w2+1) {
      rep(k,h2) {
        int p1[10]={} ,p2[10]={} ;int flag = 0;
        rep(l,10){
          p1[l] = hash_a[i+k][j][l] ^ hash_b[k][l];
          p2[l] = cumo_a[i+k][j][l] | cumo_b[k][l];
          if( (p1[l] | p2[l]) != p2[l] ) { flag ++; break; }
        }
        if( flag ) break ;
        if( k == h2-1 ) sum++;
      }
    }
  }
}
 
void Za_a_tsu(){
  rep(i,h1)rep(j,w1){
    if('0'<=s[i][j]&&s[i][j]<='9')s[i][j]=(s[i][j]-'0');
    if('a'<=s[i][j]&&s[i][j]<='z')s[i][j]=(s[i][j]-'a'+11);
    if('A'<=s[i][j]&&s[i][j]<='Z')s[i][j]=(s[i][j]-'A'+37);
  }
  rep(i,h2)rep(j,w2){
    if('0'<=t[i][j]&&t[i][j]<='9')t[i][j]=(t[i][j]-'0');
    if('a'<=t[i][j]&&t[i][j]<='z')t[i][j]=(t[i][j]-'a'+11);
    if('A'<=t[i][j]&&t[i][j]<='Z')t[i][j]=(t[i][j]-'A'+37);
  }
}
 
signed main(){
  cin >> w1 >> h1 >> w2 >> h2;
  rep(i,h1)scanf("%s",s[i]);
  rep(i,h2)scanf("%s",t[i]);
  Za_a_tsu();
  make_table();
  count_s();
  cout << sum << endl;
}

Measured memory_bytes: 103696
#include<bits/stdc++.h>
//using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb emplace_back
#define mp std::make_pair
//
#define endl "\n"
//using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=std::pair<ll,ll>;
//
constexpr ll MOD=1e9+7;
//constexpr ll MOD=998244353;
//constexpr ll MOD=10000000;
//constexpr ll MOD=1e5;
constexpr ll MAX=1e7;
constexpr ll INF=(1ll<<62);
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    srand((unsigned)time(NULL));
    ll D; cin>>D;
    const ll N=26;
    vi C(N);
    rep(i,0,N) cin>>C[i];
    vii A(D,vi(N));
    rep(i,0,D){
        rep(j,0,N) cin>>A[i][j];
    }
    vi last(N,-1);
    rep(i,0,D){
        ll max=0,memo=0;
        rep(j,0,N){
            if(max<A[i][j]+(i-last[j])*C[j]){
                max=A[i][j]+(i-last[j])*C[j];
                memo=j;
            }
        }
        cout<<memo+1<<endl;
        last[memo]=i;
    }
}


Measured memory_bytes: 3752
#include <iostream>
using namespace std;
long long b[200005];
int main(){
	long long i,j,k,p,n,a;
	cin>>n;
	if(n%2==0) p=0;
	else p=1;
	if(p==0) j=(n+2)/2;
	else j=(n+1)/2;
	if(p==0) a=-1;
	else a=1;
	for(i=1;i<=n;i++){
		cin>>k;
		b[j]=k;
		j+=a*i;
		a*=-1;
	}
	for(i=1;i<=n;i++) cout<<b[i]<<" ";
	cout<<endl;
} 

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    ll cnt[2];
    cnt[0] = 0;
    cnt[1] = 0;
    //まず自分自身の転倒数を求める
    for (ll i = 0; i < n; i++)
    {
        for (ll j = i + 1; j < n; j++)
        {
            if (a[i] > a[j])
            {
                cnt[0]++;
            }
        }
    }
    //次に、自分自身についての点灯数を求める
    for (ll i = 0; i < n; i++)
    {
        for (ll j = 0; j < n; j++)
        {
            if (a[i] > a[j])
            {
                cnt[1]++;
            }
        }
    }
    ll tmp = k*(k-1)/2;
    tmp %= MOD;
    cout << ((cnt[0] * k % MOD) + (cnt[1] * tmp % MOD)) % MOD << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char const *argv[]) {

  int i,j;
  int count = 0;
  int num_S;
  int num_T;
  int start,end,middle;


  scanf("%d",&num_S);
  int S[num_S];
  for( i = 0 ; i < num_S ; i++ ){
    scanf("%d",&S[i]);
  }

  scanf("%d",&num_T);
  int T[num_T];
  for( i = 0 ; i < num_T ; i++ ){
    scanf("%d",&T[i]);
  }

  for( i = 0 ; i < num_T ; i++ ){

    start = 0;
    end = num_S;

    while( start < end ){

      middle = ( start + end ) / 2;

      if( S[middle] > T[i] ){
        end = middle;
      }else if( S[middle] < T[i] ){
        start = middle + 1;
      }else if( S[middle] == T[i] ){
        count++;
        break;
      }

    }

  }

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1184
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());

        int start = Math.max(a,c);
        int finish = Math.min(b, d);
        if(finish-start>0){
            System.out.println(finish-start);
        }else{
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 22740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] pointInfo = new int[n][2];
		for(int i = 0;i < n;i++) {
			pointInfo[i][0] = sc.nextInt();
			pointInfo[i][1] = sc.nextInt();
		}

		int maxA = pointInfo[0][0];
		int answer =pointInfo[0][0] + pointInfo[0][1];
		for(int i =1;i <n;i++) {
			if(maxA <pointInfo[i][0]) {
				maxA = pointInfo[i][0];
				answer = pointInfo[i][0] + pointInfo[i][1];
			}
		}
		System.out.println(answer);
	}
}

Measured memory_bytes: 94772
#include <stdio.h>
#include <math.h>

int main(){
  int i,n,o;
  double x,y,z,xa,ya,ra,xb,yb,rb;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
    x=(xa-xb);
    y=(ya-yb);
    z=sqrt(x*x+y*y);
    if(z > (ra+rb)) o=0;
    else if(z >= fabs(ra-rb)) o=1;
    else if(ra > rb) o=2;
    else o=-2;
    printf("%d\n",o);
  }
  return 0;
}

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

using namespace std;
using ll=long long;

int cnt[10][10];
void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        cnt[s[0]-'0'][s.back()-'0']++;
    }
    ll res = 0;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        res += cnt[s.back()-'0'][s[0]-'0'];
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 
 using namespace std;
 
 int arr[1000005]={0};
 
 bool isPrime(int x)
 {
   for(int i=2;i<=(int)(sqrt(x));i++) 
   {
     if(x%i==0) return false;        
   }    
   return true;
 }
 
 int main()
 {
   int n;
   while(cin>>n)
   {
      if(n==1) cout<<"0"<<endl;
      else if(n==2) cout<<"1"<<endl;
      else if(arr[n]!=0) cout<<arr[n]<<endl;
      else
      {
        int count=1;
        for(int i=3;i<=n;i++)
        { 
          if(isPrime(i))
          { 
            count++;
            arr[i]=count;
          }
          else arr[i]=count;
        }
        cout<<count<<endl;
      } 
   }
   //while(1);      
   return 0;    
 }
 
 

Measured memory_bytes: 6988
#include <algorithm>
#include <cstdio>
using namespace std;
int in(){ int x; scanf("%d", &x); return x; }
int main(){
	int a[3];
	for(int i = 0; i < 3; i++) a[i] = in();
	sort(a, a + 3);
	for(int i = 0; i < 3; i++) printf("%d%s", a[i],i<2?" ":"\n");
	return 0;
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 10009
#define MOD 1000000007
#define EPS 0.0000000001

int main()
{
    long long X;
    scanf("%lld",&X);
    int i;
    long long ans=100;
    for(i=0;ans<X;i++)
    {
        ans=ans+(ans/100);
    }
    printf("%d",i);
    return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc076/tasks/abc076_c

int main() {
    string S, T; cin >> S >> T;

    if (S.length() < T.length()) {
        cout << "UNRESTORABLE" << "\n";
        return 0;
    }

    string min = "~";
    REP(i, S.length() - T.length() + 1) {
        string sub = S.substr(i, T.length());
        bool can = true;
        REP(j, sub.length()) {
            if (sub[j] != '?' && sub[j] != T[j]) can = false;
        }

        if (can) {
            string P = S;
            REP(j, T.length()) {
                P[i+j] = T[j];
            }
            REP(j, P.length()) {
                if (P[j] == '?') P[j] = 'a';
            }
            min = std::min(min, P);
        }
    }

    if (min == "~") {
        cout << "UNRESTORABLE" << "\n";
    } else {
        cout << min << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws IOException {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder output = new StringBuilder();
        boolean[][] card = new boolean[4][13];
 
        String input = br.readLine();
 
//      ????????????????????????????????????????????????°
        int n = Integer.parseInt(input);
 
        for(int i = 0; i < n; i++){
            input = br.readLine();
            String[] strArray = input.split(" ");
 
            String egara = strArray[0]; //?????????????????????
            int number = Integer.parseInt(strArray[1]); //??????????????????°???
 
            if(egara.equals("S")){
                card[0][number-1] = true;
 
            }else if(egara.equals("H")){
                card[1][number-1] = true;
 
            }else if(egara.equals("C")){
                card[2][number-1] = true;
 
            }else if(egara.equals("D")){
                card[3][number-1] = true;
 
            }else{
                break;
            }
        }
 
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 13; j++){
                if(card[i][j] == false){
                    if(i == 0){
                        output.append("S");
 
                    }else if(i == 1){
                        output.append("H");
 
                    }else if(i == 2){
                        output.append("C");
 
                    }else if(i == 3){
                        output.append("D");
                    }
                    output.append(" ").append(j+1).append("\n");
                }
            }
        }
        System.out.print(output);
    }
}

Measured memory_bytes: 24160
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt(), k = sc.nextInt();
		
		int x[] = new int[n];
		int y[] = new int[n];
		
		int cx[] = new int[n];
		int cy[] = new int[n];
		
		for(int i=0;i<n;i++){
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			cx[i] = x[i];
			cy[i] = y[i];
			
		}
		
		Arrays.sort(x);
		Arrays.sort(y);
		
		long ans = Long.MAX_VALUE;

		for(int lx=0;lx<n;lx++){ for(int rx=lx+1;rx<n;rx++){
			for(int ly=0;ly<n;ly++){for(int ry=ly+1;ry<n;ry++){
				int x1 = x[lx], x2=x[rx];
				int y1 = y[ly], y2=y[ry];
				
				int cnt = 0;
				for(int i=0;i<n;i++){
					if(x1 <= cx[i] && cx[i] <= x2 && y1 <= cy[i] && cy[i] <= y2){
						cnt++;
					}
				}
				if(cnt >= k){
					ans = Math.min(ans, (long)(x2-x1) * (y2-y1));
				}
			}
			}
		}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 24788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int q = int.Parse(Console.ReadLine());

                if (q == -1) break;

                double x = (double)q / 2;

                while (Math.Abs(x * x * x - q) >= 0.00001 * q)
                {
                    x = x - (x * x * x - q) / (3 * x * x);
                }
                sb.AppendLine(x.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1LL << 55)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 200111

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

int main(){
	ll n, k;
	scanf("%lld%lld", &n, &k);

	ll ans = 0;
	for(ll b = k + 1; b <= n; b++){
		ll cur = n / b;
		ll x = cur * (b - k);
		x += max((n % b) - k + (k > 0 ? 1 : 0), 0LL);

		//cout << b << "  " << x << endl;
		ans += x;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n - 1):
  a, b = map(int, input().split())
  g[a - 1].append(b - 1)
  g[b - 1].append(a - 1)
li = [0] * n
for i in range(q):
  p, x = map(int, input().split())
  li[p - 1] += x
s = [0]
done = [0] * n
done[0] = 1
while s:
  d = s.pop()
  for node in g[d]:
    if done[node] == 0:
      li[node] += li[d]
      s.append(node)
      done[node] = 1
print(' '.join(map(str, li)))


Measured memory_bytes: 130728
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_poizcy.hpp>
typedef long long  ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define fi first
#define se second
#define por(a,b) (((a%MOD) * (b%MOD))%MOD)
#define forg(i, b, e, c)    for (ll i = (ll)b; i < (ll)e; i+=c)
#define forr(i, b, e)    for (ll i = b; i < e; i++)
 
 
using namespace std;
//using namespace __gnu_pbds;
typedef double lldb;
typedef pair<ll, ll>  ii;
typedef pair<double, double>  iidb;
typedef pair<ll, ii>  iii;
typedef vector<ll>     vi;
typedef vector<vi>     vvi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const ll INF = 1e9;
const double PI = acos(-1);
const ll MOD= 200003;
#define initseg ll new_nodo=(nodo*2),mid=(iz+der)/2;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define tam 5100
#define offset 200
#define ptr nodo*
bool vis[tam],visdp[tam][tam];
ll dp[tam][tam];
ll go[tam],val[tam];
vector<ll> vect;
ll dfs(ll num)
{
	if (vis[num]==1)
		return 0;
	vis[num]=1;
	vect.pb(num);
	return dfs(go[num])+1;
}
ll f(ll num,ll moves)
{
	if (moves==0)
		return 0;
	if (visdp[num][moves]!=0)
		return dp[num][moves];
	ll maxx=0;
	maxx=f(go[num],moves-1)+val[go[num]];
	maxx=max(maxx,0LL);

	visdp[num][moves]=1;
	return dp[num][moves]=maxx;
}
int main()
{
	memset(visdp,0,sizeof visdp);
	memset(vis,0,sizeof vis);
	ll n,k;
	cin>>n>>k;
	forr(i,0,n)
	{
		cin>>go[i];
		go[i]--;
	}
	ll answer=-1e18;
	forr(i,0,n)
	{
		cin>>val[i];
		answer=max(answer,val[i]);
	}
	if (answer<=0)
	{
		cout<<answer<<endl;
		return 0;
	}
	vector<vector<ll> > comps;
	forr(i,0,n)
	{
		if (vis[i]==0){
			vect.clear();
			dfs(i);
			comps.pb(vect);
		}
	}

	for(auto v:comps)
	{

		ll m=v.size();
		ll auxtot=0;
		for(auto num:v)
		{
			//cout<<num<<' ';
			auxtot+=val[num];
		}
		/*
		cout<<endl;
		cout<<auxtot<<endl;
		cout<<m<<endl;*/
		if (k>=m)
		{

			ll c=(k/m),panswer=0,amax=0;
			for(auto num:v)
				amax=max(amax,f(num,m));
			answer=max(answer,amax);
			panswer=(c-1)*auxtot+amax;
			amax=0;
			for(auto num:v)
				amax=max(amax,f(num,k%m));
			panswer=max(panswer,(c)*auxtot+amax);
			//cout<<panswer<<endl;
			answer=max(answer,panswer);
		}
		else
		{
			for(auto num:v)
			{
				answer=max(answer,f(num,k));
			}
		}
	}
	cout<<answer<<endl;
}				

Measured memory_bytes: 228596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;

int main() {
    ll n,m; cin >> n >> m;
    ll a = 1,b = 1;
    if(abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1;i <= n;i++){
        a = a * i % MOD;
    }
    
    for(int i = 1;i <= m;i++){
        b = b * i % MOD;
    }
    if(abs(n-m) == 1){
        cout << a*b%MOD;
    }else{
        cout << 2*a*b%MOD;
    }
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
        int n,ans;
        double xa,ya,ra,xb,yb,rb;
        double d;

        scanf("%d",&n);
        while(n--){
                scanf("%lf%lf%lf%lf%lf%lf",&xa,&ya,&ra,&xb,&yb,&rb);
                d=sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb)); 
                if(d<fabs(ra-rb)){
                        ans=2;
                        if(ra<rb)ans=-2;
                }
                else if(d>(ra+rb))ans=0;
                else ans=1;
                printf("%d\n",ans);
        }
        return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin >> a >> b >> c;
if (a!=b&&b!=c&&c!=a){
 cout << 3 << endl;
}else if(a==b&&b==c&&c==a){
 cout << 1 << endl;
} else {
 cout << 2 << endl;
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const ll iv=(5e8)+4;
int n,q,a[3010],x,y;
ll dp[3010][3010],tmp=1,ans;
int main() {
	read(n); read(q);
	for (int i=1;i<=n;i++) read(a[i]);
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++)
		if (a[i]>a[j]) dp[i][j]=1;
	while (q--) {
		read(x); read(y); tmp=tmp*2%mod;
		for (int i=1;i<=n;i++)
			if (i!=x&&i!=y) {
				dp[i][x]=dp[i][y]=(dp[i][x]+dp[i][y])*iv%mod;
				dp[x][i]=dp[y][i]=(dp[x][i]+dp[y][i])*iv%mod;
			}
		dp[x][y]=dp[y][x]=(dp[x][y]+dp[y][x])*iv%mod;
	}
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++)
		ans+=dp[i][j],ans%=mod;
	printf("%lld\n",ans*tmp%mod);
	return 0;
}

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

int main() {
  ll x,k,d;
  cin >> x >> k >> d;
  x = abs(x);
  ll p = x/d;
  ll ans = 0;
  if (p >= k) ans = x - k*d;
  else {
    k -= p;
    x -= p*d;
    if (k % 2 == 0) ans = x;
    else ans = d-x;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

int main(){
	int n, y;
	cin >> n >> y;
	for(int i=0; i<=n; i++){
		for(int j=0; i+j<=n; j++){
			int k=n-i-j;
			if(10000*i+5000*j+1000*k==y){
				cout << i << ' ' << j << ' ' << k << '\n';
				return 0;
			}
		}
	}
	cout << "-1 -1 -1\n";
	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();
		String s = sc.next();

		int pre = s.length();
		s = s.replace("ABC", "");
		int post = s.length();

		System.out.println((pre - post) / 3);

		sc.close();
	}

}


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

def main():
    n, k = map(int, input().split())
    dk = list(map(int, input().split()))
    assert len(dk) == k

    us = set(usable(dk))
    print(form(us, n))

def form(us, n):
    for res in range(n, 10 ** 5):
        fla = True
        for c in str(res):
            if int(c) not in us:
                fla = False
                break
        if fla:
            return res
    raise Exception

def usable(dk):
    res = []
    for i in range(10):
        if i not in dk:
            res.append(i)
    return res

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define vbi vector<bool> 
#define mod 1000000007
#define INF 1000000000
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define ms(x,v) memset(x,v,sizeof x)
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define pi  3.141592653589793238
ll i,j,k;
long long dp[1000000];
void solve(){
            ll n; cin>>n;
            ll k; cin>>k;
            vl v(n);
            ll z=0;
            for(i=0;i<n;i++) cin>>v[i];
              
            for(i=1;i<n;i++){
                ll mx=1e18;
                for(j=1;j<=k;j++){
                    if((i-j)>=0)
                 mx=min((dp[max(z,i-j)]+abs(v[i]-v[max(z,i-j)])),mx);
             else break;
                }
                dp[i]=mx;
                //cout<<dp[i]<<" ";
            }
            //cnl;
            cout<<dp[n-1]<<endl;

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

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

#ifdef loc
    #include "loc_debug.h"
#else
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif

typedef long long ll;
typedef long double ld;
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i, s, n)  for(int i = s; i <= n; ++i)
#define rev(i, n, s)  for(int i = n; i >= s; --i)
#define fore(x, a) for(auto &&x : a)
#define fill(a, x) memset((a), (x), sizeof(a))
#define tcase int __t; cin >> __t; rep(tc, 1, __t)
#define F first
#define S second
#define gc getchar

const int mod = 1000000007;
#define _ %mod
const int N = 100005;



int main() {
    fast_io;
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    if(2 * q <= h) {
        h = 2 * q;
    }
    if(2 * h <= s) {
        s = 2 * h;
    }
    ll res = (n / 2) * min(2 * s, d) + (n % 2) * s;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

template<class In>
void print_array(In begin, In end) {
  cout << (*begin);
  begin++;
  for (; begin != end; begin++)
  {
    cout << " " << (*begin);
  }
  cout << endl;
}

int main()
{
  ll w, h, x, y;
  cin >> w >> h >> x >> y;

  cout << ((1.0 * w * h) / 2) << " " << ((x * 2 == w && y * 2 == h) ? 1 : 0) << endl;

  return 0;
}


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

signed main(){
	int n,q;cin>>n>>q;
	vector<int> a(n),x(q);
	for(auto&& u:a)cin>>u;
	for(auto&& u:x)cin>>u;
	for(int j=0;j<q;j++){
		int sm=0,r=0,cnt=0;
		for(int i=0;i<n;i++){
			if(i>0)sm-=a[i-1];
			if(r<i){r=i,sm=0;}
			while(r<n&&sm+a[r]<=x[j]){
				sm+=a[r];r++;
			}
			if(r>i)cnt+=r-i;
		}
	cout<<cnt<<endl;
	}
}


Measured memory_bytes: 3636
package main
 
import (
  "fmt"
  "math"
)

const inf = math.MaxInt32

func min(nums ...int) int {
    if len(nums) == 0 {
        panic("funciton min() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Min(float64(res), float64(nums[i])))
    }
    return res
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
  
func main() {
  var n int
  fmt.Scan(&n)
  h := make([]int, n)
  dp := make([]int, n)
  
  for i := range h {
    fmt.Scan(&h[i])
  }

  for i := range dp {
    dp[i] = inf
  }

  dp[0] = 0
  
  for i := 1; i < n; i++ {
		dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]))
		if i > 1 {
			dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))
        }
  }
	
  fmt.Println(dp[n-1])
}

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

using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

#define MP make_pair<int,int>

int main(){
  while(true){
    int a,b,c;
    cin>>a>>b>>c;
    if(!a)break;
    if(a>b)swap(a,b);
    if(b>c)swap(b,c);
    int x = sqrt(a*a+b*b)/2+1;
    int n;
    cin>>n;
    while(n--){
      int r;
      cin>>r;
      if(r>=x)cout<<"OK"<<endl;
      else cout<<"NA"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
bool p(ll x){
	if(x<=1) return false;
	for(ll i = 2; i*i<=x; i++){
		if(x%i==0) return false;
	}
	return true;
}
ll s[N];

int main(){
	rep(i, N){
		if(i%2==1 && p(i) && p((i+1)/2)) s[i] = 1;
	}
	rep(i, N-1) s[i+1]+=s[i];
	int n;
	cin>>n;
	rep(i, n){
		ll l, r;
		cin>>l>>r;
		cout<<s[r]-s[l-1]<<endl;
	}
	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
int n,A[50];
int solve(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}
int main(){
  int q,M,i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;
int main(){
    string a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    int na, nb, nc;
    na = a.size(), nb = b.size(), nc = c.size();
    int ca = 0, cb = 0, cc = 0;
    bool A = true, B = false, C = false;
    while (ca <= na && cb <= nb && cc <= nc){
        if(A == true){
            if(ca == na){
            ca++;
            break;
            }
            if(a.at(ca) == 'b'){
                A = false;
                B = true;
            }
            else if(a.at(ca) == 'c'){
                A = false;
                C = true;
            }
            ca++;
        }
        else if(B == true){
            if(cb == nb){
            cb++;
            break;
            }
            if(b.at(cb) == 'a'){
                A = true;
                B = false;
            }
            else if(b.at(cb) == 'c'){
                B = false;
                C = true;
            }
            cb++;
        }
        else{
            if(cc == nc){
            cc++;
            break;
            }
            if(c.at(cc) == 'a'){
                A = true;
                C = false;
            }
            else if(c.at(cc) == 'b'){
                B = true;
                C = false;
            }
            cc++;
        }
        
    }
    if(ca == na + 1)
    cout << "A" << endl;
    else if(cb == nb + 1)
    cout << "B" << endl;
    else if(cc == nc + 1) 
    cout << "C" << endl;
    return 0; 
}

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

int main(){  
	int maxX;
	int maxY;
	int N;
	cin >> maxX >> maxY >> N;	
	int minX = 0;
	int minY = 0;
	for(int i = 0; i < N; i++){
		int x;
		int y;
		int a;
		cin >> x >> y >> a;
		if(a == 1){
			minX = max(minX, x);
		}else if(a == 2){
			maxX = min(maxX, x);
		}else if(a == 3){
			minY = max(minY, y);
		}else if(a == 4){
			maxY = min(maxY, y);
		}
	}
	cout << max(0, maxX - minX) * max(0, maxY - minY) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;

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

    lli num_candidate = 0;
    for (int i = 1; i <= N; i++) {
        if (i % K == 0) num_candidate++;
    }
    lli ans = num_candidate * num_candidate * num_candidate;

    if (K % 2 == 0) {
        num_candidate = 0;
        for (int i = 1; i <= N; i++) {
            if (i % K != 0 && i % (K / 2) == 0) {
                num_candidate++;
            }
        }
        ans += num_candidate * num_candidate * num_candidate;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import collections
import heapq


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, m = list(map(int, readline().split()))
    ab = [list(map(int, readline().split())) for _ in range(n)]
    ab.sort()
    ab = collections.deque(ab)
    hq = []
    heapq.heapify(hq)
    t = 0
    for i in range(1, m + 1):
        while len(ab):
            if len(ab) != 0:
                if ab[0][0] <= i:
                    heapq.heappush(hq, -ab.popleft()[1])
                else:
                    break
            else:
                break
        if len(hq) != 0:
            t -= heapq.heappop(hq)
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 68316
#include <stdio.h>

int main(){
    int n;
    int fib[50];
    scanf("%d",&n);
    fib[0]=fib[1]=1;

    for(int i=2; i<=n; i++)
        fib[i] = fib[i-1]+fib[i-2];

    printf("%d\n",fib[n]);

    return 0;
}



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

int main(){
	ll h,w; cin>>h>>w;
	if(h==1||w==1) cout<<1<<endl;
	else cout<<(h*w+1)/2<<endl;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <vector>

using namespace std;
#define LL long long
#define ri register int

template<typename T>inline void read(T& x) {
	x = 0;
	int f = 0;
	char ch = getchar();
	for (;!isdigit(ch);ch = getchar())
		f |= (ch == '-');
	for (;isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + (ch ^ 48);
	x = f ? -x : x;
}

int n;
int s[1010][1010];
int main(){
	read(n);
	int x = 1,tot;
	for(x = 1,tot = 0;;++x){
		tot += x;
		if(tot == n) {
			break;
		}
		if(tot > n)
			return puts("No"),0;
	}
	puts("Yes");
	printf("%d",x + 1);
	int last = 0;
	for(int i = 1;i <= x + 1;++i){
		printf("\n%d ",x);
		for(int j = 1;j < i;++j)
			printf("%d ",s[j][i - 1]);
		for(ri j = i;j <= x;++j)
			printf("%d ",s[i][j] = ++last);
	}
	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 60;
const double EPS = 1e-10;

int N, W;
int w[110], v[110];
int dp[110][100010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> W;
  REP(i,N) cin>>w[i]>>v[i];
  fill_n((int*)dp,110*100010,INF);
  dp[0][0] = 0;
  REP(i,N) REP(j,100010) {
    chmin(dp[i+1][j], dp[i][j]);
    if (j+v[i]<100010) chmin(dp[i+1][j+v[i]], dp[i][j]+w[i]);
  }
  int ans = INF;
  REP(i,100010) if (dp[N][i]<=W) ans=i;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 86272
n, m = gets.chomp.split(" ").map(&:to_i)
rooms = {}
m.times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  rooms[a] = [] if rooms[a].nil?
  rooms[b] = [] if rooms[b].nil?
  rooms[a] << b
  rooms[b] << a
end

marks = { 1 => 0 }
arr = [1]

loop do
  break if arr.empty?
  room = arr.shift
  rooms[room].each do |r|
    next unless marks[r].nil?
    marks[r] = room
    arr << r
  end
end

if marks.count != n
  puts "No"
else
  puts "Yes"
  marks.delete(1)
  puts marks.sort.map(&:last)
end


Measured memory_bytes: 46300
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(998244353)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
ll gcd(ll a,ll b){if(!b)return a;else return gcd(b,a%b);}
int main()
{
	string s;
    cin>>s;
    int n = s.length();
  if(s[n-1] == 's')s+="es";
  else s+="s";
  cout<<s;
}


Measured memory_bytes: 3632
import java.util.Scanner;
public class Main
{
	static int base[][];
	static int h,w;
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		int I=1;
		while(N-->0)
		{
			String S=in.nextLine();
			String SS=in.nextLine();
			base=new int[9][9];

			for(int i=1;i<=8;i++)
			{
				String str=in.next();
				for(int j=0;j<=7;j++)
				{
					if(str.charAt(j)=='0')
						base[i][j+1]=0;
					else
						base[i][j+1]=1;
				}
			}
			w=in.nextInt();
			h=in.nextInt();

			bomb(h,w);
			System.out.println("Data "+I+++":");
			for(int i=1;i<9;i++)
			{
				for(int j=1;j<9;j++)
					System.out.print(base[i][j]);
				System.out.println();
			}	
		}
	}
	public static void bomb(int h,int w)
	{
		base[h][w]=0;
		for(int i=1;i<=3;i++)
		{
			if(h+i<9&&base[h+i][w]==1)
				bomb(h+i,w);
			if(w+i<9&&base[h][w+i]==1)
				bomb(h,w+i);
			if(h-i>=1&&base[h-i][w]==1)
				bomb(h-i,w);
			if(w-i>=1&&base[h][w-i]==1)
				bomb(h,w-i);
		}
	}
}

Measured memory_bytes: 12000
/* COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define debug(x) cout << #x << " = " << x << "\n"

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    //code here.
    int n, x, t;
    cin >> n >> x >> t;
    if (n % x == 0)
    {
        cout << (t * (n / x));
        return;
    }
    cout << (t * ((n / x) + 1));

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll T = 1;
    //cin >> T; // If only one test case then you can comment this line out.

    while (T--)
    {
        solve();

    }
    return 0;
}

Measured memory_bytes: 3596
def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)

def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max,mod=DIV):
    fac,finv,inv = [0]*max, [0]*max, [0]*max
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod -inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1]*inv[i]%mod
    class CONV:
        def __init__(self):
            pass
        def ncr(self,n,k):
            if(n<k):
                return 0
            if(n<0 or k<0 ):
                return 0
            return fac[n]*(finv[k]*finv[n-k]%mod)%mod
    return CONV()



def main():
    H,N = isRaw()
    As = isRaw()
    return "Yes" if sum(As)>=H else "No"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 53060
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


#define MAX_N 31
int n;
int dp[MAX_N];

int solve() {
  // clear
  rep(i, MAX_N) dp[i] = 0;
  // dp
  dp[0] = 1;
  dp[1] = 1;
  dp[2] = 2;
  for(int i=3; i<=n; i++) {
    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
  }
  return dp[n];
}


int main() {
  while (true) {
    cin >> n;
    if (n == 0) break;

    int ans = solve();
    int wer = ans / 3650;
    if (ans % 3650 != 0) wer += 1;
    cout << wer << '\n';
  }
  return 0;
}

Measured memory_bytes: 1156
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String line1 = br.readLine();
		String[] lineArr1 = line1.split(" ");
		int minMoney = Integer.parseInt(lineArr1[0]);

		String line2 = br.readLine();
		String[] hate = line2.split(" ");
		String money = "";
		String[] moneyArr = null;
		String answer = null;

		for (int i = minMoney; i < 100000; i++) {
			money = i + "";
			moneyArr = money.split("");
			for (int j = 0; j < moneyArr.length; ++j) {
				if(Arrays.asList(hate).contains(moneyArr[j])){
					break;
				} else {
					if(j == moneyArr.length - 1){
						answer = money;
					}
				}

			}

			if(answer != null) {
				break;
			}

		}
		System.out.println(answer);


	}

}


Measured memory_bytes: 24748
import java.util.*;

public class Main {
	private void doit(){
		
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			int n = sc.nextInt();
			int t = sc.nextInt();
			int [] data = new int[n];
			for(int i = 0; i < n; i ++){
				data[i] = sc.nextInt();
			}
			int [] calc = new int[n];
			calc[n-1] = data[n-1];
			for(int i = n - 2; i>= 0; i--){
				calc [i] = Math.max(calc[i+1], data[i]);
			}
			
			int max = 0;
			for(int i = 0; i < n; i++){
				max = Math.max(max, calc[i] - data[i]);
			}
			
			int count = 0;
			for(int i = 0; i < n; i ++){
				if(max == calc[i] - data[i]){
					count++;
				}
			}
			System.out.println(count);
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

}


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


#define li          long long int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li x;
    cin>>x;
    cout<<1-x<<endl;

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) loop(i,0,n)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int dx[]={-1,-1,0,0,1,1};
int dy[]={0,-1,1,-1,1,0};
const int inf=1000000010;
int main(){
	int n;
	while(cin>>n,n){
		vvi in(n,vi(n+1));
		rep(i,n)rep(j,n+1)cin>>in[i][j];
		int N=1<<n;
		vi dp(N,inf);
		dp[0]=0;
		rep(i,N)rep(j,n)if((i&1<<j)==0){
			int mi=in[j][0];
			rep(k,n)if(i&1<<k)mi=min(mi,in[j][k+1]);
			dp[i|1<<j]=min(dp[i|1<<j],dp[i]+mi);
		}
		int out=dp[N-1];
		cout<<out<<endl;
	}
}









Measured memory_bytes: 3312
//Floor Function

/*
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    ll a,b,n,ans=0;cin>>a>>b>>n;
    rep(i,1,n+1){
        cout << i << " " << (i*a)/b-a*(i/b) << endl;
        ans =max((i*a)/b-a*(i/b),ans);
    }

    cout << ans << endl;
    return 0;
}
*/
//Floor Function

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    ll a,b,n,ans=0;cin>>a>>b>>n;
    if(n<b)ans=(n*a)/b-(a*(n/b));
    else if(a>b)ans=((b-1)*a)/b-a*((b-1)/b);
    else if(a==b)ans=b-1;
    else if(a<b)ans=((b-1)*a)/b-a*((b-1)/b);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588