akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
      	int A[] = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        System.out.println(shoppingWithDiscount(A));
    }

    private static int shoppingWithDiscount(int[] a) {
        int totalBill = 0;
        int highest = 0;
        for (int i = 0; i < a.length; i++) {
            totalBill += a[i];
            if (highest < a[i]) {
                highest = a[i];
            }
        }

        return totalBill - highest + highest/2;
    }
}

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

int main(){
	double x1,x2,y1,y2;
	cin >> x1 >> y1 >> x2  >> y2;
	cout<<fixed<<setprecision(10)<<sqrt(pow(abs(x1-x2),2)+pow(abs(y1-y2),2))<<endl;
}


Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}

int main()
{
    int n, q, t;
    cin >> n;

    vector<int> A;
    REP(i, n){
        cin >> q;
        A.emplace_back(q);
    }

    bool dp[n+1][2001];
    REP(j, 2001) dp[0][j] = false;
    dp[0][0] = true;

    // printf("a\n");
    REP(i, n){
        REP(j, 2001){
            if(j >= A[i]){
                dp[i+1][j] = dp[i][j] || dp[i][j-A[i]];
            }else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }

    // rintf("b\n");
    cin >> q;
    REP(i, q){
        cin >> t;
        if(dp[n][t]) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 3172
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int M = in.i();
        long[] d = new long[N + M];
        for (int i = 0; i < N; i++) {
            d[i] = (in.l() << 17) + 1;
        }
        for (int i = N; i < d.length; i++) {
            d[i] = in.i() + (in.l() << 17);
        }
        Arrays.sort(d);
        long ans = 0;
        for (int i = N + M - 1, j = N - 1; i >= 0 && j >= 0; i--) {
            long b = d[i] & (1 << 17) - 1;
            long c = d[i] >> 17;
            b = Math.min(j + 1, b);
            ans += b * c;
            j -= b;
        }
        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {}
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    String s() {
        try {
            return readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


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

int a[10];
bool ans=false;
int siwake(int cun,int b,int c){
	if(cun == 10){ans=true;}
	if(a[cun]>b){siwake(cun+1,a[cun],c);}
	if(a[cun]>c){siwake(cun+1,b,a[cun]);}
	return 0;
}

int main(){
	int i,z,zc;
	cin>>z;
	for(zc=0;zc!=z;zc++){
		for(i=0;i!=10;i++){cin>>a[i];}
		siwake(0,0,0);
		if(ans==true){cout<<"YES"<<endl;
			ans=false;
		}
		else{cout<<"NO"<<endl;}
	}
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  long n,a,b,c,d;
  cin>>n>>a>>b>>c>>d;

  rep(i,n){
    long l = a - d*i, u = a - c*i;
    if(l + c*(n-i-1) <= b && b <= u + d*(n-i-1)) return true;
  }

  return false;
}

int main(){
  if(solve()) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    
    string s; cin  >> s;
    auto dp = vectors((int)s.size() + 1,4,0LL);
    int ans = 0;
    dp[0][0] = 1;
    int MOD = 1000000000 + 7;
    rep(i,s.size()){
        rep(j,dp[i].size()) {
            if (s[i] == '?') {
                dp[i+1][j] += dp[i][j]*3;
                dp[i+1][j] %= MOD;
            } else {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
        if (s[i] == 'A' || s[i] == '?'){
            dp[i+1][1] += dp[i][0];
        }
        if (s[i] == 'B' || s[i] == '?'){
            dp[i+1][2] += dp[i][1];
        }
        if (s[i] == 'C' || s[i] == '?'){
            dp[i+1][3] += dp[i][2];
        }
        rep(j,dp[i].size()){
            dp[i+1][j] %= MOD;
        }
    }
    cout << dp[s.size()][3] << endl;
}


Measured memory_bytes: 7424
from itertools import*;A=accumulate;N,K,*a=map(int,open(0).read().split());a=[0]+a;*c,=A(a);*d,=A(max(0,i)for i in a);print(max(d[i]+max(0,c[i+K]-c[i])+d[N]-d[i+K]for i in range(N-K+1)))

Measured memory_bytes: 16652
#include <stdio.h>
#include <limits.h>

#define TEST_MODE 0

int main(void) {
#if TEST_MODE
	long long  a,b;
	while(scanf("%lld%lld",&a,&b)==2) {
		if(a+b>(long long)INT_MAX || a+b<(long long)INT_MIN)return 1;
		printf("%lld\n",a+b);
	}
#else
	int a,b;
	while(scanf("%d%d",&a,&b)==2) {
		printf("%d\n",a+b);
	}
#endif
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int x, y;
    cin >> x >> y;
    if(2 * x <= y && y <= 4 * x && y % 2 == 0){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 3640
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

C = Counter(A).most_common()
C.sort()
C.reverse()

e = []
for i, j in C:
    if j >= 2:
        e.append(i)
        if j >= 4:
            e.append(i)
    if len(e) >= 2:
        break
if len(e) >= 2:
    print(e[0] * e[1])
else:
    print(0)


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

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


    if(k<a){
        res=k;
    }else if(k<=a+b){
        res=a;
    }else{
        res=a-(k-(a+b));
    }
    
    cout << res << endl;

}

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int,int>;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    int n; cin >> n;
    map<string, int> mp;
    rep(i,n) {
        string s; cin >> s;
        mp[s]++;
    }
    int ans = 0;
    for (auto x: mp) {
        ++ans;
    }
    cout << ans << endl;
    return 0;
}

























Measured memory_bytes: 19152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (1000000007);

int main()
{
	ll k,x; cin>>k>>x;
	for (int i=(x-k+1); i<=(x+k-1); i++)
		cout<<i<<" ";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
using namespace std;
int n,m,q;
int sim[100];
int dt[100][4];
int ans;

void solve(int now, int ma){
    if(now==n){
        int tmp=0;
        rep(i,q){
            if(sim[dt[i][1]]-sim[dt[i][0]]==dt[i][2]) tmp+=dt[i][3];
        }
        ans=max(ans,tmp);
        return;
    }
    for(int i=ma; i<=m; i++){
        sim[now]=i;
        solve(now+1,i);
    }
    return;
}

int main(){
    cin >> n >> m >> q;
    rep(i,q){
        int a,b,c,d; cin >> a >> b >> c >> d;
        a--; b--;
        dt[i][0]=a;
        dt[i][1]=b;
        dt[i][2]=c;
        dt[i][3]=d;
    }
    ans=0;
    solve(0,1);
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MAXN 205
//#define N 262144
#define ULL unsigned long long
#define ll long long
int main(){
    char c[1000005];
    scanf("%s",c);
    for(int i=  0;c[i]!=0;i++){
        if(c[i]>='a')printf("a");
        else printf("A");
    }
    printf("\n");
}

Measured memory_bytes: 3772
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy
#import heapq
#import math
#import string

setrecursionlimit(10**6)
input=stdin.readline

a,b=map(int,input().split())
print(a-2*b if a-2*b>=0 else 0)

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

int main()
{
    string s,t;
    int size;
    cin >> s;
    cin >> t;
    size = t.size();

    if(t == s + t[size-1])
    {
        cout << "Yes" << endl;
    }else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3632
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.List;
import java.util.ArrayList;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Collections;
import java.awt.Point;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int h = Integer.parseInt(br.readLine());
        int w = Integer.parseInt(br.readLine());
        
        
        System.out.println((n-h+1)*(n-w+1));
    }
}

class Box {
    int w;
    int h;
    public Box(int w, int h) {
        this.w = w;
        this.h = h;
    }
}

class BoxComparator1 implements Comparator<Box>{
	public int compare(Box b1, Box b2) {
		return b1.w - b2.w;
	}
}

class BoxComparator2 implements Comparator<Box> {
    public int compare(Box b1, Box b2) {
        return b1.h - b2.h;
    }
}


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

int main(){
  string s,t;
  cin >> s >> t;
  
  map<char, int> mp_s, mp_t;
  long long siz = s.size();
  long long s_trans[siz], t_trans[siz];
  
  int counter = 1;
  for(long long i=0; i<siz; i++){
    if(mp_s[s[i]] == 0){
      mp_s[s[i]] = counter;
      s_trans[i] = counter;
      ++counter;
    }else{
      s_trans[i] = mp_s[s[i]];
    }
  }
  
  counter = 1;
  for(long long i=0; i<siz; i++){
    if(mp_t[t[i]] == 0){
      mp_t[t[i]] = counter;
      t_trans[i] = counter;
      ++counter;
    }else{
      t_trans[i] = mp_t[t[i]];
    }
  }
  
  int flag = 1;
  for(long long i=0; i<siz; i++){
    if(s_trans[i] != t_trans[i]){
      flag = 0;
      break;
    }
  }
  
  if(flag == 1)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

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

#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif
	int n;
	cin>>n;
	int cnt = 0;
	int a[n];
	f(i,0,n) cin>>a[i];
	f(i,1,n) if (a[i] == a[i-1]) cnt++,i++;
	cout << cnt << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

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

void dfs(vector<int> nodes, vector<pair<int, pair<int, int>>> &edges, int depth) {
    if (nodes.size() <= 1) return;
    vector<int> left, right;
    for (int i = 0; i < nodes.size() / 2; i++) left.push_back(nodes[i]);
    for (int i = nodes.size() / 2; i < nodes.size(); i++) right.push_back(nodes[i]);
    for (int i = 0; i < left.size(); i++) {
        for (int j = 0; j < right.size(); j++) {
            edges.push_back(make_pair(depth, make_pair(left[i], right[j])));
        }
    }
    dfs(left, edges, depth + 1);
    dfs(right, edges, depth + 1);
}

int main() {

    int N;
    cin >> N;

    vector<pair<int, pair<int, int>>> edges;

    vector<int> nodes(N);
    iota(nodes.begin(), nodes.end(), 0);

    dfs(nodes, edges, 0);

    vector<vector<int>> ans(N, vector<int>(N, -1));
    for (int i = 0; i < edges.size(); i++) {
        int level = edges[i].first;
        int f = edges[i].second.first;
        int to = edges[i].second.second;
        ans[f][to] = level + 1;
    }

  //  for (int i = 0; i < N; i++) SHOW_VECTOR(ans[i]);

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1 ; j < N; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }

}






























































Measured memory_bytes: 2932
import math
a, b, C = map(int, input().split())
c = math.sqrt(a ** 2 + b ** 2 - a * b * 2 * math.cos(C))
S = a * b * math.sin(math.radians(C)) / 2
L = math.sqrt(a ** 2 + b ** 2 - a * b * 2 * math.cos(math.radians(C))) + a + b
h = 2 * S / a

print(S)
print(L)
print(h)


Measured memory_bytes: 5716
#include <iostream>
#include <cmath>
using namespace std;
const double PI = acos(-1);

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

    double r;
    cin >> r;

    double ans = 2.0 * r * PI;
    printf("%.2f\n", ans);
    return 0;
}

Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;

const int MAXN = 1e4;

int n;
string S;
int s[MAXN], num[3];
int elem[MAXN][3];
bool isElem[MAXN][3];

int getOther(int i, int j){
	if(i > j)
		swap(i, j);
	if(j == 1)
		return 2;
	if(i == 1)
		return 0;
	return 1;
}

int main(){
	cin >> n;
	cin >> S;
	for(int i = 0; i < n; ++i){
		if(S[i] == 'R') s[i] = 0;
		if(S[i] == 'G') s[i] = 1;
		if(S[i] == 'B') s[i] = 2;
		elem[i][s[i]] = isElem[i][s[i]] = 1;
		if(i)
			for(int j = 0; j < 3; ++j)
				elem[i][j] += elem[i-1][j];
		num[s[i]]++;
	}
	long long ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < i; ++j){
			if(s[i] != s[j]){
				int dist = i-j;
				int other = getOther(s[i], s[j]);
				int toAdd = num[other] - elem[i][other] - isElem[i+dist][other];
				ans += toAdd;
				// printf("(%d, %d) %d\n", j, i, toAdd);
			}
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3760
import java.util.Scanner;
import java.util.Arrays;
public class Main
{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		boolean a [] =new boolean [3];
		Arrays.fill(a, true);
		int x = scan.nextInt();
		a[x-1] = false;
		x = scan.nextInt();
		a[x-1] = false;
		for(int i =0; i< 3; i++){
		    if(a[i]){
		        System.out.print(i+1);
		        break;
		    }
		}
		
	}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o_set; 

#define     int                 ll
#define     pb                  push_back
#define     mp                  make_pair
#define     xx                  first
#define     yy                  second    
#define     all(a)              a.begin(),a.end()
#define     vi                  vector<int>
#define     vpi                 vector<pii>
#define     pii                 pair<int, int>
#define     present(DT, val)    (DT.find(val) != DT.end()) //for set and map
#define     cpresent(DT, val)   (find(all(DT),val) != DT.end()) //vectors
#define     input               "/home/pollution/Desktop/WorkSpace/C++/Files/input.txt"
#define     output              "/home/pollution/Desktop/WorkSpace/C++/Files/output1.txt"
#define     error               "/home/pollution/Desktop/WorkSpace/C++/Files/error.txt"
#define     IO()                ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     INF                 2e18
#define     MOD                 1000000007
#define     clr(x)              memset(x, 0, sizeof(x))
#define     init(x, a)          memset(x, a, sizeof(x))
#define     out(a)              for (auto i: a) cout<<i<<' '; cout<<'\n'
#define     cpy(a,b)            memcpy(a,b,sizeof(b))
#define     is(a)               to_string(a)
#define     ci(a,c)             a-c
#define     debug(i)            cout<<"point :"<<i<<'\n';
#define     setd(val,n)         cout<<fixed<<setprecision(n)<<val<<'\n'

void solve(){
    int n,k; cin>>n>>k;
    cout<<min(n%k, abs(n%k-k))<<'\n';
}

signed main() { 
    IO();
    
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
ll u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
ll d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int f(ll a){
  for(int i=2;i<=sqrt(a);i++)if(a%i<1)return 0;
  return 1;
}
int main(void){
  int n;
  scanf("%d",&n);
  char s[2][27]={
    "QAZWSXEDCRFVTGBYHNUJMIKOLP","qazwsxedcrfvtgbyhnujmikolp"
  };
  FOR(2){
    FORJ(26){
      if(n==s[i][j]){
        PRN(i+1);
        return 0;
      }
    }
  }
  PRN(0);
  return 0;
}



Measured memory_bytes: 2092
#include<iostream>
#include<cstdio>
using namespace std;
int a[5][5];
int b[10];
int main()
{	int n,sum;
	for(int i=1;i<=3;i++)
		cin>>b[i];
	a[1][1]=b[1];
	a[1][2]=b[2];
	a[2][2]=b[3];
	sum=b[3]*3;
	a[1][3]=sum-a[1][2]-a[1][1];
	a[3][2]=sum-a[1][2]-a[2][2];
	a[3][3]=sum-a[2][2]-a[1][1];
	a[3][1]=sum-a[2][2]-a[1][3];
	a[2][1]=sum-a[1][1]-a[3][1];
	a[2][3]=sum-a[1][3]-a[3][3];
	for(int i=1;i<=3;i++)
		cout<<a[i][1]<<' '<<a[i][2]<<' '<<a[i][3]<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n, input_tmp, tmp = -1, count = 0;
    vector<int> d;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> input_tmp;
        d.push_back(input_tmp);
    }
    sort(d.begin(), d.end(), greater<int>());

    for(auto mochi : d) {
        if(tmp != mochi) {
            tmp = mochi;
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cfenv>
#include <cmath>
#include <cstdlib>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite

typedef struct item{
  string name;
  int number;
  int money;
}item;

int main(){
  long long int n,k;
  cin >> n >> k;
  cout << min(n%k,abs(k-(n%k))) << endl;
}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


Measured memory_bytes: 256
//#include <fstream>
 
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
 
const int NMAX = 200005;
const int KMAX = 3005;
const int MOD = 1000000007;
 
struct point
{
	int x, y;
	point()
	{
		this->x = this->y = 0;
	}
	point(const int &x, const int &y)
	{
		this->x = x;
		this->y = y;
	}
	inline bool operator<(const point &other)const
	{
		if (this->x == other.x)
			return this->y < other.y;
		return this->x < other.x;
	}
};
 
int n, m, k;
point v[KMAX];
int fact[NMAX], invfact[NMAX], d[NMAX];
 
int lgput(int base, int exp)
{
	int res = 1;
	while (exp > 0)
	{
		if (exp & 1)
			res = (1LL * res * base) % MOD;
		base = (1LL * base * base) % MOD;
		exp >>= 1;
	}
	return res;
}
 
inline int invmod(int &x)
{
	return lgput(x, MOD - 2);
}
 
inline int comb(int n, int k)
{
	int ret = (1LL * fact[n] * invfact[k]) % MOD;
	ret = (1LL * ret * invfact[n - k]) % MOD;
	return ret;
}
 
inline int calc(int x1, int y1, int x2, int y2)
{
	int p = abs(x2 - x1);
	int q = abs(y2 - y1);
	return comb(p + q, p);
}
 
int main()
{
	//ifstream cin("test.in");
	//ofstream cout("test.out");
	cin >> n >> m >> k;
	fact[0] = 1;
	invfact[0] = invmod(fact[0]);
	for (int i = 1;i <= n + m;++i)
	{
		fact[i] = (1LL * fact[i - 1] * i) % MOD;
		invfact[i] = invmod(fact[i]);
	}
	for (int i = 1;i <= k;++i)
	{
		int x, y;
		cin >> x >> y;
		v[i] = point(x, y);
	}
	sort(v + 1, v + k + 1);
	v[++k] = point(n, m);
	for (int i = 1;i <= k;++i)
	{
		d[i] = calc(1, 1, v[i].x, v[i].y);
		for (int j = 1;j < i;++j)
		{
			if (v[j].x <= v[i].x && v[j].y <= v[i].y)
			{
				int diff = (1LL * d[j] * calc(v[j].x, v[j].y, v[i].x, v[i].y)) % MOD;
				d[i] = (d[i] - diff + MOD) % MOD;
			}
		}
	}
	cout << d[k] << "\n";
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {
		Scanner sc = new Scanner(System.in);

		int H = sc.nextInt();
		int W = sc.nextInt();
		int h = sc.nextInt();
		int w = sc.nextInt();
		int mass[][] = new int[H][W];

		int count = 0;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				mass[i][j] = 1;
			}
		}

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < W; j++) {
				mass[i][j] = 0;
			}
		}
		
		for(int j = 0; j < w; j++) {
			for (int i = 0; i < H; i++) {
				mass[i][j] = 0;
			}
		}

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (mass[i][j] == 1) {
					count++;
				}
			}
		}

		System.out.print(count);
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n), dp(n, INT_MAX);
    for (auto & x : h)
        cin >> x;
    dp[0] = 0;
    for (int i = 1; i < n; ++i)
        for (int j = 1; j <= k && j <= i; ++j)
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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; }

__attribute__ ((constructor))
void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

// void print_que(priority_queue<pair<int,int>> que){
//     for(auto u : que){
//         cout << u.second << " " << u.first << endl;
//     }
// }

int main(){
    int k, t;
    cin >> k >> t;
    map<int,int> mii;
    rep(i,t){
        int a;
        cin >> a;
        mii[i] = a;
    }
    // for(auto u : mii){
    //     cout << u.first << u.second << endl;
    // }
    // cout <<"map output finish" << endl;
    priority_queue<pair<int, int>> que;
    for(auto u : mii){
        que.emplace(u.second, u.first);
    }
    int ans = 0;
    int pre = -1;
    while(!que.empty()){
        int top_first = que.top().first;
        int top_second = que.top().second;
        que.pop();
        if(top_second != pre){
            pre = top_second;
            top_first--;
            if(top_first)
                que.emplace(top_first, top_second);
        }else{
          if(!que.empty()){
                int second_first = que.top().first;
                int second_second = que.top().second;
                que.pop();
                pre = second_second;
                second_first--;
                que.emplace(top_first, top_second);
                if(second_first){
                    que.emplace(second_first, second_second);
                }
                
            }else{
                ans += top_first;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
/* 

	 - If you fail to prepare, you are prepared to fail.	

	(C) Mark Spitz

*/

#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;

using ll = long long;

const bool dbg_flg = 1;
#define NAME(x) #x
#define debug if (dbg_flg) cerr

const int inf = 1e9 + 7;
const int MAXN = 1e5 + 5;

int n, k;
int ct[MAXN];

void solve() {
	cin >> n >> k;

	for (int i = 1; i <= k; i++) {
		int d;

		cin >> d;

		for (int j = 1; j <= d; j++) {
			int x;

			cin >> x;

			ct[x]++;
		}
	}

	int res = 0;

	for  (int i = 1; i <= n; i++) {
		if (ct[i] == 0) res++;
	}

	cout << res;
}

int main() {
	
	//~ freopen(".in", "r", stdin);
	//~ freopen(".out", "w", stdout);
	
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}

	return 0;
}

Measured memory_bytes: 3660
ab_list = []
a,b,k = map(int,input().split())
ab_than =  a  if a > b else b
for i in range(1,ab_than+1):
    if (a % i == 0 ) and (b%i == 0) :
        ab_list.append(i)
ab_list.reverse()
print(ab_list[k-1])        


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int max(int a, int b){
	return a >= b ? a : b;
}
int min(int a, int b){
	return a <= b ? a : b;
}
int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int euclid(int a, int b){
  if(a < b){
    int tmp = a;a = b;b = tmp;
  }
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,A,B,syou,dai;
  scanf("%d %d %d",&N,&A,&B);
	if(A+B>=N){
		syou = A+B-N;
	}
	else{
		syou = 0;
	}
	dai=min(A,B);
	printf("%d %d",dai,syou);
  return 0;
}


Measured memory_bytes: 128
/* Atcoder abc168b
 * See tasks at: https://atcoder.jp/contests/abc168/tasks/abc168_b
 */
#include <bits/stdc++.h>

#define until(symbol, max) for (int symbol = 0; (symbol) < (max); (symbol)++)

using namespace std;
using ll = long long;
int main()
{
    int k;
    cin >> k;

    string s;
    cin >> s;

    if (s.length() > k)
    {
        cout << s.substr(0, k) << "...";
    }
    else
    {
        cout << s;
    }

    return 0;
}


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

void inv(vector<int>& v) {
    int length = v.size();
    for (int i = 0; i < length; i++) {
        cin >> v[i];
    }
}
void inv(vector<int>& v, int length) {
    for (int i = 0; i < length; i++) {
        cin >> v[i];
    }
}

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

    if (x >= 30) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int sum[20000], temp[20000];

int inv(int n, int r, int *target) {
	int m = 1;
	for (int i = 0; i < 2*r; i++) {
		target[i] = m/n;
		m = (m%n)*10;
	}
}

int add(int r) {
	int carry = 0;
	for (int i = 2*r-1; i >= 0; i--) {
		sum[i] += temp[i] + carry;
		carry = sum[i]/10;
		sum[i] %= 10;
	}
}

int main() {
	int n, k, m, r;
	while (cin >> n >> k >> m >> r, n) {
		inv(n, r, sum);
		if (m) {
			for (int i = 1; i <= n-1; i++) {
				inv(n*i, r, temp);
				add(r);
			}
		}

		cout << sum[0] << ".";
		for (int i = 1; i <= r; i++)
			cout << sum[i];
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
 
int main() {
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  
  bitset<30> r(a[0]);
  
  for (int i = 1; i < N; i++) {
    bitset<30> p(a[i]);
    r = r ^ p;
  }
  if (r == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 640
// hackerearth incom
        #include <bits/stdc++.h>

        using namespace std;

        typedef long long ll;
        const ll N = 5e5+5;
        const ll MOD = 1000000007;
        #define all(x) x.begin(),x.end()
        #define pii pair<ll,ll>
        #define pis pair<ll,string>
        #define F first
        #define S second
        #define LCM(a,b) ((a*b)/__gcd(a,b))
        #define inf 1e15
        #define test ll cse;cin>>cse;for(ll _i=1;_i<=cse;_i++)
        #define PI 3.14159265
        #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
        const double EPS = 1E-9;
        typedef vector<vector<double>> matrix;
        typedef vector<int> vi;

int prime[N];
int nod[N];
int Exp(ll x, ll n){
    ll ans = 1, X =x,N= n;
    while(N > 0){
        if(N&1) ans = (ans*X);
        X = (X*X);
        N >>= 1;
    }
    return ans;
}
int solve(ll num){

    unordered_map<int,int> mapp;
    while(num > 1){
        mapp[ prime[num]]++;
        num /= prime[num];
    }
    // number of factors
    int res = 1;for(auto ele: mapp) res *= (ele.S+1);

    // sum of divisors/factors
    // ll ans = 1;
    // for(auto ele: mapp){
    //     ll ai = ele.F;
    //     ll pi = ele.S;

    //     ans *= (Exp(ai,pi+1)-1)/(ai-1);
    // }
    return res;
}

void sieve(){
	memset(prime,0,sizeof(prime));
    prime[0] = prime[1] = 1;

    for(int i = 2; i <= N; i++){
        if(prime[i]==0){
            for(int j=i; j <= N;j+=i) prime[j] = i;
        }
    }
}
int main(){

    fast;
	int D, T, S;

    cin >> D >> T >> S;

    int times = D / S + ((D % S)?1:0);


    if(times <= T)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }
 
typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;
 
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (300006)
ll n, ma, mb, dp[51][55][55];
spi A[51];
int main()
{
	FAST
	cin>>n>>ma>>mb;
	FOR(i,0,n-1) cin>>A[i].s.f>>A[i].s.s>>A[i].f;
	mmst(dp,-1);
	function<ll(ll,ll,ll)>lol=[&](ll pos,ll x,ll y){
		if(~dp[pos][x][y]) return dp[pos][x][y];
		if(pos==n&&x==0&&y==0) return 0ll;
		if(x<0||y<0) return LLINF;
		if(x>50||y>50) return LLINF;
		if(pos==n) return LLINF;
		ll &ans=dp[pos][x][y]=LLINF;
		ans=lol(pos+1,x,y);
		ans=min(ans,lol(pos+1,x-A[pos].s.f,y-A[pos].s.s)+A[pos].f);
		return ans;
	};
	ll ans = LLINF;
	FOR(a,1,50) { if(a>=ma&&a%ma==0)
		ans=min(ans,lol(0, a, a/ma * mb));
	}
	cout<<(ans==LLINF?-1:ans);
}


Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <set>

using namespace std;

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

	vector<string> a(n);
	set<string> s;
	cin >> a[0];
	s.insert(a[0]);
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		if (a[i - 1][a[i - 1].length() - 1] != a[i][0]) {
			cout << "No" << endl;

			return 0;
		}
		s.insert(a[i]);
	}
	if (s.size() != a.size()) {
		cout << "No" << endl;

		return 0;
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <list>
#include <set>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    while(n--)
    {
        string s; cin >> s;
        list<char> ls;
        set<char> st;
        ls.push_back(s[0]);
        st.insert(s[0]);
        for(int i = 1; i < s.size(); i += 3)
        {
            string t = s.substr(i, 2);
            if(st.count(s[i + 2])) continue;
            if(t == "->") ls.push_back(s[i + 2]);
            else ls.push_front(s[i + 2]);
            st.insert(s[i + 2]);
        }
        for(auto x : ls) cout << x;
        cout << endl;
    }
    return 0;
}




Measured memory_bytes: 3112
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {  
		Scanner input = new Scanner(System.in);
		int A = input.nextInt();
		int B = input.nextInt();
		int C = input.nextInt();
		if (A+B==C||A+C==B||B+C==A) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

int main() {
  int n,ans = 0,a;
  cin >> n;
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  rep(i,1,n+1){
    int cnt = 0,t = i;
    while(t%2 == 0){
      t /= 2;
      cnt++;
    }
    if(cnt > ans){
      ans = cnt;
      a = i;
    }
  }
  cout << a << endl;
}

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

int main() {
	int N;
	cin>>N;
	string S;
	cin>>S;
	for(int i=0; i<S.size(); i++){
		char tmp=S[i]+N;
		if(tmp>'Z'){
            tmp=tmp-'Z'+'A'-1;
            //cout<<tmp<<endl;
			
		}
		S[i]=tmp;
		cout<<S[i];
	}
	
	
	
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b) = readInputLine().split(" ").map{it.toInt()}
    
    if (a <= 5) {
        println(0)
    } else if (a <= 12) {
        println(b / 2)
    } else {
        println(b)
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 35888
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define forn(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define ford(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define int long long
#define ii pair<int,int>
#define ar array
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define sz(x) ((int)(x).size())
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
const int N = 1e6+7 ;
int d[N] ;

void solve(){
    int n ;
    cin >> n ;
    rep(i,1,N){
        for(int j = i ; j < N ; j+=i){
            d[j]++ ;
        }
    }
    int ans = 0 ;
    rep(i,1,n) ans += d[i] ;
    cout << ans << endl ;
}


int32_t main(){
    FAST_IO ;
    int t = 1 ;
//    cin >> t ;
    while(t--){
        solve() ;
    }
}


Measured memory_bytes: 11488
#include <iostream>

int main() {
    long long N, T;
    std::cin >> N >> T;
    long long ans = 0;
    long long t1, t2;
    t1 = 0;
    for (int i = 0; i < N; ++i) {
        std::cin >> t2;
        if (t2 - t1 < T) {
            ans += t2 - t1;
        } else {
            ans += T;
        }
        t1 = t2;
    }
    ans += T;
    std::cout << ans << std::endl;
    return 0;
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define ll1 1ll
#define ONE 1ll
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>
istream &operator>>(istream &is, pair<T, S> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T> void printvv(const vector<vector<T>> &v) {
  cerr << endl;
  rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
    if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
      cerr << "INF";
    } else
      cerr << v[i][j];
    cerr << (j == v[i].size() - 1 ? '\n' : ' ');
  }
  cerr << endl;
}
/*
   typedef __int128_t Int;
   std::ostream &operator<<(std::ostream &dest, __int128_t value) {
   std::ostream::sentry s(dest);
   if (s) {
   __uint128_t tmp = value < 0 ? -value : value;
   char buffer[128];
   char *d = std::end(buffer);
   do {
   --d;
 *d = "0123456789"[tmp % 10];
 tmp /= 10;
 } while (tmp != 0);
 if (value < 0) {
 --d;
 *d = '-';
 }
 int len = std::end(buffer) - d;
 if (dest.rdbuf()->sputn(d, len) != len) {
 dest.setstate(std::ios_base::badbit);
 }
 }
 return dest;
 }

 __int128 parse(string &s) {
 __int128 ret = 0;
 for (int i = 0; i < s.length(); i++)
 if ('0' <= s[i] && s[i] <= '9')
 ret = 10 * ret + s[i] - '0';
 return ret;
 }
 */

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main(signed argc, char *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  string S;
  cin >> S;
  if (S.size() < 26) {
    vector<int> v(256);
    for (auto c : S)
      v[c] = 1;
    for (char c = 'a';; c++) {
      if (v[c] == 0) {
        S.pb(c);
        break;
      }
    }
    cout<<S<<endl;
  } else {
    vector<int> v(26);
    rep(i, 0, 26) { v[i] = S[i] - 'a'; }
    if(next_permutation(all(v))){
      string t;
      rep(i,0,26){
        t.pb(v[i]+'a');
        if(S<t)break;
      }
      cout<<t<<endl;
    }
    else{
      cout<<-1<<endl;
    }
  }

  return 0;
}


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

int main() {
  int N,A[200],i;
  int cnt;
  cin >> N;
  for(i=0;i<N;i++) {
    cin >> A[i];
  }
  i = 0;
  while(1) {
    for(i=0;i<N-1;i++) {
      if(A[i]%2==0) {
        A[i] = A[i]/2;
      }
      else break;
    }
    if(A[i]%2!=0) break;
    else {
      A[N-1] = A[N-1]/2;
      cnt = cnt+1;
    }
  }
  cout << cnt << endl;
  return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n ;
	cin >> n ;
	int arr[n] ;
	for(int i = 0 ; i < n ; i++)
		cin >> arr[i] ;
	int dp[n] = {0} ;
	dp[1] = abs(arr[0] - arr[1]) ;
	for(int i = 2 ; i < n; i++){
		dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]), dp[i - 2] + abs(arr[i] - arr[ i - 2])) ;
	}	
	cout << dp[n - 1] ;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int MAXN = 1e5 + 11;
const int MAXM = 555;
const int mod = 998244353;
#define FOR(i, a, b) for(int i = (a);i <= (b); i++)
#define ROF(i, a, b) for(int i = (a);i >= (b); i--)
int n, m;
int f[3][MAXM], sg[MAXN], mark[MAXM];
vector<int> G[MAXN];
void Add(int &x, int y){
    x = x + y - (x + y >= mod ? mod : 0);
}
void Mu(int &x, int y){
    x = 1LL * x * y % mod;
}
int A(int x, int y){
    return x + y - (x + y >= mod ? mod : 0);
}
int M(int x, int y){
    return 1LL * x * y % mod;
}
int ksm(int base, int x){
    base %= mod;
    int ans = 1;
    while(x){
        if(x & 1)Mu(ans, base);
        x >>= 1;
        Mu(base, base);
    }
    return ans;
}
int main(){
    cin>>n;
    FOR(t, 0, 2){
        cin>>m;
        int u, v;
        memset(sg, -1, sizeof sg);
        memset(mark, 0, sizeof mark);
        FOR(i, 1, m){
            scanf("%d%d", &u, &v);
            if(u < v)swap(u, v);
            G[v].push_back(u);
        }
        ROF(u, n, 1){
            for(int v : G[u]){
                mark[sg[v]] = u;
            }
            sg[u] = 0;
            while(mark[sg[u]] == u)sg[u]++;
            Add(f[t][sg[u]], ksm((LL)(1e18 + 0) % mod, u));
            G[u].clear();
            //printf("u=%d sg=%d\n", u, sg[u]);
        }
    }
    int ans = 0;
    FOR(i, 0, 500){
        FOR(j, 0, 500){
            Add(ans, M(M(f[0][i],f[1][j]), f[2][i^j]));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,k;
  cin>>n>>k;
  vector <int> tree(n);
  for(int i=0;i<n;i++){
      cin>>tree[i];
  }
  sort(tree.begin(),tree.end());
  int mi=1000000001;
  for(int i=0;i<n-k+1;i++){
      //cout<<tree[i]<<i<<endl;
      mi=min(mi,tree[i+k-1]-tree[i]);
      //cout<<mi<<endl;
  }
  cout<<mi<<endl;
}

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

int main()
{
	int n;
	cin >> n;
	vector<ll> a(n),sum(n+1);
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
	}
	for(int i =0;i<n;i++)
	{
		sum[i+1] += sum[i] + a[i];
	}
	sort(sum.begin(),sum.end());
	sum.push_back(LLONG_MAX);
	ll l = 1;
	ll ans = 0;
	for(int i = 0;i<n+1;i++)
	{
		if(sum[i]==sum[i+1])
		{
			l++;
		}
		else
		{
			ans += l*(l-1)/2;
			l = 1;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6400