akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  int spare = a - b;
  int rest;
  if (spare > c){
    rest = 0;
  }else{
    rest = c - spare;
  }
  cout << rest << endl;
}

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

using namespace std;

int main()
{
    int n, m, a, b, q;
    cin >> n >> m;
    vector <int> D[n+1], T;
    int Di[n+1], C[n+1];
    for (int i = 0; i < m; i++)
    {
        cin >> a >> b;
        D[a].push_back(b);
        D[b].push_back(a);
    }
    for (int i = 0; i <= n; i++)
    {
        C[i] = 0;
        Di[i] = -1;
    }
    cin >> q;
    int v[q], d[q], c[q];
    for (int i = 0; i <= n; i++)
    {
        Di[i] = -1;
    }
    for (int i = 0; i < q; i++)
    {
        cin >> v[i] >> d[i] >> c[i];
    }
    for (int i = q-1; i >= 0; i--)
    {
        if (d[i] > Di[v[i]])
        {
            Di[v[i]] = d[i];
            T.push_back(v[i]);
            for (int y = 0; y < T.size(); y++)
            {
                a = T[y];
                if (C[a] == 0)
                {
                    C[a] = c[i];
                }
                for (int u = 0; u < D[a].size(); u++)
                {
                    b = D[a][u];
                    if (Di[b] < Di[a]-1)
                    {
                        Di[b] = Di[a]-1;
                        T.push_back(b);
                    }
                }
            }
            T.clear();
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << C[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 8952
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll big=1ll<<60;
int main(){
    ll n;
    cin>>n;
    ll a[n],dp[n][n];
    for(ll i=0;i<n;i++) cin>>a[i];
    for(ll t=0;t<n;t++){
        for(ll l=0;l<n;l++){
            ll r=l+t;
            if(r>=n) continue;
            dp[l][r]=big;
            if(l==r) dp[l][r]=0;
            else{
                ll cost=0;
                for(ll i=l;i<=r;i++) cost+=a[i];
                for(ll i=l;i<r;i++){
                    dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+cost);
                }
            }
        }
    }
    cout<<dp[0][n-1];
}

Measured memory_bytes: 1536
n = int(input())
pn = list(map(int, input().split()))

count = 0
for i in range(1,n-1):
    if pn[i-1] < pn[i] < pn[i+1] or pn[i-1] > pn[i] > pn[i+1]:
        count += 1
    
print(count)

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>   
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <deque>
#include <cstring>

using namespace std;

int main() {
    int k;
    scanf("%d", &k);
    vector<long long> a(k);
    for (int i = 0; i < k; i++)
        scanf("%lld", &a[i]);
    long long mn = 2, mx = 2;
    for (int i = k - 1; i >= 0; i--) {
        mx -= mx % a[i];
        mn += (a[i] - mn % a[i]) % a[i];
        if (mn > mx) {
            printf("-1");
            return 0;
        }
        mx += a[i] - 1;
    }
    printf("%lld %lld\n", mn, mx);
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main(){
  long long a,b,c,d,t;
  scanf("%lld %lld %lld %lld %lld",&a,&c,&b,&d,&t);
  printf("%s\n",labs(a-b)<=(c-d)*t?"YES":"NO");
  return 0;
}


Measured memory_bytes: 1660
a,b,c,k = map(int,input().split())
#lst = [1]*a + [0]*b + [-1]*c

if k <= a:
    print(1*k)
elif a < k <= a+b:
    print(1*a + 0*b)
elif a+b < k < a+b+c:
    print(1*a + (-1)*(k-(a+b)))
elif a+b+c == k:
    print(1*a + (-1)*c) 

Measured memory_bytes: 9184
using Yorukatsu024.Questions;
using Yorukatsu024.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu024.Questions
{
    /// <summary>
    /// ABC115 C
    /// </summary>
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var nk = inputStream.ReadIntArray();
            var n = nk[0];
            var k = nk[1];

            var h = new int[n];

            for (int i = 0; i < n; i++)
            {
                h[i] = inputStream.ReadInt();
            }

            Array.Sort(h);

            var minDiff = int.MaxValue;

            for (int i = 0; i < n - k + 1; i++)
            {
                minDiff = Math.Min(minDiff, h[i + k - 1] - h[i]);
            }

            yield return minDiff;
        }
    }
}


namespace Yorukatsu024
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu024.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu024.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 15584
import java.util.*;
import java.lang.*;

public class Main {
    static final int INF = (1 << 31) - 1;             
    static final int MAXN = 11111;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int x0, y0, x1, y1, x2, y2;
        int q;
        x0 = input.nextInt();
        y0 = input.nextInt();
        x1 = input.nextInt();
        y1 = input.nextInt();        
        q = input.nextInt();
        for (int i = 0; i < q; ++i) {
            x2 = input.nextInt();
            y2 = input.nextInt();
            int d = ccw(x1 - x0, y1 - y0, x2 - x1, y2 - y1);
            if (d > 0) System.out.println("COUNTER_CLOCKWISE");
            else if (d < 0) System.out.println("CLOCKWISE");            
            else {
                int a2, b2, a1, b1;
                a1 = x1 - x0;
                b1 = y1 - y0;
                a2 = x2 - x0;
                b2 = y2 - y0;
                if (a1 * a2 <= 0 && b1 * b2 <= 0 && (a1 * a1 + b1 * b1 != 0 && a2 * a2 + b2 * b2 != 0)) System.out.println("ONLINE_BACK");
                else if (Math.hypot(a1, b1) < Math.hypot(a2, b2)) System.out.println("ONLINE_FRONT");                                    
                else System.out.println("ON_SEGMENT");
            }                    
        }
    }
    
    static int ccw(int a0, int b0, int a1, int b1) {
        int d = a0 * b1 - a1 * b0;
        return d;
    }
}

Measured memory_bytes: 25148
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){

    int A,B,C,d,e,tmp,f,n;

    cin >> A >> B >> C;

    if(A>=B&&A>=C){
        //max→A
        if(B>C){
        }else{
            tmp =B;
            B=C;
            C=tmp;
        }
    }else if(B>=A&&B>=C){
        //max→B
        if(A>C){
            tmp=A;
            A=B;
            B=tmp;
        }else{
            tmp=A;
            A=B;
            B=C;
            C=tmp;
        }
    }else{
        //max→C
        if(A>B){
            tmp=C;
            C=B;
            B=A;
            A=tmp;
        }else{
            tmp=C;
            C=A;
            A=tmp;
        }
    }//ソート完了 A>B>C

    while(A!=B){
        n+=1;
        B+=1;
        C+=1;
    }

    while(A>C){
        n+=1;
        C+=2;
    }

    if(A!=C){
        n+=1;
    }

    cout << n << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll h,w;cin >> h >>w;
    vector<vector<char>> g(h,vector<char>(w));
    rep(i,h)rep(j,w)cin >> g[i][j];
    UnionFind uf(h*w),black(h*w);
    rep(i,h){
        rep(j,w){
            if(g[i][j]=='#'){
                rep(k,4){
                    ll ny=i+dy[k],nx=j+dx[k];
                    if(ny<0||nx<0||ny>=h||nx>=w)continue;
                    if(g[ny][nx]=='.'){
                        if(!uf.same(ny*w+nx,i*w+j))uf.merge(ny*w+nx,i*w+j);
                        rep(l,4){
                            ll nny=ny+dy[l],nnx=nx+dx[l];
                            if(nny<0||nnx<0||nny>=h||nnx>=w)continue;
                            if(g[nny][nnx]=='#'){
                                if(!black.same(nny*w+nnx,i*w+j))black.merge(nny*w+nnx,i*w+j);
                            }
                        }
                    }
                }
            }
        }
    }
    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(g[i][j]=='.')continue;
            ans+=uf.size(i*w+j)-black.size(i*w+j);
        }
    }
    cout <<ans <<endl;
}

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<string> stat(n), a(n), b(n);
        for(int i = 0; i < n; i++)  cin >> stat[i] >> a[i] >> b[i];
        vector<string> ans;
        while(m-- > 0){
            string x, y, z;
            cin >> x >> y >> z;
            int rule = -1;
            for(int i = 0; i < n; i++){
                bool match = true;
                for(int j = 0; j < 8; j++)  match &= (a[i][j]=='?'||a[i][j]==x[j]);
                for(int j = 0; j < 8; j++)  match &= (b[i][j]=='?'||b[i][j]==y[j]);
                if(match)   rule = i;
            }
            bool permit = false;
            if(rule != -1 && stat[rule] == "permit")    permit = true;
            if(permit){
                stringstream ss;
                ss << x << " " << y << " " << z;
                ans.push_back(ss.str());
            }
        }
        cout << ans.size() << endl;
        for(string s : ans) cout << s << endl;
    }
    return 0;
}



Measured memory_bytes: 3372
package main

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

var distance []int

type queue struct {
	q    []int
	head int
	tail int
}

func (q *queue) push(n int) {
	q.q[q.tail] = n
	q.tail++
}

func (q *queue) pop() int {
	q.head++
	return q.q[q.head-1]
}

func (q *queue) isEmpty() bool {
	return q.head == q.tail
}

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func bfs(graph [][]int, s int) {
	distance = make([]int, len(graph))

	infty := -1
	for i := 0; i < len(distance); i++ {
		distance[i] = infty
	}
	distance[s] = 0

	q := &queue{make([]int, 1000), 0, 0}
	q.push(s)

	for !q.isEmpty() {
		u := q.pop()
		for i := 0; i < len(graph); i++ {
			if graph[u][i] == 0 {
				continue // u, i間に辺がない場合
			}
			if distance[i] != infty {
				continue // 訪問済みの場合
			}
			// 訪問するnodeの始点からの距離を設定し、訪問キューに入れる
			distance[i] = distance[u] + 1
			q.push(i)
		}
	}

	// print distance
	for i, d := range distance {
		fmt.Printf("%d %d\n", i+1, d)
	}
}

func main() {
	adj := makeAdjList()
	bfs(adj, 0)
}



Measured memory_bytes: 1240
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.nextLine();
        // remaining combinations at i with num of picked chars j
        long[][] dp = new long[s.length() + 1][4];
        dp[s.length()][3] = 1;
        for (int i = s.length() - 1; i >= 0; i--) {
            char c = s.charAt(i);
            int cn = charToNum(c);
            long m = c == '?' ? 3 : 1;
            for (int j = 0; j < 3; j++) {
                dp[i][j] = (m * dp[i + 1][j]) % 1_000_000_007;
                if (cn == j || c == '?') {
                    dp[i][j] = (dp[i][j] + dp[i + 1][j + 1]) % 1_000_000_007;
                }
            }
            dp[i][3] = (m * dp[i + 1][3]) % 1_000_000_007;
        }
        System.out.println(dp[0][0]);
    }

    static int charToNum(char c) {
        if (c == '?')
            return Integer.MAX_VALUE;
        return c - 'A';
    }

}

Measured memory_bytes: 32696
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define foro(i, n) for(i=0; i<n; i++)
#define forl(i, n) for(i=1; i<=n; i++)
#define x first
#define y second
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;
int n, a[200];

ll dist(int p){
	ll sum=0;
	int i;
	foro(i, n)
		sum += pow(p - a[i], 2);
	return sum;
}

int main()
{
	int i, j, k, l, tmp;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	//int n;
	ll sum=0;
	cin >> n;
	//int a[n];
	foro(i, n){
		cin >> a[i];
		sum += a[i];
	}
	cout << min(dist(sum/n), dist(sum/n+1)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define INF 10000000000

ll a, b, c, n, m, x, y, z, w, h, ans = 0, cnt = 0, mx = 0, mn = INF;
string s;

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

    cin >> n >> h >> w;
    rep(i, n){
        cin >> a >> b;
        if(a >= h && b >= w){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
main :: IO ()
main = do
    [_, k] <- map read . words <$> getLine
    xs <- map read . words <$> getLine
    print $ solve k xs

solve :: Int -> [Int] -> Int
solve k xs = minimum $ map cost $ zip (drop (k-1) xs) xs

cost :: (Int, Int) -> Int
cost (x, y) -- x > y
    | y < 0 && 0 < x = x - y + (x `min` (-y))
    | x <= 0 = -y
    | y >= 0 = x

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

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  sort(a.rbegin(), a.rend());
  int ans = 0;
  rep(i, N)
  {
    if (i % 2 == 0)
      ans += a[i];
    else
      ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int D;
    cin >> D;
    ll c[26], sum = 0;
    rep(i, 26) {cin >> c[i]; sum += c[i];}
    ll s[D][26];
    rep(i, D){
        rep(j, 26) cin >> s[i][j];
    }
    int pre[26];
    fill(pre, pre+26, -1);
    ld x = 26, p = 1/x;
    ld P[D+1];
    P[0] = 0;
    rep2(i, 1, D){
        P[i] = P[i-1]+p*pow(1-p, i-1)*i;
    }
    int t[D];
    rep(i, D){
        ld tmp[26];
        rep(j, 26){
            tmp[j] = s[i][j] + c[j]*(i-pre[j])*P[D-i];
        }
        int res = -1;
        ld m = -INF;
        rep(j, 26){
            if(chmax(m, tmp[j])) res = j;
        }
        pre[res] = i;
        t[i] = res;
        //cout << res+1 << endl;
    }
    ll tmp = 0;
    set<int> ids[26];
    rep(i, 26) ids[i].insert(-1);
    rep(i, D){
        //cin >> t[i]; t[i]--;
        tmp += s[i][t[i]];
        pre[t[i]] = i;
        ids[t[i]].insert(i);
        rep(j, 26){
            tmp -= c[j]*(i-pre[j]);
        }
    }
    rep(i, 26) ids[i].insert(D);
    rep(k, 10){
        rep(i, D){
            rep(j, 26){
                int d, q;
                //cin >> d >> q;
                d = i, q = j;
                int p = t[d];
                ll ans = tmp-s[d][p]+s[d][q];
                set<int>::iterator it1, it2;
                it1 = ids[p].upper_bound(d);
                it2 = ids[q].upper_bound(d);
                int a1, a2, b1, b2;
                b1 = *it1, b2 = *it2;
                it1--, it1--, it2--;
                a1 = *it1, a2 = *it2;
                ans -= c[p]*(b1-d)*(d-a1);
                ans += c[q]*(b2-d)*(d-a2);
                if(chmax(tmp, ans)){
                    t[d] = q;
                    ids[p].erase(d);
                    ids[q].insert(d);
                }
            }
        }
    }
    rep(i, D) cout << t[i]+1 << endl;
}

Measured memory_bytes: 3744
# -*- coding: utf-8 -*-
"""
Created on Mon Apr  8 15:07:25 2019

@author: adachi-lab
"""

Y = 0
T = []
TT = []
TTT = []
TTTT = []
for i in range(5):
    input_code = int(input())
    T.append(input_code)
    
for q in range(5):
    TT.append(T[q]%10)
    
    if T[q]%10 == 0:
        TTT.append(T[q])
        
    else:
        TTT.append(((T[q]//10)*10)+10)
        
if min(TT) == 0:
    C = TT.count(0)
    for f in range(C):
        W1 = TT.index(min(TT))
        TT[W1] = 9
    
    W = TT.index(min(TT))
    TTT[W] = T[W]
    
else:
    W = TT.index(min(TT))
    TTT[W] = T[W]

for w in range(len(TTT)):
    Y += TTT[w]
    
print(Y)



Measured memory_bytes: 3064
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
using namespace std;



int rm=0;
int chn,n;
int cham;

int main(){
    
    cin>>n;

    int a[100005];

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

    sort(a,a+n);
    a[n]=-1;
    chn=-1;
    for(int i=0;i<=n;i++){


        if(chn==-1){
            chn=a[i];
            cham=0;
        }

        if(chn==a[i]){
            cham++;
        }else{
            if(chn<cham)rm+=cham-chn;
            if(cham<chn)rm+=cham;
            chn=a[i];
            cham=1;

        }

       // cout<<"a"<<a[i]<<"chn"<<chn<<"cham"<<cham<<"rm"<<rm<<endl;
    }
    
    if(!n){cout<<0;return 0;}

    cout<<rm;



    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long int
#define N 3001
using namespace std;
int DP[N][N];

signed main() {
    string a,b;
    cin>>a>>b;
    int n1 = a.size();
    int n2 = b.size();
    string ans;
    for(int i=0;i<=n1;i++)
    {
        bool flag = 1;
        for(int j=0;j<=n2;j++)
        {
            if(i==0 || j==0)
            {
                DP[i][j]=0;
                continue;
            }

            if(a[i-1]==b[j-1] )
            {
                //cout<<i<<" "<<j<<" "<<a[i-1]<<" ";
                DP[i][j] = DP[i-1][j-1]+1;
            }
            else
            DP[i][j] = max(DP[i-1][j], DP[i][j-1]) ;


        }
    }
    int count = DP[n1][n2];
    int x=n1,y=n2;
   while(x!=0 && y!=0)
   {
       if(DP[x][y-1]==count)
       y=y-1;
       else if(DP[x-1][y]==count)
       x = x-1;
       else
       {
           ans = ans+a[x-1];
           x=x-1,y=y-1;
           //77count--;
           //cout<<count<<" "<<DP[x][y]<<endl;
           count = DP[x][y];
       }
   }

   reverse(ans.begin(),ans.end());
   cout<<ans;

    return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <list>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int search(int A[],int n,int key){

    int i=0;
    A[n]=key;
    while(A[i] != key) i++;
    return i != n;

}


int main() {
    int n,s[10001],q,key,sum=0,i;

    cin >> n;
    for(i=0;i<n;i++){
        cin >> s[i];
    }

    cin >> q;
    for(i=0;i<q;i++){
        cin >> key;
        if(search(s,n,key)) sum++;
    }

    cout << sum << endl;


    return 0;

}

Measured memory_bytes: 3132
#include <cstdio>
#include <algorithm>
#include <limits>

constexpr int INF_I = std::numeric_limits<int>::max();
constexpr int MAX_N = 100000;

int main(){
    int N;
    int L[MAX_N];
    std::fill(L, L + MAX_N, INF_I);
    scanf("%d", &N);
    for(int i = 0; i < N; ++i){
        int A;
        scanf("%d", &A);
        *std::lower_bound(L, L + N + 1, A) = A;
    }
    printf("%d\n", std::lower_bound(L, L + N, INF_I) - L);
    return 0;
}

Measured memory_bytes: 3116
fun main(args: Array<String>) {
  val (X, Y) = readLine()!!.split(" ").map{it.toInt()}
  
  fun calcLegNum(kame: Int = 0, head: Int = X, leg: Int = Y): String {
    return if((head - kame) * 2 + kame * 4 == leg) "Yes" else if(kame > X) "No" else calcLegNum(kame + 1)
  }
  val result = if(Y % 2 != 0 || X * 4 < Y) "No" else calcLegNum()
  
  println(result)
}

Measured memory_bytes: 36456
#include <stdio.h>

int A[100001];
int par(int[],int,int);

int main(){
  int n,i,p,r,x;

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  p=1;
  r=n;
  x=par(A,p,r);
  

  for(i=1;i<=n;i++){
    if(i==x){
      printf("[%d]",A[i]);
    } else {
      printf("%d",A[i]);
    }
    if(i<n){
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}

int par(int A[],int p,int r){
  int x,i,j,s;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i =i+1;
      s=A[i];
      A[i]=A[j];
      A[j]=s;
    }
  }
  s=A[i+1];
  A[i+1]=A[r];
  A[r]=s;
  return i+1;
}

Measured memory_bytes: 992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int A,B,X; cin>>A>>B>>X;
  double P,Q,R,ans;
  P=X*2.0/A/B;
  if(P<=(double)A)
    Q=B/P;
  else{
    X=A*B*A-X;
    P=X*2.0/A/A;
    Q=P/A;
  }
  R=atan(Q);
  ans=R*180.0/M_PI;
  printf("%.10lf\n",ans);
  }



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {

    int n, x;
    cin >> n >> x;

    int ans = 0;
    int mi = 9999999;

    for(int i = 0; i < n; ++i){
        int m;
        cin >> m;
        x -= m;
        ++ans;
        mi = min(m, mi);
    }

    cout << ans + x/mi << endl;

}

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

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var str = Console.ReadLine();
                if (string.IsNullOrEmpty(str)) return;
                var a = str.Split(' ').Select(s => int.Parse(s));
                var g = gcd(a.ElementAt(0), a.ElementAt(1));
                var l = lcm(a.ElementAt(0), a.ElementAt(1), g);
                Console.WriteLine("{0} {1}", g, l);
            }
        }

        static int gcd(int a, int b)
        {
            if (a == 0 || b == 0) return 0;
            while (a != b)
            {
                if (a > b) a -= b;
                else b -= a;
            }
            return a;
        }

        static int lcm(int a, int b, int gcd)
        {
            if (a == 0 || b == 0) return 0;
            return (a / gcd) * b;
        }
    }
}

Measured memory_bytes: 18196
x,k,d = map(int,input().split())

cur = abs(x)#座標は正に
rem = k#残り移動回数

cnt = min(cur//d,rem)#0に向かって移動する回数
cur -= d*cnt #0にできる限り近づいた値
rem -= cnt

if rem > 0 :#残りがまだ残っている場合
    if rem % 2 ==1:#奇数なら1回負方向に移動するのが最小、偶数の場合は行ったり来たり往復なので同じ位置が最小
        cur -= d
ans = abs(cur)
print(ans)
    

Measured memory_bytes: 9100
#include <stdio.h>

int max(int a,int b){
    if(a > b){
        return a;
    }
    else{
        return b;
    }
}
 
int main(void){
    int N,M;
    int H[100001];
    int flag[100001] = {};
    
    scanf("%d%d",&N,&M);
    
    for(int i = 1; i <= N; i++){
        scanf("%d",&H[i]);
    }
    
    for(int i = 0; i < M; i++){
        int A,B;
        scanf("%d%d",&A,&B);
        flag[A] = max(flag[A],H[B]);
        flag[B] = max(flag[B],H[A]);
    }
    
    int cnt = 0;
    for(int i = 1; i <= N; i++){
        if(H[i] > flag[i]){
            cnt++;
        }
    }
    
    printf("%d\n",cnt);
}

Measured memory_bytes: 2488
s = 'HAKUTYUMU' + input()


while s != 'HAKUTYUMU':
    next_s = s

    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]

    if s == next_s:
        print('NO')
        exit()

    s = next_s

print('YES')


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

//void trial_1_2(int *G,int *water,int *AorB);
//void trial_3_4(int *G,int *sugar,int *CorD);

int main(){
	int A,B,C,D,E,F;
	/*A=水100A[g] B=水100B[g] C=砂糖C[g] D=砂糖D[g]
	 *
	 E=100gあたり溶ける量 F=限界質量*/
	int water[50000],sugar[100000];//総質量 水の質量 砂糖の質量
	int i,j,n=0,m=0,k=0,t,flag=0;
	int con[50000],res_Atmp[50000],res_Btmp[50000],res_tmp;//濃度と一次変数
	cin>>A>>B>>C>>D>>E>>F;
	for(i=0;A*100*i<F;i++){
		for(j=0;;j++){
			flag=0;
			if(A*100*i+B*100*j>F)break;
			for(t=0;t<n;t++){
				if(A*100*i+B*100*j==water[t]){
					flag=1;
				}
			}
			if(flag==1)continue;
			water[n]=A*100*i+B*100*j;
			//cout<<"water["<<n<<"]="<<water[n]<<endl;
			n++;
			//cout<<"water[0]="<<water[0]<<endl;
		}
	}
	for(i=0;C*i<F;i++){
		for(j=0;;j++){
			flag=0;
			if(C*i+D*j>F){
				//cout<<"tes"<<endl;
				break;
			}
			for(t=0;t<m;t++){
				if(C*i+D*j==sugar[t]){
					flag=1;
				}
			}
			if(flag==1)continue;
			sugar[m]=C*i+D*j;
			//cout<<m<<"回目"<<endl;
			//cout<<water[m]<<endl;
			m++;
		}
	}
	/*cout<<n<<endl;
	cout<<m<<endl;
*/
	/*for(t=0;t<m;t++){
		cout<<sugar[t]<<endl;
	}*/

	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			//cout<<"i="<<i<<endl;
			//cout<<water[i]<<endl;
			//cout<<sugar[j]<<endl;
			//cout<<"水="<<water[i]<<" 砂糖="<<sugar[j]<<endl;
			//cout<<"解けたかどうか＝"<<(water[i]/100)*E-sugar[j]<<endl;
			//cout<<"水+砂糖="<<water[i]+sugar[j]<<endl;
			if(((water[i]/100)*E-sugar[j])<0||water[i]+sugar[j]>F){
				//cout<<"水="<<water[i]<<" 砂糖="<<sugar[j]<<endl;
				//cout<<i<<"回目"<<endl;
				continue;
			}
			if(water[i]+sugar[j]==0){
				//cout<<i<<"回目"<<endl;
				//cout<<"水="<<water[i]<<" 砂糖="<<sugar[j]<<endl;
				continue;
			}
			con[k]=(10000*sugar[j])/(water[i]+sugar[j]);
			//cout<<con[k]<<endl;
			res_Atmp[k]=water[i]+sugar[j];
			res_Btmp[k]=sugar[j];
			//cout<<res_Atmp[k]<<res_Btmp[k]<<endl;
			k++;
		}
	}

	/*for(t=0;t<m;t++){
		cout<<con[t]<<endl;
	}*/
	res_tmp=0;n=0;m=0;
	for(i=0;i<k;i++){
		if(res_tmp<con[i]){
			res_tmp=con[i];
			m=n;
		}
		n++;
	}
	i=res_Atmp[m]; j=res_Btmp[m];
	//cout<<con[1]<<endl;
	printf("%d %d",i,j);
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S;
    cin >> S;
    if(S.substr(5,2) == "01" || S.substr(5,2) == "02" || S.substr(5,2) == "04" || S.substr(5,2) == "04"){
        cout << "Heisei" << endl;
    }
    else cout << "TBD" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();

        int i;
        for (i=0;i< s.Length; i++)
        {
            if(i%2 == 0 && s.Substring(i,1).Equals("L"))
            {
                Console.WriteLine("No");
                return;
            }
            if (i % 2 == 1 && s.Substring(i, 1).Equals("R"))
            {
                Console.WriteLine("No");
                return;
            }

        }
        Console.WriteLine("Yes");
        return;

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, Q;
vector <int> G[1000005];
int value[1000005];
int tmp = 0;

void dfs(int v, int p = -1) {
    int old = tmp;
    tmp += value[v];
    value[v] = tmp;
    for(auto u: G[v]) if(u != p) {
        dfs(u, v);
    }
    tmp = old;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> N >> Q;
    for(int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    while(Q --> 0) {
        int p, x;
        cin >> p >> x;
        value[p] += x;
    }
    dfs(1);
    for(int i = 1; i <= N; i++)
        cout << value[i] << " ";
}

Measured memory_bytes: 44160
import sys

p = [0] * 51
for i in range(19):
    p[i] = p[36-i] = (i+3)*(i+2)*(i+1)//6 - max(2*(i-9)*(i-8)*(i-7)//3,0)

for i in sys.stdin:
    print(p[int(i)])

Measured memory_bytes: 7540
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        long M = int.Parse(str[0]);
        long N = int.Parse(str[1]);
        sb.Append(Pow(M,N)+"\n");
    }
    long Pow(long X,long Y){
        if(Y == 0){
            return 1;
        }
        else if(Y % 2 == 0){
            long XX = Pow(X,Y/2);
            return XX*XX%Define.mod;
        }
        else{
            return X*Pow(X,Y-1)%Define.mod;
        }
    }
}
public static class Define{
    public const long mod = 1000000007;
}

Measured memory_bytes: 9188
var
  n,i,j,m,ans:longint;
  s:string;
  ch:char;
  b1,b2,b3:boolean;
begin
  readln(n);
  if n=23 then writeln('Christmas Eve Eve');
  if n=22 then writeln('Christmas Eve Eve Eve');
  if n=24 then writeln('Christmas Eve');
  if n=25 then writeln('Christmas');
end.


Measured memory_bytes: 128
import sys
from fractions import gcd
import bisect
 
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
s = [ni() for _ in range(n)]
print(int(sum(s) - max(s)/2))

Measured memory_bytes: 5316
import java.util.Scanner;

class Main{
  public static void main(String[] args) {
    int S, h, m, s;

    Scanner scan = new Scanner(System.in);

    S = scan.nextInt();
    h = S/3600;
    m = (S%3600)/60;
    s = (S%3600)%60;


    System.out.println(h +":"+ m +":" + s);

  }
}



Measured memory_bytes: 26204
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n,a,now=2;
	long long ans=0;
	scanf("%d%d",&n,&a);
	ans+=a-1;
	for(int i=1;i<n;i++)
	{
		scanf("%d",&a);
		if(a>now)
			ans+=(a-1)/now;
		else if(a==now)
			now++;
	}
	printf("%lld",ans);
	return 0;
}

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

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

   int count = 0;
   vector<int> v(n);

   for (int i = 0; i < n; i++)
   {
      cin >> v.at(i);
   }

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

   for (int i = 0; i < n - 2; i++)
   {
      for (int j = i; j < n - 1; j++)
      {
         for (int k = j; k < n; k++)
         {
            if (v.at(i) + v.at(j) > v.at(k) &&v.at(i)!=v.at(j)&& v.at(i)!=v.at(k)&&v.at(j)!=v.at(k))
            {
               count++;
            }
         }
      }
   }
   cout << count << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mode 1000000007
#define inf 1000000000000000007
#define eps 0.00000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(20)//use fixed before stp
#define endl '\n'
int main()
{  
    FAST
    ll n,m;
    cin>>n>>m;
    ll min=0,max=inf;
    ll l,r;
    for(ll i=0;i<m;i++)
    {
        cin>>l>>r;
        if(l>min)
            min=l;
        if(r<max)
            max=r;
    }
    ll ans=max-min+1;
    if(ans<0)
        ans=0;
    cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b;

ll dfs(ll d,ll h){
  if(d==n)return b;
  ll H=(1LL<<(n-1-d));
  ll W=(1LL<<d);
  if(h<H){
    ll f=dfs(d+1,H-1-h);
    printf( f<W ? "L" : "R" );
    return W-(f%W)-1;
  }else{
    ll f=dfs(d+1,h-H);
    if( f < W ){
      printf("R");
      return f;
    }else{
      printf("L");
      return f-W;
    }
  }
}

int main(){
  while(1){
    scanf("%lld %lld %lld",&n,&a,&b);
    if(n==0&&a==0&&b==0)break;
    a--;
    b--;
    dfs(0,a);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string a;
  cin>>a;
  for(int i=0;i<3;i++){
    if(a[i]=='1'){
      a[i]='9';
    }
    else{
      a[i]='1';
    }
  }
  cout<<a<<"\n";
  
  return 0;
}

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

using namespace std;

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

  int i = 1;
  while(N--) {
    if (i * 2 < i + K) {
      i *= 2;
    } else {
      i += K;
    }
  }

  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256
// 5/31
// 2-6-1. 線分状の格子点の個数
// 類題
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;

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

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

    vector<int> A(N);
    int Amax = -1;
    rep(i, N) {
        cin >> A[i];
        Amax = max(Amax, A[i]);
    }

    int g = A[0];
    for (int i = 1; i < N; i++) {
        g = gcd(g, A[i]);
    }

    if (K % g == 0 && K <= Amax) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> a_i(M), b_i(M), ways(N);
  
  for (int i=0;i<M;i++){
    cin >> a_i.at(i) >> b_i.at(i);
    
    for (int j=0;j<N;j++){
      if ( a_i.at(i)==j+1 || b_i.at(i)==j+1 )
        ways.at(j)++;
    }
  }
  for (int i=0;i<N;i++)
    cout << ways.at(i) << endl;
}

Measured memory_bytes: 3576
N = int(input())
W = list(map(int, input().split()))


suma = 0
sumb = 0
list = []
list2 = []
list3 = []
for i in range(N - 1):
    a = suma + W[i]
    suma = a
    list.append(a)

W.reverse()
for i in range(N - 1):
    b = sumb + W[i]
    sumb = b
    list2.append(b)

list2.reverse()
for i in range(N - 1):
    list3.append(abs(list2[i] - list[i]))

list3.sort()
print(list3[0])

Measured memory_bytes: 3064
Sa=input()
Sb=input()
Sc=input()
turn = 'a'
d = {'a':Sa,'b':Sb,'c':Sc}
while True:
    if d[turn]=='':
        print(turn.upper())
        break
    next = d[turn][0]
    d[turn] = d[turn][1:]
    turn = next

Measured memory_bytes: 3060
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = 110000;
vi e[maxn];

bool ans = false;

bool dfs(int v, int p) {
    int ch = 0;
    for (int u: e[v]) {
        if (u == p) continue;
        if (!dfs(u, v)) ++ch;
    }
    if (ch > 1) ans = true;
    return ch;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    forn(i, n - 1) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        e[x].pb(y);
        e[y].pb(x);
    }

    if (!dfs(0, -1)) ans = true;
    cout << (ans ? "First" : "Second") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 6016
//Har Har Mahadev
using namespace std;
#include <bits/stdc++.h>
#define booga cout << "booga" << endl
#define ll long long int
#define pb push_back
#define mp make_pair
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " -> " << a << endl;
	err(++it, args...);
}

void testcase(){
	ll k,x,d;
	cin >> x >> k >> d;
	x = abs(x);
	if(k <= x/d){
		cout << x - (k*d);
		return;
	}
	k -= (x/d);
	x %= d;
	if(k&1){
		cout << d-x;
	}
	else{
		cout << x;
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int chk = 0;
  int n,m;
  cin >> n >> m;
  int i;
  int a[m];
  int b[m];
  int from1[n+1]={};
  int toN[n+1]={};
  for(i=0;i<m;i++){
    cin >> a[i] >> b[i];
    if(a[i]==1)from1[b[i]]++;
    if(b[i]==n)toN[a[i]]++;
  }
  for(i=1;i<=n;i++){
    if(from1[i]>0 && toN[i]>0)chk=1;
  }
  




  
  if(chk==1)cout << "POSSIBLE";
  else cout << "IMPOSSIBLE";
  
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

map<ll,ll> M;

int main(){
    ll N;
    cin >> N;
    ll C=N/11;
    if(N%11>6){
        cout << 2*C+2 << endl;
    }
    else if(N%11==0){
        cout << 2*C << endl;
    }
    else{
        cout << 2*C+1 << endl;
    }
}


Measured memory_bytes: 256
import itertools

N = int(input())

if N%4 ==0 or N%7 ==0:
  print('Yes')
  exit()
else:
  i = itertools.product(range(N//4+1),range(N//7+1))
  

c = [a for a in i]
for i in c:
  if i[0]*4+i[1]*7 == N:
    print('Yes')
    exit()
  else:
    continue

print('No')    


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
//#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111




	void solve(){


		
		ini(x1);
		ini(x0);
		ini(x_1);
		int rick = 0;
		ini(k);
		if(k>x1){
			rick+=x1;
			k-=x1;
			if(k>x0){
				k-=x0;
				rick-=k;
				return out(rick);
			}
			else{
				return out(rick);
			}
		}
		else{
			return out(k);
		}
		









	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 3636
S = input()
K = input()
k =int(K)
flag = 0
for i in range(len(S)):
    if S[i] =="1":
        if i == k-1:
            break
        continue
    elif S[i] =="2":
        print("2")
        flag = 1
    elif S[i] =="3":
        print("3")
        flag = 1
    elif S[i] =="4":
        print("4")
        flag = 1
    elif S[i] =="5":
        print("5")
        flag = 1
    elif S[i] =="6":
        print("6")
        flag = 1
    elif S[i] =="7":
        print("7")
        flag = 1
    elif S[i] =="8":
        print("8")
        flag = 1
    elif S[i] =="9":
        print("9")
        flag = 1

    break
if flag == 0:
    print("1")

Measured memory_bytes: 3064
use proconio::input;
 
fn main() {
    input! {
        a: usize,
        b: usize,
        n: usize,
    }
 
    println!("{}", f(a, b, n.min(b-1)));
}
 
fn f(a: usize, b: usize, x: usize) -> usize {
    a * x / b - a * (x / b)
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> lnum;
#define forn(i,a,b) for(ll i=(a);i<(b); ++i)
#define nfor(i,b,a) for(ll i=(b-1);i>=a;--i)

#define ifile freopen("input.txt", "r", stdin)
#define ofile freopen("output.txt", "w", stdout)
#define fast ios_base::sync_with_stdio(0);\
             cin.tie(0);\
             cout.tie(0);
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ll_min LONG_LONG_MIN
#define ll_max LONG_LONG_MAX
#define _1 first
#define _2 second
#define sqr(a) ((a)*(a))
#define sez(v) ((int)(v.size()))
const ld PI = 3.141592653589793238462643383279;
const ld EPS = 1e-8;
const int NONE = 1e9 + 7;
const ll MOD = 1e9;
const int base = 1000*1000*1000;
const int LOG=20;
const ll maxn = 4e5+2;
const ll HASH_MODS[] = { 1000000007333ll,1000000009367ll, 1000000075747ll, 1000000158923ll, 1000000203119ll };
//////////////////////////////////////////////////////////////////////////////////////////////////////////
ll a[maxn];
int main(){
    int n;
    cin>>n;
    n*=3;
    forn(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    ll ans=0;
    int cnt=0;
    for(int i=n-2;cnt<n/3; i-=2){
          //  cout<<a[i]<<"\n";
            cnt++;
            ans+=a[i];
    }
    cout<<ans;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    string x, y; cin >> x >> y;
    if (x < y) cout << '<' << endl;
    else if (x > y) cout << '>' << endl;
    else cout << '=' << endl;
}

Measured memory_bytes: 256