akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}

int main(){
    ll n,m;
    cin >> n>>m;
    ll ans = min(n%m,abs((n%m)-m));
    cout << ans << endl;
}



Measured memory_bytes: 256
# coding=utf-8
 
class Node:
    def __init__(self, ID, left, right):
        ### information for output ###
        self.id = ID
        self.parent = -1
        self.sibling = -1
        self.degree = -1
        self.depth = 0
        self.height = 0
        self.type = None
 
        ### other information ###
        self.left_child = left
        self.right_child = right
 
def calc_depth(i):
    global node_list
 
    if node_list[i].depth != 0:
        return node_list[i].depth
 
    depth = 0
    if node_list[i].parent != -1:
        depth = calc_depth(node_list[i].parent) + 1
 
    node_list[i].depth = depth
    return depth
 
 
def calc_height(i):
    global node_list
 
    if node_list[i].height != 0:
        return node_list[i].height
 
    h1 = h2 = 0
    if node_list[i].right_child != -1:
        h1 = calc_height(node_list[i].right_child) + 1
    if node_list[i].left_child != -1:
        h2 = calc_height(node_list[i].left_child) + 1
 
    height = max(h1, h2)
    node_list[i].height = height
    return height
 
n = int(input())
data = [tuple(map(int, input().split())) for x in range(n)]
node_list = []
 
for data_row in data:
    ID, left, right = data_row
    node = Node(ID, left, right)
    node_list.append(node)
 
node_list.sort(key = lambda node: node.id)
 
for i, node in enumerate(node_list):
    left = node.left_child
    right = node.right_child
    degree = 0
 
    ### child information ###
    if left != -1:
        degree += 1
        node_list[left].parent = i
        node_list[left].sibling = right
 
    if right != -1:
        degree += 1
        node_list[right].parent = i
        node_list[right].sibling = left
 
    ### self information ###
    node.degree = degree
 
for i in range(n):
    calc_depth(i)
    calc_height(i)
 
    node = node_list[i]
 
    if node.depth == 0:
        node.type = 'root'
    elif node.height == 0:
        node.type = 'leaf'
    else:
        node.type = 'internal node'
 
    print("node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}".format(node.id, node.parent, node.sibling, node.degree, node.depth, node.height, node.type))

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
        cout << "Possible" << endl;
    else
        cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int h, w, k, sy, sx;
vector<string> s(810);
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
int d[810][810];
int dist[810][810];
const int INF = 1e9;
bool contain(int y, int x){
    return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    cin >> h >> w >> k;
    rep(i, 0, h) cin >> s[i];
    rep(i, 0, h) rep(j, 0, w){
        if(s[i][j] == 'S'){
            sy = i; sx = j; break;
        }
    }
    rep(i, 0, h){
        rep(j, 0, w){
            int tmp = min(i, min(j, min(h - 1 - i, w  - 1 - j)));
            d[i][j] = tmp;
        }
    }
    int MIN = (d[sy][sx] + k - 1) / k + 1;
    queue<P> q;
    q.push(P(sy, sx));
    rep(i, 0, h) rep(j, 0, w) dist[i][j] = INF;
    dist[sy][sx] = 0;
    while(!q.empty()){
        P p = q.front(); q.pop();
        int y = p.first;
        int x = p.second;
        MIN = min(MIN, (d[y][x] + k - 1) / k + 1);
        rep(i, 0, 4){
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(!contain(ny, nx) || dist[ny][nx] != INF) continue;
            dist[ny][nx] = dist[y][x] + 1;
            if(dist[ny][nx] > k) continue;
            if(s[ny][nx] == '#') continue;
            q.push(P(ny, nx));
        }
    }
    cout << MIN << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string S;
  cin >> S;
 
  if (S == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  } else if (S == "Rainy") {
    cout << "Sunny" << endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    int mx = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    int med = 0;
    for(int i = 0; i < n; i++){
        if(med % 2){
            if(min(abs(a[i] - mx/2), abs(a[i] - mx/2 +1))
                < min(abs(med - mx/2), abs(med - mx/2 +1))){
                med = a[i];
            }
        } else {
            if(abs(a[i] - mx/2) < abs(med - mx/2)){
                med = a[i];
            }
        }
    }
    cout << mx << " " << med << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
from operator import itemgetter
from heapq import heapify, heappop, heappush
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, T = IL()
ab = [IL() for i in range(N)]
ab.sort(key=itemgetter(0))
#print(ab)

dp = [[0]*(T+1+3000+1) for _ in range(N+1)]
ans = 0
for i in range(N):
  for j in range(T+1+3000+1):
    time, deli = ab[i]
    if 0 <= j-time < T:
      dp[i + 1][j] = max(dp[i][j], dp[i][j - time] + deli)
    else:
      dp[i + 1][j] = dp[i][j]
    ans = max(ans, dp[i + 1][j])
print(ans)

#print(dp)

Measured memory_bytes: 183896
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

bool isPrime[100010];
void set_prime() {
	for (int i = 1; i <= 100000; i++) {
		isPrime[i] = true;
	}
	isPrime[0] = false; isPrime[1] = false;
	for (int i = 2; i * i <= 100000; i++) {
		int j = 2;
		while (i * j <= 100000) {
			isPrime[i * j] = false;
			j++;
		}
	}
}
int sum[100010];
int main()
{
	set_prime();
	for (int i = 1; i <= 100000; i+=1) {
		sum[i] = sum[i - 1];
		if (i % 2 == 1) {
			if (isPrime[i] && isPrime[(i + 1) / 2]) sum[i]++;
		}
	}
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int l, r;
		cin >> l >> r;
		cout << sum[r] - sum[l - 1] << endl;
	}
}

Measured memory_bytes: 1152
def main():
    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys
    import heapq
    # from math import *
    from collections import defaultdict as dd, deque
    def data(): return input()
    def mdata(): return map(float, data().split())
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9) + 7

    n = int(data())
    P = list(mdata())
    dp = [0.0] * (n // 2 + 2)
    dp[1] = float(1)
    for i in range(n):
        p=P[i]
        for j in range(len(dp) - 1, 0, -1):
            dp[j] = dp[j - 1] * (1 - p) + dp[j] * (p)
    print(sum(dp))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3692
#include <iostream>

using namespace std;

int a,b,c,n,k,sum;
string s,q;

int main() 
{
    cin>>s;
    int nr = 0, mx = 0;
    for (int i=0; i<s.size(); i++){
        if (s[i]=='R') nr++; else { mx = max(mx,nr); nr = 0; }
    }
    mx = max(mx,nr);
    cout<<mx;
}

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

using namespace std;

int main(){
  string S;
  cin >> S;
  if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]){
    cout << "Bad" << endl;
    return 0;
  }
  cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int f(int n){
	if(n % 2)return 3 * n + 1;
	else return n / 2;
}

int main(void){
	int s, a;
	scanf("%d", &s);
	a = s;
	for(int i = 0; i < 1000000; i++){
		if(a == 1 || a == 2 || a == 4){
			printf("%d\n", i + 4);
			break;
		}
		a = f(a);
	}
	return 0;
}


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

int main()
{
    int a;
    cin >> a;
    if (a % 10 == 2 || a % 10 == 4 || a % 10 == 5 || a % 10 == 7 || a % 10 == 9)
    {
        cout << "hon" << endl;
    }
    else if (a % 10 == 0 || a % 10 == 1 || a % 10 == 6 || a % 10 == 8)
    {
        cout << "pon" << endl;
    }
    else if (a % 10 == 3)
    {
        cout << "bon" << endl;
    }
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	}
}



Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) {
        cin >> v[i];
    }
    map<int, int> m1, m2;
    rep(i, n) {
        if (i % 2 == 0) {
            m1[v[i]]++;
        } else {
            m2[v[i]]++;
        }
    }
    priority_queue<pii> pq1, pq2;
    for (auto x : m1) {
        pq1.push({x.second, x.first});
    }
    for (auto x : m2) {
        pq2.push({x.second, x.first});
    }
    pii e1, e2, o1, o2;
    e1 = pq1.top();
    pq1.pop();
    if (not pq1.empty()) e2 = pq1.top();
    o1 = pq2.top();
    pq2.pop();
    if (not pq2.empty()) o2 = pq2.top();
    int ans = n;
    if (e1.second != o1.second) {
        ans -= e1.first + o1.first;
    } else {
        ans -= max(e1.first + o2.first, e2.first + o1.first);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9264
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 2147483647;
typedef long long ll;


const int MAX_N = 1 << 17;
ll n,dat[2*MAX_N-1];

void init(int n_){
  // ????´????2???????????????
  n = 1;
  while(n < n_)  n*=2;
  //??¨????????????INF???
  for(int i = 0; i < 2 * n - 1; i++)  dat[i] = INF;
}

void update(int k, int a){
  k += n - 1;
  dat[k] = a;
  while(k > 0){
    k = (k-1)/2;
    dat[k] = min(dat[k*2+1],dat[k*2+2]);
  }
}

// ???????????????????????????query(a,b,0,0,n) [l,r)??????????????????????????¨????????????
int query(int a,int b,int k,int l,int r){
  if( r <= a || b <= l) return INF;
  
  //[a,b)???[l,r)????????¨???????????§????????°??????????????????
  if(a <= l && r <= b)  return dat[k];
  else{
    int vl = query(a,b,k*2+1,l,(l+r)/2);
    int vr = query(a,b,k*2+2,(l+r)/2,r);
    //cout << vl << "  " << vr << endl;
    return min(vl,vr);
  }
}

int main(){

  int o,q;
  cin >> o >> q;
  init(o);
  REP(i,q){
    int c,x,y;
    cin >> c >> x >> y;
    /*REP(j,2*n-1)
	cout << dat[j] << " ";
	cout << endl;*/
    if(c == 0){
      update(x,y);
    }
    else{
      int a = query(x,y+1,0,0,n);
      
      cout << a << endl;
    }
    
  }

}

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
vvc<ll> G;

// 帰りがけに考える
ll dfs(ll now){
    ll gn = G[now].size();
    if (gn == 0) return 0;

    vl A(gn);
    rep(i,gn){
        ll to = G[now][i];
        A[i] = dfs(to);
    }
    
    // 早く対戦できる相手から対戦する
    sort(all(A));

    // id回戦に対戦する
    ll id = 0;
    rep(i,gn){
        chmax(id, A[i]);
        id++;
    }
    return id;
}

int main() {
    init();
    ll N;
    cin >> N;
    G.resize(N);
    repe(i,1,N){
        ll a;
        cin >> a, a--;
        G[a].eb(i);
    }
    cout << dfs(0) << endl;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define vl vector<ll>
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define sz size()
#define en end()
#define ro return 0
#define br break
#define con continue;
#define um unordered_map<ll,ll>
#define ms(x) memset(x , 0 , so x)
#define all(x) (x).be , (x).en
#define rall(x) (x).rbegin() , (x).rend()
#define acc(x) accumulate((x).be , (x).en , 0)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define forr(i,a,b) for(ll i=a;i<b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
int main()
{
    ios;
    ll n , m ;
    cin >> n >> m ;
    vll q;
    q.pb({-1 , -1});
    forn(i , 1 , m){
       ll x , y ;
       cin >> x >> y;
        q.pb({x , y});
    }
    ll ind = 0 ;
    forn(i , 1 ,m){
       if(q[i].fi == 1 or q[i].se == 1){
        ind = i ;
        br;
       }
    }
    ll balls[n+1];
    ms(balls ) ;
    forn(i , 1 , n ){
       balls[i] = 1 ;
    }
    forn(i , 1 , ind-1){
       ll from , to ;
       from = q[i].fi ;
       to = q[i].se ;
       balls[from]--;
       balls[to]++;
    }
    if(ind == -1){
        cout << 1 << el ;
        ro ;
    }
    ll can[n+1];
    ms(can);
    if(q[ind].fi == 1){
        ll fr , too ;
        fr = q[ind].fi ;
        too = q[ind].se ;
        balls[fr]-- ;
        balls[too]++;
        can[too] = 1 ;
        can[fr] = 0 ;
    }
    else if(q[ind].se  == 1){
        ll fr , to ;
        fr = q[ind].fi ;
        to = q[ind].se ;
        balls[fr]--;
        balls[to]++;
        can[to] = 1 ;
        can[fr] = 0 ;
    }
    forn(i , ind+1 , m){
       ll from , to ;
       from = q[i].fi ;
       to = q[i].se ;
      // cout <<" i is " << i << " from is " << from  << " to is  " << to << el ;
       if(balls[from]==1){
          if(can[from] == 1){
            --can[from];
            can[to] = 1 ;
            balls[from]--;
            balls[to]++;
            con;
          }
          else if(can[from] == 0){
            balls[from]--;
            balls[to]++;
            con;
          }
       }
       else if(balls[from] > 1 ) {
          if(can[from] == 1){
            can[to] = 1 ;
            balls[from]--;
            balls[to]++;
            con;
          }
          else if(can[from] == 0 ) {
            balls[from]--;
            balls[to]++;
            con;
          }
       }
    }
    ll ans  = 0;
    forn( i  , 1 , n){
       if(can[i] == 1){
        ++ans;
       }
    }
    cout << ans << el ;
    ro ;
}




Measured memory_bytes: 3568
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
#define LL long long
#define eps 1e-6
using namespace std;
const double pi = 3.1415926535;

int main(){
    ll n,k;
    sld(n ) sld(k)
    ll sum = k;
    for(int i = 1; i < n; i ++){
        sum *= k-1;
    }
    pld(sum) pn




    return 0;

}


Measured memory_bytes: 256
n = int(input())
s = []
for _ in range(n):
    s.append(str(input()))
m = int(input())
t = []
for _ in range(m):
    t.append(str(input()))
a = []
for i in s:
    if i not in a:
        a.append(i)
for i in t:
    if i not in a:
        a.append(i)
b = []
for i in a:
    x = s.count(i)
    y = t.count(i)
    b.append(x - y)
print(max(0, max(b)))

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

int n, k, x, y;

int fee(){
    if (n > k){
        return x * k + y * (n-k);
    }else{
        return x * n;
    }
}

int main(){
    cin >> n >> k >> x >> y;
    cout << fee();
}

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

using namespace std;


int main()
{
	string S;
	cin >> S;

	for (int i = 0; i < S.length(); i++)
	{
		if (i % 2 == 0) // 0文字目はないからこれで奇数
		{
			// 奇数
			if (S.at(i) == 'L')
			{
				cout << "No" << endl;
				return 0;
			}
		}
		else
		{
			// 偶数
			if (S.at(i) == 'R')
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}

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

Measured memory_bytes: 256
/*
auth - @sportykush
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; 
 
//#define mp make_pair
#define bug(v)                    cerr<<#v<<" = "<<(v)<<endl;
#define ERASE(x)                  x.erase(unique(x.begin(),x.end()),x.end())
#define pb                        emplace_back
#define vii                       vector<int>
#define vll                       vector<ll>
#define vpll                      vector< pair <ll,ll> >
#define pll                       pair <ll,ll>
#define pii                       pair <int,int>
#define pq                        priority_queue< int >
#define khtm                      "\n"
#define F                         first
#define S                         second
#define fr(i,a,n)                 for(i=a;i<n;i++)
#define mem(arr,l)                memset(arr,l,sizeof arr)
#define ALL(x)                    x.begin(), x.end()
#define frr(i,a,n)                for(i=n-1;i>=a;i--)
#define fast                      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define testcase                  ll T; cin>>T; while(T--)


const double pi = 3.14159265359;
const int MAX = 1e6 +2;
const ll inf =  1e18;
const int N = 1010;
//const ll mod = 998244353 ;
const ll mod=1e9+7;
inline ll add(ll a,ll b){a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a,ll b){return ((a%mod)*1ll*b)%mod;}
inline ll power(ll a,ll b){ll rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}


/*
important builtin functions
__gcd(value1, value2)
__builtin_ffs(x)
  Number of leading zeroes: __builtin_clz(x)
  Number of trailing zeroes : __builtin_ctz(x)
  Number of set bits: __builtin_popcount(x)
*/
 

ll i,j,k,l,m,r,n;
ll a[MAX],b[MAX];

ll dp[MAX];

int main()
{
 

//cout << setprecision(15) << fixed;
fast

	cin >> n >> k;
	fr(i,0,n)
		cin >> a[i];

	dp[0] = 0;
	dp[1] = abs(a[1]-a[0]);
	fr(i,2,n)
	{
		ll ans = inf;
		fr(j,1,k+1)
			ans = min(dp[max(0LL,i-j)]+abs(a[max(0LL,i-j)]-a[i]),ans);
		dp[i] = ans;
	}
	cout << dp[n-1];


  return 0;
 
}


Measured memory_bytes: 5120
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;



int main(){
    string S, T;
    cin >> S >> T;

    cout << T << S << endl;

    return 0;
}

Measured memory_bytes: 3584
n,m = list(map(int,input().split()))

dp = [1e9 for _ in range(2**n)]
#dp[status]
# status : c1c2c3...を開けることができる=1としたときの2進⇒10進数(maxは1がnこ並ぶから2**n -1)
dp[0] = 0
for i in range(1,m+1):
  a, _ = list(map(int,input().split()))
  C = list(map(int,input().split()))
  s = sum([2**(c-1) for c in C]) ## 内包forできれいに書いてる
  for j in range(2**n): ## ひとつ前のステータスを総当たりでいく
    dp[j|s] = min(dp[j|s], dp[j] + a)  ## このorの書き方が美しいのか

ans = dp[2**n-1] # 全部のカギを使ったときのstatusがすべて1の時
print(ans if ans < 1e9 else -1)

Measured memory_bytes: 50648
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  long long ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int k=0;k<j;k++){
        if(l[i]<l[j]+l[k]){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key, int m) {
    return key % m;
}

int h2(int key, int m) {
    return 1 + (key % (m-1));
}

long long hh(long long key, int m, long long i) {
    return (h1(key, m) + i*h2(key, m)) % m;
}

int find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = hh(key, M, i);
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = hh(key, M, i);
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}


int main() {
    int n;
    scanf("%d", &n);
    char com[10], str[L];
    for (int i = 0; i < M; i++) H[i][0] = '\0';
    for (int i = 0; i < n; i++) {
        scanf("%s %s", com, str);
        if (com[0] == 'i') {
            insert(str);
        } else {
            if (find(str)) {
                cout << "yes" << endl;
            } else {
                cout << "no" << endl;
            }
        }
    }
}


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

int main() {
	int N, A, B, C, D;
	string S;
	cin >> N >> A >> B >> C >> D >> S;
	A--, B--, C--, D--;
	if (C < D) {
		bool check = true;
		for (int i = A; i < C; i++) {
			if (S.substr(i, 2) == "##") check = false;
		}
		for (int i = B; i < D; i++) {
			if (S.substr(i, 2) == "##") check = false;
		}
		if (check) cout << "Yes";
		else cout << "No";
	}
	else {
		bool check = false;
		for (int i = B - 1; i < D; i++) {
			if (S.substr(i, 3) == "...") check = true;
		}
		for (int i = A; i < C; i++) {
			if (S.substr(i, 2) == "##") check = false;
		}
		if (check) cout << "Yes";
		else cout << "No";
	}
}

Measured memory_bytes: 640
/*
@samaranand
*/

#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define sz(v) (int)(v).size()
using vi = vector < int >;
using vii = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';
using ull = unsigned long long int;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	//ur
	int64 d1;
	long double d2;
	cin >> d1 >> d2;
	d1 = d1 * ((int64)(d2 * 100 + 0.5));
	//cout << (d1 * d2) << nwl;
	cout << d1 / 100;


	return 0;
}


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

// 空白区切り、1行の数式を取得する
std::pair<std::string, int> GetProc()
{
    std::pair<std::string, int> pProc;
    int n, quantum;
    std::string r, s;
    std::getline(std::cin, r);
    std::stringstream ss; // std::stringstream ss{r}だとエラー
    ss << r;

    if (getline(ss, s, ' '))
        pProc.first = s;
    if (getline(ss, s, ' '))
        pProc.second = std::stoi(s);

    return pProc;
}

// ラウンドロビンスケジューリングを実行
void ExecRoundRobinScheduling(std::queue<std::pair<std::string, int>> qpairProcess, int quantum)
{
    std::pair<std::string, int> pProc;
    int time = 0;
    while (qpairProcess.size() != 0)
    {
        // プロセス完了
        if (qpairProcess.front().second - quantum <= 0)
        {
            // クオンタムちょうどの残時間か、それ以外か
            time += qpairProcess.front().second - quantum < 0? qpairProcess.front().second : quantum;
            std::cout << qpairProcess.front().first << " ";
            std::cout << time << "\n";
            qpairProcess.pop();
        }
        // プロセスが終わってなければ
        // 残処理時間を計算して末尾に移動
        else
        {
            time += quantum;
            pProc.first = qpairProcess.front().first;
            pProc.second = qpairProcess.front().second - quantum;
            qpairProcess.push(pProc);
            qpairProcess.pop();
        }
    }
}

int main()
{
    static const int MAX = 1000000;
    int n, R[MAX];
    int quantum;

    std::string r, s;
    std::getline(std::cin, r);
    std::stringstream ss; // std::stringstream ss{r}だとエラー
    ss << r;

    // プロセス数、クオンタムを取得
    if (getline(ss, s, ' '))
        n = std::stoi(s);
    if (getline(ss, s, ' '))
        quantum = std::stoi(s);

    std::queue<std::pair<std::string, int>> qpairProcess;

    for (int i = 0; i < n; i++) qpairProcess.push(GetProc());

    ExecRoundRobinScheduling(qpairProcess, quantum);

    return 0;
}


Measured memory_bytes: 6844
using System;

class ABC_125_B
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());

        string[] inputV = Console.ReadLine().Split(' ');
        string[] inputC = Console.ReadLine().Split(' ');

        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            int V = int.Parse(inputV[i]);
            int C = int.Parse(inputC[i]);

            if (V - C > 0) ans += V - C;
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
nums=str(input())
arr=list(map(int,nums))
l=len(arr)
a=0
i=0
while i<len(arr)-1:
    if i<0:
        i=0
    if arr[i]!=arr[i+1]:
        del arr[i:i+2]
        #print(arr)
        a+=2
        i-=2
    i+=1
print(a)

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		if (s.indexOf("a") != -1 && s.indexOf("b") != -1 && s.indexOf("c") != -1) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


Measured memory_bytes: 35648
#include<bits/stdc++.h>
#define ll long long int 
#define mod 998244353
#define se second
#define fi first
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971
#define MAX 9223372036854775807
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
//	cout<<fixed<<setprecision(15);
	ll n;
	cin>>n;
	ll arr[n];
	for(int a=0;a<n;a++)
	cin>>arr[a];
	ll x,y,z;
	x=arr[0];
	for(int a=1;a<n;a++)
	x=x^arr[a];
	for(int a=0;a<n;a++)
	cout<<(x^arr[a])<<" ";
	return 0;
}

Measured memory_bytes: 5220
#include<bits/stdc++.h>
/*	#include <boost/math/common_factor.hpp>  boost::math::lcm(10,20) ---> use it to find lcm. fill_n(&an[0][0],n*m,0); typedef long long ll;*/
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define PI pair<int , int >
#define mpr make_pair
#define ff first
#define ss second
#define endl "\n"
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define FO(i,a,b) for(int i = (int)a;i < (int)b;++i)
#define FE(i,a,b) for(int i = (int)a;i <= (int)b;++i)
const int MOD = 1e9+7;
const int MAXN = 1e5+3;
const int inf = 2e9;
int max(int a,int b){	if(a > b)return a; else return b; }
int min(int a, int b){	if(a < b)return a; else return b; }
int dx[] = {1,-1,0,0};
int dy[] = {0,0,-1,1};
bool cmp(PI p1,PI p2){
	if(p1.ff < p2.ff)return true;	// You should not be writing p1.ss <= p2.ss !!!
	else if(p1.ff == p2.ff){ if(p1.ss < p2.ss)return true; return false; }
	return false;
}

void solve(){
	int n;
	cin >> n;
	int ans = n*(n-1);
	cout << ans/2 << endl;
}

int32_t main(){
	IO;
	#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	#endif // ONLINE_JUDGE
	// std::cout << std::setprecision(15); std::cout << std::fixed;
	int t; t = 1;
	// cin >> t;
	FE(i,1,t)
		solve();
	return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/abc149/tasks/abc149_a
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string a;
	cin>>a;
	string b;
	cin>>b;
	cout<<b+a<<"\n";
	return 0;
}

Measured memory_bytes: 3644
/*This is the solution from Ling2Feng1, no matter AC or not.*/
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
int a[32];
int ans;
void dfs(int cur,bool even){
	if(cur==n){
		if(even) ans++;
		return;
	}
	for(int i=-1;i<2;i++){
		bool f=0;
//		cout<<cur<<" "<<a[cur]+i<<endl;
		if((a[cur]+i)%2==0) f=1;
		dfs(cur+1,even||f);
	}
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	dfs(0,0);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
const int N=200050;
int G[N],to[N<<1],nxt[N<<1],sz=0,f[N],res=0;
bool dp[N];
inline void add(int u,int v){
	to[++sz]=v;nxt[sz]=G[u];G[u]=sz;
	to[++sz]=u;nxt[sz]=G[v];G[v]=sz;
}
void dfs(int u,int fa){
    int i,v,t,max1=0,max2=0;
    for(i=G[u];i;i=nxt[i])if((v=to[i])!=fa){
        dfs(v,u);t=f[v]+1;
        if(t>max1){max2=max1;max1=t;}
        else if(t>max2)max2=t;
    }
    if(max1+max2>res)res=max1+max2;
    f[u]=max1;
}
int main(){
	int n,i,u,v;
	scanf("%d",&n);
	for(i=1;i<n;++i){
		scanf("%d%d",&u,&v);
		add(u,v);
	}
	dfs(1,0);++res;
	dp[1]=1;dp[2]=0;
	for(i=3;i<=res;++i)dp[i]=!dp[i-1]||!dp[i-2];
	puts(dp[res]?"First":"Second");
	return 0;
}

Measured memory_bytes: 19968
#include<cstdio>
#include<vector>


#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
vector<int> ball;
vector<int> tmp;
int n;
int ans;
void check(){
	int cnt = 0;
	int first;
	bool flag = false;
	for(int i = 0;i < ball.size();){
		if(ball[i]==ball[i+1]){//同じ物が続く
			cnt++;
			if(!flag){
				first = i;
				flag = true;
			}
			i++;
			continue;
		}else if(cnt >=3){//四連続以上
			int lenght = first + cnt + 1;
			vector<int>::iterator it = ball.erase(ball.begin()+first,ball.begin()+lenght);
			flag =false;
			cnt = 0;
			i = 0;
			continue;
		}
		flag = false;
		cnt = 0;
		i++;
	}
	int sp =ball.size();
	/*cout <<"change = "<<n<<endl;
	rep(i,ball.size()){
		cout <<"ball = "<<ball[i]<<endl;
	}
	cout <<endl;
	 */
	ans = min(ans,sp);
}

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)
			break;
		ball.clear();
		ans  =INF;
		int x;
		rep(i,n){
			scanf("%d",&x);
			ball.push_back(x);
		}
		tmp = ball;
		for(int i = 0;i < n;i++){
			if(ball[i]==1){
				ball[i]= 2;
				check();
				ball = tmp;
				ball[i] = 3;
				check();
				ball = tmp;
			}else if(ball[i]==2){
				ball[i]= 1;
				check();
				ball = tmp;
				ball[i] = 3;
				check();
				ball = tmp;
			}else if(ball[i]==3){
				ball[i]= 2;
				check();
				ball = tmp;
				ball[i] = 1;
				check();
				ball = tmp;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
    int N;
    bool flag = false;
    cin>>N;
    for(int i=1;i<=N;i++){
        if(N<=i*1.08&&i*1.08<N+1){
            cout<<i<<endl;
            flag = true;
            break;
        }
    }
    if(!flag){
        cout<<":("<<endl;
    }
}


Measured memory_bytes: 256
import sys
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
 
N=INT()
A=LIST()
 
# その位置にボールを入れるかを保持するA2
A2=[0]*N
B=[]
# 後ろから決めていく
for i in range(N-1, -1, -1):
    cur=i+1
    cnt=0
    # curの倍数を全部見に行く
    for j in range(cur*2, N+1, cur):
        cnt^=A2[j-1]
    # ボールを入れるべきかどうか
    if A[i]!=cnt:
        B.append(cur)
        A2[i]=1
 
print(len(B))
print(*B)

Measured memory_bytes: 67176
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

string s;
VI v(2019);

int main()
{
    cin>>s;

    int num = 0, p = 1;
    v[num]++;
    RREPALL(i,s) {
        num = ((s[i] - '0') * p + num) % 2019;
        p = p * 10 % 2019;
        v[num]++;
        //cout<<num<<endl;
    }

    ll ans = 0ll;
    REP(i,2019) {
        ans += v[i] * (v[i] - 1) / 2;
    }

    cout<<ans<<endl;

    return 0;
}


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

int main(){
    string s;
    cin >> s;
    bool c[30]={false};
    rep(i,s.size()){
        int x=s[i]-'a';
        c[x]=true;
    }
    char ans = 'a';
    rep(i,26){
        if (!c[i]){
            cout << ans << endl;
            return 0;
        }
        else{
            ans++;
        }
        
    }
    cout << "None" << endl;
    return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int d[100]={0};
    for(int i=1;i<=n;i++)
        cin>>d[i];
        
    sort(d+1,d+n+1);
    for(int i=1;i<=n;i++)
    {
        if(i&1)
            d[i] = 24-d[i];
    }
    sort(d,d+n+1);
    int tmp = 100;
    for(int i=1;i<=n;i++)
    {
        tmp = min(tmp , d[i] - d[i-1]);
    }
    tmp = min(tmp , 24 - d[n]);

    cout<<tmp<<endl;

    return 0;
}


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

int main() {
    int n, k; cin >> n >> k;
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> p, q;
    for (int i = 0; i < n; i++) {
        int c; cin >> c;
        p.push({c, i+1});
    }
    pair<int, int> wait;
    vector<int> ans;
    while (k >= 0) {
        wait = p.top(); p.pop();
        if (wait.first == 0) {
            cout << -1 << endl;
            return 0;
        }
        while (!p.empty()) {
            pair<int, int> cur = p.top(); p.pop();
            if (cur.first == 0) {
                cout << -1 << endl;
                return 0;
            }
            ans.push_back(cur.second);
            cur.first--;
            q.push(cur);
        }
        swap(p, q);
        ans.push_back(wait.second);
        wait.first--;
        q.push(wait);
        k--;
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  double p = 0;
  for (int i = 1; i <= n; i++) {
    double q = 1;
    for (int j = i; j < k; j *= 2) q /= 2;
    p += q/n;
  }
  cout << fixed << setprecision(20) << p << "\n";;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int A,B;
	cin >> A >> B;
	if(A%3==0||B%3==0||(A+B)%3==0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int a,b;
  int i,j;
  int tmp;

  scanf("%d %d",&a,&b);

  
  int k[3]={a+b, a-b, a*b};

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(k[i] < k[j]){
        if(i < j){
          tmp = k[j];
          k[j] = k[i];
          k[i] =tmp;
        }
      }
    }
  }
  printf("%d\n",k[0]);
  return 0;
}

Measured memory_bytes: 128
from collections import defaultdict
n = int(input())

a = list(map(int, input().split()))
ri = defaultdict(lambda: 0)
lj = defaultdict(lambda: 0)

ret = 0
for i in range(n):
	ri[a[i]+i]+=1
	lj[i-a[i]]+=1

for k in ri:
	if(lj[k] >= 1):
		ret+=ri[k]*lj[k]
	
#print(ri)
#print(lj)
print(ret)

Measured memory_bytes: 164060
#include<iostream>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  long long arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  long long height=0;
  for(int i=0;i<n-1;i++)
  {
    if(arr[i+1]-arr[i]<0)
    {
      height += (arr[i] - arr[i+1]);
      arr[i+1] = arr[i];
    }
  }
  cout<<height<<endl;
}

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

using namespace std;

int A[25][25], B[25];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N, M, C, cnt = 0;
	cin >> N >> M >> C;
	for (int i = 1; i <= M; ++i) cin >> B[i];
	for (int i = 1; i <= N; ++i){
		int sum = 0;
		for (int j = 1; j <= M; ++j){
			cin >> A[i][j];
			sum += A[i][j]*B[j];
		}
		if (sum + C > 0) cnt++;
	}
	cout << cnt << '\n';
	cout << flush;
	//for (int i = 0; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}

}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int compare(const void* a, const void* b){
    return *(int*)a - *(int*)b;
}

int main(void){
    int n;
    scanf("%d", &n);

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

    qsort(a, n, sizeof(int), compare);

    int tmp = a[0];
    int count = 0;
    int ans = 0;
    // int flag = 1;//全て同じ数字だったとき用
    // 最後のグループをansに加える部分がなかった
    for(int i=0; i<n; i++){
        if(a[i] == tmp){
            count += 1;
        }else{
            ans += count%2;
            tmp = a[i];
            count = 1;
        }
    }
    //その部分
    ans += count%2;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

struct Manacher {
  template <typename T>
  Manacher(const T &s) {
    T str;
    int n = s.size();
    REP(i, n) {
      str.push_back(s[i]);
      if (i + 1 < n) str.push_back('$');
    }
    n = str.size();
    radius.resize(n);
    int j = 1;
    for (int i = 0; i < n;) {
      while (i - j >= 0 && i + j < n && str[i - j] == str[i + j]) ++j;
      radius[i] = j;
      int k = 1;
      while (i - k >= 0 && i + k < n && k + radius[i - k] < j) {
        radius[i + k] = radius[i - k];
        ++k;
      }
      i += k;
      j -= k;
    }
  }

  int odd(int idx) { return (radius[idx * 2] + 1) / 2; }

  int even(int idx) { return radius[idx * 2 + 1] / 2; }

  bool is_palindrome(int left, int right) {
    int mid = (left + right - 1) / 2;
    return (((right - left) & 1) ? odd(mid) * 2 - 1 : even(mid) * 2) >= right - left;
  }

private:
  vector<int> radius;
};

int main() {
  string s; cin >> s;
  int n = s.length();
  Manacher m(s);
  cout << (m.is_palindrome(0, n) && m.is_palindrome(0, (n - 1) / 2) && m.is_palindrome((n + 1) / 2, n) ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        String contest = scan.nextLine();
        if(contest.equals("ABC")) {
            System.out.println("ARC");
            scan.close();
            return;
        } else {
            System.out.println("ABC");
            scan.close();
            return;
        }
    }
}

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

int main(){
  int n,m,l,r,a=-1,b=100001; cin>>n >>m;
  for(int i=0;i<m;i++){
    cin>>l;
    a = max(a,l);
    cin>>r;
    b = min(b,r);
  }
  cout<<max(b-a+1,0)<<endl;
}

Measured memory_bytes: 256