akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    vector<vector<int>> ans(100, vector<int>(100));
    for(int i = 50; i < 100; i++){
        for(int j = 0; j < 100; j++){
            ans[i][j] = 1;
        }
    }
    int cnta = a - 1, cntb = b - 1;
    for(int i = 0; i < 50; i += 2){
        for(int j = 0; j < 100; j += 2){
            if(cntb == 0) break;
            ans[i][j] = 1;
            cntb--;
        }
    }
    for(int i = 99; i >= 50; i -= 2){
        for(int j = 0; j < 100; j += 2){
            if(cnta == 0) break;
            ans[i][j] = 0;
            cnta--;
            
        }
    }
    map<int, char> mp;
        mp[0] = '.'; mp[1] = '#';
    cout << 100 << ' ' << 100 << endl;
    for(int i = 0; i < 100; i++){
        for(int j = 0; j < 100; j++){
            cout << mp[ans[i][j]];
        }
        cout << endl;
    }
    return 0;
}

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

int main(void){

  long long N;
  cin >> N;

  vector<long long> d(N);
  for(int i=1; i<=N; i++){
     for(int j=i; j<=N; j += i){
	d[j]++;
     }//for
  }//for

  long long sum = 0;
  for(int i=1; i<=N; i++) sum += d[i] * i;
  cout << sum << "\n";
}//main


Measured memory_bytes: 81400
// inputに入力データ全体が入る
function Main(input) {
  args = input.split(/\s/);
  balls = {};
  balls[args[0]] = args[2];
  balls[args[1]] = args[3];
  if(args[4] == args[0]) balls[args[0]] --;
  else balls[args[1]] --;
  console.log("" + balls[args[0]] + " " + balls[args[1]]);
}
//*この行以降は編集しないでください(標準入出力から一度に読み込み、Mainを呼び出します)
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int n;
  cin >> n;
  int a, count=0;
  for (int i = 0; i < n; i++){
    cin >> a;
    count += a - 1;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int a,b,c;
int main() {
    cin >> a >> b >> c;

    cout << a * b /2 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,m,i,j,t[100],h[100],st,sh,anst,ansh;
	while(1){
		scanf("%d %d",&n,&m);
		if(n==0&&m==0){
			break;
		}
		anst=ansh=100000;
		st=sh=0;
		i=0;
		while(i<n){
			scanf("%d",&t[i]);
			st+=t[i];
			i++;
		}
		i=0;
		while(i<m){
			scanf("%d",&h[i]);
			sh+=h[i];
			i++;
		}
		for(i=0;i<m;i++){
			for(j=0;j<n;j++){
				if(st+h[i]-t[j]==sh+t[j]-h[i]&&h[i]+t[j]<anst+ansh){
					anst=t[j];
					ansh=h[i];
				}
			}
		}
		if(anst+ansh==200000){
			printf("-1\n");
		}
		else{
			printf("%d %d\n",anst,ansh);
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>

int main(void){
    int ans = 0;

    // 入力 
    int N, K;
    std::cin >> N >> K;

    std::vector<bool> A(N, false);

    // 各お菓子をみて、持ってるすぬけ君をtrueにする 
    for(int i = 1; i <= K; i++){
        int ninzu = 0;
        std::cin >> ninzu;
        std::vector<int> tmp(ninzu);
        for(int i = 0; i < ninzu; i++){
            int dare = 0;
            std::cin >> dare;
            A[dare - 1] = true;
        }
    }

    // Aをみて答えをかぞえる
    for(int i = 0; i < A.size(); i++){
        if(A[i] == false){
            ans++;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _i in range(k)]
mod = 998244353

dp = [0]*(n+1)
dp[1] = 1

for p in range(2, n+1):
    for i, j in lr:
        dp[p] += dp[max(p-i, 0)] - dp[max(p-j-1, 0)]
        dp[p] %= mod
    dp[p] += dp[p-1]

print((dp[n]-dp[n-1])%mod)

Measured memory_bytes: 19844
def main():
    n, k = map(int, input().split())
    arr = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for a, b in arr:
        f = True
        for i in range(32):
            if k & (1<<i) == 0 and a & (1<<i) != 0:
                f = False
                break
        if f:
            ans += b
    for i in range(32):
        p = 1<<i
        tmp = 0
        if p & k == 0:
            continue
        for a, b in arr:
            if a <= k and a&p == 0:
                f = True
                for j in range(i+1, 32):
                    if k & (1<<j) == 0 and a & (1<<j) != 0:
                        f = False
                        break
                if f:
                    tmp += b
        if ans < tmp:
            ans = tmp
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 89752
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
int a[205],n,ans=99999,num;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		num=0;
		while(a[i])
		{
			if(a[i]%2==1) break;
			a[i]/=2;
			num++;
		}
		ans=min(ans,num);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

int n, m;
vi adj[100001];
int ind[100001];
int dp[100001];

void dfs(int x)
{
    for (int y : adj[x])
    {
        ind[y]--;
        dp[y] = max(dp[y], dp[x] + 1);
        if (ind[y] == 0)
            dfs(y);
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        ind[v]++;
    }
    vi v;
    for (int i = 1; i <= n; ++i)
        if (ind[i] == 0)
            v.push_back(i);
    
    for (int x : v)
        dfs(x);

    cout << *max_element(dp + 1, dp + n + 1);
}


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

typedef long long int ll;
typedef long unsigned lu;
typedef vector<ll> v;
typedef pair<ll,ll> p;
typedef vector <p> vp;
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define repr(i,j,k) for(ll i=k;i>=j;i--)
#define read(a,n) rep(i,0,n) cin>>a[i];
#define show(a,n) rep(i,0,n) cout<<a[i]<<" ";
#define modulus 1000000007
#define MAX 100005
#define INF 1000000001
// #define cinv vl a(n) rep(i,0,n) { cin>>a[i]; }
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL);
ll a[MAX]={0};
ll dp[MAX];

int main()
{
    fastio();
    double x,y;
    ll z;
    cin>>x>>y>>z;
    ll ans=ceil(x/y)*z;
    cout<<ans<<"\n";
}

// void mod(ll l)
// {
//     if(l>=0)
//     {
//         cout<<l%modulus<<"\n";
//     }
//     else
//     {
//         while(l<0)
//         {
//             l+=modulus;
//         }
//         cout<<l<<"\n";
//     }
    
// }
 
// ll power(ll a, ll b)
// {
//     for (ll i = 1; i <= b; i++)
//     {
//         a*=a;
//     }
    
//     return a;
// }
 
// ll sumdigit(ll a)
// {
//     ll sum=0;
//     while(a)
//     {
//         a=sum%10;
//         a=a/10;
//     }
// }

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using ll = long long;
const ll mod = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int n; cin>>n;
    vector<tuple<string,int,int>> lineup;
    rep(i,0,n){
        string s;
        int a;
        cin>>s>>a;
        lineup.emplace_back(s,100-a,i);
    }
    sort(all(lineup));
    for(auto x:lineup){
        cout<< get<2>(x)+1 <<endl;
    }
    return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;
int jmax = 100100;

int n, m;
vector<int> like;

int main() {
    scanf("%d%d", &n, &m);
    like.assign(m+1, 0);
    rp(i, 0, n) {
        int k;
        scanf("%d", &k);
        rp(j, 0, k) {
            int a;
            scanf("%d", &a);
            like.at(a) ++;
        }
    }
    int res = 0;
    rp(i, 0, m+1) {
        if (like.at(i) == n) res++;
    }
    printf("%d", res);
    return 0;
} 

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = 0;
    COMinit();

    ll minus = 0;
    rep(i, N - K + 1) {
        ll max_i = i + K - 1;
        ll a = A[i];
        minus += (a * COM(N - (i + 1), K - 1)) % MOD;
        minus %= MOD;
        if (minus < 0) minus += MOD;
    }
    ll plus = 0;

    rep2(i, K - 1, N) {
        ll a = A[i];
        plus += (a * COM(i, K - 1)) % MOD;
        plus %= MOD;
        if (plus < 0) plus += MOD;
    }
    ans = plus - minus;
    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 13056
N,M,Q = map(int, input().split())
train = [[0 for _ in range(N)] for _ in range(N)]

for _ in range(M):
    l,r = map(int, input().split())
    train[l-1][r-1] += 1

query = [tuple(map(int, input().split())) for _ in range(Q)]

"""
l~rの間を走ってるやつ
→ {l~l + l~l+1 + l~l+2 + ... + l~r} + {l+1~l+1 + l+1~l+2 + ... + l+1~r} + ... + {r~r}
の発想
"""
accum = [[0 for _ in range(N)] for _ in range(N)]

for l in range(N):
    for r in range(l,N):
        if l == r:
            accum[l][r] = train[l][r]
        else:
            # l始まりでrまでのどこかに行くやつ = l始まりでr-までのどこかに行くやつ + l始まりでrまで行くやつ
            accum[l][r] = accum[l][r-1] + train[l][r]


for p,q in query:
    cnt = 0
    # l~rの間に完全に収まるもの = l始まりでrまでのどこかで止まるもの + l+1始まりでrまでのどこかで止まるもの + ... + r-1始まりでrまでのどこかで止まるもの + r始まりでrまでのどこかで止まるもの
    for i in range(p-1,q):
        cnt += accum[i][q-1]

    print(cnt)




Measured memory_bytes: 81496
def get_ints():
	return map(int, input().split())
def get_list():
	return list(map(int, input().split()))

n = int(input())
dp = [0 for ans in range(10050)]
for x in range(1, 105):
	for y in range(1, 105):
		for z in range(1, 105):
			v = x*x + y*y + z*z + x*y + y*z + z*x
			if v < 10050:
				dp[v] += 1
for i in range(n):
	print(dp[i + 1])

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef long long ll;
const long long MOD=1e09+7;



#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vi vector<int>

int main(){
  


  int n;
  cin>>n;
  vector<double> data(n);
  rep(i,n){
    double tmp;
    cin>>tmp;
    data.at(i)=tmp;
  }
  
  sort(data.begin(),data.end());
  
  double answer=data.at(0);
  
  rep2(i,1,n){
    answer=(answer+data.at(i))/2;
  }
  
  cout<<fixed<<setprecision(10);
  
  cout<<answer<<endl;
  


  
}



Measured memory_bytes: 256
#include<stdio.h>

int cnt;

int insertionSort(int A[],int n,int g)
{
	int i,j;
	int v;
	
	for(i=g;i<n;i++)
	{
		v=A[i];
		j=i-g;
		while(j>=0&&A[j]>v)
		{
			A[j+g]=A[j];
			j=j-g;
			cnt++;
		}
		A[j+g]=v;
	}
	return cnt;
}

void shellSort(int A[], int n)
{
	int i;
	int h=1,m=0;
	int Gt[1000];
	int G[1000];
	
	for(i=0;;i++)
	{
		if(h>n)
		{
			m=i-1;
			break;
		}
		if(i==0)
		{
			h=3*i+1;
		}
		else
		{
			h=3*h+1;
		}
		
		Gt[i]=h;
	}
	printf("%d\n",m);
	
	for(i=0;i<m;i++)
	{
		G[i]=Gt[m-1-i];
	}
	
	for(i=0;i<m;i++)
	{
		if(i!=0){printf(" ");}
		printf("%d",G[i]);
	}printf("\n");
	
	for(i=0;i<m;i++)
	{
		cnt=insertionSort(A,n,G[i]);
	}
	printf("%d\n",cnt);
}

int main(void)
{
	int i;
	int n;
	
	scanf("%d",&n);
	
	int A[n];
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	shellSort(A,n);
	
	for(i=0;i<n;i++)
	{
		printf("%d\n",A[i]);
	}
	
	return 0;
}


Measured memory_bytes: 5696
n, y = gets.split.map(&:to_i)

def find_comb(n, y)
  (0..n).each do |i10000|
    (0..(n-i10000)).each do |i5000|
      i1000 = n - i10000 - i5000
      return [i10000, i5000, i1000].map(&:to_s).join(' ') if 10000 * i10000 + 5000 * i5000 + 1000 * i1000 == y
    end
  end

  '-1 -1 -1'
end

puts find_comb(n, y)

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX + 1];

int solve()
{
    int ans = 0;

    bool V[MAX];
    for (int i = 0; i < n; i++) {
        B[i] = A[i];  // 配列Aを配列Bにコピーする
        V[i] = false;  // 配列Vのすべての要素をfalseとする
    }
    sort(B, B+n);  // 配列Aをコピーした配列Bをソートする
    for (int i = 0; i < n; i++) {
        // 配列TではBの要素をはじめから記録する
        // 添字はBの要素，値は何番目の要素か
        T[B[i]] = i;  // 配列TでBのi番目の要素の部分をiとする
    }
    for (int i = 0; i < n; i++) {
        if (V[i]) continue;  // Vの要素がfalseのときは下の処理を行う(サイクルに登場するとtrueになる)
        int cur = i;  // curは現在iの添字
        int S = 0;  // Sはコストの合計
        int m = VMAX;
        int an = 0;
        while(1) {
            // ここではサイクルを探す
            V[cur] = true;  // 現在iの添字の要素のVをtrueとする
            an++;  // anをインクリメント
            int v = A[cur];  // vをAの現在の添字の要素
            m = min(m, v);  // mをm(= VMAX)とv(= Aの現在の要素)の小さい方とする
            S += v;  // Sにvを加算する
            cur = T[v];  // curをTのv番目の要素とする
            if (V[cur]) break;  // もしがすでに触れた部分ならばwhileから抜ける
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }

    return ans;
}

int main()
{
    cin >> n;
    s = VMAX;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;

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

    // solve
    ll ans = K;
    for (int i = 0; i < N - 1; ++i) {
        ans *= K - 1;
    }

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
using namespace std;
int main(){
 int n=0;
 cin>>n;
ll a[n];
ll b[n];
rep(i,n){
  a[i]=0;
  b[i]=0;
}
 ll k=0;
 rep(i,n){
   cin>>k;
   b[i]=k;
   a[k-1]++;
 }
 ll sum=0;
rep(i,n){
  sum+=(a[i]-1)*(a[i])/2;
}
rep(i,n){
  cout<<sum-a[b[i]-1]+1<<endl;
}
}

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


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = long.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long[] flag = new long[n];
        flag[0] = 0;
        for (long i = 1; i < n; i++)
        {
            if (a[i - 1] < a[i]) flag[i] = 1;
            else if (a[i - 1] > a[i]) flag[i] = -1;
            else flag[i] = flag[i - 1];
        }

        long ans = 1000;
        long num = 0;
        for (long i = 0; i < n - 1; i++)
        {
            if (flag[i + 1] == 1)
            {
                if (ans >= a[i])
                {
                    num += ans / a[i];
                    ans -= num * a[i];
                }

            }
            else
            {
                if (num > 0)
                {
                    ans += num * a[i];
                    num = 0;
                }
            }

            if (i + 1 == n - 1)
            {
                if (num > 0)
                {
                    ans += num * a[i + 1];
                    num = 0;
                }
            }
        }

        // 出力
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 28028
n,x=map(int,input().split())
l=list(map(int,input().split()))

d=[0]
ans=1
for i in range(1,n+1):
    d.append(d[i-1]+l[i-1])
    if d[i]<=x:
        ans+=1
    else:
        ans+=0

print(ans)

Measured memory_bytes: 3060
n = int(input())
A = list(map(int, input().split()))

mod = 10 ** 9 + 7

def gcd(x, y):
    x, y = max(x, y), min(x, y)
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)

def lcm(x, y):
    return x * y // gcd(x, y)

l = 1
for i in range(len(A)):
    l = A[i] * l // gcd(A[i], l)

l %= mod
B = 0
for i in range(len(A)):
    B += l * pow(A[i], mod - 2, mod)
    B %= mod

print(B)

Measured memory_bytes: 74584
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll gcd(ll a, ll b){
  ll v0 = a, v1 = b, v2 = v0%v1;
  while(v2>0){
    v0 = v1;
    v1 = v2;
    v2 = v0%v1;
  }
  return v1;
}

int main() {
  ll a, b;
  ll ans1, ans2;
  while(cin>>a>>b){
    ans1 = gcd(a, b);
    ans2 = a*b/ans1;
    cout<<ans1<<" "<<ans2<<endl;
  }
}



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

using namespace std;


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


  int X;
  cin >> X;

  int x = X % 100;

  int cnt = x / 5;
  x %= 5;
  cnt += x / 4;
  x %= 4;
  cnt += x / 3;
  x %= 3;
  cnt += x / 2;
  x %= 2;
  cnt += x;

  int res = (X / 100) >= cnt ? 1 : 0;
  cout << res << endl;
}


Measured memory_bytes: 256
//高橋君だけで考えると…h1=t1で確定, t1 < t2ならh2=t2で確定でそうでないならh2=1～t2のどれか…
//結局、最大値を更新してなければ、色々自由なわけだ。同様に、青木君についても考えると…
//各山について「ありうる高さ」を計算できるから、その通り数をかけてほい。

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cassert>
#define int long long
using namespace std;

int n;
int t[100000];
int a[100000];

signed main() {
	int i;
	int maxi;		//最大値格納用
	
	cin >> n;
	for (i = 0; i < n; i++) { cin >> t[i]; }
	for (i = 0; i < n; i++) { cin >> a[i]; }
	
	static int ht[100000];		//ht[i] = 高橋君の条件のみを使った時, 山iの高さが確定するなら-1, そうでないなら高さの上限を格納
	
	ht[0] = -1;
	maxi = t[0];
	for (i = 1; i < n; i++) {
		if (maxi < t[i]) {
			maxi = t[i];
			ht[i] = -1;		//h[i] = t[i]で確定
		}
		else {
			ht[i] = maxi;	//h[i] <= maxi
		}
	}
	
	static int ha[100000];
	ha[n - 1] = -1;
	maxi = a[n - 1];
	for (i = n - 2; i >= 0; i--) {
		if (maxi < a[i]) {
			maxi = a[i];
			ha[i] = -1;		//h[i] = a[i]で確定
		}
		else {
			ha[i] = maxi;	//h[i] <= maxi
		}
	}
	
	int ans = 1;
	for (i = 0; i < n; i++) {
		if (ht[i] == -1 && ha[i] == -1) {
			if (t[i] != a[i]) {
				ans = 0;
			}
		}
		else if (ht[i] == -1) {
			if (t[i] > ha[i]) {
				ans = 0;
			}
		}
		else if (ha[i] == -1) {
			if (a[i] > ht[i]) {
				ans = 0;
			}
		}
		else {
			ans *= min(ht[i], ha[i]);
		}
		ans %= 1000000007;
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if ((a==b && b!=c) || (b==c && a!=c) || (a==c && b!=c)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path;

int main() {
	ll A, B;
	cin >> A >> B >> N;
	ll M = min(N, B - 1);
	cout << (A * M) / B - A * (M / B);
}

Measured memory_bytes: 3600
//mangesh2102000

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

int n;
int a[3005];
int dp[3005][3005][2];

int solve1(int s,int e,int p)
{
	if(dp[s][e][p] != -1)
		return dp[s][e][p];

	if(s==e && p==0)
		return dp[s][e][p] = a[s];

	if(s==e && p==1)
		return dp[s][e][p] = 0;

	if(s > e)
		return dp[s][e][p] = 0;

	if(p==0)
		return dp[s][e][p] = max(a[s]+solve1(s+1,e,1),a[e]+solve1(s,e-1,1));
	else
		return dp[s][e][p] = min(solve1(s+1,e,0),solve1(s,e-1,0));
}

void solve(int t)
{
    cin >> n;
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    for(int i=0;i<=n;i++)
    {
    	for(int j=0;j<=n;j++)
    	{
    		dp[i][j][0] = dp[i][j][1] = -1;
    	}
    }

    int X = solve1(1,n,0);
    int Y = sum - X;
    cout << X-Y << "\n";
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 141312
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<iomanip>
int main(){
  int n;
  cin>>n;
  vector<double>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  double sum=a[0];
  for(int i=1;i<n;i++){
    sum=(sum+a[i])/2;
  }
  cout<<fixed;
  cout<<setprecision(5)<<sum;
  return 0;
}

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

void growKochCurve(vector<pair<double, double>> &, int);

int main(int argc, char const *argv[])
{
    vector<pair<double, double>> vertices{make_pair(0.0, 0.0), make_pair(100.0, 0.0)};

    int n = 0;
    cin >> n;

    growKochCurve(vertices, n);

    for (auto it = vertices.begin(); it != vertices.end(); ++it)
    {
        cout << fixed << setprecision(8) << abs((*it).first) << " " << abs((*it).second) << endl;
    }

    return 0;
}

void growKochCurve(vector<pair<double, double>> &vertices, int depth)
{
    pair<double, double> s(make_pair(0.0, 0.0)), t(make_pair(0.0, 0.0)), u(make_pair(0.0, 0.0));

    for (int j = 0; j < depth; ++j)
    {
        auto it = vertices.begin(); 
        for (int i = 0; i < pow(4, j); ++i)
        {
            s.first = (2.0 * (*it).first + (*(it + 1)).first) / 3.0;
            s.second = (2.0 * (*it).second + (*(it + 1)).second) / 3.0;
            t.first = ((*it).first + 2.0 * (*(it + 1)).first) / 3.0;
            t.second = ((*it).second + 2.0 * (*(it + 1)).second) / 3.0;
            // cout << "s = (" << s.first << ", " << s.second << ")" << endl;
            // cout << "t = (" << t.first << ", " << t.second << ")" << endl;

            u.first = s.first + 0.5 * (t.first - s.first) + 0.5 * sqrt(3.0) * (t.second - s.second);
            u.second = s.second + 0.5 * (t.second - s.second) - 0.5 * sqrt(3.0) * (t.first - s.first);            
            // cout << "u = (" << u.first << ", " << u.second << ")" << endl;

            it++;
            it = vertices.insert(it, s);
            it++;
            it = vertices.insert(it, u);
            it++;
            it = vertices.insert(it, t);
            it++;
        }
    }
}

// void kochnize(vector<pair<double, double>> &vertices, int &depth, int max_depth) {
//     pair<double, double> s(make_pair(0.0, 0.0)), t(make_pair(0.0, 0.0)), u(make_pair(0.0, 0.0));

//     s.first = (2.0 * vertices[0].first + vertices[1].first) / 3.0;
//     s.second = (2.0 * vertices[0].second + vertices[1].second) / 3.0;
//     t.first = (vertices[0].first + 2.0 * vertices[1].first) / 3.0;
//     t.second = (vertices[0].second + 2.0 * vertices[1].second) / 3.0;

//     u.first = 0.5 * (t.first + s.first) - 0.5 * sqrt(3.0) * (t.second - s.second);
//     u.second = 0.5 * (t.second - s.second) + 0.5 * sqrt(3.0) * (t.first - s.first);

//     {
//         auto it = vertices.begin() + 1;
//         vertices.insert(it + 1, {s, u, t});
//     }

//     vector<pair<double, double>> v1{vertices[0], s}, v2{s, u}, v3{u, t}, v4{t, vertices[1]}
//     kochnize(v1, depth + 1, max_depth);
//     kochnize(v2, depth + 1, max_depth);
//     kochnize(v3, depth + 1, max_depth);
// }


Measured memory_bytes: 3560
#include<cstdio>

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if (a>=b and b>=c) printf("%d %d %d\n",c,b,a);
    else if (c>=a and a>=b) printf("%d %d %d\n",b,a,c);
    else if (b>=c and c>=a) printf("%d %d %d\n",a,c,b);
    else if (a>=c and c>=b) printf("%d %d %d\n",b,c,a);
    else if (b>=a and a>=c) printf("%d %d %d\n",c,a,b);
    else if (c>=b and b>=a) printf("%d %d %d\n",a,b,c);
    return 0;
}


Measured memory_bytes: 2764
n,k = map(int,input().split())
D = set([int(d) for d in input().split()])
num = set([0,1,2,3,4,5,6,7,8,9])
D = list(num - D)
D.sort(reverse=True)
_ = 10**7
def abcC(x, ans):
    if len(x) == len(str(n))+3:
        return ans
    if n <= int(x) < ans:
        ans = int(x)
    elif n > int(x):
        for i in D:
            ans = abcC(x+str(i),ans)
    return ans
        
print(abcC('0',_))

Measured memory_bytes: 3188
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

B = set(A)

X = [1, 1 if 1 not in B else 0]
for i in range(2, N + 1):
    x = (X[-1] + X[-2]) % 1000000007
    X.append(x if i not in B else 0)

print(X[N])


Measured memory_bytes: 13216
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void) {



	int r = 0 ;
	int c = 0;

	int rc[101][101] = { 0 };



	scanf("%d %d", &r, &c);
	int row = 0;
	int cul = 0;

	for (row = 0; row < r; row++) { // 配列読み込み
		for (cul = 0; cul < c; cul++) {
			scanf("%d", &rc[row][cul]);
		}
	}

	
	for (cul = 0; cul < c; cul++) {
		int temp_culsum = 0;
		for (row = 0; row < r; row++) {
			temp_culsum += rc[row][cul];
		}
		rc[row][cul] = temp_culsum;
		temp_culsum = 0;
	}

	// row
	for (row = 0; row < r+1; row++) {
		int temp_rowsum = 0;
		for (cul = 0; cul < c; cul++) {
			temp_rowsum += rc[row][cul];
			printf("%d ", rc[row][cul]);
		}
		rc[row][cul] = temp_rowsum;
		printf("%d\n", rc[row][cul]);
		temp_rowsum = 0;

	}

	

	return 0;
}


Measured memory_bytes: 2060
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int n, k;
int a[11];


int main(int argc, char const* argv[])
{
	while(true){
			cin >> n >> k;
			if(n == 0)break;
			vector<int> vec;
			for(int i = 0; i < n; i++){
					vec.pb(i);
					cin >> a[i];
			}
			set<ll> st;
			do{
					ll aa = 0;
					for(int i = 0; i < k; i++){
							if(a[vec[i]] > 9)aa = aa * 100;
							else aa = aa * 10;
							aa += a[vec[i]];
					}
					st.insert(aa);
			}while(next_permutation(vec.begin(), vec.end()));
			cout << st.size() << endl;
	}
	return 0;
}



Measured memory_bytes: 3180
class UnionFind
  def initialize(size) @a = Array.new(size, -1) end
  def root(x) @a[x] < 0 ? x : @a[x] = root(@a[x]) end
  def same?(x, y) root(x) == root(y) end
  def size(x) return -@a[root(x)] end

  def unite(x, y)
    x = root(x)
    y = root(y)
    return false if x == y

    x,y = y,x if @a[x] > @a[y]
    @a[x] += @a[y]
    @a[y] = x
    true
  end
end

require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n,m = gets.chomp.split.map(&:to_i)
uf = UnionFind.new(n+m+1)

langs = Array.new(n)
n.times do |i|
  langs = gets.chomp.split.map(&:to_i)
  k = langs.shift
  langs.each do |lang|
    uf.unite(i, n + lang)
  end
end

root = uf.root(0)
n.times do |i|
  if uf.root(i) != root
    puts 'NO'
    exit
  end
end

puts 'YES'


Measured memory_bytes: 8532
#include <iostream>
using namespace std;
typedef string::const_iterator State;
string s;
bool assign[11];
bool fom(State& be){
	if(*be=='T'){
		be++;
		return 1;
	}
	if(*be=='F'){
		be++;
		return 0;
	}
	if('a'<= *be && *be <= 'k'){
		bool x=assign[*be-'a'];
		be++;
		return x;
	}
	if(*be=='-'){
		be++;
		return !fom(be);
	}
	if(*be=='('){
		be++;
		bool x=fom(be);
		if(*be=='+'){
			be++;
			bool y=fom(be);
			be++;
			return x || y;
		}else if(*be=='*'){
			be++;
			bool y=fom(be);
			be++;
			return x && y;
		}else{
			be+=2;
			bool y=fom(be);
			be++;
			return (!x) || y;
		}
	}
}
int main(){
	while(true){
		cin >> s;
		if(s[0]=='#') break;
		bool ok=true;
		for(int i=0;i<2048;i++){
			for(int j=0;j<11;j++) assign[j]=(i>>j)&1;
			State be=s.begin();
			bool x=fom(be);
			be++;
			bool y=fom(be);
			if(x!=y){
				ok=false;
				break;
			}
		}
		cout << (ok ? "YES\n" : "NO\n");
	}
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
 
  ll n, m, x;
  cin >> n >> m >> x;
  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(n));
  rep(i, n) {
    cin >> c[i];
    a[i].resize(m);
    rep(j, m) cin >> a[i][j];
  }
  ll ans = LONG_LONG_MAX;
  int N = n;	// 状態を持つ対象の数
  for(int bit=0; bit<(1<<N); ++bit) {
    vector<ll> score(m, 0);
    ll totalC = 0;
    for(int i=0; i<N; i++) {
    	if(bit & 1<<i) {
        // ここに bitが1の時、つまり組み合わせに含む場合の処理を書く.
        totalC += c[i];
        rep(j, m) score[j]+=a[i][j];
      }
    }
    bool clear = true;
    rep(j, m) {
      if (score[j] < x) {
        clear = false;
        break;
      }
    }
    if (clear) {
      ans = min(ans, totalC);
    }
  }
  if (ans == LONG_LONG_MAX) ans = -1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
ll dx[8]={1,1,1,0,0,-1,-1,-1};
ll dy[8]={1,0,-1,1,-1,1,0,-1};
int main(void){
    // Your code here!
    ll h,w;
    cin>>h>>w;
    string s0[h][w];
    rep(0,i,h){
        string s;
        cin>>s;
        rep(0,j,w)s0[i][j]=s.substr(j,1);
    }
    rep(0,i,h){
        rep(0,j,w){
            ll sum=0;
            rep(0,k,8){
                ll x=i+dx[k],y=j+dy[k];
                if((x>=h||x<0)||(y>=w||y<0))continue;
                if(s0[x][y]=="#")++sum;
            }
            if(s0[i][j]==".")s0[i][j]=to_string(sum);
        }
    }
    rep(0,i,h){
        rep(0,j,w)cout<<s0[i][j];
        cout<<endl;
    }
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>

int main(){

  int a, b;
  int i,j, temp;
  int count = 0;
  char s1,s2,s3,s4,s5;
  
  scanf("%d",&a);
  scanf("%d",&b);


  
  /*
  for(i=a; i<=b; i++){
    s1 = i / 10000 + '0';
    temp = i - ( s1 + 0) * 10000;

    s2 = temp / 1000 + '0';
    temp = temp - (s2 + 0) * 1000;

    s3 = temp / 100 + '0';
    temp = temp - (s3 + 0) * 100;
    
    s4 = temp / 10 + '0';
    temp = temp - (s4 + 0) * 10;
    
    s5 = temp + '0';
    
    if( s1 == s5 && s2 == s4){
      count++;
      printf("%c %c %c %c %c  ", s1,s2,s3,s4,s5);
      
    }


    
  }
  */

  j = a;
  while(j <= b){
  i = j;
  
    temp = i;
    temp /= 10;
    temp *= 10;
    s5 = (i - temp) + '0';
    i /= 10;


    temp = i;
    temp /= 10;
    temp *= 10;
    s4 = (i - temp) + '0';
    i /= 10;


    
        temp = i;
    temp /= 10;
    temp *= 10;
    s3 = (i - temp) + '0';
    i /= 10;


        temp = i;
    temp /= 10;
    temp *= 10;
    s2 = (i - temp) + '0';
    i /= 10;


        temp = i;
    temp /= 10;
    temp *= 10;
    s1 = (i - temp) + '0';
    i /= 10;


    
    if( s1 == s5 && s2 == s4){
      count++;

    }


    j++;
  }
  
  

 printf("%d", count);

  return 0;
}


Measured memory_bytes: 128
fn main() {
    let mut first_line = String::new();
    std::io::stdin().read_line(&mut first_line).unwrap();
    let n: usize = first_line.trim().parse().unwrap();
    let mut second_line = String::new();
    std::io::stdin().read_line(&mut second_line).unwrap();
    let vec: Vec<&str> = second_line.split_whitespace().collect();

    let mut ans = 0;
    for i in 0..n {
        for j in (i + 1)..n {
            let tako_x: u32 = vec[i].parse().unwrap();
            let tako_y: u32 = vec[j].parse().unwrap();
            ans += tako_x * tako_y;
        }
    }
    print!("{}", ans)
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(ALL(L));
    reverse(ALL(L));
    int ans = 0;
    rep(i, K) ans += L[i];
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

	double x[8];
	double y[8];
double dist(int i,int j)
{
	return sqrtl((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
int main()
{
	int n;
	vector<int> v;
	double ans=0;
	double cnt=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
		v.push_back(i);
	}
	do
	{
		for(int i=1;i<n;i++)
		{
			ans+=dist(v[i-1],v[i]);
		}
		cnt++;
	}while(next_permutation(v.begin(),v.end()));
	cerr<<cnt<<endl;
	cout<<setprecision(12)<<ans/cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
var
	ans,n,k,t,now:int64;
	i,j,l,m:longint;
begin
	read(n,k);
	for i:=0 to 10 do begin
		t:=0;
		for j:=1 to 5 do begin
			now:=0;
			for l:=0 to 2 do begin
				for m:=0 to 2 do begin
					inc(now,(i+l)*7+j+m);
				end;
			end;
			if now mod 11=k then inc(t);
		end;
		if n>=i+3 then begin
			inc(ans,t*(n-i+8)div 11)
		end;
	end;
	writeln(ans);
end.

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

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}
//const int INF = 0x3f3f3f3f;
//const int mod=1e9+7;
//const double pi=3.14159265359;
//###################################################################

int main(){
    ll x=LLD(),k=LLD(),d=LLD();
    if(x<0)x*=-1;
    ll tmp=x;
    x-=(min((x/d),k)*d);
    k-=min(tmp/d,k);
    ll ans;
    if(k%2==0)ans=x;
    else ans=abs(x-d);
    cout<<ans;
}

Measured memory_bytes: 3756
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

let reader = new Reader();
let N = reader.readInt();
let S = reader.readLine();
let counter: Map<string, number> = new Map();
let alphabet = "abcdefghijklmnopqrstuvwxyz";

for(let c of alphabet) {
	counter.set(c, 0);
}

let answer = 0,
	modulo = 1000000007;
for(let c of S) {
	let sum = 1;
	counter.forEach((value, key) => {
		if (key != c)
			sum = (sum*(value+1))%modulo;
	});
	answer = (answer+sum)%modulo;
	counter.set(c, counter.get(c)+1);
}

console.log(answer);


Measured memory_bytes: 35152
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto hw = readln.split.to!(int[]);
    auto h = hw[0];
    auto w = hw[1];

    auto ret = "";

    foreach (_; 0..(w+1)) ret ~= "#";
    ret ~= "#\n";

    foreach (_; 0..h) {
        ret ~= "#";
        ret ~= readln.chomp;
        ret ~= "#\n";
    }

    foreach (_; 0..(w+2)) ret ~= "#";

    writeln(ret);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		ArrayList<Integer>[] graph = new ArrayList[n];
		for (int i = 0; i < n; i++) {
		    graph[i] = new ArrayList<>();
		}
		for (int i = 0; i < n - 1; i++) {
		    int a = sc.nextInt() - 1;
		    int b = sc.nextInt() - 1;
		    graph[a].add(b);
		    graph[b].add(a);
		}
		long ans = k;
		for (int i = 0; i < graph[0].size(); i++) {
		    ans *= k - i - 1;
		    ans %= MOD;
		    ans *= getCount(graph[0].get(i), 0, k, graph);
		    ans %= MOD;
		}
		System.out.println(ans);
   }
   
   static long getCount(int target, int from, int types, ArrayList<Integer>[] graph) {
       int idx = 2;
       long ret = 1;
       for (int x : graph[target]) {
           if (x == from) {
               continue;
           }
           ret *= types - idx;
           ret %= MOD;
           ret *= getCount(x, target, types, graph);
           ret %= MOD;
           idx++;
       }
       return ret;
   }

}


Measured memory_bytes: 113532
import java.util.Scanner;

class Main{

    public static void main(String[] args){
        
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        scanner.close();
        if(s.charAt(2)==s.charAt(3) && s.charAt(4)==s.charAt(5)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    string s,t;
    cin >> s >> t;
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    
    
    return 0;
}



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

int gcd(int x, int y){
	if(x>y){
		swap(x,y);
	}
	int z = y%x;
	if(z==0){
		return x;
	} else {
		return gcd(z,x);
	}
}

int main(){
	int x,y;
	cin >> x >> y;
	int result = gcd(x,y);
	cout<<result<<endl;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division

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

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

int main(){
  int n,k; cin >> n >> k;
  vector<vector<int> > ki(n);
  rep(i,n-1){
    int a,b; cin >> a >> b;
    a--; b--;
    ki[a].push_back(b);
    ki[b].push_back(a);
  }
  vector<int> visit(n,0);
  vector<int> ko(n,0);
  queue<P> nord;
  nord.push(P(0,-1));
  mint ans=1;
  while(!nord.empty()){
    int now=nord.front().first;
    int par=nord.front().second;
    visit[now]++;
    nord.pop();
    if(par==-1) ans*=k;
    else{
      int num=2;
      if(par==0) num=1;
      ans*=k-(num+ko[par]);
      ko[par]++;
    }
    rep(i,ki[now].size()){
      if(visit[ki[now][i]]) continue;
      nord.push(P(ki[now][i],now));
    }
    //cout << ans.x << endl;
  }
  cout << ans.x << endl;
return 0;
}

Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
ll N;
vector<int> a;
const ll INF = 1e12;

int main()
{
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> a[i];
        --a[i];
    }

    vector<int> res(N);
    for (int i = 0; i < N; ++i)
    {
        int index = a[i];
        res[index] = i + 1;
    }

    for (int i = 0; i < N; ++i)
    {
        cout << res[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1664
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        char cs = line.charAt(0);
        char ce = line.charAt(line.length() - 1);
        int len = line.length() - 2;
        System.out.println(String.valueOf(cs) + len + String.valueOf(ce));
    }
}

Measured memory_bytes: 22356
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb1 push_back
#define mod 1000000007LL
#define INF 1234567890

const int maxn = 2e5 + 10;


//initialization here
//

//
//initialization finish


// your function is here
//



//
// your function finished



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

	// your code is here
	//
	string s; cin >> s;

	string ans;
	rep(i, s.size())
	{
		if (s[i] == 'B')
		{
			if (ans.size() == 0)continue;
			else  ans.erase(ans.end() - 1);
		}
		else ans += s[i];
	}

	Print(ans);
	//
	// your code finished

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

template<typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>;
template<typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
std::istream& operator>>(std::istream &is, std::vector<T> &v)
{
  for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) {
    is >> v[i];
  }
  return is;
}

using namespace std;

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

  vector<uint64_t> A(N);
  cin >> A;
  sort(A.begin(), A.end());

  uint64_t M = A[N - 1];
  vector<bool> dp(M + 1, true);
  vector<uint64_t> cnt(M + 1, 0);
  dp[0] = false;
  N_TIMES(n, N) {
    ++cnt[A[n]];
    for (uint64_t v = A[n] * 2; v <= M; v += A[n]) {
      dp[v] = false;
    }
  }

  uint64_t count = 0;
  N_TIMES(n, N) {
    if (cnt[A[n]] == 1 && dp[A[n]]) {
      ++count;
    }
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 12552