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

using namespace std;

int h[100005];
long long cost[100005];

int main(){

	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> h[i];
	}
	cost[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		cost[i] = min(cost[i-1]+abs(h[i]-h[i-1]), cost[i-2]+abs(h[i]-h[i-2]));
	}
	cout << cost[n-1];
}

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

#define debug(x) cerr<<#x<<'='<<x<<'\n'
char s[666];
int main(void) {
	scanf("%s", s+1);
	if (s[1]=='Y' && s[2]=='A' && s[3]=='K' && s[4]=='I') {
		cout<<"Yes";
	} else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    double N,M,all=0;
    cin>>N>>M;
    vector<double> A(N);
    for(auto &x:A){
        cin>>x;
        all+=x;
    }
    double t = all/M/4;
    sort(A.begin(), A.end(),std::greater<int>());
    for(int i=0;i<M;i++){
        if(A[i]<t){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[]args){
		
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt(); 
		int m=sc.nextInt();
		int l[]=new int[m];
		int r[]=new int[m];
		for(int i=0;i<m;i++){
			l[i]=sc.nextInt();
			r[i]=sc.nextInt();
		}
		int max=0;
		int min=1000000;
		
		for(int i=0;i<m;i++){
			if(max<l[i]){
				max=l[i];
			}
			if(min>r[i]){
				min=r[i];
			}
		}
		
		int count=0;
		
		
		for(int i=1;i<=n;i++){
			if(i>=max && i<=min){
				count++;
			}
		}
		
		System.out.println(count);
	}
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  map<int, int> m;
  rep(i, N) {
    int a; cin >> a;
    m[a]++;
  }
  ll sum = 0;
  for(auto e: m) {
    if (e.first < e.second) {
      sum += e.second - e.first;
    }
    else if (e.first > e.second) {
      sum += e.second;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c;
  while(cin>>a>>b>>c,a){
    if(c==0){
      if(a==1&&b<0)cout<<a<<' '<<0<<' '<<1<<' '<<b<<endl;
      else cout<<a<<' '<<b<<' '<<1<<' '<<0<<endl;
    }
    else{
      for(int j=1;j<=a;j++){
        if(a%j==0){
          if(a/j>=j)
            for(int i=10000;i>=-10000;i--){
              long long t,p=0;
              if(i*j+a/j*p==b&&p*i==c){
                cout<<a/j<<' '<<i<<' '<<j<<' '<<p<<endl;
                goto L;
              }
              if(i!=0){
                if(c%abs(i)==0)t=c/i;
                else continue;
              }
              else continue;
              if(i*j+a/j*t==b&&t*i==c){
                if(j*j==a&&i<t)cout<<a/j<<' '<<t<<' '<<j<<' '<<i<<endl;
                else cout<<a/j<<' '<<i<<' '<<j<<' '<<t<<endl;
                goto L;
              }
            }
          else break;
        }
      }
      cout<<"Impossible"<<endl;L:;
    }
  }
}

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

int main(){
    int n,max=0;
    bool ans =true;
    cin >>n;
    vector<int> h(n);
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    max = h[0];
    for(int i=1;i<n;i++){
        if(max<=h[i]) max=h[i];
        else if(max-h[i]>1) ans=false;
    }
    if(ans==true) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
#define Graph vector<vector<int>>
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
#define inf 1000000321

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

int price[2000],value[2000];
ll dp[2000][2000];

int main(){
    ll N,x;
    cin >> N >> x;
    vector<ll> X(N);
    ll sa = 0;
    for(int i = 0;i < N;i++){
        cin >>X[i];
    }
    sort(all(X));
    sa = abs(x-X[0]);
    for(int i = 1;i < N;i++){
        sa = __gcd(sa,abs(x-X[i]));
    }
    cout << sa << endl;
}

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

using namespace std;

using ll = long long;


int main() {
    ll N, K;
    ll R, S, P;
    string T;

    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    map<char, ll> points;
    points['r'] = P;
    points['p'] = S;
    points['s'] = R;

    ll ans = 0;
    vector<bool> used(T.length(), false);
    for (ll i = 0; i < T.length(); i++) {
        ll t = 0;
        if (i - K < 0 || T[i] != T[i - K]) {
            t = points[T[i]];
            used[i] = true;
        } else if (T[i] == T[i - K] && !used[i - K]) {
            t = points[T[i]];
            used[i] = true;
        }
        // cout << t << endl;
        ans += t;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#define FALSE 0
#define TRUE 1
struct Card{
  char suit, value;
};

void bubble(struct Card A[], int N){
  int i,j;
  struct Card t;
  for(i = 0; i < N; i++){
    for(j = N-1; j >= i+1; j--){
      if(A[j].value < A[j-1].value){
        t = A[j];
        A[j] = A[j-1];
        A[j-1] = t;
      }
    }
  }
}

void selection(struct Card A[], int N){
  int i,j;
  int minj;
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(A[j].value < A[minj].value)
        minj = j;
    }
    struct Card t = A[i];
    A[i] = A[minj];
    A[minj] = t;
  }
}

void print(struct Card A[], int N){
  int i;
  for(i = 0; i < N; i++){
    if(i > 0)
      printf(" ");
    printf("%c%c",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(struct Card C1[],struct Card C2[], int N){
  int i;
  for(i = 0; i < N; i++){
    if(C1[i].suit != C2[i].suit)
      return FALSE;
  }
  return TRUE;
}

int main(){
  struct Card C1[100], C2[100];
  int i,N;
  char ch;

  scanf("%d",&N);
  for(i = 0; i < N; i++){
    scanf("%1s%1s",&C1[i].suit,&C1[i].value);
  }

  for(i = 0; i < N; i++)
    C2[i] = C1[i];

  bubble(C1,N);
  selection(C2, N);

  print(C1, N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N) == TRUE){
    printf("Stable\n");
  }
  else
    printf("Not stable\n");

  return 0;
}




Measured memory_bytes: 2036
import java.io.*;
import java.util.*;

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

	int n = sc.nextInt();
	int i = 1;
	while (n != 0) {
	    System.out.println("Case " + i++ + ": " + n);
	    n = sc.nextInt();
	}
    }
}

Measured memory_bytes: 42288
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void calc(int n, int[] a) {
    auto costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];

    // たとえば、2 と 3 は作るのに 5 本必要だけど、数を大きくしたいので 2 を作ることはない
    int[int] cand;
    foreach (e; a) {
        if (e in cand) cand[e] = min(cand[e], costs[e]);
        else cand[e] = costs[e];
    }

//    writeln(cand);

    auto keys = cand.keys;
    keys.sort!((a, b) => costs[a] < costs[b]);

    auto vals = keys.map!(k => costs[k]).array;
    auto dp = new int[][](cand.keys.length, n + 1);

    for (int i = 0; i < vals.length; i++) {
        // i 行目を i-1 行目で初期化
        if (i > 0) dp[i][] = dp[i-1][];

        int cost = vals[i];
        if (cost <= n)
            dp[i][cost] = max(dp[i][cost], 1);
        for (int j = 0; j <= n; j++) {
            if (dp[i][j] && j + cost <= n) {
                if (i == 0) dp[i][j + cost] = max(dp[i][j + cost], dp[i][j] + 1);
                else dp[i][j + cost] = max(dp[i][j + cost], dp[i][j] + 1);
            }
        }
    }

    int[] ans;
    keys.sort!"a > b";
    int rest = dp[vals.length - 1][n];
    int total = n;
    foreach (k; keys) {
        if (rest == 0) break;

        for (int i = rest; i > 0; i--) {
            int x = costs[k] * i; // k を i 本作る

            if (total - x >= 0) {
                // 作るとして、残りが整合性あっているか調べる

                if (dp[$-1][total - x] == rest - i) {
                    if (rest - i == 0 && total - x > 0) continue;

                    total -= x;
                    rest -= i;

                    for (int j = 0; j < i; j++) {
                        ans ~= k;
                    }
                    break;
                }
            }
        }

    }
    ans.sort!"a > b";
    writeln(ans.map!(text).join());


}

void main() {
    int n, m; scan(n, m);
    auto a = readints;
    calc(n, a);
}


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

using namespace std;

long long n, m, a[200000];
priority_queue < long long > f;

void Process()
{
    for (int i=1; i<=m; i++)
    {
        long long t = f.top();      f.pop();

        t /= 2;     f.push(t);
    }

    long long res = 0;
    while (f.size() != 0)
    {
        res += f.top();     f.pop();
    }

    cout << res;
}

void Input()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);

    cin >> n >> m;
    for (int i=1; i<=n; i++)
        {
            cin >> a[i];    f.push(a[i]);
        }
}

int main()
{
    Input();
    Process();
    return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main()
{
  int a[3];
  for(int i = 0; i < 3; i++)
    cin >> a[i];

  sort(a, a + 3);

  int ans = 0;

  while(a[1] < a[2]){
    a[0]++; a[1]++;
    ans++;
  }
  while(a[0] < a[1]){
    a[0] += 2;
    ans++;
  }
  if(a[0] != a[1]){
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
H,W,M = map(int,input().split())
T = []
N_H = [0 for h in range(H)]
N_W = [0 for w in range(W)]
for _ in range(M):
	h,w = map(int,input().split())
	h -= 1
	w -= 1
	N_H[h] += 1
	N_W[w] += 1
	T.append((h,w))
nh = max(N_H)
h_candidate = [h for h in range(H) if N_H[h] == nh]
nw = max(N_W)
w_candidate = [w for w in range(W) if N_W[w] == nw]

combination = len(h_candidate) * len(w_candidate)
cnt = 0
for (h,w) in T:
	if N_H[h] == nh and N_W[w] == nw:
		cnt += 1
if cnt == combination:
	print(nh + nw - 1)
else:
	print(nh + nw)

Measured memory_bytes: 77460
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

int main(){
    int n, x;
    while (true){
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                for(int k = j+1; k <= n; k++){
                    if (i + j + k == x) ans++;
                }
            }
        }
        cout << ans << endl;    
    }
    return 0;
}


Measured memory_bytes: 3080
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8
from heapq import *

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], i8[:]), cache=True)
def main(S, C):
    N = len(C)
    INF = 1 << 60
    ind_l = np.where(S == -1)[0][:-1] + 1
    ind_r = np.where(S == -1)[0][1:]

    # (cost, 文字列番号、文字数、perfix or suffix)
    q = [(0, 0, 0, 0)] * 0
    for i in range(N):
        l, r = ind_l[i], ind_r[i]
        for n in range(0, r - l + 1):
            # 左から n 文字が回文
            if np.all(S[l:l + n] == S[l:l + n][::-1]):
                # うしろ r - l - n 文字が余る
                heappush(q, (C[i], i, r - l - n, 0))
            # 右から n 文字が回文
            if np.all(S[r - n:r] == S[r - n:r][::-1]):
                heappush(q, (C[i], i, r - l - n, 1))
    dist = np.full((50, 21, 2), INF, np.int64)
    for cost, i, n, pref_flag in q:
        dist[i, n, pref_flag] = cost

    while q:
        cost, i, n, pref_flag = heappop(q)
        if cost > dist[i, n, pref_flag]:
            continue
        if n == 0:
            # 回文になった！
            return cost
        A = S[ind_l[i]:ind_r[i]]
        A = A[:n] if pref_flag else A[-n:]
        for j in range(N):
            B = S[ind_l[j]:ind_r[j]]
            match_len = min(n, len(B))

            if pref_flag:
                ok = np.all(A[-match_len:] == B[:match_len][::-1])
            else:
                ok = np.all(A[:match_len] == B[-match_len:][::-1])
            if not ok:
                continue
            if pref_flag:
                if n > match_len:
                    nxt = (cost + C[j], i, n - match_len, 1)
                else:
                    nxt = (cost + C[j], j, len(B) - match_len, 0)
            else:
                if n > match_len:
                    nxt = (cost + C[j], i, n - match_len, 0)
                else:
                    nxt = (cost + C[j], j, len(B) - match_len, 1)

            if dist[nxt[1], nxt[2], nxt[3]] <= nxt[0]:
                continue
            dist[nxt[1], nxt[2], nxt[3]] = nxt[0]
            heappush(q, nxt)
    return -1

N = int(readline())
S = []
C = []
for _ in range(N):
    w, c = readline().split()
    S.append(w)
    C.append(int(c))
S = np.array(list(b' '.join(S)), np.int64)
S[S == ord(' ')] = -1
S = np.insert(S, 0, -1)
S = np.append(S, -1)
C = np.array(C, np.int64)

print(main(S, C))

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

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=1e7+10, maxm=5e4+10, lg=21, mod=998244353, inf=1e18;

ll pwm(ll a,ll b){ll ret=1;for(;b;b>>=1,(a*=a)%=mod)if(b&1)(ret*=a)%=mod;return ret;}
ll fac[maxn],inv[maxn];
ll C(ll n,ll r){return fac[n]*inv[r]%mod*inv[n-r]%mod;}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	fac[0]=inv[0]=1; for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod, inv[i]=pwm(fac[i],mod-2);
	ll n,c=0; cin>>n;
	for(int i=n/2+1;i<=n;i++) (c+=C(n,i)*pwm(2,n-i)%mod)%=mod;
	cout<<(pwm(3,n)-2*c%mod+mod)%mod;
	
	return 0;
}



 


Measured memory_bytes: 159872
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
 
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
vi adj[100005] ;
bool visited[100005] ;
bigint dist[100005] ;
int par[100005] ;
void bfs( int src ){
    visited[src] = 1 ;
    dist[src] = 0 ;
    par[src] = -1 ;
    queue<int> q ;q.push(src) ;
    while( !q.empty() ){
        int v = q.front() ;
        q.pop() ;
        for( int u : adj[v] ){
            if( !visited[u] ){
                dist[u] = dist[v] + 1 ;
                q.push(u) ;
                visited[u] = 1 ;
                par[u] = v ;
            }
        }
    }
}

int main(){
    FAST_IO ;
    memset(dist, -1, sizeof(dist)) ;
    int N , M ; cin >> N >> M ;
    for( int i = 0 ; i < M ; i++ ){
        int x , y ; cin >> x >> y ;
        adj[x].push_back(y) ;
        adj[y].push_back(x) ;
    }
    bfs(1) ;
    bool flag = true ;
    for( int i = 2 ; i <= N ; i++ ){
        if( dist[i] == -1 ){
            flag = false ;
            break ;
        }
    }
    if( !flag )
        cout << "No" << endl ;
    else{
        cout << "Yes" << endl ;
        for( int i = 2 ; i <= N ; i++ )
            cout << par[i] << endl ;
    }
    return 0 ;
}


Measured memory_bytes: 11384
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) ((x)%2)
typedef long long ll;
typedef long double ld;
const ll oo=2*1000*1000*1000;
const int _cnt=1000*1000;
const int _p=1000*1000*1000+7;
int o(int x) { return x%_p; }
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; }
using namespace std;

void file_put(){
	freopen("filename.in","r",stdin);
	freopen("filename.out","w",stdout);
}

int n,a[100005],ans=0,t=0;

int main(){
	//file_put();
	
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d",&a[i]);
	a[0]=1;
	while (ans<n) {
		ans++;
		t=a[t];
		if (a[t]==2) return 0*printf("%d\n",ans);
	}
	printf("%d\n",-1);
  
	return 0;
}


Measured memory_bytes: 640
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

	static long diff(long a, long b, long c) {
		long max = Math.max(Math.max(a, b), c);
		long min = Math.min(Math.min(a, b), c);
		return max - min;
	}

	static long solve2(long W, long H, long one) {
		// System.out.printf("%d %d %d %n", W, H, one);
		if (W < 0) return Integer.MAX_VALUE;
		if (H < 0) return Integer.MAX_VALUE;
		if (one < 0) return Integer.MAX_VALUE;

		// 横
		long h = H / 2;
		long min = diff(W * h, W * (H-h), one);
		long w = W / 2;
		long min2 = diff(w * H, (W - w) * H, one);
		return Math.min(min, min2);
	}

	static long solve(long W, long H) {
		long min = Integer.MAX_VALUE;
		// 横分割
		long h = H / 3;
		min = Math.min(min, solve2(W, H - h, W * h));
		h += 1;
		min = Math.min(min, solve2(W, H - h, W * h));
		// 縦
		long w = W / 3;
		min = Math.min(min, solve2(W - w, H, w * H));
		w += 1;
		min = Math.min(min, solve2(W - w, H, w * H));

		return min;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		long min = solve(W, H);
		System.out.println(min);
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll x,k,d; cin >> x >> k >> d;
    x = abs(x);
    ll fir = min(k,x/d);
    x -= d*fir;
    k -= fir;
    if(k == 0){
        cout << x << "\n";
        return 0;
    }
    if(abs(x - d) < x){
        x = abs(x-d);
        k--;
    }
    if(k&1LL){
        cout << min(abs(x-d),(x+d)) << "\n";
    }else cout << x << "\n";
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int main()
{
  int n;
  cin>>n;
  cout<<n*(n+1)/2<<endl;
  
	return 0;
}

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

int main() {
	int a[10];
	rep(i, 10) {
		cin >> a[i];
	}
	sort(a, a + 10);
	cout << a[9] << endl << a[8] << endl << a[7] << endl;
	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
signed main()
{
  int n,m;
   cin>>n>>m;int sum =0;
   double arr[n];
  for(int  i =0;i<n;i++)
    {cin>>arr[i];sum+=arr[i];}
  sort(arr,arr+n,greater<int>());

  double threshold = sum/(4.0*m);
  int count=0;
  for(int  i =0;i<n;i++)
  {
     if(arr[i]>=threshold)
      count++;
  }
  if(count>=m)
  cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cmath>

#define mst(a,b)memset(a, b, sizeof(a))
#define repi(a,b)for(ll i = a; i < b; i++)
#define repj(a,b)for(ll j = a; j < b; j++)
#define pii pair<int,int>

#ifdef LOCAL
#define fre()freopen("in.txt","r",stdin)
#endif
#ifndef LOCAL
#define fre()
#endif

//static int x = []() {
//	std::ios::sync_with_stdio(false);
//	std::cin.tie(NULL);
//	return 0;
//}();

#define FASTIO
#ifdef FASTIO
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//#define scanf abcabc
//#define printf abcabc
#endif
//#ifndef FASTIO
//#define cin abcabc
//#define cout abcabc
//#endif

typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;

using namespace std;


int a[110];
int main() {
	int n, sum = 0, ans = INF; cin >> n;
	repi(0, n) {
		cin >> a[i];
		sum += a[i];
	}
	int tsum = 0, ind = 0;
	repi(0, n) {
		tsum += a[i];
		int d = abs(sum - 2 * tsum);
		if (ans > d) {
			ans = d;
			ind = i;
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int m1,m2,d1,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1!=m2){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3580
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
int GCD(int a, int b) {
	if (a % b == 0) return b;
	return GCD(b, a % b);
}
void Skip() {
	int N, X;
	cin >> N >> X;
	long long bef;
	for (size_t i = 0; i < N; i++)
	{
		long long x;
		cin >> x;
		x = abs(x - X);
		if (i > 0) {
			x = GCD(x, bef);
		}
		bef = x;
	}

	cout << bef;
}
int main() {
	Skip();
	return 0;
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    i64 sum = 0;
    i64 max = 0;
    for (i32 i = 0; i < N; i++) {
        i64 A;
        cin >> A;
        if (i != 0 && max > A) {
            sum += max - A;
        }
        if (max < A) max = A;
    }
    cout << sum << endl;
}


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

int main() {
    int N, M, C;
    cin >> N >> M >> C;

    int A[N][M], B[M];
    rep(i, M) cin >> B[i];
    rep(i, N) rep(j, M) cin >> A[i][j];

    int ans = 0;
    rep(i, N) {
        int sum = C;
        rep(j, M) sum += A[i][j] * B[j];
        if (sum > 0) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    K = int(input())
    ans = 0
    prev = 0
    seen = set()
    tenmod = 10 % K
    sevenmod = 7 % K
    for  i in range(K):
        m = ((tenmod * prev) + sevenmod ) % K
        if m == 0:
            print(i+1)
            break
        if m in seen:
            print(-1)
            break
        seen.add(m)
        prev = m
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 78084
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll n,m,k,x=0,y=0,c=0,q,ans=0;
  cin>>n;
 cout<<(n - 2)*180;

}

signed main(){
   
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 200010
struct Data
{
	int many0,many1,id; Data(int x=0,int y=0,int z=0) {many0=x,many1=y,id=z;}
	bool operator < (const Data &a) const {return 1ll*many0*a.many1<1ll*many1*a.many0;}
}tmp;
priority_queue <Data> q;
int fa[N],up[N],many[N][2],n,kind; long long ans;
int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d",&up[i]);
	for(int i=1;i<=n;i++) scanf("%d",&kind),many[i][kind]++,fa[i]=i;
	for(int i=2;i<=n;i++) q.push(Data(many[i][0],many[i][1],i));
	while(!q.empty())
	{
		tmp=q.top(); q.pop();
		if(tmp.many0!=many[tmp.id][0]||tmp.many1!=many[tmp.id][1]) continue;
		int fap=find(up[tmp.id]);
		ans+=1ll*many[fap][1]*many[tmp.id][0],many[fap][0]+=many[tmp.id][0],many[fap][1]+=many[tmp.id][1];
		fa[tmp.id]=fap; if(fap!=1) q.push(Data(many[fap][0],many[fap][1],fap));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 8052
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

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

Measured memory_bytes: 384
// package ABC043

object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val charSeq = inputs.head.toSeq

  println(solve(charSeq))

  def solve(chars: Seq[Char]): String = {
    val charBuffer = scala.collection.mutable.ArrayBuffer.empty[Char]
    chars.foreach { c =>
      c match {
        case '0'  => charBuffer.append(c)
        case '1'  => charBuffer.append(c)
        case 'B' if charBuffer.length > 0 => charBuffer.remove(charBuffer.length - 1)
        case _    => ()
      }
    }
    charBuffer.mkString
  }
}

Measured memory_bytes: 25408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;

int main() {
	int n;
	cin>>n;
	if(n==1){
		cout<<"Hello World"<<endl;
	}else{
		int x,y;
		cin>>x>>y;
		cout<<x+y<<endl;
	}


	return 0;
}


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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;

//////////////////////////////////////////


int N, L;
void Input() {

    cin >> N >> L;
}



void Solve() {

    int sum = 0;
    int mn = -300000, mx = 300000;
    L = L - 1;
    for(int i = 1; i <= N; i++) {

        int temp = L + i;
        if(temp >= 0) mx = min(temp, mx);
        if(temp < 0) mn = max(mn, temp);
        sum += temp;

    }

    mn = mn * -1;

    if(mx == 0) cout << sum << endl;
    else if(mn <= mx) cout << sum + abs(mn) << endl;
    else {


        cout << sum - mx << endl;
    }

}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}



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

int main() {
  int n, m;
  cin >> n >> m;
  if(m == 0) cout << 0 << " " << 0 << endl;
  else{
    int pe = 0, s;
    vector<int> v(m);
    vector<string> w(m);
    unordered_set<int> us;
    for(int i = 0; i < m; ++i){
      cin >> v[i] >> w[i];
      if(w[i] == "AC") us.insert(v[i]);
    }
    s = us.size();
    for(int i = 0; i < m; ++i){
      if(w[i] == "AC" && us.count(v[i])) us.erase(v[i]);
      if(us.count(v[i]) && w[i] == "WA") ++pe;
    }
    cout << s << " " << pe << endl;
  }
  return 0;
}

Measured memory_bytes: 10276
#include <iostream>
#include <vector>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

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

    int q, b, e, k;
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d", &b, &e, &k);
        int countNum = count(vec.begin() + b, vec.begin() + e, k);
        printf("%d\n", countNum);
    }
    return 0;
}



Measured memory_bytes: 3220
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto S = readln.split[0], T = readln.split[0];
	int[26] s_data, t_data;
	int[26] s_ord, t_ord;
	
	int ord = 1;
	foreach ( c; S ) {
		if (s_ord[c-'a'] == 0) {
			s_ord[c-'a'] = (ord++);
			s_data[ s_ord[c-'a']-1 ]++;
		}
		else s_data[ s_ord[c-'a']-1 ]++;
	}
	
	ord = 1;
	foreach ( c; T ) {
		if (t_ord[c-'a'] == 0) {
			t_ord[c-'a'] = (ord++);
			t_data[ t_ord[c-'a']-1 ]++;
		}
		else t_data[ t_ord[c-'a']-1 ]++;
	}
	
	writeln(s_data == t_data ? "Yes" : "No");
}

Measured memory_bytes: 2744
#include <bits/stdc++.h>
#define LARB 1
#define RARB 30000
#define inf 1e18
#define zeros(x) ((x^(x-1))&x)
#define endl '\n'
#define eps 1e-9
#define mod 1000000007
#define NMAX 300

using namespace std;

typedef long long ll;
typedef long double ld;

ll x, y, tot;


int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>x>>y;
    tot += max(0LL, 4 - x);
    tot += max(0LL, 4 - y);
    if (x==1 && y==1)
        tot+=4;
    cout<<tot*100000;
    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, x, y;
    cin >> n >> x >> y;
    ll ans[n + 1];
    memset(ans, 0, sizeof ans);

    repd(s, 1, n + 1) {
        repd(t, s, n + 1) {
            ll path0 = abs(s - t);
            ll path1 = abs(s - x) + 1 + abs(t - y);
            ll path2 = abs(s - y) + 1 + abs(t - x);
            ll temp = min(min(path0, path1), path2);
            ans[temp]++;
        }
    }

    repd(i, 1, n) { cout << ans[i] << endl; }

    return 0;
}



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

long long N;

struct data_t {
    double start;
    double end;
    double v;
};
long long t[105];
long long v[105];

struct data_t arr[105];

double cal(double time){
	double mini = INT_MAX;

	for(long long i = 0; i <= N + 1; i++){
		if(time < arr[i].start){
			mini = min(mini, -1 * time + arr[i].start + arr[i].v);
		}else if(arr[i].start<= time && time <= arr[i].end){
			mini = min(mini, arr[i].v);
		}else{
			mini = min(mini, time - arr[i].end + arr[i].v);
		}
	}
	return mini;
}

int main(){
	cin >> N;

	for(long long i = 0; i < N; i++){
		cin >> t[i];
	}

	for(long long i = 0; i < N; i++){
		cin >> v[i];
	}

	arr[0].start = 0;
	arr[0].end = 0;
	arr[0].v = 0;

	long long cur = 0;
	for(long long i = 0; i < N; i++){
		arr[i + 1].start = cur;
		arr[i + 1].end = cur + t[i];
		arr[i + 1].v = v[i];
		cur += t[i];
	}
	arr[N+1].start = cur;
	arr[N+1].end = cur;
	arr[N+1].v = 0;

	double ans = 0;
	double speed = 0;
	for(double time = 0; time <= cur; time += 0.5){
		double nextspeed = cal(time);
		ans += (speed + nextspeed)*0.25;
		speed = nextspeed;
	}
	printf("%.10f\n", ans);
}

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

int main(){
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    int x[n];
    int y[m];
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    for(int i = 0; i < m; i++){
        cin >> y[i];
    }
    int x_max = *max_element(x, &x[n]);
    int y_min = *min_element(y, &y[m]);
    if(X < Y && x_max < y_min && X < y_min && x_max < Y){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }

    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int N = S.size();
    int count_0 = 0;
    int count_1 = 0;

    for(int i = 0; i < N; i++){
        if(S[i] == '1'){
            count_1++;
        }
        else{
            count_0++;
        }
    }

    cout << 2 * min(count_0, count_1) << endl;
}

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


bool used[400][400];
int tonari[4][2]={
    {1,0},
    {0,1},
    {-1,0},
    {0,-1},
};

void solve(long long H, long long W, vector<string> S){
    
    for(size_t i = 0; i < 400; i++)
    {
        fill(used[i],used[i]+400,false);
    }
    
    long long ans=0;
    
    for(size_t i = 0; i < S.size(); i++)
    {
        for(size_t j = 0; j < S[i].size(); j++)
        {
            if(used[i][j]==true){
                continue;
            }
            long long b=0,w=0;
            queue<pair<int,int>> q;
            q.push(make_pair(i,j));
            used[i][j]=true;
            while(!q.empty()){
                auto a=q.front();q.pop();
                switch(S[a.first][a.second]){
                    case '.':
                        w++;
                        break;
                    case '#':
                        b++;
                        break;
                }
                
                for(size_t ii = 0; ii < 4; ii++)
                {
                    pair<int,int> bb=a;
                    bb.first+=tonari[ii][0];
                    bb.second+=tonari[ii][1];
                    if(bb.first<0||bb.first>H-1||bb.second<0||bb.second>W-1){
                        continue;
                    }
                    if(used[bb.first][bb.second]){
                        continue;
                    }
                    if(S[bb.first][bb.second]!=S[a.first][a.second]){
                        used[bb.first][bb.second]=true;
                        q.push(bb);
                    }
                    
                }
            }
            ans+=b*w;
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    vector<string> S(H);
    for(int i = 0 ; i < H ; i++){
        cin >> S[i];
    }
    solve(H, W, S);
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define FOR(i,a,b) for (register ll i=(a);i<=(b);i++)
#define For(i,a,b) for (register ll i=(a);i>=(b);i--)
#define mem(i,j) memset(i,j,sizeof(i))
#define GO(u) for (register ll j=f[u];j!=-1;j=nxt[j])
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll mod=1e9+7;
ll n;
ll f[N][20],Ans;
char s[N];
ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') {x=(x<<1)+(x<<3)+c-'0';c=getchar();}
	return f*x;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	f[0][0]=1;
	FOR(i,1,n)
	{
		if (s[i]=='?')
		{
			FOR(p,0,9)
				FOR(j,0,12)
					f[i][(j*10+p)%13]=(f[i][(j*10+p)%13]+f[i-1][j])%mod;
		}
		else
		{
			FOR(j,0,12)
				f[i][((j*10+s[i]-'0'))%13]=(f[i][((j*10+s[i]-'0'))%13]+f[i-1][j])%mod;
		}
	}
	Ans=f[n][5];
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 16512
#include <stdio.h>
int S[500000];
int L[250002], R[250002];
int cnt = 0;
#define  SENTINEL 2147483647 
void merge(int *A, int left, int mid, int right)
{
	int n1, n2;
	int i, j, k;
	n1 = mid - left;
	n2 = right - mid;
	for (i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	L[i] = SENTINEL;
	for (i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}
	R[i] = SENTINEL;
	for (i = 0,j = 0, k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}

}

void mergeSort(int *A, int left, int right)
{
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main()
{
	int i, n;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &S[i]);
	}
	mergeSort(S, 0, n);
	for (i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", S[i]);
	}
	printf("\n%d\n", cnt);
}


Measured memory_bytes: 5604
import heapq
 
mod=10**9+7
n,k=map(int,input().split())
arr=list(map(int,input().split()))
q=[]
cnt_plus=0
for i in range(n):
  if arr[i]>0:
    cnt_plus+=1
    heapq.heappush(q,(-arr[i],1))
  elif arr[i]<0:
    heapq.heappush(q,(arr[i],-1))
  else:
    heapq.heappush(q,(0,0))
pick=[]
prev_plus=0
prev_minus=0
cnt=0
for i in range(k):
  tmp,flag=heapq.heappop(q)
  tmp*=-1
  if flag==0:
    print(0)
    exit()
  if flag==1:
    pick.append(tmp)
    prev_plus=tmp
  if flag==-1:
    if cnt==0:
      prev_minus=tmp
      cnt+=1
    else:
      cnt=0
      pick.append(prev_minus)
      pick.append(tmp)
if cnt==0:
  ans=1
  for i in range(k):
    ans*=pick[i]
    ans%=mod
  print(ans%mod)
else:
  cand_plus=0
  cand_minus=0
  while len(q)!=0:
    tmp,flag=heapq.heappop(q)
    tmp*=-1
    if flag==1 and cand_plus==0:
      cand_plus=tmp
    if flag==-1 and cand_minus==0:
      cand_minus=tmp
  if (k%2==1 and cnt_plus==0) or (cand_plus==0 and cand_minus==0):
    if arr.count(0)!=0:
      print(0)
      exit()
    else:
      q=[]
      for i in range(n):
        heapq.heappush(q,abs(arr[i]))
      ans=1
      for _ in range(k):
        ans*=heapq.heappop(q)
        ans%=mod
      print((-ans)%mod)
  else:
    if prev_plus*cand_plus>=prev_minus*cand_minus:
      pick.append(cand_plus)
    else:
      if prev_plus!=0:
        pick.remove(prev_plus)
        pick.append(prev_minus)
        pick.append(cand_minus)
      else:
        pick.append(cand_plus)
    ans=1
    for i in range(k):
      ans*=pick[i]
      ans%=mod
    print(ans%mod)

Measured memory_bytes: 40824
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int[] DR = { 1, 0, -1, 0 };
	static int[] DC = { 0, 1, 0, -1 };

	public static void main(String[] args) throws Exception {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int s = sc.next().charAt(0) - 'A';
			int t = sc.next().charAt(0) - 'A';
			int b = sc.next().charAt(0) - 'A';
			int r = s / 3;
			int c = s % 3;
			double[][] prob = new double[3][3];
			prob[r][c] = 1;
			for (int i = 0; i < N; ++i) {
				double[][] next = new double[3][3];
				for (int j = 0; j < 3; ++j) {
					for (int k = 0; k < 3; ++k) {
						for (int l = 0; l < 4; ++l) {
							int nr = j + DR[l];
							int nc = k + DC[l];
							if (nr < 0 || 3 <= nr || nc < 0 || 3 <= nc || nr * 3 + nc == b) {
								next[j][k] += prob[j][k] / 4;
							} else {
								next[nr][nc] += prob[j][k] / 4;
							}
						}
					}
				}
				prob = next;
			}
			System.out.printf("%.9f\n", prob[t / 3][t % 3]);
		}
	}
}

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

struct card {
    char suit;
    int value;
};

void bubbleSort(struct card A[], int N) {
    for (int i = 0; i < N - 1; i++) {
        for (int j = N - 1; j > i; j--) {
            if (A[j].value < A[j - 1].value) {
                swap(A[j], A[j - 1]);
            }
        }
    }
    return;
}

void selectionSort(struct card B[], int N) {
    for (int i = 0; i < N - 1; i++) {
        int min_id = i;
        for (int j = i; j < N; j++) {
            if (B[j].value < B[min_id].value) {
                min_id = j;
            }
        }
        swap(B[i], B[min_id]);
    }
    return;
}

bool isStable(struct card A[], struct card B[], int N) {
    for (int i = 0; i < N; i++) {
        if (A[i].suit != B[i].suit) {
            return false;
        }
    }
    return true;
}

void print(struct card A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
    return;
}

int main() {
    int N;
    cin >> N;
    card A[50], B[50];
    for (int i = 0; i < N; i++) {
        cin >> A[i].suit >> A[i].value;
        B[i] = A[i];
    }

    bubbleSort(A, N);
    print(A, N);
    cout << "Stable" << endl;

    selectionSort(B, N);
    print(B, N);
    cout << (isStable(A, B, N) ? "Stable" : "Not stable") << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>

using namespace std;

int n;
int tmp;
double ans = 0.0;

int main()
{
    cin >> n;

    for (int i = 0; i < n; ++i) {
        cin >> tmp;
        ans += (double)(1.0 / tmp);
    }
    ans = 1.0 / ans;

    printf("%lf\n", ans);

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS (1e-8)
#define MOD 1000000007
#define PI 3.141592653589793
#define RMAX 4294967295
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vd = vector<double>;
using vP = vector<P>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvd = vector<vector<double>>;
using vvP = vector<vector<P>>;
using comp = complex<double>;
using vcomp = vector<complex<double>>;
using pqli = priority_queue<int, vector<int>, greater<int>>;
using pqlll = priority_queue<ll, vector<ll>, greater<ll>>;
using pqlP = priority_queue<P, vector<P>, greater<P>>;


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

	int N, K;
	cin >> N >> K;

	int x = 1;
	for (int i = 0; i < N; ++i) {
		int op1 = x * 2;
		int op2 = x + K;
		if (op1 < op2) {
			x = op1;
		}
		else {
			x = op2;
		}
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

struct range {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { ++i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr range(itr l_, itr r_) noexcept : l(l_), r(std::max(l_, r_)) { }
  constexpr iterator begin() const noexcept { return l; }
  constexpr iterator end() const noexcept { return r; }
};

struct revrange {
  using itr = int64_t;
  struct iterator {
    itr i;
    constexpr iterator(itr i_) noexcept : i(i_) { }
    constexpr void operator ++ () noexcept { --i; }
    constexpr itr operator * () const noexcept { return i; }
    constexpr bool operator != (iterator x) const noexcept { return i != x.i; }
  };
  const iterator l, r;
  constexpr revrange(itr l_, itr r_) noexcept : l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr iterator begin() const noexcept { return r; }
  constexpr iterator end() const noexcept { return l; }
};

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  i32 X;
  std::cin >> X;
  std::cout << 360 / std::gcd(360, X) << '\n';
  return 0;
}


Measured memory_bytes: 3628
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
import copy
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

n, x, t = map(int, input().split())
if n%x == 0:
    print(t*n//x)
else:
    print(t * (n // x+1))



Measured memory_bytes: 68076