akhauriyash/Code-Regression huggingface dataset:
import heapq
N,K = map(int,input().split())

L = [[] for _ in range(N)]
All = []
s = set([])
for i in range(N):
  t,d = map(int,input().split())
  t-=1 #0スタートに
  heapq.heappush(L[t], -d) #最大から取り出したいので負にする。
  heapq.heappush(All,[-d,t]) #すべてから大きい順に取り出せるように 
  s.add(t)

#print(L,s)
point = 0
ns = 0 #現在の種類
later = []
now = []
syurui = set([])
while len(now) < K and All:
  temp = heapq.heappop(All)
  if temp[1] not in syurui:
    ns += 1
    point -= temp[0]
    syurui.add(temp[1])
    heapq.heappush(now, -1*temp[0])
  else:
    later.append(temp)
for i in later:
  heapq.heappush(All,i)

point += ns*ns
while len(now) < K:
  temp = heapq.heappop(All)
  point -= temp[0]
  heapq.heappush(now, -1*temp[0])

#print(ns,point)
#print(now,All,All[0][0])
while All and now[0] < -1*All[0][0]:
  temp = heapq.heappop(All)
  dele = heapq.heappop(now)
  #print(temp,dele)
  upoint = point - temp[0] - dele - ns*ns + (ns-1)**2
  #print(upoint,point)
  if upoint >= point:
    point = upoint
    ns -= 1
  else:
    break
    
print(point)
#print(All)
#print(now)
  

Measured memory_bytes: 41552
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
    static void solve(int arr[],int k){
        
        int t[]=new int[k+1];
        
        for(int i=1;i<=k;i++){
            
            for(int j=0;j<arr.length;j++){
                
                if(i-arr[j]>=0){
                    if(t[i-arr[j]]==0){
                        t[i]=1;
                        
                        break;
                    }
                }
                
            }
            
           
            
        }
        
        if(t[k]==0){
        System.out.println("Second");
        }
        else{
            System.out.println("First");
        }
        
    }
    
    
    
    
    
	public static void main (String[] args) throws java.lang.Exception
	{
	
	Scanner s=new Scanner(System.in);
	int n=s.nextInt();
	int k=s.nextInt();
	
	int arr[]=new int[n];
	
	for(int i=0;i<arr.length;i++){
	    arr[i]=s.nextInt();
	}
	solve(arr,k);
	
	
	
	
	}
}


Measured memory_bytes: 23764
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < N; ++i) {
		string S; cin >> S;
		if (S == "AC") ++ac;
		if (S == "WA") ++wa;
		if (S == "TLE") ++tle;
		if (S == "RE") ++re;
	}
	cout << "AC x " << ac << nl;
	cout << "WA x " << wa << nl;
	cout << "TLE x " << tle << nl;
	cout << "RE x " << re << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3632
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::input;
//use proconio::marker::Usize1;
use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;

const M: u64 = 1000_000_007;

fn main() {
    input! {
        k:u64,
        s:Chars
    }
    let n = s.len();
    // 最後の文字以降におく文字数をiとすると、
    // 文字のえらび方は、25.pow(k-i)*26.pow(i)
    // また、n-1 文字の挿入位置は (k-i+n-1 choose n-1)
    // n choose k = n*(n-1)*...*(n-k+1) /(k*...*1) なので、
    // あとは、各iについて、合計すればよい。
    let mut fact = vec![1u64; 2000010];
    let mut inv_fact = vec![1u64; 2000010];
    fact[0] = 1;
    for i in 0..2000005 {
        fact[i + 1] = fact[i] * ((i + 1) as u64) % M;
        inv_fact[i] = modInv(fact[i]);
    }
    let mut ans = 0u64;
    for i in 0..k + 1 {
        ans += choose(n + (k as usize) - (i as usize) - 1, n - 1, &fact, &inv_fact)
            * modPow(25u64, k - i as u64)
            % M
            * modPow(26u64, i as u64)
            % M;
    }
    println!("{}", ans % M);
}
fn choose(n: usize, k: usize, fact: &Vec<u64>, inv_fact: &Vec<u64>) -> u64 {
    fact[n as usize] * inv_fact[n - k] % M * inv_fact[k] % M
}
fn modPow(x: u64, a: u64) -> u64 {
    if a == 0 {
        1
    } else {
        if a == 1 {
            x
        } else {
            if a % 2 != 0 {
                (modPow(x, a - 1) * x) % M
            } else {
                let t = modPow(x, a / 2);
                t * t % M
            }
        }
    }
}
fn modInv(x: u64) -> u64 {
    modPow(x, M - 2)
}


Measured memory_bytes: 38124
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int l, r, d;
  cin>>l>>r>>d;
  int ans = 0;
  FORe(i, l, r) {
    if(i % d) continue;
    ans++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        // 主処理
        boolean judge = s.equals("ABC");
        String result = judge ? "ARC" : "ABC";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35732
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
    //code here...
    
    ll k, num=  7, ans=1;
    
    cin >> k;
    
    if(k%2==0 || k%5==0){
		cout << "-1\n";
		return;
	}
	
	
	while(1){
		if(num%k==0){
			cout << ans << "\n";
			return;
		}
		if(ans>k){
			cout << "-1\n";
			return;
		}
		
		num = (num%k)*10 + 7;
		ans++;
	}
}


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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}


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

using namespace std;

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

    unsigned long long int ans = 0;
    if (N >= K) {
        ans += ((N-K)/K+1)*((N-K)/K+1)*((N-K)/K+1);
    }

    if (K%2==0 && N >= K/2) {
        ans += ((N-K/2)/K+1)*((N-K/2)/K+1)*((N-K/2)/K+1);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;scanf("%d",&n);
	int c=0,a=0;
	for(int i=1;i<=n;i++){
		int x;scanf("%d",&x);
		if(x==i){
			c++;
		}
		else{
			a+=(c+1)/2;c=0;
		}
	}
	a+=(c+1)/2;
	printf("%d\n",a);
}

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

int main() {

	int tate, yoko, sikaku;
	int row, column, twice;

	cin >> tate >> yoko;
	sikaku = tate * yoko;
	
	cin >> row >> column;
	twice = row * column;

	sikaku -= (row*yoko) + (column*tate);
	sikaku += twice;

	cout << sikaku << endl;

	return 0;
}

Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n, k = map(int, input().split())
x = [0]*((10**5)+1)
for i in range(n):
    a, b = map(int, input().split())
    x[a] += b
y = 0
for i in range(len(x)):
    y += x[i]
    if y >= k:
        print(i)
        exit()


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

int H, W;
int sx, sy, gx, gy;
int dp[1009][1009];
char c[1009][1009];

int main() {
	// 入力
	cin >> H >> W;
	cin >> sx >> sy >> gx >> gy;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) cin >> c[i][j];
	}

	// 初期化
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) dp[i][j] = (1 << 30);
	}
	queue<pair<int, int>> Q, Q2;
	Q.push(make_pair(sx, sy));
	dp[sx][sy] = 0;

	// 本質部分
	while (!Q.empty()) {
		// Step #1. 隣接するマスに移動
		while (!Q.empty()) {
			int px = Q.front().first, py = Q.front().second; Q2.push(Q.front()); Q.pop();
			int dx[4] = { -1, 0, 1, 0 };
			int dy[4] = { 0, 1, 0, -1 };
			for (int i = 0; i < 4; i++) {
				int ex = px + dx[i], ey = py + dy[i];
				if (ex <= 0 || ey <= 0 || ex > H || ey > W || c[ex][ey] == '#') continue;
				if (dp[ex][ey] > dp[px][py]) {
					dp[ex][ey] = dp[px][py];
					Q.push(make_pair(ex, ey));
				}
			}
		}

		// Step #2. ワープホールを使う
		while (!Q2.empty()) {
			int px = Q2.front().first, py = Q2.front().second; Q2.pop();
			for (int i = -2; i <= 2; i++) {
				for (int j = -2; j <= 2; j++) {
					int ex = px + i, ey = py + j;
					if (ex <= 0 || ey <= 0 || ex > H || ey > W || c[ex][ey] == '#') continue;
					if (dp[ex][ey] > dp[px][py] + 1) {
						dp[ex][ey] = dp[px][py] + 1;
						Q.push(make_pair(ex, ey));
					}
				}
			}
		}
	}

	if (dp[gx][gy] == (1 << 30)) cout << "-1" << endl;
	else cout << dp[gx][gy] << endl;
	return 0;
}

Measured memory_bytes: 8552
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int rooms[4][3][10];
    int n,b,r,f,v;
    cin>>n;
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                rooms[i][j][k]=0; 
            }
        }
    }
    for(int i=0;i<n;i++){
        cin>>b>>r>>f>>v;
        rooms[b-1][r-1][f-1]=rooms[b-1][r-1][f-1]+v;
        
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++){
                if(k==9){
                    cout<<" "<<rooms[i][j][k]<<endl;
                }
                else{
                        cout<<" "<<rooms[i][j][k];
                }
            }
        }
        if(i!=3){
            cout<<"####################"<<endl;;
        }
    } 
}



Measured memory_bytes: 3088
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> map(H, vector<char>(W));
	vector<vector<int>> L(H, vector<int>(W));
	vector<vector<int>> R(H, vector<int>(W));
	vector<vector<int>> U(H, vector<int>(W));
	vector<vector<int>> D(H, vector<int>(W));
	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			char c;
			cin >> c;
			map[h][w] = c;
		}
	}
	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			if (map[h][w] == '#') {
				U[h][w] = 0;
				L[h][w] = 0;
			}
			else {
				if (h != 0) {
					U[h][w] = U[h - 1][w] + 1;
				}
				else {
					U[h][w] = 1;
				}

				if (w != 0) {
					L[h][w] = L[h][w - 1] + 1;
				}
				else {
					L[h][w] = 1;
				}
			}


			int _h = H - 1 - h;
			int _w = W - 1 - w;
			if (map[_h][_w] == '#') {
				D[_h][_w] = 0;
				R[_h][_w] = 0;
			}
			else {
				if (_h != H - 1) {
					D[_h][_w] = D[_h + 1][_w] + 1;
				}
				else {
					D[_h][_w] = 1;
				}

				if (_w != W - 1) {
					R[_h][_w] = R[_h][_w + 1] + 1;
				}
				else {
					R[_h][_w] = 1;
				}
			}
		}
	}


	int Lamp = 0;
	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			Lamp = max(Lamp, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
		}
	}

	cout << Lamp << endl;

	return 0;
}

Measured memory_bytes: 67200
a={0}
_,*s=range(10)
while s:
  v=s.pop()
  a|={v}
  for w in range(max(0,v%10-1),min(10,v%10+2)):
    w+=v*10
    if w<4e9:s+=w,
print(sorted(a)[int(input())])

Measured memory_bytes: 12284
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest;
  l=2*i;
  r=2*i+1;

  if(l <= H && A[l] > A[i]) largest=l;
  else largest=i;
  if(r <= H && A[r] > A[largest]) largest=r;

  if(largest != i)
  {
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }
}

int main(){
  cin >> H;

  for(int i=1; i<=H; i++) cin >> A[i];

  for(int i=H/2; i>=1; i--) maxHeapify(i);

  for(int i=1; i<=H; i++)
  {
    cout << " " << A[i];
  }
  cout << endl;

  return 0;
}



Measured memory_bytes: 5040
s = str(input())
s1 = s[:2]
s2 = s[2:]

ans = 'NA'
if 0 < int(s1) <= 12 and 0 < int(s2) <= 12:
    ans = 'AMBIGUOUS'
if 0 < int(s1) <= 12 and int(s2) > 12:
    ans = 'MMYY'
if int(s1) > 12 and 0 < int(s2) <= 12:
    ans = 'YYMM'
if 0 < int(s1) <= 12 and int(s2) == 0:
    ans = 'MMYY'
if int(s1) == 0 and 0 < int(s2) <= 12:
    ans = 'YYMM'

print(ans)


Measured memory_bytes: 38484
Q = int(input())
MOD = 10 ** 6 + 3

P = 2 * MOD
fact = [0] * P
fact[0] = 1
for i in range(1, P):
    fact[i] = fact[i - 1] * i
    fact[i] %= MOD

rfact = [0] * P
rfact[P - 1] = pow(fact[P - 1], MOD - 2, MOD)
for i in range(P - 2, -1, -1):
    rfact[i] = rfact[i + 1] * (i + 1)
    rfact[i] %= MOD

for i in range(Q):
    x, d, n = map(int, input().split())
    if d == 0:
        print(pow(x, n, MOD))
    else:
        rd = pow(d, MOD - 2, MOD)
        rx = (rd * x) % MOD
        if rx == 0:
            print(0)
        elif rx + n - 1 >= MOD:
            print(0)
        else:
            print((fact[rx + n - 1] * pow(fact[rx - 1], MOD - 2, MOD) * pow(d, n, MOD)) % MOD)

Measured memory_bytes: 85340
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 1001001001
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;
 

int main(){
    int ans = 0;
    int MAX = 0;
    rep(i,3){
        int x; cin >> x;
        ans += x;
        MAX = max(MAX, x);
    }
    cout << ans - MAX << endl;


}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 2
5 1 4
2 3
1 5"""
        output = """14"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4"""
        output = """338"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3 2
100 100 100
3 99
3 99"""
        output = """300"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """11 3
1 1 1 1 1 1 1 1 1 1 1
3 1000000000
4 1000000000
3 1000000000"""
        output = """10000000001"""
        self.assertIO(input, output)

def resolve():
    (N,M)=(int(i) for i in input().split())
    A=[int(i) for i in input().split()]
    A.sort()
    BC=[[int(i) for i in input().split()] for i in range(M)]
    BC.sort(key=lambda x: x[1] , reverse=True)
    fst=0
    for i in BC:
        cnt=i[0]
        val=i[1]
        while  cnt>0:
            if fst>=N:
                break
            if A[fst]<val:
                A[fst]=val
                cnt-=1
                fst+=1
            else:
                break
        else:
            continue
        break
    print(sum(A))



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 94228
using System;
using System.Linq;
using System.Collections.Generic;

namespace MSPC2020
{
    class A
    {
        static void Main(string[] args)
        {
            //var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var LRd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var X = int.Parse(Console.ReadLine());
            //var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

            if (400 <= X && X <= 599) Console.WriteLine("8");
            if (600 <= X && X <= 799) Console.WriteLine("7");
            if (800 <= X && X <= 999) Console.WriteLine("6");
            if (1000 <= X && X <= 1199) Console.WriteLine("5");
            if (1200 <= X && X <= 1399) Console.WriteLine("4");
            if (1400 <= X && X <= 1599) Console.WriteLine("3");
            if (1600 <= X && X <= 1799) Console.WriteLine("2");
            if (1800 <= X && X <= 1999) Console.WriteLine("1");

        }
    }
}


Measured memory_bytes: 27492
package main

import (
	"fmt"
	"strconv"
//	"sort"
//	"math"
//	"regexp"
)


var s string
var ans int

func main(){
	fmt.Scan(&s)
	var n int = len(s)-2
	var t string = string(s[0]) + strconv.Itoa(n) + string(s[len(s)-1])
	fmt.Println(t)

}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};



signed main() {
	int n;
	scanf("%d", &n);
	int ans = 0;
	REP(i, n) {
		ans += i+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { A: number, B: number, C: number } => {
  const [A, B, C] = lines[0].split(' ').map(line => +line)
  const obj = { A, B, C }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { A, B, C } = parseLines(lines)
  let answer = C - (A - B)
  answer = answer < 0 ? 0 : answer
  return `${answer}`
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


Measured memory_bytes: 7500
N = int(input())
T = list(map(int, input().split()))
M = int(input())
X = [[] for _ in range(M)]
for i in range(M):
    X[i] = list(map(int, input().split()))

total = sum(T)
for i in range(M):
    print(total -T[X[i][0]-1] +X[i][1])


Measured memory_bytes: 38384
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

int n;

int main(){
    scanf("%d" , &n);
    n--;
    long long sm = 1ll * n * (n + 1ll) / 2;
    printf("%lld\n" , sm);
}


Measured memory_bytes: 256
import collections, heapq, math, sys

n, k = map(int, sys.stdin.readline().rstrip().split(' '))
dislikes = map(int, sys.stdin.readline().rstrip().split(' '))
dislikess= set(dislikes)
for i in range(9):
  if i not in dislikess:
    smallest = i
    break
cp = n
s = []
while cp:
  s.append(cp%10)
  cp //= 10
s.append(0)
idx = -1
found = True
for i in range(len(s)):
  z = s[i]
  if i == len(s) - 1:
    if not found:
        if smallest == 0:
            for m in range(1, 10):
                if m not in dislikess:
                    s[i] = m
                    break
        else:
            s[i] = smallest
        idx = i-1
    break
  if not found or z in dislikess:
    found = False
    for j in range(z+1, 10):
      if j not in dislikes:
        s[i] = j
        found = True
        break
    if not found:
    	idx = i
    else:
    	idx = i - 1
  else:
    found = True
if s[-1] == 0:
  s.pop()
for i in range(idx+1):
  s[i] = smallest

ret = 0
while len(s):
  ret *= 10
  ret += s.pop()
print(ret)



Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int main(){
	char b;
	cin >> b;
	if(b == 'T'){
		cout << 'A';
	}
	if(b == 'A'){
		cout << 'T';
	}
	if(b == 'C'){
		cout << 'G';
	}
	if(b == 'G'){
		cout << 'C';
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int a[5];

signed main() {
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (!a[i]) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int main() {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	printf("%d",max(0,c-a+b));
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 1010101;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[8] = { 1,-1,0,0,1,1,-1,-1 };
ll dy[8] = { 0,0,1,-1,1,-1,1,-1 };
ll d[110][2];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 1;i <n;++i) {
		ans += (n - 1) / i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3612
N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7

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

for i, a in enumerate(A, start=1):
    accDp = [0] * (K + 2)
    for k in range(1, K + 2):
        accDp[k] = accDp[k - 1] + dp[k - 1]

    for k in range(K + 1):
        dp[k] = (dp[k] + accDp[k] - accDp[max(0, k - a)]) % MOD

print(dp[K] % MOD)


Measured memory_bytes: 64464
#include<stdio.h>
#include<limits.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,m[100][100];
void dijkstra(){
  int min,i,j,u;
  int d[100],color[100];
  for(i=0;i<n;i++){
    d[i]=INT_MAX;
    color[i]=WHITE;
  }
  d[0]=0;
  color[0]=GRAY;
  while(1){
    min=INT_MAX;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i]&&color[i]!=BLACK){
	u=i;
	min=d[i];
      }
    }
    if(u==-1)break;
    color[u]=BLACK;
    for(j=0;j<n;j++){
      if(color[j]!=BLACK&&m[u][j]!=INT_MAX){
	if(d[j]>d[u]+m[u][j]){
	  d[j]=d[u]+m[u][j];
	  color[j]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(d[i]==INT_MAX)d[i]=-1;
    printf("%d %d\n",i,d[i]);
  }
}

int main(){
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m[i][j]=INT_MAX;
    }
  }
  int k,c,u,v;
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      scanf("%d",&c);
      m[u][v]=c;
    }
  }
  dijkstra();
  return 0;
}



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

using namespace std;
using ll = long long;

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

  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> v;
  map<int, vector<int>> mp;
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    v.emplace_back(p, y);
    mp[p].push_back(y);
  }
  for (auto &[k, v] : mp) {
    sort(v.begin(), v.end());
  }

  for (auto [p, y] : v) {
    auto it = lower_bound(mp[p].begin(), mp[p].end(), y);
    int d = distance(mp[p].begin(), it) + 1;
    cout << setfill('0') << right << setw(6) << p;
    cout << setfill('0') << right << setw(6) << d << endl;
  }

  return 0;
}


Measured memory_bytes: 14804
def test():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))
    dp = [float('inf')]*N
    dp[0] = 0
 
    for i in range(1, N):
        dp[i] = min(dp[j] + abs(H[i] - H[j]) for j in range(max(i-K, 0), i))
 
    print(dp[-1])
 
if __name__ == '__main__':
    test()

Measured memory_bytes: 13980
n = int(input())
v = list(map(int,input().split()))

e = v[::2]
o = v[1::2]

ev = {}
ov = {}
for t in e :
    if t in ev :
        ev[t] = ev[t] + 1
    else :
        ev[t] = 1

for t in o :
    if t in ov:
        ov[t] = ov[t] + 1
    else :
        ov[t] = 1

ev = sorted(ev.items(),key=lambda x : x[1],reverse=True)
ov = sorted(ov.items(),key=lambda x : x[1],reverse=True)

#li = []
#for elm in list(ev.keys()) :
#    li.append([0,[elm,ev[elm]]])
#for elm in list(ov.keys()) :
    #li.append([1,[elm,ov[elm]]])
#li.sort(key=lambda x : x[1][1],reverse=True)
#print(li)

ee  = ev[0][0]
oo  = ov[0][0]

es0 = ev[0][1]
os0 = ov[0][1]
ans = n - es0 - os0

if ee == oo:
    tmp1 = n - es0
    tmp2 = n - os0

    if len(ev) > 1:
        es1 = ev[1][1]
        tmp1 = n  - es1  - os0

    if len(ov) > 1:
        os1 = ov[1][1]
        tmp2 = n  - es0  - os1

    if tmp1 > tmp2 :
        ans = tmp2 
    else :
        ans = tmp1

print(ans)




Measured memory_bytes: 18784
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a;
    int b[26]={0};
    while( cin >> a ){
        if(a - 'a' >= 0 && a-'a' <26){
            int num = a - 'a';
            b[num]++;
        }else if(a - 'A' >= 0 && a-'A' <26){
          int num = a - 'A';
          b[num]++;
        }
    }
    for(int i = 0; i < 26; i++){
        printf("%c : %d", i+'a', b[i]);
      cout << endl;
    } 
}


Measured memory_bytes: 3224
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const LL mod = 1000000007ll;
 
LL N,M;
vector<pair<LL,LL>> key;//pair<その鍵で開けられる宝箱,鍵のコスト>
 
LL ans = 0;
 
void solve(){
	vector<LL> dp(((LL)1)<<N,INF);
	dp[0] = 0;
	for(int bit=0;bit<(1<<N);bit++){
		for(int i=0;i<M;i++){
			int next = bit | ((int)key[i].first);
			dp[next] = min(dp[next],dp[bit]+key[i].second);
		}
	}
	ans = ((dp[(1<<N)-1]==INF)? -1:dp[(1<<N)-1]);
}
 
int main(){
	cin >> N >> M;
	for(int i=0;i<M;i++){
		LL a,b;
		cin >> a >> b;
		LL correspond_treasure = 0;
		for(int k=0;k<b;k++){
			LL key_type;
			cin >> key_type;
			correspond_treasure |= (((LL)1)<<(key_type-1));
		}
		key.emplace_back(correspond_treasure,a);
	}
 
	solve();
 
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr double PI = 3.14159265358979;


template<int Modulus> 
struct ModInt {
    long long x;
    ModInt(long long x = 0) :x((x%Modulus + Modulus)%Modulus) {}
    constexpr ModInt &operator+=(const ModInt a) {if ((x += a.x) >= Modulus) x -= Modulus; return *this;}
    constexpr ModInt &operator-=(const ModInt a) {if ((x += Modulus - a.x) >= Modulus) x -= Modulus; return *this;}
    constexpr ModInt &operator*=(const ModInt a) {(x *= a.x) %= Modulus; return *this;}
    constexpr ModInt &operator/=(const ModInt a) {return *this *= a.inverse();}

    constexpr ModInt operator+(const ModInt a) const {return ModInt(*this) += a.x;}
    constexpr ModInt operator-(const ModInt a) const {return ModInt(*this) -= a.x;}
    constexpr ModInt operator*(const ModInt a) const {return ModInt(*this) *= a.x;}
    constexpr ModInt operator/(const ModInt a) const {return ModInt(*this) /= a.x;}
    
    friend constexpr ostream& operator<<(ostream& os,const ModInt<Modulus>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<Modulus>& a) {return is >> a.x;}
    
    ModInt inverse() const {// x ^ (-1) 
        long long a = x,b = Modulus,p = 1,q = 0;
        while (b) {long long d = a/b; a -= d*b; swap(a,b); p -= d*q; swap(p,q);}
        return ModInt(p);
    }
    ModInt pow(long long N) {// x ^ N 
        ModInt a = 1;
        while (N) {
            if (N&1) a *= *this;
            *this *= *this;
            N >>= 1;
        }
        return a;
    }
};

using mint = ModInt<1000000007>;
//using mint = ModInt<998244353>;
struct Combination {
    int N;
    //using mint = ModInt<1000000007>;
    //using mint = ModInt<998244353>;
    vector<mint> fact,ifact,invs;
    Combination(int N): N(N),fact(N + 1),ifact(N + 1) {
        fact[0] = fact[1] = 1;
        ifact[0] = ifact[1] = 1;
        for (int i = 2;i < N + 1;++i) {fact[i] = fact[i - 1] * i;}
        ifact[N] = fact[N].inverse();
        for (int i = N;i >= 1;--i) {ifact[i - 1] = ifact[i] * i;}
    }
    void invs_build() {
        invs.resize(N + 1);
        invs[1] = 1;
        for (int i = 2;i < N + 1;++i) invs[i] = fact[i] * ifact[i - 1];
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n - k];
    }
    mint npk(int n,int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n - k];
    }
};

int main() {
    int N,M; cin >> N >> M;
    mint ans = 0;
    Combination cmb(M);

    rep(i,N + 1) {
        if (i%2 == 0) ans += cmb(N,i) * cmb.npk(M,i) * cmb.npk(M-i,N-i) * cmb.npk(M-i,N-i);
        else ans -= cmb(N,i) * cmb.npk(M,i) * cmb.npk(M-i,N-i) * cmb.npk(M-i,N-i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11088
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,j;
	scanf("%d",&a);
	scanf("%d",&s);
	scanf("%d",&d);
	scanf("%d",&f);
	g=a+s+d+f;
	h=g/60;
	j=g%60;
	printf("%d\n",h);
	printf("%d\n",j);
	return 0;
}

Measured memory_bytes: 1024
a, b, c = map(int, input().split())

if a == b and b == c and a % 2 == 0:
    print(-1)
    exit()

ans = 0
while True:
    if a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        ans += 1
        a, b, c = (b + c) // 2, (a + c) // 2, (a + b) // 2
    else:
        break

print(ans)


Measured memory_bytes: 3060
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans = -1;
    ll x,y;
    cin>>x>>y;
    FOR(i,1,2000){
        int a = i * 0.08;
        int b = i * 0.1;
        if(x==a && y==b){
            ans = i;
            break;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>

int main()
{
    double a, b, c;
    double d, e, f;

    while (std::cin >> a >> b >> c >> d >> e >> f) {
        double x = (c * e - b * f) / (a * e - b * d);
        double y = (c * d - a * f) / (b * d - a * e);
        if (x == -0) {
            x = 0;
        }
        if (y == -0) {
            y = 0;
        }
        std::cout << std::fixed << std::setprecision(3)
                  << x << " " << y << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1280
/**
*	created: 15.08.2020 21:13:35
**/
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
using P = pair<int,int>;
#define int long long
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,s,n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int x, k, d; cin >> x >> k >> d;
    int n1 = abs(x)%d;
    int n2 = -n1+d;
    int t = abs(x)/d;
    if (t >= k) {
        cout << abs(x) - k * d << endl;
    }
    else {
        if ((t-k)%2 == 0) cout << n1 << endl;
        else cout << n2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
n,k = map(int, input().split())
al = list(map(int, input().split()))

bit_cnts = [0]*41
for a in al:
    for i in range(41):
        if a&(1<<i) > 0:
            bit_cnts[i] += 1


dp_same = [0]*42
dp_small = [0]*42
small_flag = False
for i in range(41,0,-1):
    curr_bit = i-1
    kbit = 0
    if k&(1<<curr_bit) > 0: kbit = 1
    if kbit == 0:
        dp_same[i-1] = dp_same[i] + pow(2,curr_bit)*bit_cnts[curr_bit]
        if small_flag:
            dp_small[i-1] = dp_small[i] + pow(2,curr_bit)*(n-bit_cnts[curr_bit])
            dp_small[i-1] = max(dp_small[i-1], dp_small[i] + pow(2,curr_bit)*(bit_cnts[curr_bit]))
    else:
        dp_same[i-1] = dp_same[i] + pow(2,curr_bit)*(n-bit_cnts[curr_bit])
        dp_small[i-1] = dp_same[i]+pow(2,curr_bit)*(bit_cnts[curr_bit])
        if small_flag:
            dp_small[i-1] = max(dp_small[i-1], dp_small[i] + pow(2,curr_bit)*(n-bit_cnts[curr_bit]))
            dp_small[i-1] = max(dp_small[i-1], dp_small[i] + pow(2,curr_bit)*(bit_cnts[curr_bit]))
        small_flag = True

ans = max(dp_same[0],dp_small[0])
print(ans)

Measured memory_bytes: 84536
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;

struct Edge{int to,from,cost;};

#define debug cout

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) debug << *i << " "; debug << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<=(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n);i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<=(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define SS stringstream
#define X second
#define Y first
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

const int dx[]={1,-1,0,0,1,-1,1,-1,0};
const int dy[]={0,0,1,-1,1,-1,-1,1,0};

map<int,int> m;

int main() {
	int n;
	IL{
		cin>>n;
		if(n==0)break;
		m.clear();
		int a;
		rep(i,n){
			cin>>a;
			if(m.count(a)==0){
				m[a]=1;
			}else{
				++m[a];
			}
		}
		int res,r=0;
		for(map<int,int>::iterator i=m.begin();i!=m.end();++i){
			if(i->second>r){
				res=i->first;
				r=i->second;
			}
		}
		if(r>n/2)cout<<res<<endl;
		else cout<<"NO COLOR"<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


int main() {
  int x, a, b;
  cin >> x >> a >> b;
  if (b <= a) {
    cout << "delicious" << endl;
  }
  else if (b - a <= x) {
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
Int powi(Int x, Int y) {
    Int ans = 1;
    for (int i = 0; i < y; i++) {
        ans *= x;
    }
    return ans;
}
int main() {
    Int N; cin >> N;
    Int t = 1;
    for (int i = 1; i <= 100; i++) {
        if (N < t + powi(26, i)) {
            N -= t;
            string ans(i, '@');
            for (int j = i - 1; j >= 0; j--) {
                ans[j] = 'a' + N % 26;
                N /= 26;
            }
            cout << ans << endl;
            return 0;
        } else {
            t += powi(26, i);
        }
    }
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<list>
#include<bitset>
#include<sstream>
using namespace std;

// 最大公約数を求める関数
long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

int main() {

	long long N, M;
	cin >> N >> M;

	string S, T;
	cin >> S;
	cin >> T;

	long long x = gcd(max(N, M), min(N, M));

	long long n = N / x;
	long long m = M / x;

	long long ans = -1;

	string str_n = "";
	string str_m = "";

	for (long long i = 0; i < N; i += n) {
		str_n += S.substr(i, 1);
	}

	for (long long i = 0; i < M; i += m) {
		str_m += T.substr(i, 1);
	}

	if (str_n == str_m) {
		ans = x * n * m;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3732
#include<cstdio>
#include<cstdlib>
#include<algorithm>
const int MaxN=500010;
int N,K,A[MaxN],B[MaxN],pos[MaxN],nums[MaxN],cnt;
int lb(int x){
	int l=-1,r=cnt,mid;
	while(r-l>1)nums[mid=l+r>>1]<x?l=mid:r=mid;
	return r;
}
#define Def int o,int L,int R
#define Mid (L+R>>1)
#define Ls o<<1,L,Mid
#define Rs o<<1|1,Mid,R
long long T[1<<20];
long long query(int i){
	int o=1,L=0,R=cnt;
	while(R-L>1&&!T[o]){
		if(i<Mid)o<<=1,R=Mid;
		else o=o<<1|1,L=Mid;
	}
	return T[o]?T[o]:nums[R]-1;
}
void modify(Def,int l,int r,long long v){
	if(l==r)return;
	if(l==L&&r==R)T[o]=v;
	else{
		if(T[o])T[o<<1]=T[o<<1|1]=T[o],T[o]=0;
		if(r<=Mid)modify(Ls,l,r,v);
		else if(l>=Mid)modify(Rs,l,r,v);
		else modify(Ls,l,Mid,v),modify(Rs,Mid,r,v);
	}
}
long long dfs(Def){
	if(T[o])return T[o]-nums[R]+1;
	if(R-L==1)return 0;
	long long l=dfs(Ls),r=dfs(Rs);
	return l<r?l:r;
}
int main(){
	scanf("%d%d",&N,&K);
	long long sum=0;
	for(int i=0;i<N;i++){
		scanf("%d%d",A+i,B+i);
		if(B[i]==1&&K<A[i]*2)return puts("-1"),0;
		sum+=A[i]*2;
	}
	nums[cnt++]=0;
	nums[cnt++]=K;
	for(int i=N;i--;){
		pos[i]=(pos[i+1]+2ll*A[i])%K;
		nums[cnt++]=pos[i];
	}
	std::sort(nums,nums+cnt);
	cnt=std::unique(nums,nums+cnt)-nums-1;
	for(int i=N;i--;){
		pos[i]=lb(pos[i]);
		if(B[i]==1){
			long long v=query((pos[i]+cnt-1)%cnt);
			if(!pos[i])v-=K;
			if(pos[i+1]<pos[i]){
				modify(1,0,cnt,pos[i+1],pos[i],v);
			}
			else{
				modify(1,0,cnt,pos[i+1],cnt,v+K);
				modify(1,0,cnt,0,pos[i],v);
			}
		}
	}
	printf("%lld\n",dfs(1,0,cnt)+sum);
}

Measured memory_bytes: 10496