akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){

  int a,i,j,d500,d100,d50,d10,d5,d1;

  while(1){
    
    scanf("%d",&a);

    if(a != 0){
      
      a=1000-a;
      
      d500=a/500;
      a -= 500*d500;
      
      d100=a/100;
      a -= 100*d100;
      
      d50=a/50;
      a -= 50*d50;
      
      d10=a/10;
      a -= 10*d10;
      
      d5=a/5;
      a -= 5*d5;
      
      d1=a/1;
      
      //printf("%d %d %d %d %d\n",d500,d100,d10,d5,d1);
      
      printf("%d\n",d500+d100+d50+d10+d5+d1);

    } else {

      break;

    }

  }
    
  return 0;
  
}
  
  

Measured memory_bytes: 600
import sys
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    _n, _m, k = map(int, input().split())
    ns = list(map(int, input().rstrip().split()))
    ms = list(map(int, input().rstrip().split()))
    sum = 0
    count = 0
    for v in ns:
        if sum + v > k:
            break
        else:
            sum += v
            count += 1

    ans_now = count
    ans = ans_now
    i = count - 1
    for v in ms:
        if sum + v > k:
            while sum + v > k:
                if i < 0:
                    break
                sum -= ns[i]
                i -= 1
                ans_now -= 1
            if sum + v > k:
                break
            sum += v
            ans_now += 1
        else:
            sum += v
            ans_now += 1
        ans = max(ans, ans_now)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    ss = Counter([IS() for _ in range(n)])
    m = II()
    tt = Counter([IS() for _ in range(m)])
    tt_key = set(tt.keys())
    maxv = 0
    for s, c in ss.items():
        cnt = c
        if s in tt_key:
            cnt -= tt[s]
        maxv = max(maxv, cnt)
    print(maxv)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3404
import sys
from collections import defaultdict, deque
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
S = list(input().strip())

if "a" in S and "b" in S and "c" in S:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
int minPath[100007];
void dfs(int src, vector<int> adj[], bool visited[])
{
    visited[src] = true;
    // cout << src << " ";

    for (auto c : adj[src])
    {
        if (!visited[c])
            dfs(c, adj, visited);
    }
    return;


}
void dfs1(int src, vector<int> adj[], int curr, bool visited[])
{

    visited[src] = true;
    // minPath[src] = min(minPath[src], curr);
    minPath[src] = curr;

    for (auto c : adj[src])
    {
        if (!visited[c])
        {
            //  minPath[c] = minPath[src] + 1;
            dfs1(c, adj, src + 1, visited);
        }
    }
    //visited[src] = false;

}
void findAns()
{
    int a;
    cin >> a;

    float ans = pow(a, 2) + pow(a, 3) + a;
    cout << ans;

}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
//     cout << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s" << "\n";
// #endif

    fastio;

    // ll int t;
    // cin >> t;,
    findAns();
}


Measured memory_bytes: 4076
import static java.util.Arrays.deepToString;

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	public void run() {
		for (;sc.hasNext();) {
			long q = sc.nextLong();
			if (q < 0) break;
			double x = q/2.0;
			double e = 0.00001 * q;
			while (Math.abs(x * x * x - q) >= e) {
				x = x - (x * x * x - q) / (3 * x * x);
			}
			System.out.printf("%.6f\n", x);
		}
	}
}

Measured memory_bytes: 18036
import math

n = int(input())
a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
# print(a)
# print(b)
# a[i]のボタンを押すとa[0]からa[i]まですべてが+1
# 上位から決めていけばよい
add = 0
for i in reversed(range(n)):
    # a[i]がb[i]の倍数,つまりa[i] = b[i] * k
    # a[i] = b[i] * math.ceil(a[i] / b[i])
    a[i] += add
    add += b[i] * math.ceil(a[i] / b[i]) - a[i]
# print(a)
print(add)

Measured memory_bytes: 15016
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<string>
#include<iostream>
#define R(i, n) for(int i = 0; i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d",  &a, &b, &c)
#define P(a) printf("%d\n", a)
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> IR;

int main(){
	string s;
	cin >> s;
	int ans;
	for(int i = 1; i * 2 < s.length(); i++){
		if(s.substr(0, i) == s.substr(i, i)) ans = i * 2;
	}
	P(ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        int arr[] = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = i; j <= n; j += i) {
                arr[j]++;
            }
        }

        long sum = 0;
        for (int i = 1; i < arr.length; i++) {
            sum += 1L * i * (long)arr[i];
        }

        System.out.println(sum);
    }
}


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

int main(){
    int N;
    cin>>N;
    if(N>=100&&N<=111){cout<<111<<endl;}
    if(N>111&&N<=222){cout<<222<<endl;}
    if(N>222&&N<=333){cout<<333<<endl;}
    if(N>333&&N<=444){cout<<444<<endl;}
    if(N>444&&N<=555){cout<<555<<endl;}
    if(N>555&&N<=666){cout<<666<<endl;}
    if(N>666&&N<=777){cout<<777<<endl;}
    if(N>777&&N<=888){cout<<888<<endl;}
    if(N>888&&N<=999){cout<<999<<endl;}
}

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

using namespace std;

int A, B, K;

int main() {
	cin >> K >> A >> B;
	for (int i = A; i <= B; i++) {
		if (i % K == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
vector<pair<int, int>> g;
int main() {
  int n,m;
  cin >> n >> m;
  int a,b;
  
  for(int i =0;i<n;i++){
    cin >> a >> b;
    g.push_back(make_pair(a,b));
  }
  sort(g.begin(), g.end());
  //降順のpq
  priority_queue<int> pq;
  int j = 0;
  long long res = 0;
  for(int i = 1;i< m+1;i++){
    while(j< n && g[j].first<= i ){
      pq.push(g[j].second);
      j+=1;
    }
    if(pq.size() > 0){
      res += pq.top();
      pq.pop();
    }
    
  }
  cout << res;
}


Measured memory_bytes: 1908
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

struct Data{
	string name;
	int w, l, d,sum,id;
};

int main()
{
	int n,cnt=0;
	
	while (cin >> n, n) {
		if (cnt++)cout << endl;
		vector<Data> s(n);
		for (int i = 0; i < n; i++) {
			s[i].id = i;
			cin >> s[i].name >> s[i].w >> s[i].l >> s[i].d;
			s[i].sum = s[i].w * 3 + s[i].d;
		}

		for (int i = 0; i < n-1; i++) 
			for (int j = i+1; j < n; j++) 
				if (s[i].sum < s[j].sum)swap(s[i], s[j]);
		
		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (i == j)continue;
				if (s[i].sum == s[j].sum) {
					if (s[i].id > s[j].id)swap(s[i], s[j]);
				}
			}
		}

		for (int i = 0; i < n; i++)
			cout << s[i].name << ','<< s[i].sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3152
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <numeric>

using namespace std;

typedef long long ll;

int main(void){
    ll n,k;
    cin >> n >> k;
    ll ans = k == 1 ? 0 : n - k;
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()
N = 10 ** 9 + 7
d = {}

for c in s:
  if c in d:
    d[c] += 1
  else:
    d[c] = 1

ans = 1

for c in d:
  ans = ans * (d[c] + 1) % N
    
print(ans - 1)

Measured memory_bytes: 3188
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = input()
	if N[-1] == "0" or N[-1] == "1" or N[-1] == "6" or N[-1] == "8":
		print("pon")
	elif N[-1] == "3":
		print("bon")
	else:
		print("hon")
	




if __name__ == '__main__':
	main()

Measured memory_bytes: 64668
import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {
    val reader = System.`in`.bufferedReader()
    val writer = PrintWriter(System.out, false)

    var tokenizer: StringTokenizer = StringTokenizer("")

    fun next(): String {
        while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(reader.readLine())
        return tokenizer.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextLine() = reader.readLine()



    fun PrintWriter.solve() {
        var (n,m) = List(2){nextInt()}
        var arr = IntArray(n){nextInt()}

        var tot =  arr.sum()

        var cnt = 0
        for (item in arr){
            if (item*4*m >= tot)cnt++
        }


        if (cnt >= m)println("Yes")
        else println("No")


    }

    writer.solve()
    writer.flush()


}




Measured memory_bytes: 38392
import Foundation

func main(){
   let line = readLine()!.split(separator: " ")

   let a = Int(line[0])!
   let b = Int(line[1])!

   var answer: Int = 0
   var multiplier1 = 1
   let multiplier2 = max(a, b)
   let multiplier3 = min(a, b)
   while answer == 0 {
      if multiplier2 * multiplier1 % multiplier3 == 0 {
         answer = multiplier2 * multiplier1
      }
      multiplier1 += 1
   }

   print(answer)
}
main()

Measured memory_bytes: 13496
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.math.BigInteger; 
import java.util.Scanner; 
public class Main
{
    /*
    static String getSum(BigInteger N) 
    { 
        // Initialize result 
       BigInteger f = new BigInteger("0"); // Or BigInteger.ONE 
  
        // Multiply f with 2, 3, ...N 
        while(N.compareTo(BigInteger.valueOf(0))!=0)
        {
            f=(f.add(N.remainder(10))).remainder(9);
            N=N.divide(10);
        }
        string s;
        if(((f.remainder(9)).compareTo(0))==0)
         s="Yes";
        else s="No";
        return s; 
    } 
    */
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
        BigInteger N = new BigInteger(sc.next());
        BigInteger f = new BigInteger("0"); // Or BigInteger.ONE 
  
        // Multiply f with 2, 3, ...N 
        /*
        while(N.compareTo(BigInteger.valueOf(0))!=0)
        {
            f=(f.add(N.remainder(BigInteger.valueOf(10)))).remainder(BigInteger.valueOf(9));
            N=N.divide(BigInteger.valueOf(10));
        }
        */
        String s;
        if(((N.remainder(BigInteger.valueOf(9))).compareTo(BigInteger.valueOf(0)))==0)
         s="Yes";
        else s="No";
	//	System.out.println(getSum(n)); 
	System.out.println(s); 
	}
}


Measured memory_bytes: 41844
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    string S; cin >> S;
    string T;
    rep(i,SZ(S)){
        T+=(char)('A'+(S[i]-'A'+N)%26);
    }
    cout << T << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int V = scanner.nextInt();
        int E = scanner.nextInt();
        scanner.nextLine();

        TopologicalSort ts = new TopologicalSort(V);
        for (int i = 0; i < E; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            ts.addEdge(e[0], e[1]);
        }

        List<Integer> sortedNodes = ts.run();
        for (int n: sortedNodes) {
            System.out.println(n);
        }
    }
}


class TopologicalSort {

    private int size;
    private int[] inDeg;
    public Map<Integer, Set<Edge>> edges;

    public TopologicalSort(int size) {
        this.size = size;
        inDeg = new int[size];
        edges = new HashMap<>();
    }

    public void addEdge(int from, int to) {
        inDeg[to]++;
        if (!edges.containsKey(from)) {
            edges.put(from, new HashSet<>());
        }
        edges.get(from).add(new Edge(from, to, 1));
    }

    public List<Integer> run() {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < size; i++) {
            if (inDeg[i] == 0) {
                stack.push(i);
            }
        }

        List<Integer> sortedNodes = new ArrayList<>();
        while (!stack.isEmpty()) {
            int node = stack.pop();
            sortedNodes.add(node);
            for (Edge e: edges.getOrDefault(node, Collections.emptySet())) {
                inDeg[e.to]--;
                if (inDeg[e.to] == 0) {
                    stack.push(e.to);
                }
            }
        }

        // Not DAG
        if (sortedNodes.size() < size) {
            return Collections.emptyList();
        }
        return sortedNodes;
    }
}


class Edge {
    public final int from;
    public final int to;
    public final int cost;

    public Edge(int from, int to, int cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return from == edge.from &&
                to == edge.to &&
                cost == edge.cost;
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to, cost);
    }
}



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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  vector<vector<int>> c(3,vector<int>(3, 0));

  for(int i = 0; i < 3; i++){
    for(int j = 0; j < 3; j++){
      cin >> c.at(i).at(j);
    }
  }

  bool flg = false;
  int range = 1000;
  for(int a1 = -range; a1 <= range; a1++){
    // cerr << a1 << endl;
    int b1 = c[0][0] - a1;
    int b2 = c[0][1] - a1;
    int b3 = c[0][2] - a1;

    int a2 = a1 - c[0][0] + c[1][0];
    int a3 = a1 - c[0][0] + c[2][0];

    bool f1 = (a2 + b2 == c[1][1]);
    bool f2 = (a2 + b3 == c[1][2]);
    bool f3 = (a3 + b2 == c[2][1]);
    bool f4 = (a3 + b3 == c[2][2]);
    flg = f1 && f2 && f3 && f4;
    if(flg) break;
  }

  cout << (flg ? "Yes" : "No") << endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

int main() {
	ll n;
	cin>>n;
	ll res[110]={0};
	for(int num=2; num<=n; num++){
		int c = num;
		for(int i=2; i<=num; i++){
			while(c%i==0){
				res[i]++;
				c/=i;
			}
		}
	}
	ll ans=0;
	ll cnt1=0;
	ll cnt2=0;
	ll cnt3=0;
	ll cnt4=0;
	ll cnt5=0;
	ll cnt6=0;
	ll cnt7=0;
	ll cnt8=0;

	rep(i,2,n+1) {
		if(res[i]>=4) cnt1++;
		else if(res[i]>=2 && res[i]<4) cnt2++;
	}
	ans+=cnt1*(cnt1-1)/2*(cnt1-2+cnt2);


	rep(i,2,n+1) {
		if(res[i]>=14) cnt3++;
		else if(res[i]>=4 && res[i]<14) cnt4++;
	}
	ans+=cnt3*(cnt3-1+cnt4);

	rep(i,2,n+1) {
		if(res[i]>=24) cnt5++;
		else if(res[i]>=2 && res[i]<24) cnt6++;
	}
	ans+=cnt5*(cnt5-1+cnt6);

	rep(i,2,n+1) {
		if(res[i]>=74) cnt7++;
	}
	ans+=cnt7;

	rep(i,2,n+1) {
		if(res[i]>=4 && res[i<=24]) cnt8++;
	}
	cout<<ans;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

vector <vi> adj;
vi visited;
int n, m;

void input()
{
	int x, y;
	cin >> n >> m;
	adj.resize(n + 1, vi(n + 1));
	visited.resize(n + 1);
	
	FOR (i, 1, m)
	{
		cin >> x >> y;
		adj[x][y] = adj[y][x] = 1;
	}
}

int bfs (int x)
{
	int red = 1, blue = 0;
	queue <int> q;
	q.push(x); 
	visited[x] = 1;
	
	while (!q.empty())
	{
		int v = q.front();
		q.pop();
		FOR (u, 1, n)
		    if (u == v || adj[u][v]) continue;
		    
		    else if (!visited[u])
			{
				q.push(u);
				visited[u] = -visited[v];
				if (visited[u] == 1) red++;
				else blue++;
			}
			
			else if (visited[u] == visited[v]) 
	        {
	        	cout << -1;
	        	exit(0);
	        }
	}
	return abs(blue - red);
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);	
	input();
	
	vi sorrow;
	int sum = 0, cnt = 0, unhappy;
	FOR (i, 1, n)
	   if (!visited[i])
	   {
	      sorrow.push_back(bfs(i));
	      sum += sorrow.back();
	      cnt++;
	   }
	   
	unhappy = sum;
	sum /= 2; 
	int dp[cnt + 1][sum + 1] = {}, sad;
	FOR (i, 1, cnt)
	   FOR (j, 1, sum)
	   {
	    	dp[i][j] = dp[i - 1][j];
	        if (sorrow[i - 1] <= j)
	        	dp[i][j] = max(dp[i][j], dp[i - 1][j - sorrow[i - 1]] + sorrow[i - 1]);
	   }
	   
	sad = (abs(dp[cnt][sum] * 2 - unhappy) + n)/2;
	cout << (sad*(sad - 1) + (n - sad)*(n - sad - 1))/2;
}

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

typedef long long ll;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

vector<int> grafo[MAXN];
ll dp[MAXN][2];
int N;

ll solve(int v, int c, int p) {

	if (dp[v][c] != -1) return dp[v][c];

	ll tot = 1;
	for (int u : grafo[v]) {
		if (u == p) continue;
		if (c == 0) tot = (tot * (solve(u, 0, v) + solve(u, 1, v))) % MOD;
		else tot = (tot * solve(u, 0, v)) % MOD;
	}

	return dp[v][c] = tot;

}

int main() {

	memset(dp, -1, sizeof(dp));

	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}

	printf("%lld\n", (solve(1, 0, -1) + solve(1, 1, -1)) % MOD );

	return 0;

}

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

int main() {
 long long  A, B, C, K;
 cin >> A >> B >> C >> K;
 cout << endl;
 if (K > 1000000000000000000)
   cout << "Unfair" ;
 else if (K % 2 == 0) 
   cout << A - B;
 else 
   cout << B - A;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const double pi=acos(-1),eps=1e-8;
const int maxn = 1<<17;
const int mod = 1e9+7;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
int coutt[4][2]= {{0,1},{1,0},{-1,0},{0,-1}};
ll a[100000];
ll f(ll x,ll y,ll z)
{
    return x*x+y*y+z*z+x*y+y*z+x*z;
}
int main()
{

    int n;
    scanf("%d",&n);
    for(int i=1;i<=100;i++)
    {
        for(int j=1;j<=100;j++)
        {
            for(int k=1;k<=100;k++)
            {
                a[f(i,j,k)]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        printf("%lld\n",a[i]);
    }
 	return 0;
}


Measured memory_bytes: 4228
#include <iostream>
#include <string>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  bool ans = true;
  int a, b; cin >> a >> b;
  string s; cin >> s;
  REP(i, s.size()) {
    if (i == a) {
      if (s[i] != '-') ans = false;
    } else {
      if (s[i] < '0' or s[i] > '9') ans = false;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
a_max = max(a)
max_c = a.count(a_max)

for i in range(n) :
  if a[i] != a_max :
    print(a_max)
  else :
    if max_c == 1 :
      a[i] = 0
      print(max(a))
    else :
      print(a_max)

Measured memory_bytes: 12532
def getN():
    return int(input())


def getNM():
    return map(int, input().split())


def getList():
    return list(map(int, input().split()))

w,h = getNM()
n = getN()
nums = getList()

seq = []
for i in range(n):
    seq = seq + [(i+1) for kazu in range(nums[i])]

for dan in range(w):
    subset = seq[h*dan:h*(dan+1)]
    if dan % 2 == 0:
        print(" ".join(map(str,subset)))
    else:
        print(" ".join(map(str, subset[::-1])))

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n, k;
    cin >> n >> k;
    vector<i64> p(n);
    for (auto& e : p) cin >> e;
    sort(all(p));
    cout << accumulate(begin(p), begin(p) + k, 0l) << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3664
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;



int main(){
    ll n,a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    bool j=false;
    n--;
    for(int i=0;i<=n;i++){
        ll mi=a;
        ll mx=a;
        mx+=d*i;
        mi+=c*i;
        mi-=d*(n-i);
        mx-=c*(n-i);
        if(mi<=b && b<=mx){j=true;}
    }
    cout<<(j?"YES":"NO")<<endl;
    
    
    return 0;
}


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


public class Main {

  void solve() throws IOException {
    int n = nextInt();
    int[] p = new int[n * n];
    for (int i = 0; i < n * n; i++) {
      p[i] = nextInt() - 1;
    }
    int[][] hatred = new int[n][n];
    int[][] hall = new int[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        hall[i][j] = 1;
        hatred[i][j] = Math.min(Math.min(i, j), Math.min(n - i - 1, n - j - 1));
      }
    }
    int ans = 0;
    for (int i = 0 ; i < n * n; i++) {
      int x = p[i] % n;
      int y = p[i] / n;
      LinkedList<Point> q = new LinkedList<>();
      q.add(new Point(x, y));
      ans += hatred[x][y];
      hall[x][y] = 0;
      while (!q.isEmpty()) {
        Point current = q.pollFirst();
        int nextHatred = hatred[current.x][current.y] + hall[current.x][current.y];
        for (int j = 0; j < 4; j++) {
          Point next = current.shift(j);
          if (next.isGood(n) && nextHatred < hatred[next.x][next.y]) {
            hatred[next.x][next.y] = nextHatred;
            q.addLast(next);
          }
        }
      }
    }
    out.println(ans);
  }

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

  class Point {
    int x,y;

    public Point(int x, int y) {
      this.x = x;
      this.y = y;
    }

    Point shift(int dir) {
      return new Point(x + dx[dir], y + dy[dir]);
    }

    boolean isGood(int n) {
      return x >= 0 && x < n && y >= 0 && y < n;
    }
  }

  public static void main(String[] args) throws IOException {
    new Main().run();
  }

  void run() throws IOException {
    reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
    tokenizer = null;
    out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
    solve();
    reader.close();
    out.flush();

  }

  BufferedReader reader;
  StringTokenizer tokenizer;
  PrintWriter out;

  int nextInt() throws IOException {
    return Integer.parseInt(nextToken());
  }

  long nextLong() throws IOException {
    return Long.parseLong(nextToken());
  }

  double nextDouble() throws IOException {
    return Double.parseDouble(nextToken());
  }

  String nextToken() throws IOException {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine());
    }
    return tokenizer.nextToken();
  }
}


Measured memory_bytes: 60664
n = int(input())
A = [[0, 0, 0]] + [list(map(int, input().split())) for i in range(n)]

no = 0
for i in range(1,n+1):
    if (A[i][0]-A[i-1][0])%2 != (abs(A[i][1]-A[i-1][1]) + abs(A[i][2]-A[i-1][2]))%2 :
        no = 1
    elif A[i][0]-A[i-1][0] < abs(A[i][1]-A[i-1][1]) + abs(A[i][2]-A[i-1][2]) :
        no = 1
if no == 1 :
    print("No")
else :
    print("Yes")


Measured memory_bytes: 28068
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  string s,t;
  cin >> s >> t;
  int i,j,ans=(1<<29);
  for(i=0;i<=s.size()-t.size();i++){
    int sum=0;
    for(j=0;j<t.size();j++){
      if(s[i+j]!=t[j]){
        sum++;
      }
    }
    ans=min(ans,sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a,b,a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,n,m,m1,m2,n1,n2,o,p1,p2,p3,p4,
q1,q2,q3,q4,r,s,t,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,cnt,lim;
string str1,str2;   
int main()
{
    c1=0;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
    if(a<=k){
        c1=a;
        k=k-a;
    }else{
        c1+=k;
        k=0;
    }
    if(b<=k){
        k=k-b;
    }else k=0;
    if(k){
        c1=(c1-k);
    }
    printf("%lld\n", c1);
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3832
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
	vector<pair<int, int>> x(100), y(100);
	int n, m, o, t, h, k = 0;
	o = t = h = 10;
	cin >> n >> m;
	vector<int> s(m), c(m);
	for(int i = 0; i < m; ++i) {
		cin >> s.at(i) >> c.at(i);
		if(s.at(i) == 1) {
			o = min(o, c.at(i));
		}
		if(s.at(i) == 2) {
			t = min(t, c.at(i));
		}
		if(s.at(i) == 3) {
			h = min(h, c.at(i));
		}
		x.at(s.at(i)).first += 1;
		if(x.at(s.at(i)).first > 0 && c.at(i) == x.at(s.at(i)).second) {
			x.at(s.at(i)).first -= 1;
			x.at(s.at(i)).second = c.at(i);
		}
		if(x.at(s.at(i)).second == 0)
			x.at(s.at(i)).second = c.at(i);
		else if(x.at(s.at(i)).second != c.at(i)) {
			cout << "-1" << endl;
			return 0;
		}
		if(x.at(s.at(i)).second == c.at(i))
			x.at(s.at(i)).first = 1;
		if(x.at(s.at(i)).second != c.at(i))
			k = 1;
		if(s.at(i) == 1 && c.at(i) == 0) {
			if(n == 1) {
				cout << 0 << endl;
				return 0;
			}
			cout << "-1" << endl;
			return 0;
		}
		if(x.at(s.at(i)).first != 0)
			if(x.at(s.at(i)).second != c.at(i)) {
				cout << "-1" << endl;
				return 0;
			}
		/*if(x.at(s.at(i)).second != c.at(i)) {
			cout << "-1" << endl;
			return 0;
		}*/
		/*if(x.at(s.at(i)).second!=c.at(i)) {
			cout << "-1" << endl;
			return 0;
		}*/
	}
	if(o == 10) {
		o = 1;
		if(n == 1)
			o = 0;
	}
	if(t == 10) {
		t = 0;
	}
	if(h == 10)
		h = 0;

	cout << o;
	if(n == 2)
		cout << t;
	if(n == 3)
		cout << t << h;
	cout << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
char ma[888][888];
int n,m,k,dist[888][888],pis[888][888],mn;
queue<pair<int,int> > q;
bool In(int x,int y)
{
	return (x>=0 && x<n && y>=0 && y<m);
}
int main()
{
	mn=1e9;
	scanf("%d%d%d",&n,&m,&k);
	for (int i=0;i<n;i++)
	scanf("%s",ma[i]);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			pis[i][j]=min(min(i,j),min(n-i-1,m-j-1));
			pis[i][j]=(pis[i][j]+k-1)/k;
		}
	}
	memset(dist,-1,sizeof(dist));
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (ma[i][j]=='S') 
			{
				q.push(make_pair(i,j));
				dist[i][j]=0;
				mn=min(mn,pis[i][j]+1);
			}
		}
	}
	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		if (dist[x][y]==k) break;
		for (int i=0;i<4;i++)
		{
			int xx=x+dx[i],yy=y+dy[i];
			if (In(xx,yy) && ma[xx][yy]=='.' && dist[xx][yy]==-1)
			{
				mn=min(mn,pis[xx][yy]+1);
				dist[xx][yy]=dist[x][y]+1;
				q.push(make_pair(xx,yy));
			}
		}
	}
	printf("%d\n",mn);
	return 0;
}

Measured memory_bytes: 7168
import java.util.*;

class Main {

    static void solve (int n, int m, ArrayList<Integer> d, ArrayList<Integer> p) {
        OUTER:
        while (m > 0 && (!p.isEmpty()) ) {
            int pMax = Collections.max(p); 
            for (int i = 0; i < p.size(); i++) {
                if (p.get(i) == pMax) {
                    if (m >= d.get(i)) {
                        m -= d.get(i);
                        p.remove(i);
                        d.remove(i);
                        continue OUTER;
                    } else {
                        d.set(i, d.get(i) - m);
                        m = 0;
                        continue OUTER;
                    }
                }
            }
        }

        int res = 0;
        for(int i = 0; i < p.size(); i++) {
            res += d.get(i) * p.get(i);
        }

        System.out.println(res);
    }

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while(true) {
            int n = sc.nextInt();
            int m = sc.nextInt();

            if (n == 0 && m == 0)   break;

            ArrayList<Integer> d = new ArrayList<Integer>();
            ArrayList<Integer> p = new ArrayList<Integer>();

            for(int i = 0; i < n; i++) {
                d.add(sc.nextInt());
                p.add(sc.nextInt());
            }

            solve(n, m, d, p);
        }

    }
}

Measured memory_bytes: 14000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var a = cin.ArrayLong(n);
            var ans = 0;
            if (!a.Contains(1))
            {
                Console.WriteLine(-1);
                return;
            }

            var i = 0;
            var ex = 1;
            while(i < n)
            {
                if (a[i] == ex)
                {
                    ex++;
                }
                else
                {
                    ans++;
                }
                i++;
            }
            

           

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


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

int main() {
  long long n, k;
  cin >> n >> k;
  int d[60][200001]; //街jから2^i回移動した先の街を記録する配列d[i][j]
  for(int i = 1; i <= n; i++) cin >> d[0][i];
  for(int i = 1; i < 60; i++) {
    for(int j = 1; j <= n; j++) {
      d[i][j] = d[i-1][d[i-1][j]];
    }
  }
  int pos = 1;
  for(int i = 59; i >= 0; i--) {
    if((k >> i) & 1) pos = d[i][pos];
  }
  cout << pos << "\n";
}

Measured memory_bytes: 50512
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 440;
#define int ll

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

vector<ll> a(n_max);
vector<vector<ll>> memo(n_max, vector<ll>(n_max));
ll dfs(ll left, ll right){
    if(memo[left][right])return memo[left][right];
    if(right == left + 1)return 0;
    ll sum = 0;
    ll ans = INF;
    for(ll i = left; i < right; i++)sum += a[i];
    for(ll i = left + 1; i < right; i++){
        chmin(ans, dfs(left, i) + dfs(i, right) + sum);
    }

    return memo[left][right] = ans;
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    rep(i,n) cin >> a[i];

    cout << dfs(0, n) << endl;
}

Measured memory_bytes: 1792
cat<<EOF>Source.cpp
#include <iostream>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;

int max(int a,int b){
	return a>b?a:b;
}
int x[100000],y[100000],x_mod_k[100000],x_div_k[100000];
char s[100000][2];
int n,k;

void add(int*cnt,int x,int t){
	if((x_div_k[x]&1)==0){
		if(t==0){
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
		else{
			cnt[k-x_mod_k[x]]++;
		}
	}
	else{
		if(t==0){
			cnt[k-x_mod_k[x]]++;
		}
		else{
			cnt[0]++;
			cnt[k-x_mod_k[x]]--;
		}
	}
}
int ans[2000];
int main(){
	scanf("%d%d",&n,&k);
	rep(i,n){
		scanf("%d%d%s",&x[i],&y[i],s[i]);
		x_mod_k[i]=y[i]%k;
		x_div_k[i]=y[i]/k;
	}
	int Max=0;
	#pragma omp parallel for
	rep(i,k){
		int cnt[max(n,k)];
		rep(j,max(n,k))cnt[j]=0;
		rep(j,n){
			if(s[j][0]=='B'){
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,0);
				}
				else{
					add(cnt,j,1);
				}
			}
			else{
				if(((x[j]+i)/k)%2==0){
					add(cnt,j,1);
				}
				else{
					add(cnt,j,0);
				}
			}
		}
		rep(j,k){
			if(j)cnt[j]+=cnt[j-1];
			ans[i]=max(ans[i],max(cnt[j],n-cnt[j]));
		}
	}
	rep(i,k)Max=max(Max,ans[i]);
	cout<<Max<<endl;
}
EOF
g++ -O3 Source.cpp -o Source -fopenmp -std=c++11
./Source

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

int n,m,a[10],dp[10005];
int c[10]={0,2,5,5,4,5,6,3,7,6};

int main()
{
	cin >> n >> m;
	for(int i = 0; i < m; i++) cin >> a[i];
	dp[0]=1;
	for(int i = 0; i < m; i++){
		for(int j = c[a[i]]; j <= n;j++)
			dp[j] = max(dp[j],dp[j-c[a[i]]]+1);
	}
	sort(a,a+m);
	m--;
	while(n>0){
		if(n-c[a[m]] >= 0 && dp[n]==dp[n-c[a[m]]]+1){
			n -= c[a[m]];
			cout<<a[m];
		}else m--;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int k, x;

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

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

int main() {
    int n;
    cin >> n;
    int a[3*n];
    for (int i=0; i<3*n; i++) cin >> a[i];
    sort(a, a+3*n, greater<int>());
    long int sum = 0;
    for (int i=0; i<n; i++) {
        sum += a[2*i+1];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
int dp[2];
char s[100010];
int main(){
	scanf("%s", s);
	int cur =  s[0];
	bool chk = 0;
	int cnt = 0;
	int len = strlen(s);
	dp[0] =1;
	for(int i = 1; i < len; i++){
		if(s[i] == cur){
			if(chk == 1)
				chk = 0;
			else
				chk = 1;
			dp[chk]++;
		}
		else{
			dp[chk]++;
		}
		cur = s[i];
	}
	printf("%d\n", min(dp[0],  dp[1]));
}

Measured memory_bytes: 256
import scala.annotation.tailrec

object Main extends App {
  import scala.io.StdIn._

  val Array(a, n, m) = readLine.trim.split(' ').map(_.toInt)
  println(
    count(a, n, m)
  )
  @tailrec def count(a: Int, n: Int, m: Int, y: Long = 1, res: Int = 0): Int = {
    val x = exponent(a + y, n)
    if (x > m) res
    else count(a, n, m, y + 1, if (sumDigits(x) == y) res + 1 else res)
  }
  def sumDigits(x: Long): Long = {
    x match {
      case 0L ⇒ 0
      case _ ⇒ x % 10 + sumDigits(x / 10)
    }
  }
  def exponent(a: Long, e: Int): Long = {
    e match {
      case 1 ⇒ a
      case _ ⇒ a * exponent(a, e - 1)
    }
  }
}



Measured memory_bytes: 43992
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def f(B):
    '''
    000  = 1   = 0
    001
    010  = 1
    011
    100  = 1
    101
    '''
    B += 1
    if B%4 == 0:
        return 0
    if B%4 == 1:
        return B-1
    if B%4 == 2:
        return 1
    return (B-1)^1


def solve():
    A, B = read_ints()
    return f(A-1)^f(B)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 61964
using System;

public class dice
{
    private int[] data;
    public dice()
    {
        data = new int[] { 1, 5, 6, 4, 2, 3 };
        // 0: ceilling 1: front 2: floor 3:right:4:back:5:left
    }
    public void roll(char c)
    {
        var w = new int[6];
        Array.Copy(data, w, 6);
        if (c == 'n') { data[4] = w[0]; data[0] = w[1]; data[1] = w[2]; data[2] = w[4]; }
        else if (c == 's') { data[1] = w[0]; data[2] = w[1]; data[4] = w[2]; data[0] = w[4]; }
        else if (c == 'e') { data[3] = w[0]; data[5] = w[2]; data[2] = w[3]; data[0] = w[5]; }
        else { data[5] = w[0]; data[3] = w[2]; data[0] = w[3]; data[2] = w[5]; }
    }
    public int peek(int n) => data[n];
}


public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var d = new dice();
            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().Trim();
                d.roll(s[0]);
            }
            var ans = d.peek(0);
            Console.WriteLine(ans);
        }
    }
}



Measured memory_bytes: 13892
a = list(map(int, input().split()))
HP = a[0]

x = []
for i in range(a[1]):
    x1, y1 = [int(i) for i in input().split()]
    x.append((x1, y1))

max_tup = max(x, key=lambda x: x[0])
max_a = max_tup[0]
dp = [0] * (HP + max_a)

for i in range(1, len(dp)):
    dp[i] = min(dp[i - a] + b for a, b in x)

print(dp[HP])

Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define gc getchar()
#define mp make_pair
#define P pair<int,int>
#define ri register int
#define rb register bool
#define rc register char
#define t(i) edge[i].to
#define w(i) edge[i].wei
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
#define e(i,x) for(ri i=head[x];i;i=edge[i].nxt)

const int N=2e5+10;
int n,a[N],l,r;
bool b[N];

il int read()
{
	rc ch=gc;ri x=0;rb y=1;
	while(ch!='-' && (ch<'0' || ch>'9'))ch=gc;
	if(ch=='-')ch=gc,y=0;
	while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
	return y?x:-x;
}
il bool chck(){rp(i,2,n)if(b[i]==b[i-1])return 0;return 1;}
il bool check(ri dat)
{
	rp(i,1,n)b[i]=(a[i]>dat);ri mid=(n+1)>>1;if(chck())return b[1];
	rp(i,1,mid-1){if(b[mid+i]==b[mid+i-1])return b[mid+i];if(b[mid-i]==b[mid-i+1])return b[mid-i];}
}

int main()
{
	//freopen("2165.in","r",stdin);freopen("2165.out","w",stdout);
	n=r=read()*2-1;rp(i,1,n)a[i]=read();
	while(l<r){ri mid=(l+r)>>1;if(!check(mid))r=mid;else l=mid+1;}printf("%d",l);
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  set<int> D;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    D.insert(d);
  }
  cout << D.size() << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  while(true){
    int n;
    scanf("%d", &n);

    if(n == 0){
      break;
    }

    vector<pii> v(n);

    v[0] = MP(0, 0);
    REP(i,n-1){
      int a, b;
      scanf("%d %d", &a, &b);
      v[i+1] = MP(v[a].first + dx[b], v[a].second + dy[b]); 
    }

    int max_x = -INF, min_x = INF, min_y = INF, max_y = -INF;
    REP(i,n){
      int x = v[i].first, y = v[i].second;
      max_x = max(max_x, x);
      min_x = min(min_x, x);
      max_y = max(max_y, y);
      min_y = min(min_y, y);
    }

    printf("%d %d\n", max_x - min_x + 1, max_y - min_y + 1);
  
  }
  return 0;
}




Measured memory_bytes: 3144
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Thu Dec 27 21:11:18 2018
//
package main

import "fmt"

func main() {
	var N, X int
	fmt.Scan(&N, &X)

	total := 0
	min := 1 << 50
	for i := 0; i < N; i++ {
		var m int
		fmt.Scan(&m)
		total += m
		if m < min {
			min = m
		}
	}
	fmt.Println(N + (X-total)/min)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e];
int n, m;
vector<int>adj[e];
bool vs[e];

//beginner 1999 127

int main()
{
    int r, d, x;
    cin >> r >> d >> x;
    for(int i=1; i<=10; i++){
        x = r*x - d;
        cout << x <<"\n";
    }
}


Measured memory_bytes: 50468