akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N + 1);
    vector<int>B(N);
    vector<int>a(N + 1);
    rep(i, N + 1) {
        cin >> A[i];
        a[i] = A[i];
    }
    rep(i, N) {
        cin >> B[i];
        if (A[i] >= B[i])A[i] -= B[i];
        else if (A[i] + A[i + 1] <= B[i]) {
            A[i] = 0;
            A[i + 1] = 0;
        }
        else {
            A[i + 1] -= B[i] - A[i];
            A[i] = 0;
        }
    }
    long long ans = 0;
    rep(i, N + 1)ans += a[i] - A[i];
    cout << ans << endl;
}

Measured memory_bytes: 4556
package main

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

type IntMap map[ // IntMap は、map[Int][Int]に便利メソッドを追加します.
int]int

func lib_AbsInt(value int) int {
	return int(math.Abs(float64(value)))
}
func lib_MinInt(values ...int) (min int, err error) {
	if len(values) == 0 {
		return 0, errors.New("empty slice is given")
	}
	min = values[0]
	for _, value := range values {
		if min > value {
			min = value
		}
	}
	return
}
func lib_NewIntMap() IntMap {
	return map[int]int{}
}
func (m IntMap) ChMin(key, value int, values ...int) (replaced bool, valueAlreadyExist bool) {
	min, _ := lib_MinInt(append(values, value)...)
	if v, ok := m[key]; ok {
		if v > min {
			m[key] = min
			return true, true
		} else {
			return false, true
		}
	}
	m[key] = min
	return true, false
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const initialBufSize = 4096
	const maxBufSize = 1000000
	scanner.Buffer(make([]byte, initialBufSize), maxBufSize)
	scanner.Split(bufio.ScanWords)
	var N int64
	scanner.Scan()
	N, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	var K int64
	scanner.Scan()
	K, _ = strconv.ParseInt(scanner.Text(), 10, 64)
	h := make([]int, N)
	for i := int64(0); i < N; i++ {
		scanner.Scan()
		t, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		h[i] = int(t)
	}
	fmt.Println(solve(int(N), int(K), h))
}
func solve(N int, K int, h []int) int {
	m := lib_NewIntMap()
	m[0] = 0
	for i := 0; i < N; i++ {
		for j := 1; j <= K; j++ {
			if i+j < len(h) {
				m.ChMin(i+j, m[i]+lib_AbsInt(h[i+j]-h[i]))
			}
		}
	}
	return m[N-1]
}


Measured memory_bytes: 9984
n = int(input())
mod = 10**9+7
dp = [[[[0]*4 for _ in [0]*4] for _ in [0]*4] for _ in [0]*(n+1)]
dp[0][3][3][3] = 1
for i in range(1, n+1):
  for c1 in range(4):
    for c2 in range(4):
      for c3 in range(4):
        for k in range(4):
          if (c2, c3, k) == (0, 1, 2) : continue
          if (c2, c3, k) == (1, 0, 2) : continue
          if (c2, c3, k) == (0, 2, 1) : continue
          if (c1, c3, k) == (0, 1, 2) : continue
          if (c1, c2, k) == (0, 1, 2) : continue
          dp[i][c2][c3][k] += dp[i-1][c1][c2][c3]
ans = 0
for c1 in range(4):
  for c2 in range(4):
    for c3 in range(4):
      ans += dp[-1][c1][c2][c3]
      ans %= mod
print(ans)

Measured memory_bytes: 3444
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long ll;

int N;
ll A[200001];
ll acc[200002];

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }
    for (int i = 0; i < N; i++) {
        acc[i + 1] = acc[i] + A[i];
    }
    ll ans = 1LL << 62;
    int i = 1, k = 3;
    for(int j = 2; j < N - 1; j++) {
        while(i + 1 < j) {
            ll newarea = acc[i + 1] - acc[0];
            ll area = acc[i] - acc[0];
            if (abs(newarea - (acc[j] - newarea)) > abs(area - (acc[j] - area))) break;
            i++;
        }
        while(k + 1 < N) {
            ll newarea = acc[k + 1] - acc[j];
            ll area = acc[k] - acc[j];
            if (abs(newarea - (acc[N] - acc[j] - newarea)) > abs(area - (acc[N] - acc[j] - area))) break;
            k++;
        }
        ll mi = min(min(acc[i], acc[j] - acc[i]), min(acc[k] - acc[j], acc[N] - acc[k]));
        ll ma = max(max(acc[i], acc[j] - acc[i]), max(acc[k] - acc[j], acc[N] - acc[k]));        
        ans = min(ans, ma - mi);
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define dump(x) cerr << #x << " = " << x << endl;
#define debug(x) cerr << #x << " = " << x << " (L" << __LINE__ << ")"   \
  << " " << __FILE__ << endl;

int main(int argc, char *argv[])
{
  int s, tmp;
  cin >> s;
  vector<int> v;
  v.push_back(s);
  for(int i = 1; ; i++) {
    if(v.at(i-1) % 2 == 0) {
      tmp = v.at(i-1) / 2;
    } else {
      tmp = v.at(i-1) * 3 + 1;
    }

    for(int j = 0; j < (int)v.size(); j++) {
      if(tmp == v.at(j)) {
        cout << i + 1 << endl;
        return 0;
      }
    }
    v.push_back(tmp);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FOR(type,a,b,c,d) for(type i = a;i b c;i += d)
#define QUICK ios_base::sync_with_stdio(0);cout << fixed;
#define MOD 1000000007

string upper(string);
string lower(string);
bool isalup(string);
bool isalow(string);

int main(){

    int a;cin >> a;
    if(a<=599)
        cout << 8;
    else if(a<=799)
        cout << 7;
    else if(a<=999)
        cout << 6;
    else if(a<=1199)
        cout << 5;
    else if(a<=1399)
        cout << 4;
    else if(a<=1599)
        cout << 3;
    else if(a<=1799)
        cout << 2;
    else if(a<=1999)
        cout << 1;



    return 0;
}









            string upper(string a){
                for(char& c:a){
                    if(islower(c))
                        c -= 32;
                   }
                return a;
            }
                string lower(string a){
                    for(char& c : a){
                        if(isupper(c))
                            c += 32;
                    }
                    return a;
                }
                bool isalup(string a){
                    for(char& c: a){
                        if(islower(c))
                            return false;
                    }
                    return true;
                }
                bool isalow(string a){
                    for(char& c:a){
                        if(isupper(c))
                            return false;
                    }
                   return true;
                }


Measured memory_bytes: 3632
n = gets.to_i
ps = (2*n).times.map{ gets.split.map(&:to_i)}
rel = Array.new(2*n+2){[]}
(n...2*n).each{|i|
    n.times{|j|
        if ps[j][0]<ps[i][0] and ps[j][1]<ps[i][1]
           rel[j] << i
        end
    }
    rel[i] << 2*n+1
}
n.times{|i| rel[2*n] << i}
visited = []

find = ->i{
    return [i] if i==2*n+1
    rel[i].each{|j|
        unless visited[j]
            visited[j] = true
            tmp = find[j]
            if tmp
               tmp << i
               return tmp
            end
        end
    }
    return nil
}

retain = ->a{
    a.each_cons(2){|i,j|
        rel[i] << j
        rel[j].delete(i)
    }
}

res = 0
loop{
    seq = find[2*n]
    break unless seq
    visited = []
    retain[seq]
    res += 1
}
p res

Measured memory_bytes: 4092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
#define BIT_FLAG_1 (1<<1) // 0000 0000 0000 0010
#define BIT_FLAG_2 (1<<2) // 0000 0000 0000 0100
#define BIT_FLAG_3 (1<<3) // 0000 0000 0000 1000
#define BIT_FLAG_4 (1<<4) // 0000 0000 0001 0000
#define BIT_FLAG_5 (1<<5) // 0000 0000 0010 0000
#define BIT_FLAG_6 (1<<6) // 0000 0000 0100 0000
#define BIT_FLAG_7 (1<<7) // 0000 0000 1000 0000

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;    
}

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

int n,mod,s[3010][3010],jc[3010],inv[3010],ans;

int quickmi(int a,int b,int m=mod)
{
	int t=1;
	for (; b; b>>=1,a=1ll*a*a%m)
		if (b&1) t=1ll*t*a%m;
	return t;
}

int main()
{
	scanf("%d%d",&n,&mod),s[0][0]=1;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=i; j++)
			s[i][j]=(s[i-1][j-1]+1ll*j*s[i-1][j])%mod;
	jc[0]=1;
	for (int i=1; i<=n; i++) jc[i]=1ll*jc[i-1]*i%mod;
	inv[n]=quickmi(jc[n],mod-2);
	for (int i=n; i; i--) inv[i-1]=1ll*inv[i]*i%mod;
	for (int i=1; i<=n; i++)
		for (int j=2; j<=i; j++) s[i][j]=1ll*s[i][j]*jc[j]%mod;
	for (int i=1; i<=n; i++)
	{
		int nw=0;
		for (int j=0,ww=quickmi(2,n-i),w=1; j<=i; j++,w=1ll*w*ww%mod)
			nw=(nw+1ll*(s[i][j+1]+s[i][j])*w%mod*inv[j])%mod;
		nw=1ll*nw*inv[i]%mod*inv[n-i]%mod*jc[n]%mod*quickmi(2,quickmi(2,n-i,mod-1))%mod;
		ans=(ans+1ll*((i&1)?1:(mod-1))*nw)%mod;
	}
	ans=quickmi(2,quickmi(2,n,mod-1))-ans;
	return printf("%d\n",(ans+mod)%mod),0;
}

Measured memory_bytes: 34304
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N=1e5+7;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans;
        ll a1=b/c,a2=b/d,a3=b/(c*d/gcd(c,d));
        ll b1=a/c,b2=a/d,b3=a/(c*d/gcd(c,d));
        if(b1*c<a)
            b1++;
        if(b2*d<a)
            b2++;
        if(b3*(c*d/gcd(c,d))<a)
                b3++;
    /*if(a1*c<b)
        a1++;
    if(a2*d<b)
        a2++;
    if(a3*c*d<b)
        a3++;*/
            ll x1=(a1-b1+1),x2=(a2-b2+1),x3=(a3-b3+1);
            if(a1<b1)x1=0;
            if(a2<b2)x2=0;
            if(a3<b3)x3=0;
    ans=b-a+1-x1-x2+x3;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int s = 0;
			int ans = 0;
			for(int i=1;i<=12;i++){
				s += sc.nextInt()-sc.nextInt();
				if(ans==0&&s>=n)ans=i;
			}
			System.out.println(ans==0?"NA":ans);
		}
	}
}

Measured memory_bytes: 34568
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		int n = sc.nextInt();
		calc(n);
	}
	public void calc(int n){
		int[] memo = new int[100001];
		for(int i = 0; i < n; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			for(int j = a-1; j < b; j++){
				memo[j] += 1;
			}
		}
		
		int max = 0;
		for(int i = 0; i < 100001; i++){
			int d = memo[i];
			if(d > max){
				if(d >= i) {
					d = i;
					max = d;
				}
			}
		}
		
		System.out.println(max);
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 99880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

// DAME: ハミルトンパス
vector<bool> seen;
int n, m, ans;
void dfs(const Graph &G, int v){
    bool all_seen = true;
    for(int i=0; i<n; i++){
        if(seen[i] == false && i!=v){
            all_seen = false;
            break;
        }
    }

    if(all_seen){
        ans++;
        return;
    }
    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        dfs(G, next_v);
    }
    seen[v] = false;
}

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

    Graph G(n);
    for(int i=0; i<m; ++i){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    seen.assign(n, false);
    dfs(G, 0);

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

Measured memory_bytes: 256
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
#include<set>
#include<queue>
#include<deque>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<tuple>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(ll i = 1;i <=  n; i++)
#define rrep(i,n) for(ll i = n -1;i >= 0;i--)
#define ALL(obj) rbegin(obj), rend(obj)
typedef long long int ll;
typedef long double ld;
const ll INF = 1e9;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}ll n,k,sum = 0,p = 1e8,m; string s;

int main() {
	cin >> n >> k; vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll right = 0;
	rep(left, n) {
		while (right < n && sum < k) {
			sum += a[right];
			right++;
		}
		if (sum < k) break;
		p = min(p, right - left);
		if (left == right) right++;
		else sum -= a[left];
	}if (p == 1e8) cout << 0 << endl;
	else cout << p << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Point{
	bool operator<(const struct Point &arg) const{
		if(y != arg.y)return y < arg.y;
		return x < arg.x;
	};
	Point(){
		x = 0;
		y = 0;
		town_id = 0;
	}
	Point(double arg_x,double arg_y,int arg_town_id){
		x = arg_x;
		y = arg_y;
		town_id = arg_town_id;
	}
	void set(double arg_x,double arg_y,int arg_town_id){
		x = arg_x;
		y = arg_y;
		town_id = arg_town_id;
	}
	double x,y;
	int town_id;
};

struct Edge{
	bool operator<(const struct Edge &arg) const{
		return cost < arg.cost;
	}
	int from,to;
	double cost;
};

int boss[100],height[100];
Edge edge[1000];


int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int IS_SAME(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		height[x]++;
	}
}


bool calcGaiseki(Point left,Point base, Point right){
	double gaiseki = (left.x-base.x)*(right.y - base.y)-(left.y-base.y)*(right.x-base.x);
	if(gaiseki < -0.00000001)return false;
	else{
		return true;
	}
}

double calc_dist(Point a,Point b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

int main(){

	vector<Point> V,UP,DOWN;
	Point point[100];

	int N,R;
	double x,y;

	scanf("%d %d",&N,&R);

	for(int i = 0; i < N; i++){
		scanf("%lf %lf",&x,&y);
		point[i].set(x,y,i);
		V.push_back(Point(x,y,i));
	}

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

	UP.push_back(V[0]);
	UP.push_back(V[1]);

	DOWN.push_back(V[V.size()-1]);
	DOWN.push_back(V[V.size()-2]);

	for(int i = 2; i < V.size(); i++){
		while(UP.size() > 1 && calcGaiseki(UP[UP.size()-2],UP[UP.size()-1],V[i]) == false)UP.pop_back();
		UP.push_back(V[i]);
	}

	for(int i = V.size()-3; i >= 0; i--){
		while(DOWN.size() > 1 && calcGaiseki(DOWN[DOWN.size()-2],DOWN[DOWN.size()-1],V[i]) == false){
			DOWN.pop_back();
		}
		DOWN.push_back(V[i]);
	}


	double ans = 0.0;

	for(int i = 0; i < N; i++){
		boss[i] = i;
		height[i] = 0;
	}

	for(int i = DOWN.size()-1; i >= 1;i--){
		ans += calc_dist(DOWN[i],DOWN[i-1]);
		unite(DOWN[i].town_id,DOWN[i-1].town_id);
	}

	for(int i = UP.size()-1; i >= 1 ;i--){
		ans += calc_dist(UP[i],UP[i-1]);
		unite(UP[i].town_id,UP[i-1].town_id);
	}

	for(int i = 0; i < R; i++){
		scanf("%d %d",&edge[i].from,&edge[i].to);
		edge[i].from--;
		edge[i].to--;
		edge[i].cost = calc_dist(point[edge[i].from],point[edge[i].to]);
	}
	sort(edge,edge+R);

	for(int i = 0; i < R; i++){
		if(!IS_SAME(edge[i].from,edge[i].to)){
			unite(edge[i].from,edge[i].to);
			ans += edge[i].cost;
		}
	}
	printf("%.10lf\n",ans);

}



Measured memory_bytes: 3308
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n;
  int i,j=0;
  double b,x;
  string s;
  
  cin>>n;
  
  for(i=0;i<n;i++){
    cin>>x>>s;
    if(s=="JPY")
      j+=x;
    else
      b+=x;
  }
  cout<<j+b*380000.0<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

int n, m;
ll v[60];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }

    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) {
            if (i + j > m || i + j > n) break;
            int num = m - (i + j);
            vector<ll> vec;
            ll sum = 0;
            for (int x = 0; x < i; ++x) {
                vec.emplace_back(v[x]);
                sum += v[x];
            }
            for (int x = 0; x < j; ++x) {
                vec.emplace_back(v[n - 1 - x]);
                sum += v[n - 1 - x];
            }
            sort(vec.begin(), vec.end());
            for (int k = 0; k < min(num, (int) vec.size()); ++k) {
                if (vec[k] > 0) break;
                sum -= vec[k];
            }
            ans = max(ans, sum);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

string s;
int k;

vector<string> t;

int main(){
	cin>>s;
	cin>>k;
	
	for(int i=0;i<=s.size();i++){
		string ss;
		for(int j=i;j<i+k&&j<s.size();j++){
			ss+=s[j];
			t.push_back(ss);
		}
	}
	
	sort(t.begin(),t.end());
	t.erase(unique(t.begin(),t.end()),t.end());
	cout<<t[k-1]<<endl;
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define N 100005
#define rep(i,a,n) for(int i=a;i<n;++i)
#define pb push_back
#define mp make_pair
#define LL long long
#define fi first
#define se second

set<int>f;
void fun(int n){
    int i,s,m=sqrt(2*n);
    while(m*(m+1)<n*2)
        ++m;
    while(m*(m+1)>2*n)
        --m;
    ++m;
    s=(m+1)*m/2;
    s-=n;
    for(i=1;i<=m;++i){
        if(i==s) continue;
        cout<<i<<' ';
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    fun(n);
    return 0;
}


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

#define mx 200005
#define ll long long 

int ar[mx];
char ch[mx];

int m,n,k,ii;


void solve()
{
	scanf("%d%s",&n,ch);
	if(n==1)
	{
		printf("0\n");
		return;
	}
	int be=0,en=n-1,re=0;
	while(be<en)
	{
		while(be<en && ch[be]!='W')be++;
		while(be<en && ch[en]!='R')en--;
		if(be==en)break;
		re++;
		be++;
		en--;

	}
	printf("%d\n",re );
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif

	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

int a[100001][3],f[100001][3];

int main(){
	int N;
	scanf("%d",&N);
	for(int i=1;i<=N;++i)
		scanf("%d%d%d",&a[i][0],&a[i][1],&a[i][2]);
	f[1][0]=a[1][0];
	f[1][1]=a[1][1];
	f[1][2]=a[1][2];
	for(int i=2;i<=N;++i){
		f[i][0]=max(f[i-1][1],f[i-1][2])+a[i][0];
		f[i][1]=max(f[i-1][0],f[i-1][2])+a[i][1];
		f[i][2]=max(f[i-1][0],f[i-1][1])+a[i][2];
	}
	int ans=max(f[N][0],f[N][1]);
	cout<<max(ans,f[N][2])<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
  int N; cin >> N;
  vector<ll> A(N+1),B(N);
  for (int i = 0; i < N+1; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  
  ll ans = 0;
  for (int i = N-1; i >= 0; i--) {
    if (B[i] >= A[i+1]) {
      ans += A[i+1];
      B[i] -= A[i+1];
      ans += min(B[i],A[i]);
      A[i] = max(A[i]-B[i],ll(0));
    } else ans += B[i];
  }
  
  cout << ans << endl;
    
}

Measured memory_bytes: 1792
M, N = [int(k) for k in input().split(' ')]
import math 
res = 0

if N >= 2:
  res += (math.factorial(N) // math.factorial(2) // math.factorial(N - 2))

if M >= 2:
  res += (math.factorial(M) // math.factorial(2) // math.factorial(M - 2))

print(res)

Measured memory_bytes: 3060
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a = inpl()
for i in a:
    if i%2==0:
        print(0)
        break
else:
    a.sort()
    print(a[0]*a[1])

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;



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

  vector<vector<pair<int, string>>> dp(12);


  dp[0].emplace_back(make_pair(0, ""));

  for (int i = 1; i <= n; i++){
    for (int j = 0; j < dp[i-1].size(); j++){
      int num = dp[i-1][j].first;
      string s = dp[i-1][j].second;
      for (int k = 0; k < num + 1; k++){
        string t = {('a' + k)};
        if (k < num)
          dp[i].emplace_back(make_pair(num, s + t));
        else
          dp[i].emplace_back(make_pair(num + 1, s + t));
      }
    }
  }

  for (int i = 0; i < dp[n].size(); i++){
    cout << dp[n][i].second << endl;
  }
  

  return 0;
}


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

typedef long long int ll;

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<pair<ll,ll>> ab(m);
    for(ll i = 0;i < m;i++){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());
    vector<ll> c(n);
    c[0] = 0;
    for(ll i = 0;i < m - 1;i++){
        if(ab[i].first != ab[i + 1].first){
            c[ab[i + 1].first - 1] = i + 1;
        }
    }
    bool f = false;
    for(ll i = 0;ab[i].first == 1;i++){
        ll t = ab[i].second;
        if(c[t - 1] != 0){
            for(ll j = 0;ab[c[t - 1] + j].first == t;j++){
                if(ab[c[t - 1] + j].second == n){
                    f = true;
                    break;
                }
            }
        }
        if(f){
            break;
        }
    }

    if(f){
        cout << "POSSIBLE";
    }
    else{
        cout << "IMPOSSIBLE";
    }

    return 0;
}

Measured memory_bytes: 4992
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextInt();
		long M = sc.nextInt();
		
		
		List<D> list = new ArrayList<>((int)N);
		for (int i = 0; i < N; i++) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			list.add(new D(b,a));
		}
		
		list = list.stream().sorted().collect(Collectors.toList());
		
		
		long sum = 0;
		for (D d : list) {
			if (d.count <= M) {
				M -= d.count;
				sum += d.val * d.count;
			} else {
				sum += d.val * M;
				break;
			}
		}
		
		System.out.println(sum);
	}
	
	static class D implements Comparable<D>{
		long count;
		long val;
		
		D (long count, long val) {
			this.count = count;
			this.val = val;
		}
				
		@Override
		public int compareTo(D o) {
			if (this.val > o.val)
				return 1;
			else if (this.val < o.val)
				return -1;
			
			return 0;
		}
		
		
	}
}


Measured memory_bytes: 95096
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean humi = true;
        String s = sc.next();
        String[] sArray = s.split("");
        for (int i = 0; i < sArray.length; i++) {
            if ((i + 1) % 2 == 0) {
                if ((sArray[i].equals("L")) || (sArray[i].equals("U")) || (sArray[i].equals("D"))) {
                } else {
                    humi = false;
                }
            } else {
                if ((sArray[i].equals("R")) || (sArray[i].equals("U")) || (sArray[i].equals("D"))) {
                } else {
                    humi = false;
                }
            }
            if (!humi)
                break;
        }
        if (humi) {
            System.out.println("Yes");
        } else {
            System.out.println("No");

        }
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[] = {-1,0,1,0,-1,-1,1,1};
const int dy[] = {0,-1,0,1,1,-1,1,-1};

int main(){
  int n; cin>>n;
  int c[n],dp[101010];
  rep(i,n) cin>>c[i];
  rep(i,n) dp[i]=INF;
  rep(i,n){
    int key=lower_bound(dp,dp+n,c[i])-dp;
    //cout<<key<<endl;
    dp[key]=c[i];
  }
  int ans=0;
  rep(i,n) if(dp[i]!=INF) ans=i+1;
  //rep(i,n) cout<<c[i]<<" ";
  //cout<<endl;
  //rep(i,n) cout<<dp[i]<<" ";
  //cout<<endl;
  cout<<ans<<endl;
}



Measured memory_bytes: 3916
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
string N;

int main(int argc, char const *argv[])
{
    cin>>N;
    if(N[0]=='9'||N[1]=='9'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::unordered_map<int64_t, int64_t> a;
    for (int64_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        if (t > 0) {
            a[t - 1] = a[t - 1] + 1;
        }
        a[t] = a[t] + 1;
        a[t + 1] = a[t + 1] + 1;
    }

    auto maxV = std::make_pair<int64_t, int64_t>(0, 0);
    for (auto v: a) {
        if (maxV.second < v.second) {
            maxV = v;
        }
    }

    std::cout << maxV.second << std::endl;

    return 0;
}


Measured memory_bytes: 4260
import bisect

n,k = map(int,input().split())
a = list(map(int,input().split()))

ind = [[] for _ in range(2*10**5 + 1)]
for i,num in enumerate(a):
    ind[num].append(i)

for i in range(1,2*10**5 + 1):
    if(ind[i]):
        ind[i].append(ind[i][0] + n)

before = []
cnt = 0
now = a[0]
while(True):
    right = bisect.bisect_right(ind[now], cnt%n)
    cnt += ind[now][right] - ind[now][right-1] + 1
    if(ind[now][right] >= n):
        before.append(ind[now][right-1])
    now = a[cnt%n]
    if(cnt%n == 0):
        break

if(cnt//n==1):
    print('')
    exit()

cyc = k%(cnt//n)

cnt = before[cyc-1]
ans = []
while(cnt < n):
    now = a[cnt]
    right = bisect.bisect_right(ind[now],cnt)
    if(ind[now][right] >= n):
        ans.append(now)
        cnt += 1
    else:
        cnt = ind[now][right] + 1

print(' '.join(map(str,ans)))

Measured memory_bytes: 128464
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#endif

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <vector>

using namespace std;

typedef long long LL;
static const LL INF = 1LL << 60;

template<typename T, int SIZE, T DEF_VAL, const T& Compare(const T&, const T&)>
class SegmentTree {
	vector<T> val;
public:
	SegmentTree() : val(SIZE * 2, DEF_VAL) { }
	void update(int i, const T& value) {
		i += SIZE;
		val[i] = value;
		while (i > 1) i >>= 1, val[i] = Compare(val[i * 2], val[i * 2 + 1]);
	}
	T get(LL a, LL b, int l = 0, int r = SIZE, size_t i = 1) {
		if (r <= a || b <= l) return DEF_VAL;
		if (a <= l && r <= b) return val[i];
		return Compare(get(a, b, l, (l + r) / 2, i * 2), get(a, b, (l + r) / 2, r, i * 2 + 1));
	}
	LL find_leftmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
		if (Compare(val[i], value) != val[i]) return -1;
		if (r <= a || b <= l) return -1;
		if (i >= SIZE) return i - SIZE;
		LL leftmost_index = find_leftmost_index(a, b, value, l, (l + r) / 2, i * 2);
		if (leftmost_index >= 0) return leftmost_index;
		return find_leftmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
	}
	LL find_rightmost_index(LL a, LL b, const T& value, int l = 0, int r = SIZE, int i = 1) {
		if (Compare(val[i], value) != val[i]) return -1;
		if (r <= a || b <= l) return -1;
		if (i >= SIZE) return i - SIZE;
		LL rightmost_index = find_rightmost_index(a, b, value, (l + r) / 2, r, i * 2 + 1);
		if (rightmost_index >= 0) return rightmost_index;
		return find_rightmost_index(a, b, value, l, (l + r) / 2, i * 2);
	}
};

void solve(long long H, long long W, std::vector<long long> &A, std::vector<long long> &B) {
	SegmentTree<long long, 1 << 18, INF, min> st;
	for (int i = 0; i < W; ++i) {
		st.update(i, 0);
	}
	for (LL y = 0; y < H; ++y) {
		LL a = A[y], b = B[y];
		while (true) {
			LL min_value = st.get(a, b);
			if (min_value == INF) break;
			LL index = st.find_leftmost_index(a, b, min_value);
			LL next_cost = min_value + b - index;
			if (b < W && next_cost < st.get(b, b + 1)) {
				st.update(b, next_cost);
			}
			st.update(index, INF);
		}
		LL cost = y + 1 + st.get(0, W);
		cout << (cost < INF ? cost : -1) << endl;
	}
}

int main() {
    long long H;
	scanf("%lld", &H);
	long long W;
	scanf("%lld", &W);
	std::vector<long long> A(H);
	std::vector<long long> B(H);
	for (int i = 0; i < H; i++) {
		scanf("%lld", &A[i]); A[i]--;
		scanf("%lld", &B[i]);
	}
	solve(H, W, A, B);
	return 0;
}


Measured memory_bytes: 10424
/*================================================================
*
*   创 建 者： badcw
*   创建日期： 2020/6/21 20:02
*
================================================================*/
#include <bits/stdc++.h>

#define ll long long
using namespace std;

const int maxn = 1003;
const int mod = 1e9+7;
ll qp(ll a, ll n, ll mod = ::mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(int argc, char* argv[]) {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
    sort(a.begin(), a.end());
    int res = 0;
    for (int i = 0; i < k; ++i) res += a[i];
    printf("%d\n", res);
    return 0;
}

Measured memory_bytes: 3780
// organize and work - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long 
void solve(){
	string s;	cin>>s;
	if(s[0]=='S'){cout<<"Cloudy\n";
	} else if(s[0]=='C'){cout<<"Rainy\n";
		} else{
			cout<<"Sunny\n";}
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;//cin>>t;
	t=1;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

bool[10^^5+1] NS;

void main()
{
    auto nk = readln.split.to!(int[]);
    auto N = nk[0];
    auto K = nk[1];

    auto as = readln.split.to!(int[]);

    foreach (i; 0..K+1) {
        bool win;
        foreach (j; 0..N) if (i >= as[j] && !NS[i - as[j]]) {
            win = true;
            break;
        }
        NS[i] = win;
    }

    writeln(NS[K] ? "First" : "Second");
}

Measured memory_bytes: 384
#include <stdio.h>
int main(){
	int x=0,y=0,z=0,a,b,c,d,e=0,f=0,m[100][100],n[100],sum=0;

	scanf("%d %d",&a,&b);
	while(1){
		while(1){
			if(z==b)
				break;
			scanf("%d",&c);
			m[y][z]=c;
			z++;
		}
		z=0;
		y++;
		if(y==a)
			break;
	}
	while(1){
		if(x==b)
			break;
		scanf("%d",&d);
		n[x]=d;
		x++;
	}
	while(1){
		while(1){
			if(e==b){
				printf("%d\n",sum);
				sum=0;
				goto loop;
			}
			sum += m[f][e]*n[e];
			e++;
		}
		loop:
		e=0;
		f++;
		if(f==a)
			break;
	}
	return 0;
}

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

const int MAX = 1e5 + 10;
typedef long long int ll;
typedef pair<ll,ll> pii;

vector<pii> a[MAX];
ll dist[MAX]={0};

void dfs(int x,int p) {

	for(auto y:a[x]) {
		if(y.first != p) {
			//cout<<"Adding edge : "<<x<<" -> "<<y.first<<" wright : "<<y.second<<endl;
			dist[y.first] = dist[x] + y.second;
			dfs(y.first,x);
		}
	}
}

int main()
{
	int n; cin>>n;
	for(int i=0;i<n-1;i++) {
		ll u,v,w; cin>>u>>v>>w;
		pii t; t.first = v; t.second = w;
		pii y; y.first = u; y.second = w;
		//cout<<u<<" "<<v<<" "<<w<<endl;
		a[u].push_back(t); a[v].push_back(y);
	}

	dfs(1,1);

	for(int i=1;i<=n;i++){
		cout<<dist[i]%2<<endl;
	}
	
}

Measured memory_bytes: 10240
#include <iostream>

using namespace std;

typedef long long ll;

int main () {
  ll n, a, b;
  cin >> n >> a >> b;

  if (a > b) {
    cout << 0 << endl;
    return 0;
  }

  if (n == 1 && a != b) {
    cout << 0 << endl;
    return 0;
  } 
  
  ll mx = (n - 1) * b + a;
  ll mn = (n - 1) * a + b;
  cout << mx - mn + 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int a,b,C;
    double S,L,h,t;
    double PI=acos(-1);
    
    scanf("%d %d %d",&a,&b,&C);
    h=b*sin(C*PI/180);
    t=b*cos(C*PI/180);
    S=0.5*a*h;
    L=a+b+sqrt(h*h+(a-t)*(a-t));
    
    printf("%lf\n",S);
    printf("%lf\n",L);
    printf("%lf\n",h);
    
    return 0;
}


Measured memory_bytes: 2048
S = list(input())

g = 0
k = 0
for i in range(0,len(S)):
  if S[i] == "1":
    if i % 2 == 0:
      g += 1
    else:
      k += 1

fill_1_g = int(len(S)/2) - g
fill_1_k = int(len(S)/2) - k
if len(S) % 2 == 1:
  fill_1_g += 1

print(min([fill_1_g + k, fill_1_k + g]))



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

typedef long long ll;

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main()
{
    string S;
    string T;
    string U;

    int A;
    int B;

    cin >> S;
    cin >> T;

    cin >> A;
    cin >> B;

    cin >> U;

    if(S==U){
        cout << A-1 << " " << B << endl;
    }
    else{
        cout << A << " " << B-1 << endl;
    }


    return 0;
}

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

int n;
void dfs(char maxc, string ans){
    if(ans.size() == n) {
        cout << ans << endl;
        return;
    }
    for(char c = 'a'; c <= maxc; c++){
        if(c == maxc) dfs(maxc + 1, ans + c);
        else dfs(maxc, ans + c);
    }
}

signed main() {
    cin >> n;

    dfs('a', "");
}

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

using namespace std;

int main()
{
    int a;
    char c;
    string b;
    map<string, int> cnt;
    while (cin >> a >> c >> b) {
        cnt[b]++;
    }
    cout << cnt["A"] << endl;
    cout << cnt["B"] << endl;
    cout << cnt["AB"] << endl;
    cout << cnt["O"] << endl;
    return 0;
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long a,i,j,k;
    double b,c,d,ct=0.00;
    cin>>a;
    cin>>b>>c;
    vector<double>vc;
    for( i=0; i<a; i++)
    {
        cin>>d;
        vc.push_back(b-d*6.00/1000.00);
    }

    ct=vc[0];
    k=0;
    for( i=1; i<a; i++)
    {
        //cout<<abs(ct-c)<<" "<<abs(vc[i]-c)<<endl;
        if((abs(ct-c))>(abs(vc[i]-c)))
        {

            k=i;
            ct=vc[i];

        }



    }

    cout<<k+1;



}


Measured memory_bytes: 256
c=[0]*6**8
n,a=open(0)
for a in a.split():c[int(a)]+=1
print(('not','psaeitr'[any(c:=[max(0,sum(c[i::i])-1)for i in range(2,6**8)])::2]+'wise')[max(c)+1<int(n)],'coprime')

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

using ll = long long;

const int mod = 1e9 + 7;

bool is_prime[1000001];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    fill(is_prime, is_prime + 1000001, true);
    for (int i = 2; i <= 1000000; i++) {
        if (!is_prime[i])
            continue;
        for (int j = i * 2; j <= 1000000; j += i) {
            is_prime[j] = 0;
        }
    }
    int X;
    cin >> X;
    for (int i = X; i <= 1000000; i++) {
        if (is_prime[i]) {
            cout << i << endl;
            return 0;
        }
    }
}

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

void myReplace(int be, int en, string& src) {
    string replacement;
    cin >> replacement;

    src.erase(be, en - be + 1);
    src.insert(be, replacement);
}

void myReverse(int be, int en, string& src) {
    int i = be, j = en;
    while (1) {
        if (i >= j) {return;}
        src[i] = src[i] ^ src[j];
        src[j] = src[i] ^ src[j];
        src[i] = src[i] ^ src[j];
        ++i;
        --j;
    }
}

void myPrint(int be, int en, string& src) {
    string tmp = "";
    tmp.assign(src, be, en - be + 1);

    cout << tmp << endl;
}

int main() {
//    freopen("in.txt", "r", stdin);

    int q, be, en;
    string op, src, p;

    cin >> src >> q;
    for (int i = 0; i < q; ++i) {
        cin >> op >> be >> en;

        if (op == "replace") {myReplace(be, en, src);}
        else if (op == "reverse") {myReverse(be, en, src);}
        else if (op == "print") {myPrint(be, en, src);}
    }
}

Measured memory_bytes: 3208
import java.util.*;
public class Main{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		if(n % k < k - (n %k))
			k = n % k;
		else 
			k = k - (n %k);
		System.out.println(k);
	}
}

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


int main(){
  int H, W;
  cin >> H >> W;
  
  for(int x = 0; x < W+2; x++){
    cout <<"#";
  }
  cout << endl;
  for(int y = 0; y < H; y++){
    cout <<"#";
    for(int x = 0; x < W; x++){
      char c;
      cin >> c;
      cout << c;
    }
    cout <<"#"<< endl;
  }
  
  for(int x = 0; x < W+2; x++){
    cout <<"#";
  }
  
  
  return 0;
}

Measured memory_bytes: 256
m, d = map(int, input().split())
counter = 0
for mon in range(1, m + 1):
    for day in range(1, d + 1):
        if day >= 22 and int(str(day)[0]) >= 2 and int(str(day)[1]) >= 2:
            if int(str(day)[0]) * int(str(day)[1]) == mon:
                counter += 1
print(counter)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <iostream>

int main() {
  int a;
  int b;
  int C;
  std::cin >> a >> b >> C;

  double d2a = M_PI / 180;
  double area;
  area = 0.5 * a * b * sin(C * d2a);

  double c;
  c = sqrt((a * a) + (b * b) - 2 * a * b * cos(C * d2a));
  double circumference;
  circumference = a + b + c;

  double height;
  height = b * sin(C * d2a);

  printf("%.4f\n", area);
  printf("%.4f\n", circumference);
  printf("%.4f\n", height);

  return 0;
}

Measured memory_bytes: 3464
#include "bits/stdc++.h"
#pragma optimize("unroll-loops");
#pragma optimize("Ofast");
// #include "pch.h"    
using namespace std;

#ifdef DEBUG_BUILD
#  define DEBUG(x) cerr << x
#else
#  define DEBUG(x) do {} while (1)
#endif

#define imie(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)

using ll = long long;
const ll nax = 1e7 + 10;
const int mod = 1e9 + 7;
vector<int> primes;

int abs(int a, int b) {
    if(a > b) {
        return a - b;
    }
    return b - a;
}

int main() {
    int x, n;
    cin >> x >> n;
    unordered_map<int, bool> here;
    while(n--) {
        int p;
        cin >> p;
        here[p] = true;
    }
    
    
    int mn = INT_MAX;
    int ans;
    
    for(int a = -1000; a <= 1000; ++a) {
        if(here.count(a) == 0) {
            if(abs(a, x) < mn) {
                mn = abs(a, x);
                ans = a;
            }
        }
    }
    
    cout << ans << "\n";
}
    
    
    
    
    














Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
/*
alias p='g++ -std=c++17 -O2 pra.cpp'
alias pg='g++ -std=c++17 -O2 -g pra.cpp'
alias s='g++ -std=c++17 -O2 -g subpra.cpp'
alias ss='g++ -std=c++17 -O2 -g sspra.cpp'
ulimit -c unlimited
alias a='./a.out'
cd programming
cd cpp
cd practice

*/
using ll = long long;
#define rep(i, n) for(int i=0; i<(n); i++)
//if (i) cout << " "; で最初のみ空白文字を出力することができる
#define Sort(v) sort((v).begin(), (v).end())
#define pb push_back
using veci = vector<int>;
using vecs = vector<string>;
using vecd = vector<double>;
using vecl = vector<long long>;
using G = vector<vector<int>>;
using P = pair<int, int>;
double PI = acos(-1);
ll lINF = LLONG_MAX; ll lmINF = LLONG_MIN;
int INF = INT_MAX; int mINF = INT_MIN;
//const ll mod = 1000000007;
int main() {
    cout.precision(10);
    cin.tie(0);//cin高速化
    string a;
    cin >> a;
    vecs s(3, " ");
    for (int bit=0; bit < (1<<3); bit++){//2通りある部分で、全パターンの列挙
        int ans=a[0]-'0';
        for(int i=0; i<3; i++){
            if (bit&(1 << i)){//フラグが立っていれば
                s[i] = "+";
                ans += a[i+1]-'0';
            }
            else{
                s[i] = "-";
                ans -= a[i+1]-'0';
            }
        }
        if (ans == 7){
            cout << a[0] << s[0] << a[1] << s[1] << a[2] << s[2] << a[3] << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	int n;
	while (scanf("%d", &n), n){
		int magic[16][16] = {0};
		int hn = n / 2;
		int x, y;
		int i, j;
		int number = 1;
		
		y = x = hn;
		y++;
		
		while (number <= n * n){
			if (magic[y][x]){
				y = (y + 1 + n) % n;
				x = (x - 1 + n) % n;
				continue;
			}
			magic[y][x] = number;
			y = (y + 1) % n;
			x = (x + 1) % n;
			number++;
		}
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				printf("%4d", magic[i][j]);
			}
			puts("");
		}
	}
	return (0);
}

Measured memory_bytes: 620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL; 

int get_mojisu(int i)
{
	int ans = 1;
	while(i / 10)
	{
		ans++;
		i /= 10;
	}

	return ans;
}



//ここから書き始める
int main(int argc, char const *argv[])
{
	int N,M;
	cin >> N >> M;

	vector<tuple<int,int,int>> city(M);
	int p_inf[N];
	REP(i,N+1)
	{
		p_inf[i] = 1;
	}
	string ans[M];

	REP(i,M)
	{
		int tmp1,tmp0;
		//cin >> get<1>(city[i]) >> get<0>city[i];
		cin >> tmp1 >> tmp0;
		city[i] = make_tuple(tmp0,tmp1,i);
	}
	int kami,simo;

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

	REP(i,M)
	{
		string kami_st,simo_st;
		int ken = get<1>(city[i]);
		kami_st = to_string(ken);
		dump(kami_st)
		simo = p_inf[ken];
		simo_st = to_string(simo);
		dump(simo_st)
		p_inf[ken]++;

		int ken_mojisu = get_mojisu(ken);
		dump(ken_mojisu)
		int num_mojisu = get_mojisu(simo);
		dump(num_mojisu)
		REP(t,6-ken_mojisu)
		{
			kami_st = '0' +  kami_st;
			dump(kami_st)
		}
		REP(t,6-num_mojisu)
		{
			simo_st = '0' + simo_st;
			dump(simo_st)
		}

		ans[get<2>(city[i])] = kami_st + simo_st;



	}
	REP(i,M)
	{
		cout << ans[i] << endl;
	}


	

}


Measured memory_bytes: 10112
#include <iostream>
using namespace std;
int main(){
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	int pt1,pt2,pt3;
	pt1=a*x+b*y;
	pt2=(x>y?y:x)*2*c;
	pt3=(x>y?x:y)*2*c;
	if(x>y){
		pt2+=(x-y)*a;
	}else{
		pt2+=(y-x)*b;
	}
	printf("%d\n",(pt1>pt2)?(pt2>pt3?pt3:pt2):(pt1>pt3?pt3:pt1));
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
char out(int l[]){
  if(l[0]!='s'&&l[0]==l[3]&&l[3]==l[6]) return l[0];
  if(l[0]!='s'&&l[0]==l[4]&&l[4]==l[8]) return l[0];
  if(l[0]!='s'&&l[0]==l[1]&&l[1]==l[2]) return l[0];
  if(l[1]!='s'&&l[1]==l[4]&&l[4]==l[7]) return l[1];
  if(l[2]!='s'&&l[2]==l[5]&&l[5]==l[8]) return l[2];
  if(l[2]!='s'&&l[2]==l[4]&&l[4]==l[6]) return l[2];
  if(l[3]!='s'&&l[3]==l[4]&&l[4]==l[5]) return l[3];
  if(l[6]!='s'&&l[6]==l[7]&&l[7]==l[8]) return l[6];
  return 'd';
}
int main(void){
  string line;
  while(cin>>line){
    int s[9];
    REP(i,9)s[i]=line[i];
    cout<<out(s)<<endl;
  }
  return 0;
}

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

int an(int a, int r, int D) {
	return r*a - D;
}

int main() {
	int ant[11];
	int r, D, a;
	cin >> r >> D >> a;
	ant[0] = a;
	for (int i = 1; i < 11; i++) {
		ant[i] = an(ant[i - 1], r, D);
		cout << ant[i] << endl;
	}
}

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

int main()
{
	int n,m,k[30],a[30][30],v=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>k[i];
		for(int j=0;j<k[i];j++) cin>>a[i][j];
	}
	
	for(int i=1;i<=m;i++){
		for(int j=0;j<n;j++){
			bool f=0;
			for(int l=0;l<k[j];l++){
				if(i==a[j][l]){
					f=1;
					break;
				}
			}
			if(f==0) break;
			if(j==n-1) v++;
		}
	}
	
	cout<<v<<endl;
	
	return 0;
}


Measured memory_bytes: 256