akhauriyash/Code-Regression huggingface dataset:
#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 int ll;

typedef long double lld;

#define REP(i,n) for(int i=0;i<n;i++)
#define EPS (1e-7)
#define INF (1e9 + 1)
#define PI (acos(-1))

int N, X;
int L[110];

int main()
{
	cin >> N >> X;
	REP(i, N) cin >> L[i];
	int v = 0;
	int ans = 1;
	REP(i, N) {
		v += L[i];
		if (v <= X) ans++;
		else break;
	}
	cout << ans << endl;
}

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

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		System.out.println((fs.nextInt()*3 + fs.nextInt())/2);
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)

#define ln << endl

const int MOD = 1e9 + 7;

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

    if(N > M / 2)
        cout << M / 2;
    else
        cout << N + (M - N * 2) / 4 ln;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define gcd(a,b)     __gcd(a,b)
#define lcm(a,b)     (a*b)/gcd
#define rep(i,n)     for(int i=0;i<n;i++)
#define Rep(i,n)     for(int i=1;i<=n;i++)
#define REP(i,j,n)   for(int i=j;i<=n;i++)
#define FOR(i,n)   for(int i=n;i>=0;i--)
#define n_digit(n)   floor(log10(n))+1





int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n,k;cin>>n>>k;
    int ar[n];
    rep(i,n) cin>>ar[i];
    sort(ar,ar+n);
    int sum=0;
    rep(i,k){
        sum=sum+ar[i];
    }
    cout<<sum<<endl;
    return 0;

    
}

Measured memory_bytes: 3604
#include<iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;

int main(void) {
	int n, m= 0;
	int a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);

	for (int i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1])m++;
	}
	cout << n - m << endl;
	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  DPk
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
int main(int argc, const char * argv[]) {
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    vector<bool> dp(k+1);
    int mn=100005;
    rep(i,n) {
        cin>>a.at(i);
        if(mn>a.at(i))mn=a.at(i);
    }
    rep(j,mn) dp.at(j)=false;

    for (int i=1; i<=k; i++) {
        rep(j,n){
            if(i-a.at(j)<0)continue;
            if (dp.at(i-a.at(j))==false) {
                dp.at(i)=true;
            }
        }
    }
    if (dp.at(k)==true) {
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dp[200100] = {};
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    int p[200100];
    cin >> n;
    rep(i,n) cin >> p[i];
    rep(i,n){
      dp[p[i]] += dp[p[i]-1] + 1;
    }
    int res = 0;
    REP(i,1,n+1) res = max(res,dp[i]);
    cout << n-res << endl;
    return 0;
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  
  rep(i, M)
  {
    int tmp_A;
    cin >> tmp_A;
    
    N -= tmp_A;
    
    if (0 > N)
    {
      break;
    }
  }
  
  if (0 > N)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << N << endl;
  }
  

  return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int x = 0;
		int y = 0;
		x = 800*n;
		int z = n/15;
		y = z*200;
			System.out.println(x-y);
	}
}


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

int main(){
    int n;cin >> n;
    vector<long long int> red(n+1);
    vector<long long int> blue(n+1);
    priority_queue<int, vector<int>, greater<int> > first;
    priority_queue<int> end;
    vector<int> mid(n);
    long long int max = 0;
    long long int min = 0;
    for(int i = 0; i<n;i++){
        int b;cin>>b;
        max += b;
        first.push(b);
    }
    red[0] = max;
    for(int l = 0; l<n;l++){
        int b; cin >> b;
        mid[l] = b;
        if(b > first.top()){
            max -= first.top();
            max += b;
            first.pop();
            first.push(b);
        }
        red[l+1] = max;
        //cout << max << endl;
    }
    for(int i = 0; i<n;i++){
        int b; cin>>b;
        min += b;
        end.push(b);
    }
    blue[n] = min;
    for(int l = 0; l<n;l++){
        int b = mid[n-1-l];
        if(b < end.top()){
            min -= end.top();
            min += b;
            end.pop();
            end.push(b);
        }
        blue[n-1-l] = min;
        //cout << min << endl;
    }
    long long int ans = red[0] - blue[0];
    for(int i = 1;i<=n; i++){
        if(ans < red[i]-blue[i]){
            ans = red[i]-blue[i];
        }
    }
    cout << ans << endl;
}

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

int main() {
	int N, X, fx = 0;
	cin >> N;
	X = N;
	for (int i = 0; i < 9; i++) {
		fx += N % 10;
		N   = N / 10;
	}
	if (X % fx == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b;
    cin >> a >> b;
    if (a <= 8 && b <= 8){
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  map<int, ll> C;
  for (int i = 0; i < (int)(N); ++i) {
    cin >> A[i];
    ++C[A[i]];
  }

  ll S = 0;
  for (auto& p : C) {
    S += p.second * (p.second - 1) / 2;
  }

  for (int k = 0; k < (int)(N); ++k) {
    ll m = C[A[k]];
    cout << S - m * (m - 1) / 2 + (m - 1) * (m - 2) / 2 << endl;
  }

  return 0;
}


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

int main()
{
    long long int x;
    cin >> x;
    long long int ans = -1;
    long long int cnt = 0;

    while(ans == -1)
    {
        if(x == 0)
        {
            ans = cnt;
        }
        else if(x <= 6)
        {
            ans = cnt + 1;
        }
        else if(x <= 11)
        {
            ans = cnt + 2;
        }
        else
        {
            long long int e = x / 11;
            cnt += e*2;
            x = x % 11;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
package main

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

func main() {
	nextReader = newScanner()
	n := nextString()
	for _, c := range n {
		if c == '7' {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


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

int main() {
    int n; cin >> n;
    
    int ans = 0;
    map<int, int> f;
    vector<int> a(n, 0);

    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        f[x] += 1;
        a[i] = x;
    }

    for(int i = 0; i < n; ++i) {
        ans = max(ans, f[a[i]] + f[a[i] - 1] + f[a[i] + 1]);
    }

    cout << ans << "\n";
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			for(int i = 0; i < 5; i++) {
				int a = sc.nextInt();
				if(a == 0) {
					System.out.println(i+1);
				}
			}
			


		}catch(Exception e) {
			e.printStackTrace();

		}

	}
}

Measured memory_bytes: 35780
def gcd(x,y):
    if x%y == 0:
        return y
    return gcd(y,x%y)
def lcm(x,y):
    return x//gcd(x,y)*y

N, M = map(int,input().split())
S = input()
T = input()

flag = True
K = gcd(N,M)
L = lcm(N,M)
for i in range(K):
    if S[i*N//K] != T[i*M//K]:
        flag = False
print(L if flag else -1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}

signed main(){

#ifndef ONLINE_JUDGE
   // freopen("input.txt","r", stdin);
#endif

    fastIO

    char c;
    cin >> c;
    cout << (char)(c + 1);

    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {

  var inp = input.split(' ');
  var num = parseInt(inp[0] + inp[1]);

  var tmp1 = Math.sqrt(num);
  var tmp2 = parseInt(Math.sqrt(num));

  // console.log(tmp1);
  // console.log(tmp2);

  if (tmp1 - tmp2 === 0) {
    console.log('%s', 'Yes');
  } else {
    console.log('%s', 'No');
  }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

bool intersects(pair<ll, ll> p1, pair<ll, ll> p2) {
    return min(p1.second, p2.second) > max(p1.first, p2.first);
}

bool comp(pair<ll, ll> p1, pair<ll, ll> p2) {
    return p1.second < p2.second;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, x, l;
    cin >> n;
    vector<pair<ll, ll>> a(n);
    for (ll i = 0; i < n; i++) {
        cin >> x >> l;
        a[i] = {x - l, x + l};
    }
    sort(a.begin(), a.end(), comp);
    ll ans = n;
    for (int i = 0; i < n - 1; ++i) {
        int j = i + 1;
        while (j < n && intersects(a[i], a[j])) {
            --ans;
            ++j;
        }
        i = j - 1;
    }
    cout << ans;
    return 0;
}


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


struct Data {
    int p;
    ll id;
    Data(int p, ll id) : p(p), id(id){}
    bool operator < (const Data &d) const {
        return p > d.p;
    }
};

int main() {
    int H, W, M;
    cin >> H >> W >> M;
    int h[M], w[M];
    int ch[H]{}, cw[W]{};
    int r_max = 0;
    int c_max = 0;
    for (int i = 0; i < M; i++) {
        cin >> h[i] >> w[i];
        h[i]--;
        w[i]--;
        ch[h[i]]++;
        cw[w[i]]++;
        r_max = max(r_max, ch[h[i]]);
        c_max = max(c_max, cw[w[i]]);
    }
    ll cnt_r = 0;
    ll cnt_c = 0;
    for (int i = 0; i < H; i++) {
        if (r_max == ch[i]) cnt_r++;
    }
    for (int i = 0; i < W; i++) {
        if (c_max == cw[i]) cnt_c++;
    }
    ll v = cnt_r * cnt_c;
    for (int i = 0; i < M; i++) {
        if (ch[h[i]] == r_max && cw[w[i]] == c_max) {
            v--;
        }
    }
    if (v == 0) {
        cout << r_max + c_max - 1<< "\n";
    } else {
        cout << r_max + c_max << "\n";
    }
    return 0;
}

Measured memory_bytes: 8296
//package atcoder.beginner144;

import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
//        try {
//            FastScanner in = new FastScanner(new FileInputStream("src/input.in"));
//            PrintWriter out = new PrintWriter(new FileOutputStream("src/output.out"));
        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int a = in.nextInt(), b = in.nextInt();
        out.println(a >= 1 && a <= 9 && b >= 1 && b <= 9 ? a * b : -1);
        out.close();

//        }
//        catch (IOException e) {
//            e.printStackTrace();
//        }
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}




Measured memory_bytes: 21844
def main():

    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*m]
    g = [[] for _ in [0]*n]
    [g[a-1].append(b-1) for a, b in ab]
    [g[b-1].append(a-1) for a, b in ab]

    import heapq
    h = [(0, 0)]
    heapq.heapify(h)
    d = [10**10]*n
    while h:
        dis, i = heapq.heappop(h)
        if d[i] == 10**10:
            d[i] = dis
            for j in g[i]:
                if d[j] == 10**10:
                    heapq.heappush(h, (dis+1, j))

    print("Yes")
    for i in range(1, n):
        minimum = 10**9
        dire = None
        for j in g[i]:
            if d[j] < minimum:
                minimum = d[j]
                dire = j
        print(dire+1)


main()


Measured memory_bytes: 75404
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
#define N 200010
inline int read(){
	int 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 x*f;
}
int n,a[N],b[N],ans,l,r;
inline bool check(int x){
	int l=n-1,r=n+1;
	for(int i=1;i<=2*n-1;i++){
		a[i]=(b[i]>=x);	
	}
	while(l>=1){
		if(a[l]==a[l+1]){
			return a[l];
		}
		if(a[r]==a[r-1]){
			return a[r];
		}
		--l,++r;
	}
	return a[1];
}
int main(){
//	freopen("pyramid.in","r",stdin);
//	freopen("pyramid.out","w",stdout);
	n=read();
	for(int i=1;i<=2*n-1;i++){
		b[i]=read();
	}
	l=1,r=1e8;
	while(l<r){
		int mid=(l+r)>>1;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else{
			r=mid;
		}
	}	
	printf("%d\n",ans);
	return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d; 

    int l = a + b;
    int r = c + d;

    if (l > r) {
        cout << "Left" << endl;
    }
    else if (l < r) {
        cout << "Right" << endl;
    }
    else {
        cout << "Balanced" << endl;
    }
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    if solve() {
        println!("Yes");
    } else {
        println!("No");
    }
}
fn solve() -> bool {
    let v = read_vec::<usize>();
    let (h, w) = (v[0], v[1]);
    let mut s = Vec::new();
    for _ in 0..h {
        s.push(read::<String>().chars().collect::<Vec<_>>());
    }
    let mut count = vec![0; 26];
    for i in 0..h {
        for &ch in s[i].iter() {
            count[ch.to_digit(36).unwrap() as usize - 10] += 1;
        }
    }
    let mut odd_count = 0;
    let mut even_count = 0;
    for i in 0..26 {
        if count[i] % 2 == 1 {
            odd_count += 1;
        } else if count[i] % 4 != 0 {
            even_count += 1;
        }
    }
    debug!(odd_count, even_count);
    if h == 1 && w == 1 {
        return true;
    } else if h == 1 || w == 1 {
        return odd_count <= 1;
    }

    if h % 2 == 0 && w % 2 == 0 {
        return odd_count == 0 && even_count == 0;
    } else if h % 2 == 1 && w % 2 == 1 {
        return odd_count == 1 && (even_count <= (h - 1) / 2 + (w - 1) / 2);
    } else if h % 2 == 0 {
        return odd_count == 0 && even_count <= h / 2;
    } else {
        assert!(w % 2 == 0);
        return odd_count == 0 && even_count <= w / 2;
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll x,k,d; cin >> x >> k >> d;
    x = abs(x); debug(x);
    if(x/d >= k)cout << x-k*d << endl;
    else{
        if((k-x/d)%2)cout << abs(x%d - d) << endl;
        else cout << x%d << endl;
    }
}


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

// #define int long long
 
 
// signed main(){
//     map<int,int>mp;
//     vector<long long>vec;
//     vector<long long>d;
//     int n;
//     cin>>n;
//     long long arr[10000001];
//     for(int i = 0;i<n;++i){
//         {cin>>arr[i];mp[arr[i]]++;}
//         if(arr[i]&1)vec.push_back(i+1);
//     }
//     int q;
//     cin>>q;
//     while(q--)
//     {
//         d.clear();
//         long k;
//         long long f = 0;
//         cin>>k;
//         // if(!(k%2))
//         // {
//             f+=(n*(n-1));
//             f/=2;
//             for(int i = 1;i<=sqrt(k);++i)
//             {
//                 if(k%i==0)
//                 {
//                     d.push_back(i);
//                     d.push_back(k/i);
//                 }
//             }
//             for(int i = 0;i<d.size();++i)
//             {
//                 if(find(arr,arr+n,d[i])!=arr+n)f+=mp[d[i]];
//             }
//             cout<<f<<endl;
//         }
//         else
//         {
//             if(vec.size()==0)
//             cout<<0<<endl;
//             else
//             {
//                 f+=(n*(n-1));
//                 f/=2;
//                 for(int i = 1;i<=sqrt(k);++i)
//             {
//                 if(k%i==0)
//                 {
//                     d.push_back(i);
//                     if(i!=k/i)
//                     d.push_back(k/i);
//                 }
//             }
//             for(int i = 0;i<d.size();++i)
//             {
//                 if(find(arr,arr+n,d[i])!=arr+n)f+=mp[d[i]];
//             }
//                 int g=((vec[0]-1)*(vec[0]-2));
//                 g/=2;
//                 f-=g;
//                 int h= (n-vec[vec.size()-1])*(n-vec[vec.size()-1]-1);
//                 h/=2;
//                 f-=h;
//                 for(int i = 0;i<vec.size()-1;++i)
//                 {
//                     int q = vec[i+1]-vec[i]-1;
//                     int h = (q*(q-1));
//                     h/=2;
//                     f-=h;
//                 }
//                 cout<<f<<endl;
//             }
//         }
//     }
//     return 0;
// }

#include<bits/stdc++.h>

using namespace std;


int main()
{
    map<int,int>mp;
    int n;
    int sum=0;
    cin>>n;
    int arr[100],arr1[100],arr2[100];
    for(int i = 1; i<=n; ++i)cin>>arr[i];
    for(int i = 0; i<n; ++i){
        int x;cin>>x;sum+=x;
    }
    for(int i=1;i<n;++i)cin>>arr1[i];
    for(int i=1;i<n;++i)
    {
        if(arr[i]==arr[i+1]-1)sum+=arr1[arr[i]];
    }
    cout<<sum;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
#include<iomanip>
#include<algorithm>
#include<map>
#include<math.h>
#include<string.h>
#define ll long long
#define eb emplace_back
#define pb push_back
#define ins insert 
#define mp make_pair
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define M 1e9+7
#define inf 1000000000000000000
using namespace std;
const int mod = 1e9 + 7;
void add_self(int& a, int b) {
    a += b;
    if(a >= mod) {
        a -= mod;
    }
}
void sub_self(int& a, int b) {
    a -= b;
    if(a < 0) {
        a += mod;
    }
}

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> dp(k + 1);
    // dp[i] - the number of ways such that we used i candies so far
    dp[0] = 1;
    for(int child = 0; child < n; ++child) {
        int up_to;
        scanf("%d", &up_to);
        vector<int> fake(k + 1);
        for(int used = k; used >= 0; --used) {
            int tmp = dp[used];
            int L = used + 1;
            int R = used + min(up_to, k - used);
            if(L <= R) {
                add_self(fake[L], tmp);
                if(R + 1 <= k) {
                    sub_self(fake[R+1], tmp);
                }
            }
            //~ for(int i = L; i <= R; ++i) {
                //~ add_self(dp[i], tmp);
            //~ }
        }
        int prefix_sum = 0;
        for(int i = 0; i <= k; ++i) {
            add_self(prefix_sum, fake[i]);
            add_self(dp[i], prefix_sum);
        }
    }
    printf("%d\n", dp[k]);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>

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

    int n, m; std::cin >> n >> m;
    std::vector<int> cities(n + 1);
    while (m--) {
        int a, b; std::cin >> a >> b;
        cities[a]++; cities[b]++;
    }
    for (int i = 1; i <= n; i++) {
        std::cout << cities[i] << std::endl;
    }
}



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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000001)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  ll sum[100010];
  rep(i,N){
    cin >> a[i];
  }
  sort(all(a));
  sum[0] = a[0];
  rep(i,N){
    if(i!=0)sum[i]=sum[i-1]+a[i];
  }

  /*
  rep(i,N){
    cout << sum[i] << " ";
  }
  cout << endl;
  */

  for(int i=N-2; i>=0; i--){
    if(sum[i]*2<a[i+1]){
      cout << N-i-1 << endl;
      return 0;
    }
  }
  cout << N << endl;
}

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

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

    int ans = 0;

    int left[10] = {};
    for (int l = 0; l <= N - 3; l++)
    {
        int num_l = stoi(S.substr(l, 1));
        if (left[num_l] == 1) continue;
        else left[num_l]++;

        int center[10] = {};
        for (int c = l + 1; c <= N - 2; c++)
        {
            int num_c = stoi(S.substr(c, 1));
            if (center[num_c] == 1) continue;
            else center[num_c]++;

            int right[10] = {};
            for (int r = c + 1; r <= N - 1; r++)
            {
                int num_r = stoi(S.substr(r, 1));
                if (right[num_r] == 1) continue;
                else
                {
                    right[num_r]++;
                    ans++;
                }
            }
        }
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=1e6+9;
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    ll g=0,ans=1;
    ll y;
    cin>>y;
    x--;
    ans=y;
    while (x--){
        cin>>y;
        ans=ans/__gcd(y,ans)*y;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// #define int long long int
#define ii pair<int,int> 
#define f first
#define s second
#define pb push_back

int r,c;
int v[999][18278];
map<ii,string> m;

ii id(string s){
    int ten=1;
    int ts=1;
    int x=0,y=0;
    for(int i=s.length()-1;i>=0;i--){
        if(isdigit(s[i])){
           x+= (s[i]-48)*ten;
           ten*=10;
        }
        else if(isalpha(s[i])){
            y+= (s[i]-65)*ts;
            ts*=26;
        }
    }
    x--;
    y--;
    return make_pair(x,y);
}
int cal(int i,int j){
    
    if(v[i][j]!=INT_MAX)return v[i][j];
    string s = m[{i,j}];
    string ip;
    istringstream iss(s);
    int ans=0;
    while(getline(iss,ip,'+')){
        ii loc = id(ip);
        ans+=cal(loc.f,loc.s);
    }
    v[i][j]=ans;
    return ans;
    
}
int32_t main(){
    int t;
    cin>>t;
    if(t>=30)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;

int main() {
    int n; cin >> n;
    ll a[n], b[n]; for (int i = n - 1; i >= 0; --i) cin >> a[i] >> b[i];
    ll ans = 0;
    rep(i, n) {
        a[i] += ans;
        if (a[i] == 0 || a[i] == b[i]) continue;
        else if (a[i] < b[i]) ans += b[i] - a[i];
        else {
            if (a[i] % b[i] == 0) continue;
            ans += b[i] - a[i] % b[i];
        }
        //cout << ans << endl;
    }
    cout << ans << endl;
}





Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;

LL n,ans = 0;
LL a[200005],b[200005];
LL c[200005],d[200005];

int main(){
	ios::sync_with_stdio(false);
	cin >> n;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b + 1,b + 1 + n);
	for(LL i = 1;i <= n;i ++) a[i] = lower_bound(b + 1,b + 1 + n,a[i]) - b;
	
	for(LL i = 1;i <= n;i ++) if((a[i] & 1) != (i & 1)) ans ++;
	ans >>= 1;
	cout << ans << endl;
	return 0;
}
//

Measured memory_bytes: 4352
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int e[101][101];
    int R, C, r, c;
    int s, total;
 
    scanf("%d%d", &R, &C);
    for (r = 1; r <= R; r++) {
        for (c= 1; c <= C; c++) scanf("%d", &e[r][c]);
    }
     
    for (r = 1; r <= R; r++) {
        s = 0;
        for (c = 1; c <= C; c++) s += e[r][c];
        e[r][0] = s;
    }
    total = 0;
    for (c = 1; c <= C; c++) {
        s = 0;
        for (r = 1; r <= R; r++) s += e[r][c];
        e[0][c] = s;
        total += s;
    }
    for (r = 1; r <= R; r++) {
        for (c = 1; c <= C; c++) printf("%d ", e[r][c]);
        printf("%d\n", e[r][0]);
    }
    for (c = 1; c <= C; c++) printf("%d ", e[0][c]);
    printf("%d\n", total);
    return 0;
}


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

long long int dp[17][153][2] = {0}, arr[17], m = 0;

long long int getsum(int index, int& n, int flag, long long int sum){
    if(index>n){
        m = max(m, sum);
        return sum;
    }
    if(dp[index][sum][flag]) return dp[index][sum][flag];
    int limit = 0;
    if(flag) limit = arr[n-index+1];
    else limit = 9;
    long long int res = 0;
    for(int i = 0; i <= limit; i++){
       if(i==limit && flag) res += getsum(index + 1, n, 1, sum + i);
       else res += getsum(index + 1, n, 0, sum + i);
    }
    
    return dp[index][sum][flag] = res;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long int a;
    cin >> a;
        
        int x = 0;
        memset(dp, 0, sizeof(dp));
        while(a){
            x++;
            arr[x] = a%10;
            a /= 10;
        }
        long long int ans = 0;
        ans = getsum(1, x, 1, 0);
    
        cout << m << "\n";
    return 0;
}

Measured memory_bytes: 3636
#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;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator
const int mod=1e9+7;

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pair<pii, pair<int, pii> >, null_type, less<pair<pii, pair<int, pii> > >, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

const int N=3e5+5;
int rows[N],cols[N];
vi adj[N];

int32_t main()
{
	fast;
	int h,w,m;cin>>h>>w>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;cin>>x>>y;
		rows[x]++;
		cols[y]++;
		adj[x].pb(y);
	}

	multiset<int> s;
	for(int i=1;i<=w;i++)
		s.insert(cols[i]);

	int ans=0;


	for(int i=1;i<=h;i++)
	{
		int maxi=0;
		for(int j=0;j<adj[i].size();j++)
		{
			maxi=max(maxi,cols[adj[i][j]]);
			s.erase(s.find(cols[adj[i][j]]));
		}

		ans=max(ans,rows[i]);

		if(maxi)
			ans=max(ans,rows[i]+maxi-1);
		if(s.size())
			ans=max(ans,rows[i]+*s.rbegin());

		for(int j=0;j<adj[i].size();j++)
			s.insert(cols[adj[i][j]]);
	}

	cout<<ans<<endl;

}

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

const int maxn = 2e3 + 10;
const int maxp = 61;
const int inf = 1e9;
const long long mod = 1e9 + 7;

int n;
int pw[maxn];
int pb[maxn];
char cc[maxn+maxn];
int aa[maxn+maxn];

int cnt[2][maxn + maxn][maxn];
int dp[maxn][maxn];

int f(int w, int b)
{
    if (w == n &&  b == n)
        return 0;
    if (dp[w][b] != -1)
        return dp[w][b];
    int ans = inf;
    if (w != n)
    {
        int cost = cnt[0][pw[w]][w+1] + cnt[1][pw[w]][b];
        ans = min(ans, f(w+1, b) + cost);
    }
    if (b != n)
    {
        int cost = cnt[0][pb[b]][w] + cnt[1][pb[b]][b+1];
        ans = min(ans, f(w, b+1) + cost);
    }
    return dp[w][b] = ans;
}

void precalc()
{
    for (int col = 0; col <= 1; ++col)
    for (int i = 0; i < n + n; ++i)
    for (int j = n - 1; j >= 0; --j)
    {
        cnt[col][i][j] += cnt[col][i][j + 1];
    }
}

main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n + n; ++i)
    {
        char c;
        int pos;
        cin >> c >> pos;
        pos--;
        cc[i] = c;
        aa[i] = pos;
        if (c == 'W')
        {
            pw[pos] = i;
            for (int j = i; j < n + n; ++j)
                cnt[0][j][pos] = 1;
        }
        else
        {
            pb[pos] = i;
            for (int j = i; j < n + n; ++j)
                cnt[1][j][pos] = 1;
        }
    }
    precalc();
	memset(dp, -1, sizeof(dp));
	cout << f(0, 0) << "\n";
}


Measured memory_bytes: 158208
#include "bits/stdc++.h"
using namespace std;
int main()
{
  long long int a,b;
  cin>>a>>b;
  if(b*2>=a)
  {
    cout<<"0"<<endl;
  }
  else if(a>b*2)
  {
    cout<<a-(b*2)<<endl;
  }
  return 0;
}

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

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

using namespace std;

string s;
char end;

void func(char c,int turn)
{
	if(turn == s.size())
	{
		end = c;
		return;
	}

	if(c == 'A')
	{
		if(s[turn] == '0') func('X',turn+1);
		else if(s[turn] == '1') func('Y',turn+1);
		else
		{
			end = 'N';
			return;
		}
	}
	if(c == 'X')
	{
		if(s[turn] == '1') func('Z',turn+1);
		else
		{
			end = 'N';
			return;
		}
	}
	if(c == 'Y')
	{
		if(s[turn] == '0') func('X',turn+1);
		else
		{
			end = 'N';
			return;
		}
	}
	if(c == 'Z')
	{
		if(s[turn] == '0') func('W',turn+1);
		else if(s[turn] == '1') func('B',turn+1);
		else 
		{
			end = 'N';
			return;
		}
	}
	if(c == 'W')
	{
		if(s[turn] == '0') func('B',turn+1);
		else if(s[turn] == '1') func('Y',turn+1);
		else
		{
			end = 'N';
			return;
		}
	}
	if(c == 'B')
	{
		if(s[turn] == '0') func('Y',turn+1);
		else if(s[turn] == '1') func('X',turn+1);
		else
		{
			end = 'N';
			return;
		}
	}
}

int main()
{
	while(cin >> s)
	{
		if(s == "#") break;

		func('A',0);

		if(end == 'B') cout << "Yes" << endl;
		else cout << "No" << endl;

	}

	return 0;
}

Measured memory_bytes: 1180
//============================================================================
// Name        : HelloWorld.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
int L,R;
int main() {
	cin>>L>>R;
	int A=L/2019;
	int B=R/2019;
	int ans=2019;
    if(A==B){
    	for(int i=L;i<R+1;i++){
    		for(int j=i+1;j<R+1;j++){
        		ans=min(ans,((i % 2019) * (j % 2019)) % 2019);
    		}
    	}
    }else{
    	ans=0;
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ull = unsigned long long;

const ull MOD = 1000000007;

int main(void)
{
    int D;
    cin >> D;
    cout << "Christmas";
    lpsb(i, D, 25) cout << " Eve";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
from operator import itemgetter
n = int(input())
t = [list(map(int,input().split())) for i in range(n)]

t.sort(key=lambda x: x[1])
cost = 0
for i in t:
    cost += i[0]
    if cost > i[1]:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 53704
using System;
using System.Linq;
 
namespace paiza3.AtCoder.AtCoderBeginnerContest
{
	public class ABC086
	{
		static void Main(string[] args)
		{
			var result = string.Join("", Console.ReadLine().Split(' '));
			double res_double = Math.Sqrt(int.Parse(result));
			double res_int = Math.Round(res_double);
			Console.WriteLine(res_double==res_int ? "Yes" : "No");
		}
	}
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main()
{
    char a[11];
    int i,j,b[11]= {0},max;
    gets(a);
    for(j=0; j<11; )
    {
        for(i=0; i<strlen(a); i++)
        {

            if(a[i]=='A'||a[i]=='T'||a[i]=='C'||a[i]=='G')
                b[j]++;
            else if(a[i]==' ')
                break;
            else
                j++;
        }
        break;
    }
    max=b[0];
    for(j=1;j<11;j++)
    {
        if(max<b[j])
            max=b[j];
    }
    printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(A) for A in input().split()]
for k in range(N):
    if k == N -1:
        print("{}".format(A[k]))
    else:
        print("{}".format(A[k]), end = " ")
for i in range(1, N):
    j = i -1
    v = A[i]
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
    A[j+1] = v
    for k in range(N):
        if k == N -1:
            print("{}".format(A[k]))
        else:
            print("{}".format(A[k]), end = " ")

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef int Cost;
struct Edge {
  int src, dst; Cost cost;
  Edge(int s, int d, Cost c) : src(s), dst(d), cost(c) {}
};
typedef vector<Edge>  Edges;
typedef vector<Edges> Graph;
typedef vector<Cost>  Array;
typedef vector<Array> Matrix;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int coins[] = {10, 50, 100, 500};
  bool print_blank = false;
  int p;
  while (cin >> p, p) {
    int coin[4], rcoin[4];
    cin >> coin[0] >> coin[1] >> coin[2] >> coin[3];

    p = coin[0] * 10 + coin[1] * 50 + coin[2] * 100 + coin[3] * 500 - p;
    for (int i = 3; i >= 0; i--) {
      rcoin[i] = p / coins[i];
      p -= rcoin[i] * coins[i];
    }

    if (print_blank) cout << endl;
    else print_blank = true;

    for (int i = 0; i < 4; i++) {
      if (coin[i] > rcoin[i]) cout << coins[i] << " " << coin[i] - rcoin[i] << endl;
    }
  }
  return 0; 
}

Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

typedef struct edge_{
	int to,cost;
}edge;

class graph{ 
	typedef long long cost_type;
	typedef int edge_type;
	typedef pair<cost_type,edge_type> P; 	//first:最短経路コスト second:頂点番号
	
	private:
		vector<vector<edge> > gra; 	//グラフ本体
		priority_queue<P,vector<P>,greater<P> > que; 	//最短経路の値の小さいものから取り出せる
		edge_type V; 	//頂点の個数
	  vector<cost_type> dp; 	//開始地点からの最小コストを格納する配列
	
	public:
		void init(int num){
			V = num;
			dp.assign(V,numeric_limits<cost_type>::max());
			gra.assign(V,vector<edge>());
		}

		void setCost(edge_type from , edge_type to , edge_type cost){
			edge e = {to , cost};
			edge e2 = {from , cost};
			gra[from].push_back( e );
			gra[to].push_back(e2);
		}	

		void setDirectCost(edge_type from , edge_type to , edge_type cost){
			edge e = {to , cost};
			gra[from].push_back( e );
		}	

		void dijkstra(edge_type s){
			dp[s] = 0;
			que.push(pair<cost_type,edge_type>(0,s)); 

			while(!que.empty()){
				P p = que.top();
				que.pop();
				edge_type v = p.second;
				if( dp[v] > p.first ) continue;
				for(edge_type i = 0 ; i < gra[v].size() ; i++ ){
					edge e = gra[v][i];
					if( dp[e.to] > dp[v] + e.cost ){
						dp[e.to] = dp[v] + e.cost;
						que.push(pair<cost_type,edge_type>(dp[e.to],e.to));
					}
				}
			}
		}

		cost_type getCost(edge_type to){
			return dp[to];
		} 

};

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

	graph g;
	g.init(n);

	rep(i,0,n-1){
		ll u,v,w;
		cin >> u >> v >> w;
		u--; v--;
		g.setCost(u,v,w);
	}

	g.dijkstra(0);

	cout << 0 << endl;
	rep(i,1,n){
		ll c = g.getCost(i);
		if( c % 2 ) cout << 1 << endl;
		else cout << 0 << endl;
	}

	ret 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a=0,b=0,x=0,count=0;

	scanf("%lld %lld %lld",&a,&b,&x);
	    if(a>0){
	    
	      a-=1;
	      count=(b/x)-(a/x);
	    } 
		else{
	     count=b/x;
	     count++;
        } 
	
     printf("%lld",count);
   
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

string solve(int a, int b) {
  if (a < 0 && b < 0) {
    if ((abs(a + b) - 1) % 2 == 0)
      return "Positive";
    else
      return "Negative";
  } else if (a > 0 && b > 0) {
    return "Positive";
  }
  return "Zero";
}

int main() {
  int a, b;
  cin >> a >> b;
  cout << solve(a, b) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;

  scanf("%d",&a);
  b = a/100;
  c = (a-b*100)/10;
  d = a-b*100-c*10;
   
  if(b==7||c==7||d==7){
    printf("Yes");
  }
  else printf("No");
}


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

using namespace std;

int f(int x, int y) {
	return ceil((log(x) - log(y)) / log(4));
}

int a[222222];
long d[2][222222][16];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int k = 0; k < 2; k++) {
		for (int i = n - 1; i--;) {
			for (int j = 0; j < 16; j++) {
				int r = max(0, f(a[i], a[i + 1]) + j);
				d[k][i][j] = r < 16 ? d[k][i + 1][r] + r : d[k][i + 1][15] + r + (n - i - 2)*(r - 15);
			}
		}
		if (!k) for (int i = 0; i < n / 2; i++)
			swap(a[i], a[n - i - 1]);
	}

	long m = 1e18;
	for (int i = 0; i < n; i++)
		m = min(m, (d[0][i][0] + d[1][n - i][0]) * 2 + i);
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 54272
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int db[112345][20];

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  vector<int> x(n);
  rep(i,n) cin>>x[i];
  int len;
  cin>>len;
  int r=0;
  rep(l,n){
    while(r+1<n && x[r+1]-x[l]<=len) ++r;
    db[l][0]=r;
  }
  rep(i,19) rep(j,n) db[j][i+1]=db[db[j][i]][i];
  //rep(j,20){rep(i,n) cout<<db[i][j]<<",";cout<<endl;}
  int q;
  cin>>q;
  int a,b;
  while(q--){
    cin>>a>>b; --a; --b;
    if(a>b) swap(a,b);
    int re=0;
    rrep(i,20) if(db[a][i]<b){
      a=db[a][i];
      re+=1<<i;
    }
    cout<<re+1<<endl;
  }
  return 0;
}


Measured memory_bytes: 9088