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

public class P
{
    public int pos { get; set; }
    public int step { get; set; }
}

public class Hello
{
    public const int INF = 999999999;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        var b = new int[n];
        for (int i = 0; i < n; i++) b[i] = INF;
        for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        var ret = goBfs(n, a, b);
        Console.WriteLine(ret);
    }
    public static void putStep(int start, int now, int d, int step, int[] a, int[] b, Queue<P> q)
    {
        var aL = a.Length;
        now += d;
        while (now <= aL -1)
        {
            var at = a[now];
            var bt = b[now];
            if (at == 0 && step < bt) { b[now] = step; q.Enqueue(new P { pos = now, step = step }); return; }
            else if (bt == step | bt == start) return;
            else if (bt != 0 && bt < step) return;
            else { b[now] = step; now += at; }
        }
    }
    public static int goBfs(int n, int[] a, int[] b)
    {
        var goal = a.Length - 1;
        var now = 0; var step = 1; var start = 0;
        var q = new Queue<P>();
        for (int i = 1; i <= 6; i++) putStep(start, now, i, step, a, b, q);
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (w.pos >= goal) return w.step;
            for (int i = 1; i <= 6; i++)
                putStep(w.pos, w.pos, i, w.step + 1, a, b, q);
        }
        return 0;
    }
}



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

int main() {
    string str;
    while (cin >> str, str != "0") {
        int s = 0;
        REP(i, str.size()) s += str[i] - '0';
        cout << s << endl;
    }
}

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


using namespace std;

#define MAXL 100010
#define MOD 1000000007

char s[MAXL];
int pd[MAXL][2];

int main() {
    scanf("%s", s+1);
    int n = strlen(s+1);
    int i, j;
    reverse(s+1, s+1+n);
    if (s[n]=='0') {
        pd[n][0]=1;
        pd[n][1]=0;
    }
    else {
        pd[n][0]=2;
        pd[n][1]=1;
    }
    for (i=n-1; i>=1; i--) {
        if (s[i]=='0') {
            pd[i][0]=pd[i+1][0];
        }
        else {
            pd[i][0]=2*pd[i+1][0];
            pd[i][0]%=MOD;
        }
        if (s[i]=='0') {
            pd[i][1]=2*pd[i+1][1];
            pd[i][1]%=MOD;
            pd[i][1]+=pd[i+1][1];
            pd[i][1]%=MOD;
        }
        else {
            pd[i][1]=2*pd[i+1][1];
            pd[i][1]%=MOD;
            pd[i][1]+=pd[i+1][1];
            pd[i][1]%=MOD;
            pd[i][1]+=pd[i+1][0];
            pd[i][1]%=MOD;
        }
    }
    //printf("%d %d\n", pd[2][0], pd[2][1]);
    //printf("%d %d\n", pd[1][0], pd[1][1]);
    int ans = pd[1][0]+pd[1][1];
    printf("%d\n", ans%MOD);
    return 0;
}








Measured memory_bytes: 1152
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;


int main(){

	int n,table[10],tmp;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0; i < 10; i++)table[i] = 0;

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

		for(int i = 0; i < 10; i++){
			if(table[i] == 0){
				printf("-\n");
			}else{
				for(int k = 0; k < table[i]; k++)printf("*");
			}
			printf("\n");
		}
	}

    return 0;
}

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

int main() {
	int n, k;
	cin >> n >> k;
	if( (n-1) % (k-1)==0) cout << (n - 1) / (k - 1);
       else cout << (n - 1) / ( k - 1 ) + 1;
}


Measured memory_bytes: 3608
num = sorted(list(map(int,input().split())))

ans = num[2]-num[1]
num[0] += num[2]-num[1]
num[1] += num[2]-num[1]

while num[0]<num[1]:
    ans += 1
    num[0] += 2
    
if num[0] != num[1]:
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    REP(i, n) cin >> a[i];

    ll ans = 0;
    REP(i, n - 1) {
        if (a[i] + a[i + 1] > k) {
            ans += (a[i + 1] + a[i]) - k;
            ll e = min(a[i + 1], (a[i + 1] + a[i]) - k);
            a[i + 1] -= e;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define MAX 100
#define INF (1<<29)
typedef pair<int, int> pii;

int main()
{
    int n, d, m;
    while (cin >> n >> d, n) {
        int N = 0;
        vector<int> cap[MAX];        
        for (int i = 0; i < n; i++) {
            cin >> m;
            cap[i].resize(m);
            for (int j = 0; j < m; j++, N++) {
                cin >> cap[i][j];                
            }
        }
        bool possible = 1;
        vector<int> cur(n, 0), sum(n, 0);        
        while (N--) {
            int p = -1, maxi = -INF;
            vector<pii> v(n);
            for (int i = 0; i < n; i++) {
                v[i] = pii(sum[i], i);
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < n; i++) {
                if (cur[i] == (int)cap[i].size()) {
                    continue;
                }
                int j = 0;
                for (; j < n; j++) {
                    if (v[j].second != i) {
                        break;
                    }
                }
                if (sum[i] + cap[i][cur[i]] > maxi &&
                    sum[i] + cap[i][cur[i]] - v[j].first <= d) {
                    maxi = sum[i] + cap[i][cur[i]];
                    p = i;
                }
            }
            if (p == -1) {
                possible = 0;
                break;
            }
            
            sum[p] += cap[p][cur[p]++];
        }
        cout << (possible ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    long t = scan.nextLong();
	    long nt[]=new long[n+1];
	    nt[0]=0;
	    for(int i=1;i<=n;i++) {
	    	nt[i]=scan.nextLong();
	    }
	    scan.close();
	    long x=0;
	    for(int i=1;i<=n;i++) {
	    	x+=Math.min(t, nt[i]-nt[i-1]);
	    }
	    System.out.println(x+t);
	}

}

Measured memory_bytes: 65280
N = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for i in range(N):
    for j in range(i,N):
        for k in range(j,N):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
                if abs(l[i]-l[j]) < l[k] < l[i] + l[j]:
                    ans += 1
print(ans)


Measured memory_bytes: 9068
def calc(x) -> int:
  sum = 0
  while x//10!=0:
    sum += x%10
    x = x//10
  sum+=x
  return sum


n = int(input())
best_score = float('inf')
for a in range(1,n):
  b = n-a
  score = calc(a)+calc(b)
  if score < best_score:
    best_score = score
print(best_score)
  

Measured memory_bytes: 2940
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        List<List<Integer>> li = new ArrayList<>();
        for (int i = 0; i < m; ++i) li.add(new ArrayList<>());

        for (int i = 0; i < m; ++i) {
            int num = sc.nextInt();
            for (int j = 0; j < num; ++j) {
                int s = sc.nextInt() - 1;
                li.get(i).add(s);
            }
        }

        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < m; ++i) p.add(sc.nextInt());

        int res = 0;
        for (int bit = 0; bit < (1<<n); ++bit) {
            int ok = 0;
            for (int i = 0; i < m; ++i) {
                int cnt = 0;
                for (Integer val : li.get(i)) {
                    if ((bit & (1<<val)) != 0) ++cnt;
                }
                if (cnt % 2 == p.get(i)) ++ok;
            }
            if (ok == m) ++res;
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 21972
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

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

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int n, l;
    cin >> n >> l;

    vector<string> s(n);
    for(int i = 0; i < n; i++) cin >> s[i];

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

    for(int i = 0; i < n; i++){
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n = int(input())
d = dict()
for i in range(n):
    w, t = map(int, input().split())
    if t in d:
        d[t] = d[t] + w
    else:
        d[t] = w
d = sorted(d.items(), key=lambda x:x[0])
now = 0
ans = True
for x in d:
    t, w = x
    now = now + w
    if now > t:
        ans = False
        break
print('Yes' if ans else 'No')

Measured memory_bytes: 43868
s = list(input())
i = 0
for s_ in s:
    i += 1
    if i % 2 == 1:
        if not (s_ == "R" or s_ == "U" or s_ == "D"):
            print("No")
            exit()
    else:
        if not(s_ == "L" or s_ == "U" or s_ == "D"):
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
N = int(input())
A = tuple(map(int, input().split()))
def p(n):
    """ """
    min_facts = [0] * (n+1)
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        if not is_prime[i]:
            continue
        min_facts[i] = i
        
        for j in range(i*2, n+1, i):
            is_prime[j] = False
            if min_facts[j] == 0:
                min_facts[j] = i
    return min_facts

min_facts = p(max(A))
fact_counts = dict()
for a in A:
    appeared = set()
    while min_facts[a] > 0:
        f = min_facts[a]
        if not f in appeared:
            fact_counts.setdefault(f, 0)
            fact_counts[f] += 1
            appeared.add(f)
        a //= f

pairwise = True
for c in fact_counts.values():
    if c > 1:
        pairwise = False
        break

if pairwise:
    print('pairwise coprime')
else:
    if max(fact_counts.values()) == N:
        print('not coprime')
    else:
        print('setwise coprime')


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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & (-x))
#define BIT(a,b) ((ll)(a&(1<<b))==0 ? false : true)

const ll MAXN=1e2+10;

vector <ll> p[4];

pll a[MAXN];

ll e[4][MAXN];

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

    ll n,w,res=0;
    cin>>n>>w;

    cin>>a[0].X>>a[0].Y;
    p[0].pb(a[0].Y);

    ll k=a[0].X;

    for(ll i=1;i<n;i++)
    {
        cin>>a[i].X>>a[i].Y;

        p[a[i].X-k].pb(a[i].Y);
    }

    sort(p[0].begin() , p[0].end());
    reverse(p[0].begin() , p[0].end());

    if (p[0].size()>0)
    {
        e[0][0]=p[0][0];

        for(ll i=1;i<p[0].size();i++)
        {
            e[0][i]=e[0][i-1]+p[0][i];
        }
    }

    sort(p[1].begin() , p[1].end());
    reverse(p[1].begin() , p[1].end());

    if (p[1].size()>0)
    {
        e[1][0]=p[1][0];

        for(ll i=1;i<p[1].size();i++)
        {
            e[1][i]=e[1][i-1]+p[1][i];
        }
    }

    sort(p[2].begin() , p[2].end());
    reverse(p[2].begin() , p[2].end());

    if (p[2].size()>0)
    {
        e[2][0]=p[2][0];

        for(ll i=1;i<p[2].size();i++)
        {
            e[2][i]=e[2][i-1]+p[2][i];
        }
    }

    sort(p[3].begin() , p[3].end());
    reverse(p[3].begin() , p[3].end());

    if (p[3].size()>0)
    {
        e[3][0]=p[3][0];

        for(ll i=1;i<p[3].size();i++)
        {
            e[3][i]=e[3][i-1]+p[3][i];
        }
    }

    for(ll i=0;i<=p[0].size();i++)
    {
        ll r=0;

        for(ll j=0;j<=p[1].size();j++)
        {
            for(ll u=0;u<=p[2].size();u++)
            {
                for(ll y=0;y<=p[3].size();y++)
                {
                    r=k*i + k*j + k*u + k*y + j + 2*u + 3*y;

                    ll x=0;

                    if (i!=0)
                    {
                        x+=e[0][i-1];
                    }

                    if (j!=0)
                    {
                        x+=e[1][j-1];
                    }

                    if (u!=0)
                    {
                        x+=e[2][u-1];
                    }

                    if (y!=0)
                    {
                        x+=e[3][y-1];
                    }

                    if (r<=w)
                    {
                        res=max(res , x);
                    }
                }
            }
        }
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
n1 = Array.new(N + 1, false)
nN = Array.new(N + 1, false)
M.times do |i|
    a, b = gets.split.map(&:to_i)
    n1[b] = true if a == 1
    nN[a] = true if b == N
end

(1..N).each do |i|
    if n1[i] && nN[i]
        puts 'POSSIBLE'
        exit
    end
end

puts 'IMPOSSIBLE'

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

#define INF 1e9
using namespace std;
using ll = long long;

int main() {

    ll A, B, X; cin >> A >> B >> X;

    if (X < A) {
        puts("NO");
    } else {
        if (X > A + B) {
            puts("NO");
        } else {
            puts("YES");
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
typedef long long int LL;
using namespace std;
int n;
LL a[115];
LL gcd(LL x,LL y){
    if(y==0) return x;
    return gcd(y,x%y);
}
void solve()
{
    LL lcm = 1;
    for(int i=1;i<=n;i++)
    {
        lcm = lcm/gcd(lcm,a[i])*a[i];
    }
    cout<<lcm<<endl;
    //printf("lld\n",lcm);
}
int main()
{
    while(~scanf("%d",&n))
    {
        for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define read(x) scanf("%d",&x)
ll a;
int b,b1,b2;
int main(){
	ios::sync_with_stdio(false);
	scanf("%lld",&a);
	scanf("%1d.%1d%1d",&b,&b1,&b2);
	ll c=a*b+a*b1/10+a*b2/100;
	if (a*b1%10+(a*b2/10%10)>=10) ++c;
	cout<<c<<endl;
	return 0; 
}

Measured memory_bytes: 3760
import Data.List
import qualified Data.Set as S
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B

type Vertex = Int
type Weight = Int
type Edge = ((Vertex, Vertex), Weight)

snub = S.toList . S.fromList

readInt = maybe undefined fst . B.readInt

untilFix f x = let x1 = f x in if x1 == x then x else untilFix f x1

kruskal :: [Edge] -> Int
kruskal = fst . _kruskal initial 0 . sortOn snd

_kruskal :: UnionFind -> Int -> [Edge] -> (Int, UnionFind)
_kruskal uf acc [] = (acc, uf)
_kruskal uf acc (((a,b),d):abd)
  | same uf a b = _kruskal uf acc abd
  | otherwise = _kruskal (merge uf a b) (acc + d) abd

main = do
  _ <- getLine
  xys <- map ((\[x,y] -> (x+1, y+1)) . map readInt . B.words) . B.lines <$> B.getContents
  let xyis = zip (snub xys) [1 ..]
  let xysx = xyis
  let xysy = sortOn (snd . fst) xyis
  print (built xysx xysy)

built xysx xysy = kruskal (edgex ++ edgey)
  where
    edgex = zipWith (\((xi,yi),i) ((xj,yj),j) -> ((i,j), min (abs (xj-xi)) (abs (yj-yi)))) xysx (tail xysx)
    edgey = zipWith (\((xi,yi),i) ((xj,yj),j) -> ((i,j), min (abs (yj-yi)) (abs (xj-xi)))) xysy (tail xysy)

data UnionFind = UnionFind {tree :: M.IntMap Point, rk :: M.IntMap Rank}
type Point = Int
type Rank = Int

initial :: UnionFind
initial = UnionFind (M.singleton 0 0) M.empty

(!?) :: UnionFind -> Point -> Point
(!?) uf p = M.findWithDefault 0 p (tree uf)

rep :: UnionFind -> Point -> Point
rep uf = untilFix (uf !?)

rank :: UnionFind -> Point -> Rank
rank uf = (rk uf M.!)

isolate :: UnionFind -> Point -> Bool
isolate uf p = rep uf p == 0

merge :: UnionFind -> Point -> Point -> UnionFind
merge uf p1 p2
  | i1 && i2 = UnionFind (M.insert p2 p1 (M.insert p1 p1 (tree uf))) (M.insert p1 2 (rk uf))
  | i1 = UnionFind (M.insert p1 rp2 (tree uf)) (M.insert rp2 (rk2 + 1) (rk uf))
  | i2 = UnionFind (M.insert p2 rp1 (tree uf)) (M.insert rp1 (rk1 + 1) (rk uf))
  | rp1 /= rp2 && rk1 > rk2 = UnionFind (M.insert p2 rp1 (M.insert rp2 rp1 (tree uf))) (M.insert rp1 (rk1 + rk2) (rk uf))
  | rp1 /= rp2 = UnionFind (M.insert p1 rp2 (M.insert rp1 rp2 (tree uf))) (M.insert rp2 (rk1 + rk2) (rk uf))
  | otherwise = uf
  where
    i1 = isolate uf p1
    i2 = isolate uf p2
    rk1 = rank uf rp1
    rk2 = rank uf rp2
    rp1 = rep uf p1
    rp2 = rep uf p2

same :: UnionFind -> Point -> Point -> Bool
same uf p1 p2
  | p1 == p2 = True
  | otherwise = not (isolate uf p1) && (rep uf p1 == rep uf p2)


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

using namespace std;



long long   max(long long a,long long b,long long  c)
{
    if(a>b&&a>c)
    return a;
    else if(b>a&&b>c)
    return b;
    return c;
    
}
int main() {
    
   
   
   
   
   
   int n,m;
   cin>>n>>m;
long     long wt[n];
    long long  p[n];
   for(int i=0;i<n;i++)
   {
       cin>>wt[i]>>p[i];
   }
    
long long  a[n+1][m+1];
for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
           if(i==0||j==0)
           a[i][j]=0;
           else
           {
               if((j-wt[i-1])>=0)
               a[i][j]=max(a[i-1][j],a[i-1][j-wt[i-1]]+p[i-1]);
               else
a[i][j]=a[i-1][j];
               
               
           }
            
            
            
        }
    }
        
        
        
    cout<<a[n][m];
     
return 0;
        
    
}


Measured memory_bytes: 79104
# -*- coding: utf-8 -*-
#ABC131C
import sys

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))
a=hoge[0]
b=hoge[1]
c=hoge[2]
d=hoge[3]

total=b-a+1

csum=(b//c-(a-1)//c)
total-=csum

dsum=(b//d-(a-1)//d)
total-=dsum

cdlcm=lcm(c,d)
cdsum=(b//cdlcm-(a-1)//cdlcm)
total+=cdsum

print(total)



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


using namespace std;
using ll = long long;
using ull = unsigned long long;



void solve(){

    string s;
    cin>>s;

    int n = s.length();
    //cout<<n<<"\n";
    int i=0,j=n-1;
    //cout<<i<<" "<<j<<"\n";
    while(i<=j){
        if(s[i]!=s[j]){
            cout<<"No";
            return;
        }
        i++;j--;
    }
    i = 0;
    j=(n-1)/2; j--;
    //cout<<i<<" "<<j<<"\n";
    while(i<=j){
        if(s[i]!=s[j]){
            cout<<"No";
            return;
        }
        i++;j--;
    }
    i=(n+3)/2;
    j=n-1; j--;
    //cout<<i<<" "<<j<<"\n";
    while(i<=j){
        if(s[i]!=s[j]){
            cout<<"No";
            return;
        }
        i++;j--;
    }
    cout<<"Yes";
}
 
int main(){
     
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
 
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    // int t;
    // cin>>t;
 
    // while(t--)
        solve();
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long int
#define INF (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    ll N; cin>>N;
    ll ix=0,v;
    for(ll i = 0; i < N; i++){
        ll a,b;
        cin>>a>>b;
        if(ix<a){
            ix = a;
            v = b;
        }
    }
    cout<<ix+v<<endl;
    return 0;
}

Measured memory_bytes: 256
// ITP1_5_A:   Print a Rectangle
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int H, W;
	int h, w;

	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0) break;
		for (h = 0; h < H; h++) {
			for (w = 0; w < W; w++){
		if(w==0||w==W-1||h==0||h==H-1)
		printf("#");
		else
		printf(".");
		
		}
		putchar('\n');
	}
	
		putchar('\n');
	}
	return 0;
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def Yes(): print("Yes"); return
def No(): print("No"); return

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

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

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]


#############
# Main Code #
#############

N = inputI()
S = inputS()

ans = 0
for i in range(N+1):
  s1 = set(S[:i])
  s2 = set(S[i:])
  ans = max(ans,len(s1 & s2))
  
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 2010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

string L;
ll f[100010], mu[100010];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    f[0] = 1;
    FOR(i,1,100000) f[i] = f[i-1] * 3 % MODBASE;
    mu[0] = 1;
    FOR(i,1,100000) mu[i] = mu[i-1] * 2 % MODBASE;
    cin >> L;
    int n = SZ(L);
    int cnt = 0;
    ll res = 0;
    FOR(i,0,n-1)
        if (L[i] == '1') {
            int remain = n-1-i;
            res = (res + mu[cnt] * f[remain] % MODBASE) % MODBASE;
            cnt++;
        }
    res = (res + mu[cnt]) % MODBASE;
    cout << res;
    return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  int n,m,x;
  cin>>n>>m>>x;
  veci p(m);
  rep(i,m)cin>>p[i];
  veci v(n,0);
  rep(j,m){
    v[p[j]]=1;
  }
  int cur=0;
  //left
  for(int k=x;k>0;k--)cur+=v[k];
  int ma=cur;
  cur=0;
  for(int l=x;l<n;l++)cur+=v[l];
  ma=min(cur,ma);
  cout<<ma<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int i,j,H,W;

  for(scanf("%d%d",&H,&W);H!=0||W!=0;scanf("%d%d",&H,&W)){
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        if(i==0||i==H-1||j==0||j==W-1)putchar('#');
        else putchar('.');
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 1000
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	fsc := NewFastScanner()
	S1 := fsc.Next()
	S2 := fsc.Next()
	for i := 0; i < 3; i++ {
		if S1[i] != S2[2-i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	deque<char> sq;
	int q;
	string s;
	cin >> s >> q;
	FOR(i, 0, s.size()-1) {
		sq.push_back(s[i]);
	}
	bool isrev = false;
	FOR(i, 1, q) {
		int t;
		cin >> t;
		if (t == 1) {
			isrev = !isrev;
		}
		else {
			int f;
			cin >> f;
			char c;
			cin >> c;
			if (f == 1) {
				if (isrev) {
					sq.push_back(c);
				}
				else {
					sq.push_front(c);
				}
			}
			else {
				if (isrev) {
					sq.push_front(c);
				}
				else {
					sq.push_back(c);
				}
			}
		}
	}
	if (isrev) {
		reverse(ALL(sq));
	}
	FOR(i, 0, sq.size() - 1) {
		cout << sq[i];
	}
	cout << endl;
	return(0);
}

Measured memory_bytes: 896
S = gets.chomp

front = S.slice(0, 2).to_i
back = S.slice(2, 2).to_i

if front.between?(0, 99) && front.between?(1, 12)
  front_pos = "A"
elsif front.between?(1, 12)
  front_pos = "M"
else
  front_pos = "Y"
end

if back.between?(0, 99) && back.between?(1, 12)
  back_pos = "A"
elsif back.between?(1, 12)
  back_pos = "M"
else
  back_pos = "Y"
end

if front_pos == "A" && back_pos == "A"
  puts "AMBIGUOUS"
elsif front_pos == "Y" && (back_pos == "A" || back_pos == "M")
  puts "YYMM"
elsif back_pos == "Y" && (front_pos == "A" || front_pos == "M")
  puts "MMYY"
else
  puts "NA"
end


Measured memory_bytes: 1788
H,W=map(int, input().split())
S = [input() for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            isOK = False
            if i > 0 and S[i-1][j] == '#':
                isOK = True
            elif i < H-1 and S[i+1][j] == '#':
                isOK = True
            elif j > 0 and S[i][j-1] == '#':
                isOK = True
            elif j < W-1 and S[i][j+1] == '#':
                isOK = True
            if not isOK:
                break
    else:
        continue
    print('No')
    break
else:
    print('Yes')




Measured memory_bytes: 3064
from heapq import *
N,M=map(int,input().split())
X=[[] for i in range(M)]
A,B=0,0
for i in range(N):
  A,B=map(int,input().split())
  if A>M:
    continue
  X[-A].append(B)
P=0
Q=[]
heapify(Q)
for i in range(M-1,-1,-1):
  for j in range(len(X[i])):
    heappush(Q,-X[i][j])
  if len(Q):
    P-=heappop(Q)
print(P)

Measured memory_bytes: 89216
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    #define mp make_pair
    #define pb push_back
    //#define M_PI           3.1415926535  /* pi */
    typedef long double ld;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef vector<ll> vi;
    const int maxN = 100224;

    void solve(){
      ll n;
      cin >> n ;
      ll a[n];
      rep(i, n) cin >> a[i];
      vi v;
      
      rep(i, n) {
        if(a[i] > i+1){
          cout<<-1<<endl;
          return;
        }
        //cout<<"sdfa"<<endl;
        //v.at(a[i] -1) = a[i];
        v.insert(v.begin() + (a[i]-1), a[i]);
      }
      trav(i, v) cout << i << endl;
    }

    
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      solve();
      return 0;
    }     

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

map<ll,ll> mp;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec v(n);
    ll total =0;
    ll ans = 0;
    mp[0]++;
    rep(i,n){
        cin>>v[i];
        total+=v[i];
        ans += mp[total];
        mp[total]++;
    }
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 14336
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

# import math
# import numpy as np
# import copy
# from collections import defaultdict, Counter
# from itertools import product
# from bisect import bisect_left, bisect_right

INF = float("INF")

def s_inpl(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))

N, K = s_inpl()
a = inpl()

dp = [INF] * N

dp[0] = 0

for i in range(1, N):
    for j in range(1, K+1):
        if j - i > 0:
            continue
        dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]))

print(dp[N-1])

Measured memory_bytes: 56788
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

var (
        ns    []string
        stack = make([]int, 20000)
)

func main() {
        for _, value := range ns {
                push(value)
        }
        fmt.Println(stack[len(stack)-1])
}

func init() {
        scanner := bufio.NewScanner(os.Stdin)
        scanner.Scan()
        ns = strings.Fields(scanner.Text())
}

func push(element string) {
        if strings.Contains("+-*", element) {
                rv := pop()
                lv := pop()
                switch element {
                case "+":
                        stack = append(stack, lv+rv)
                case "-":
                        stack = append(stack, lv-rv)
                case "*":
                        stack = append(stack, lv*rv)
                }
                return
        }
        ev, _ := strconv.Atoi(element)
        stack = append(stack, ev)
}

func pop() int {
        tv := stack[len(stack)-1]
        stack = stack[:len(stack)-1]
        return tv
}


Measured memory_bytes: 1332
#include <stdio.h>

int main(void)
{
	int x,y,tmp;
	while(1){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0) break;
		if(x>y){
			tmp=x;
			x=y;
			y=tmp;
		}
			printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  ll x,k,d,ans;
  cin>>x>>k>>d;
  if(x<0){
    x=-x;
  }
  long double s=(long double)x/d;
  if(k<=s){
    cout<<x-k*d;
  }else if((ll)(k-floor(s))%2==0){
    cout<<x%d;
  }else{
    cout<<d-x%d;
  }
}

Measured memory_bytes: 3632
//
//  main.cpp
//  C - Dubious Document 2
//
//  Created by wenhan on 2017/10/28.
//  Copyright © 2017年 wenhan. All rights reserved.
//

#include <iostream>
#include <cstring>
using namespace std;
int main() {
    string s,t,ss[1000],w;
    cin>>s>>t;
    bool f=false;
    int k=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!='?')
        {
            for (int j=0; j<t.size();j++ ) {
                if(t[j]==s[i])
                {
                    w=s;
                    int a1=j-1,a2=j+1;
                    int b1=i-1,b2=i+1;
                    while(a1>=0&&b1>=0)
                    {
                        if(t[a1]==s[b1]||s[b1]=='?')
                        {
                             w[b1]=t[a1];
                            a1--;
                            b1--;
                        }
                        else
                            break;
                    }
                    while(b2<s.size()&&a2<t.size())
                    {
                        if(t[a2]==s[b2]||s[b2]=='?')
                        {
                            w[b2]=t[a2];
                            a2++;
                            b2++;
                         
                        }
                        else
                            break;
                    }
                    if(a1<0&&a2>=t.size())
                    {
                        f=true;
                        ss[k++]=w;
                    }
                }
            }
        }
    }
    int v=int(t.size())-1;
    w=s;
    for(int i=int(s.size())-1;i>=0;i--)
    {
        if(v<0)
        {
            f=true;
            ss[k++]=w;
            v=0;
            break;
        }
        if(s[i]=='?')
        {
            if(v>=0)
                w[i]=t[v];
            v--;
        }
        else
        {
            v=int(t.size())-1;
            w=s;
        }
    }
    if(v<0)
    {
        f=true;
        ss[k++]=w;
    }
    if(f)
    {
        for(int i=0;i<k;i++)
            for(int j=0;j<ss[i].size();j++)
                ss[i][j]=(ss[i][j]=='?')?'a':ss[i][j];
        w=ss[0];
        for(int i=1;i<k;i++)
            if(w>ss[i])
                w=ss[i];
        cout<<w<<endl;
    }
    else
        cout<<"UNRESTORABLE"<<endl;
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
	Scanner stdIn = new Scanner(System.in);
        String S = stdIn.next();
	String T = stdIn.next();
	int A = stdIn.nextInt();
	int B = stdIn.nextInt();
	String U =stdIn.next();
	if(U.equals(S)){
	    A-=1;
	}else if(U.equals(T)){
	    B-=1;
	}
	System.out.println(A+" "+B);
    }
}


Measured memory_bytes: 22484
import java.util.*;
	public class Main {
		public static void main(String[] args)
		{
			Scanner sc=new Scanner(System.in);
			int tot=0;
			int len=sc.nextInt();
			int tri[]=new int[len];
			for(int l=0;l<len;l++)
				tri[l]=sc.nextInt();
			
			Arrays.sort(tri);
		   for(int i=0;i<len-2;i++)
		   {
			   for(int j=i+1;j<len-1;j++)
			   {
				   if(tri[i]==tri[j])
				    continue;			   
				   else
				   {
					   for(int k=j+1;k<len;k++)
					   {
						   if(tri[i]==tri[k]||tri[j]==tri[k])
							   continue;
						   else
						   {
							   if(tri[i]+tri[j]>tri[k])
								   tot++;
						   }
					   }
				   }
			   }
		   }
			System.out.println(tot);
		}

	}



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

int n;
int a[32];
int b[32][32][3];
int ans = 0;

int ck(int bt){
	for(int i=0;i<n;i++){
		if((bt & (1<<i)) == 0){
			continue;
		}
		for(int j=0;j<a[i];j++){
			int cc = (bt & (1<<b[i][j][0]));
			if((cc!=0 && b[i][j][1]==0) || (cc==0 && b[i][j][1]==1))return (0);
		}
	}

	// great
	int ret = 0;
	for(int i=0;i<n;i++){
		int cc = (bt & (1<<i));
		if(cc!=0)ret++;
	}

	ans = max(ret,ans);

	return(0);
}

int mk(int now,int bt){
	if(now < n){
		mk(now+1,bt);mk(now+1,bt | (1<<now));
	}
	else{
		ck(bt);
	}

	return(0);
}

int main(){

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i];j++){
			cin>>b[i][j][0]>>b[i][j][1];
			b[i][j][0]--;
		}
	}

	mk(0,0);

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

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  SORT(a);
  ll total1 = 0;
  ll total2 = 0;
  if (n % 2) {
    rep(i, 0, n / 2) total1 -= 2 * a[i];
    rep(i, n / 2, n / 2 + 2) total1 += a[i];
    rep(i, n / 2 + 2, n) total1 += 2 * a[i];

    rep(i, 0, n / 2 - 1) total2 -= 2 * a[i];
    rep(i, n / 2 - 1, n / 2 + 1) total2 -= a[i];
    rep(i, n / 2 + 1, n) total2 += 2 * a[i];
  } else {
    total1 = a[n / 2] - a[n / 2 - 1];
    rep(i, 0, n / 2 - 1) total1 -= 2 * a[i];
    rep(i, n / 2 + 1, n) total1 += 2 * a[i];
  }

  cout << max(total1, total2) << endl;
}


Measured memory_bytes: 1024