akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while( x->left != NIL ) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while( x->right != NIL ) x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ){
      u = u->left;
    }

    else{
      u = u->right;
    }
  }

  return u;

}

Node treeSuccessor(Node x){
  if ( x->right != NIL ){
    return treeMinimum(x->right);
  }
  
  Node y = x->parent;

  while( y != NIL && x == y->right ){
    x = y;
    y = y->parent;
  }

  return y;

}

void treeDelete(Node z){
  Node x,y; 
  
  if ( z->left == NIL || z->right == NIL ){
    y = z;
  }

  else{
    y = treeSuccessor(z);
  }

  if ( y->left != NIL ){
    x = y->left;
  }

  else{
    x = y->right;
  }

  if ( x != NIL ){
    x->parent = y->parent;
  }
  

  if ( y->parent == NIL ){
    root = x;
  }
  else {
    if (y == y->parent->left){
      y->parent->left = x;
    }

    else{
      y->parent->right = x;
    }

  }

  if ( y != z ){
    z->key = y->key;
  }

  free(y);

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    }

    else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  }

  else {

    if (z->key < y->key) {
      y->left = z;
    }

    else {
      y->right = z;
    }

  }

}

void inorder(Node u){
  if ( u == NIL ){
    return;
  }

  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Node u){
  if ( u == NIL ){
    return;
  }
  
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);

}


int main(){

  int n, i, x;
  char com[20];

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){

    scanf("%s", com);
    if ( strcmp(com, "find") == 0 ){

      scanf("%d", &x);

      Node t = treeSearch(root, x);

      if ( strcmp(com, "findMin") == 0 ){

	Node minn = treeMinimum(t);
	printf("%d\n", minn->key);
      }

      else if ( strcmp(com, "findMax") == 0 ){
	Node maxn = treeMaximum(t);
	printf("%d\n", maxn->key);
      }

      else {

	if ( t != NIL ){
	  printf("yes\n");
	}

	else {
	  printf("no\n");
	}
	
      }
    }
    else if ( com[0] == 'i' ){

      scanf("%d", &x);

      insert(x);
    }
    else if ( strcmp(com, "print") == 0 ){


      inorder(root);

      printf("\n");

      preorder(root);

      printf("\n");
    }
    else if ( strcmp(com, "delete") == 0 ){

      scanf("%d", &x);

      treeDelete(treeSearch(root, x));
    }
  }


  return 0;

}



Measured memory_bytes: 20440
using System;
using System.Collections.Generic;
using System.Linq;
class god {
  static void Main(){
    string read = Console.ReadLine();
    var S  = read.Length;
    var zero = 0;
    var one = 0;
    for (int i = 0; i < read.Length; i++)
    {
      if(read[i] =='0'){
        zero += 1;
      }else{
        one += 1;
      }
    }
    var last =  Math.Abs(zero - one);
    Console.WriteLine(S - last);
  }
}

Measured memory_bytes: 13152
n=int(input())
d=input().split(' ')
list=[]

list3=[]
for i in d:
  list.append(int(i))
list.sort()
if(list[int(n/2)-1]==list[int(n/2)]):
   print(0)
else :
  print(list[int(n/2)]-list[int(n/2)-1])


Measured memory_bytes: 14396
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner) = {
    val N = sc.nextInt
    var H = sc.nextLong
    val A, B = Array.fill(N)(0L)
    for (i <- Range(0, N)) {
      A(i) = sc.nextLong
      B(i) = sc.nextLong
    }
    val maxA = A.sorted.reverse(0)
    var ans = 0L
    for (x <- B.filter(x => x > maxA).sorted.reverse) {
      if (H > 0) {
        ans += 1
        H -= x
      }
    }
    if (H > 0) {
      ans += (H - 1) / maxA + 1
    }
    println(ans)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}



Measured memory_bytes: 75064
#include<stdio.h>
#define MAX 100000
 
int A[MAX],n;
 
int partition( int p, int r ){
  int x,i,j,t;
  x = A[r];
  i = p - 1;
  for( j = p ; j < r ; j++){
    if( A[j] <= x ){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i + 1;
}
 
int main( void ){
  int i,q;
 
  scanf("%d",&n);
  for( i = 0 ; i < n ; i++){
    scanf("%d", &A[i]);
  }
 
  q = partition( 0 , n - 1 );
 
  for( i = 0 ; i < n ; i++ ){
    if( i ){
      printf(" ");
    }
    if( i == q ){
      printf("[");
    }
    printf("%d",A[i]);
    if( i == q ){
      printf("]");
    }
  }
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, M, X;
  cin >> N >> M >> X;
  vec< int > a(M);
  REP(i, M) { cin >> a[i]; }
  auto itr = lower_bound(ALL(a), X);
  int ans = itr - a.begin();
  print(min(ans, M - ans));
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication29 {
    class Program {
        static void Main(string[] args) {
            //入力と出力
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int k = int.Parse(str[1]);
            var result = Method(n,k);
            Console.WriteLine(result);
        }


        private static int Method(int n, int k) {

            int result = k;//k色
            for (int i = 1; i <= n-1; i++) {
                result = result * (k - 1);
            }
            return result;

        }
    }
}


Measured memory_bytes: 13140
import java.util.*;
import static java.lang.System.*;

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

	
	public static void D(Scanner sc) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int D = sc.nextInt();
		HashMap<Integer, int[]> map = new HashMap<Integer, int[]>();
		for(int i=1;i<H+1;i++) {
			for(int j=1;j<W+1;j++) {
				map.put(sc.nextInt(),new int[] {i,j});
			}
		}
		int[] dist = makedist2(map,D,H*W);
		int q = sc.nextInt();
		for(int i=0;i<q;i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			out.println(dist[r]-dist[l]);
		}
		
	}
	
	//
	public static int[] makedist2(HashMap<Integer, int[]> map, int d, int hw) {
		int[] ret = new int[hw+1];
		for(int i=1;i<=d;i++) {
			for(int j=i+d;j<=hw;j+=d) {
				ret[j] = ret[j-d]+ Math.abs(map.get(j)[0]-map.get(j-d)[0]) + Math.abs(map.get(j)[1]-map.get(j-d)[1]);
			}
		}
		return ret;
	}

	
}


Measured memory_bytes: 98652
//Md.Fahd
//HSTU CSE18

#include<bits/stdc++.h>
#define READ_IN freopen("Input.txt","r",stdin);
using namespace std;
const int maxe = 500005;
struct can{
         int aa[26];
} tree[maxe*3];



char ar[maxe];

void make(int node,int b,int e)
{
    if(b==e)
    {
            tree[node].aa[ar[b]-'a']++;

        return;
    }

    int left = node*2;
    int right = node*2+1;
    int mid = (b+e)/2;

    make(left,b,mid);
    make(right,mid+1,e);

    for(int i=0;i<26;i++)
    {
        tree[node].aa[i]=tree[left].aa[i]+tree[right].aa[i];
    }

    //tree[node].aa=tree[left].aa + tree[right].aa;
}

vector<int> ck(int node,int b,int e,int i,int j)
{
    if(i>e || j<b){
        vector<int> as(26,0);
        return as;
    }

    if(b>=i && e<=j){

        vector<int> as(26,0);
        for(int i=0;i<26;i++)
        {
            as[i]=tree[node].aa[i];
        }
        return as;
    }

    int left = node*2;
    int right = node*2+1;
    int mid  = (b+e)/2;
    vector<int> p1(26,0);
    p1= ck(left,b,mid,i,j);
    vector<int> p2(26,0);
    p2= ck(right,mid+1,e,i,j);


    vector<int> p3(26,0);

    for(int i=0;i<26;i++)
    {
        p3[i]+=p1[i];
        p3[i]+=p2[i];
    }

    return p3;
}

void update(int node ,int b,int e,int i,int newvalue)
{
    if(i>e || i<b)
        return ;

    if(b==i && e==i)
    {

            tree[node].aa[ar[b]-'a']=0;
            for(int i=0;i<26;i++)
            {
                tree[node].aa[i]=0;
            }
            ar[b]=newvalue;
        tree[node].aa[newvalue-'a']++;

        return;
    }

     int left = node*2;
    int right = node*2+1;
    int mid = (b+e)/2;

    update(left,b,mid,i,newvalue);
    update(right,mid+1,e,i,newvalue);


    for(int i=0;i<26;i++)
    {
        tree[node].aa[i]=tree[left].aa[i]+tree[right].aa[i];
    }

}

int main(void)
{
    //READ_IN

    int ff;
    cin >> ff;


    string ss; cin >> ss;

    for(int i=1;i<=ss.size();i++)
    {
        ar[i]=ss[i-1];
    }

    int n = ss.size();

   make(1,1,n);

   int q; cin >> q;

   while(q--)
   {
       int a;
       cin >> a;

       if(a==1)
       {
           int index;
           cin >> index;
           char value;
           cin >> value;


           update(1,1,n,index,value);
       }
       else
       {
           int l,r;
           cin >> l >> r;


           vector<int> aa(26,0);

           aa = ck(1,1,n,l,r);

           int cnt = 0;
           for(int i=0;i<26;i++)
           {
               if(aa[i]>0)
                cnt++;
           }
           cout << cnt << endl;
       }
   }






    return 0;
}


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

ll n,mod=1000000007ll,ans=1ll;
ll a[100005],num[3]={0};

int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		ll cnt=0,id;
		cin>>a[i];
		if (a[i]==num[0])
		{
			cnt++;
			id=0;
		}
		if (a[i]==num[1])
		{
			cnt++;
			id=1;
		}
		if (a[i]==num[2])
		{
			cnt++;
			id=2;
		}
		ans*=cnt;
		ans%=mod;
		num[id]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
/*
power and fast-scan code taken from geeks for geeks
*/

#include <bits/stdc++.h>
#define MODD 1000000007LL
#define MAX_SIZE 100000000
#define MAX_N 100001
using namespace std;
typedef long long ll;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return a % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}

// void fastscan(int &number) 
// { 
//     //variable to indicate sign of input number 
//     bool negative = false; 
//     register int c; 
  
//     number = 0; 
  
//     // extract current character from buffer 
//     c = getchar(); 
//     if (c=='-') 
//     { 
//         // number is negative 
//         negative = true; 
  
//         // extract the next character from the buffer 
//         c = getchar(); 
//     } 
  
//     // Keep on extracting characters if they are integers 
//     // i.e ASCII Value lies from '0'(48) to '9' (57) 
//     for (; (c>47 && c<58); c=getchar()) 
//         number = number *10 + c - 48; 
  
//     // if scanned input has a negative sign, negate the 
//     // value of the input number 
//     if (negative) 
//         number *= -1; 
// } 

bool comp(ll &a, ll &b){
    return a>b;
}

bool _pal(string s){
    ll n=s.length();
    for(ll i=0, j=n-1;i<j;i++, j--){
        if(s[i]!=s[j]){
            return false;
        }
    }
    return true;

}

int main(){


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll l;
    cin>>l;
    if(l%3==0){ 
        cout<<fixed<<setprecision (12) <<(l*l*l)/27.0<<endl;
        return 0;
    }
    double c=l/3.0;
    // cout<<"c; "<<c<<endl;
    // c+=1.0;
    double a=l/3.0;
    double sum=a+c+c;
    // cout<<"sum; "<<sum<<endl;
    if(sum!=l){
        a=l-c-c;
    }
    // cout<<"a; "<<a<<" c; "<<c<<endl;
    double ans=a*a*c*1.0;
    cout<<fixed<<setprecision (12) << ans<<endl;

    return 0;
}


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

int main() {
    string s,t; cin >> s >> t;
    int ans = 0;
    rep(i,s.size()) if(s[i] != t[i]) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3824
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

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

    char temp = '0';
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (temp != str[i])
        {
            count++;
            temp = str[i];
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#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 bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    string s;
    int k;
    cin >> s >> k;
    ll cnt = 0;
    ll cnt2 = 0;
    ll cnt3 = 0;
    string s1 = s;
    string s2 = s + s;
    string s3 = s + s + s;
    rep(i, s1.size() - 1)
    {
        if (s1[i] == s1[i + 1])
        {
            s1[i + 1] = 0;
            cnt++;
        }
    }
    rep(i, s2.size() - 1)
    {
        if (s2[i] == s2[i + 1])
        {
            s2[i + 1] = 0;
            cnt2++;
        }
    }
    rep(i, s3.size() - 1)
    {
        if (s3[i] == s3[i + 1])
        {
            s3[i + 1] = 0;
            cnt3++;
        }
    }
    if (k == 1)
    {
        cout << cnt << endl;
    }
    else if (k % 2 == 1)
    {
        cout << cnt + (cnt3 - cnt) * (k / 2) << endl;
    }
    else
    {
        cout << cnt + (cnt3 - cnt) * (k / 2 - 1) + (cnt2 - cnt) << endl;
    }
    //    cout << cnt + (cnt2 - cnt) * (k - 1) << endl;

    return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        solve();
    }

    static void solve() {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        Ball[] balls = new Ball[n];

        for (int i = 0; i < n; i++) {
            balls[i] = new Ball(scanner.nextInt(), scanner.nextInt());
        }
        if (n == 1) {
            System.out.println(1);
            return;
        }

        int result = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    int dx = balls[i].x - balls[j].x;
                    int dy = balls[i].y - balls[j].y;

                    int current = 0;
                    for (int k = 0; k < n; k++) {
                        int res = 1;
                        for (int l = 0; l < n; l++) {
                            if (balls[k].x - balls[l].x == dx && balls[k].y - balls[l].y == dy) {
                                res = 0;
                                break;
                            }
                        }
                        current += res;
                    }
                    result = Math.min(result, current);
                }
            }
        }

        System.out.println(result);
    }

    static class Ball {

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

        int x;
        int y;
    }
}


Measured memory_bytes: 24660
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;

struct UnionFind {
    vector<int> data;
    int sz;
    vector<vector<int>> mem;
    UnionFind(int sz) : data(sz, -1), sz(sz), mem(sz) {
        for (int i = 0; i < sz; i++) init(i);
    }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x; sz--;
        mem[x].insert(mem[x].end(), mem[y].begin(), mem[y].end());
        mem[y].clear();
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    vector<int>& operator[](int x) { return mem[root(x)]; }
    void init(int x) { int r = root(x); mem[r] = {r}; }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
    int size() { return sz; }
};

int main() {
    int n, q; cin >> n >> q;
    UnionFind uf(n);
    for (int i = 0; i < q; i++) {
        int com, a, b; cin >> com >> a >> b;
        if (com == 0) {
            uf.unionSet(a, b);
        } else {
            cout << uf.findSet(a, b) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3688
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;

  cin>>n;


  cout<<n*(n+1)/2<<endl;
}


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

void dfs(int keta, ll val, vector<ll> &all){
    // valはそこまでの数。下位1桁は%10で取れる。下位1桁のaddを作成する。
    all.push_back(val);

    // 10桁以上は考えなくてOK
    if(keta>=10) return;

    // 次のketaへ進む
    for(int j=-1;j<=1;j++){
        int add = (val % 10) + j;
        if (add >= 0 && add<=9) dfs(keta+1, val*10+add, all);
    }
}

// header area
int main(){
    int K; cin >> K;
    vector<ll> all;
    for(int v=1;v<10;v++) dfs(1, v, all);

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

    cout << all[K-1] << endl;

    return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
   int ans,anss,A,Z;
    A= 'A';
    Z= 'Z';
  for(int i=0 ; i <s.size() ; i++){
    ans = s.at(i)+n;
    if(ans > Z){
      anss= ans-Z-1+A;
    }
    else anss =ans;
    
    
    cout << char(anss);
    
  }
      
}


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

int main() {
  int N,K,i,A,B,c=1;
  cin>>N>>K;

  for(i=0;i<N;i++){
  	A=c*2;
    B=c+K;
    if(A<B) c=A;
    else c=B;
  }
  
  cout<<c<<endl;
}


Measured memory_bytes: 256
X,K,D = list(map(int, input().split()))
co,ans = divmod(abs(X),D)
if (K - co) > 0:
    if (K - co) % 2 == 0:
        pass
    else:
        ans = abs(ans) - D
else:
    ans = abs(X) - K*D

print(abs(ans))

Measured memory_bytes: 9148
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 500100;
const int mod = 1e9 + 7;
struct rivers
{
	int k, b, id;
}r[maxn];
bool cmpk(const rivers &a, const rivers &b) 
{
	if(a.k == b.k)
		return a.b < b.b;
	return a.k < b.k;
}
bool cmpb(const rivers &a, const rivers &b)
{
	return a.b < b.b;
}
struct qus
{
	int l, r;
	bool operator<(const qus &a) const
	{
		if(r == a.r)
			return l < a.l;
		return r < a.r;
	}
}q[maxn];
int n;
long long dp[maxn] = {0}, h[maxn] = {0};
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n;
	for(int i = 1; i <= n; i ++)
		cin >> r[i].b >> r[i].k;
	sort(r + 1, r + n + 1, cmpk);
	for(int i = 1; i <= n; i ++)
		r[i].id = i;
	sort(r + 1, r + n + 1, cmpb);
	int mn = n + 1;
	for(int i = n; i >= 1; i --)
	{
		mn = min(mn, r[i].id);
		q[r[i].id].l = mn;
	}
	int mx = 0;
	for(int i = 1; i <= n; i ++)
	{
		mx = max(mx, r[i].id);
		q[r[i].id].r = mx;
	}
	sort(q + 1, q + n + 1);
	/*
	for(int i = 1; i <= n; i ++)
		cout << q[i].l << " " << q[i].r << endl;
		*/
	dp[0] = h[0] = 1;
	int p = 1;
	for(int i = 1; i <= n; i ++)
	{
		h[i] = h[i - 1];
		for(; q[p].r == i && p <= n; p ++)
		{
			long long a = (h[q[p].r] - (q[p].l > 1 ? h[q[p].l - 2] : 0) + mod) % mod;
			(dp[i] += a) %= mod;
			(h[i] += a) %= mod;
		}
		//cout << p << " " << i << " " << dp[i] << " " << h[i] << endl;
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 14080
#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,n) for(int j=0;j<n;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((int)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define m_p make_pair
typedef long long ll;
typedef double db;
typedef vector<string> ve;
typedef vector<pair<int, int> > vepa;
typedef set<string>se;
typedef map<string,int> mpp;
const ll N=1024,OO=1e14,MOD=1e9+7;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,k,a,b,cnt,sum,mx,mn,arr[N];
bool f,vis[N];
int main(){
   IOS;
   cin>>n;
   rep(i,n)
   {
       cin>>a;
       if(a>mx)mx=a;
       else sum+=(mx-a);
   }
   cout<<sum;
go;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
  std::cerr << " " << head;
  debug_impl(tail...);
}
#define debug(...)\
  std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
  debug_impl(__VA_ARGS__);\
  std::cerr << std::noboolalpha;

template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v) {
  for (auto & x : v) is >> x;
  return is;
}

template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
  auto n = v.size();
  os << "{";
  for (size_t i = 0; i < n; i++)
    {os << (i > 0 ? "," : "") << v.at(i);}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, k, q;
  std::cin >> n >> k >> q;
  std::vector< int > b(n, 0);
  loop(q) {
    int x; std::cin >> x;
    x--;
    b.at(x)++;
  }
  // debug(b);
  rep(i, 0, n) {
    auto ret = b.at(i) > q - k;
    std::cout << (ret ? "Yes" : "No") << std::endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int gcd( int x, int y )
{
  int temp = 0;

  if ( x < y ) {
    temp = x;
    x = y;
    y = temp;
  }

  if ( y < 1 ) return 1;

  if ( x % y == 0 ) return y;
  else gcd( y, x % y );

}

int main()
{
  int x, y;
  int result = 0;

  scanf("%d %d",&x, &y);

  result = gcd(x, y);
  printf("%d\n",result);
  return 0;
}


Measured memory_bytes: 2088
n, k, q = map(int, input().split())

pi = {}

for i in range(1, n+1):
    pi.setdefault(i, k-q)

for i in range(1, q+1):
    ai = int(input())
    pi[ai]=pi[ai]+1

for i in range(1, n+1):
    if pi[i]>0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 17900
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;

#define NUM 10000
int v_num, e_num;
vector<int> V[NUM];
int d[NUM];
queue<int> Q;

void init(){
    for(int i = 0; i < v_num; i++){
        d[i] = 0;
    }

    for(int i = 0; i < e_num; i++){
        int s, t;
        scanf("%d", &s);
        scanf("%d", &t);
        V[s].push_back(t);
        d[t]++;
    }

    for(int i = 0; i < v_num; i++){
        if(d[i] == 0)
            Q.push(i);
    }
}

void t_sort(){
    while(!Q.empty()){
        int f = Q.front(); Q.pop();
        printf("%d\n", f);
        for(int i = 0; i < V[f].size(); i++){
            d[V[f][i]]--;
            if (d[V[f][i]] == 0){
                Q.push(V[f][i]);
            }
        }
    }
}

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

    init();

    t_sort();
}




Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

ll H, W;
string s[22];
ll dx[]={0, -1, 0, 1};
ll dy[]={-1, 0, 1, 0};
ll dis[22][22];

void bfs(ll sx, ll sy) {
  ll i, j;
  queue<P> q;
  
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      dis[i][j]=INF;
    }
  }
  
  dis[sx][sy]=0;
  q.push({sx, sy});
  while(q.size()) {
    P f=q.front(); q.pop();
    ll x=f.ft, y=f.sc;
    
    for(i=0; i<4; i++) {
      ll tx=x+dx[i];
      ll ty=y+dy[i];
      
      if(tx<0 || ty<0 || tx>=H || ty>=W) continue;
      if(s[tx][ty]=='#') continue;
      if(dis[tx][ty]!=INF) continue;
      
      dis[tx][ty]=dis[x][y]+1;
      q.push({tx, ty});
      
      
    }
    
    
  }
  
  
}

int main(void) {
  cin >> H >> W;
  ll i, j;
  ll k, l;
  
  for(i=0; i<H; i++) {
    cin >> s[i];
  }
  
  ll ans=0;
  for(i=0; i<H; i++) {
    for(j=0; j<W; j++) {
      if(s[i][j]=='#') continue;
      
      
      bfs(i, j);
      
      for(k=0; k<H; k++) {
        for(l=0; l<W; l++) {
          if(s[k][l]=='#') continue;
          
          chmax(ans, dis[k][l]);
        }
      }
      
    }
  }
  
  
  pt(ans);
  
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;

string S;
int main (){
    cin >> S;
    int p = 0;
    for(int i=0; i<3; i++){
        if(S[i] == 'o') p += 100;
    }
    cout << 700 + p << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
int a[100000];
int main(void)
{
	int n,min=INF,max=0,cnt=0,i;
	scanf("%d",&n);
	FOR(i,0,n){
		scanf("%d",&a[i]);
		min=MIN(min,a[i]);
		max=MAX(max,a[i]);
	}
	if(max-min>1) puts("No");
	else if(max==min){
		if(max==n-1) puts("Yes");
		else if(max<=n/2) puts("Yes");
		else puts("No");
	}else{
		FOR(i,0,n) if(a[i]==min) cnt++;
		if(cnt==n-1) puts("No");
		else if(max>cnt&&max<=(n-cnt)/2+cnt) puts("Yes");
		else puts("No");
	}
	return 0;
}
    
    


Measured memory_bytes: 512
N = int(input())

l1 = []
l2 = []
for _ in range(N):
    s = int(input())
    if s % 10 == 0:
        l2.append(s)
    else:
        l1.append(s)
l1.sort()

while l1 and sum(l1) % 10 == 0:
    l1 = l1[1:]
if not l1:
    print(0)
else:
    print(sum(l1) + sum(l2))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main(void){
  int A,B,C;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  if(A+B+C>=22){
    printf("bust");
  }
  else{
    printf("win\n");
  }
  return 0;
}

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

#define MOD 1000000007
template<typename ty1,typename ty2>
inline int add(ty1 x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x += y; return x < MOD ? x : x - MOD;
}
template<typename ty1,typename ty2>
inline void addto(ty1 &x, ty2 y) {
		  if(y>=MOD)y%=MOD;
		  if(x>=MOD)x%=MOD;
	      x += y; if (x >= MOD) x -= MOD;
}
template<typename ty1,typename ty2>
inline int sub(ty1 x, ty2 y) {
		if(y>=MOD)y%=MOD;
		 if(x>=MOD)x%=MOD;
        x -= y; return x < 0 ? x + MOD : x;
}
template<typename ty1,typename ty2>
inline void subto(ty1 &x, ty2 y) {
	if(y>=MOD)y%=MOD;
	if(x>=MOD)x%=MOD;
    x -= y; if (x < 0) x += MOD;
}
template<typename ty1,typename ty2>
inline int mul(ty1 x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        return 1ll * x * y % MOD;
}
template<typename ty1,typename ty2>
void multo(ty1 &x, ty2 y) {
        if(y>=MOD)y%=MOD;
		if(x>=MOD)x%=MOD;
        x=1ll * x * y % MOD;
}

#define MAX 2002
string a;
string b;
string c;

#define MAXX 1000000
#define BASE 500000
bool ab[MAXX];
bool ac[MAXX];
bool bc[MAXX];

int main(){
	cin>>a>>b>>c;
	auto check=[&](char aa,char bb){return aa!='?'&&bb!='?';};
	for(int i=0;i<a.size();i++){
		for(int j=0;j<b.size();j++){
			if(check(a[i],b[j])&&a[i]!=b[j]){
				ab[i-j+BASE]=true;
			}
		}
	}
	for(int i=0;i<a.size();i++){
		for(int j=0;j<c.size();j++){
			if(check(a[i],c[j])&&a[i]!=c[j]){
				ac[i-j+BASE]=true;
			}
		}
	}
	for(int i=0;i<b.size();i++){
		for(int j=0;j<c.size();j++){
			if(check(b[i],c[j])&&b[i]!=c[j]){
				bc[i-j+BASE]=true;
			}
		}
	}
	int ans=INT_MAX;
	//int a=max({2,3,4});
	for(int i=-4000;i<=4000;i++){
		for(int j=-4000;j<=4000;j++){
			if(ab[i+BASE]==false&&ac[j+BASE]==false&&bc[j-i+BASE]==false){
				ans=min(ans,max({(int)a.size(),i+(int)b.size(),j+(int)c.size()})-min({(int)0,i,j}));
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main () {
    long long sum = 0;
    string s;

    cin >> s;
    for(int i = 0; i < s.size(); i++) {
        sum += s[i] - '0';
    }

    if (sum % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3704
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int x, y;
	scanf("%d %d", &x, &y);
	if (y < 0 && (y - x) % 2 == 0) {
		printf("Negative\n");
		return 0;
	}
	if (x <= 0 && y >= 0) {
		printf("Zero\n");
		return 0;
}
	printf("Positive\n");
	return 0;
}

Measured memory_bytes: 128
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 10 ** 9 + 7

B,W = map(int,readline().split())

def cumprod(arr):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

U = 2*10**5 + 100
x = np.arange(U,dtype=np.int64); x[0] = 1
fact = cumprod(x)
x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod(x)[::-1]

x = np.full(U,pow(2,MOD-2,MOD),dtype=np.int64); x[0] = 1
pow2_inv = cumprod(x)

# 各時点で、単色になっている確率
black_only = np.zeros(B+W,np.int64)
x = fact[W-1:B+W-1] % MOD * fact_inv[0:B] % MOD * fact_inv[W-1] % MOD
black_only[W:B+W] = pow2_inv[W:B+W] * x % MOD
np.cumsum(black_only,out=black_only)
black_only %= MOD

white_only = np.zeros(W+B,np.int64)
x = fact[B-1:W+B-1] % MOD * fact_inv[0:W] % MOD * fact_inv[B-1] % MOD
white_only[B:W+B] = pow2_inv[B:W+B] * x % MOD
np.cumsum(white_only,out=white_only)
white_only %= MOD

answer = (1+black_only-white_only) * pow(2,MOD-2,MOD) % MOD
print('\n'.join(answer.astype(str)))

Measured memory_bytes: 70948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x,y;cin >> x >> y;
	if(x>=0 && x<=y) cout << y-x << endl;
	else if(x>=0 && y>=0) cout << min(y-(-x)+1,abs(x)-y+2) << endl;
	else if(x>=0 && abs(y)<=x) cout << y-(-x)+1 << endl;
	else if(x>=0) cout << abs(y)-x+1 << endl;
	else if(y>=0 && abs(x)>=y) cout << min(abs(x)-y+1,y-x) << endl;
	else if(y>=0) cout << y-abs(x)+1 << endl;
	else if(abs(x)>=abs(y)) cout << abs(x)-abs(y) << endl;
	else cout << abs(y)-abs(x)+2 << endl;
}

Measured memory_bytes: 256
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)
#define cio ios::sync_with_stdio(false);

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int a[110];
    int tt = 0;
    for (int i = 0;i < n;i ++) {
        scanf("%d",a + i);
        tt += a[i];
    }
    itn ok = 0;
    for (int i = 0;i < n;i ++)
    {
        if (a[i] * 4 * m >= tt) {
            ok ++;
        }
    }
    if (ok >= m) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 888
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - Transfer
            var line = ReadLine();
            int A = line[0];
            int B = line[1];
            int C = line[2];

            if (A - B > C)
            {
                Console.WriteLine(0);
            }
            else
            {
                Console.WriteLine(C - (A - B));
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
N, _ = inpl()
A = inpl()

if N == 1:
    print(*A)
    exit()

L = [0]*(N+1)
R = [0]*(N+1)

for i in range(N-1):
    R[A[i]] = A[i+1]
    L[A[i+1]] = A[i]

lm = A[0]
rm = A[-1]

for q in inpl():
    if q == rm:
        l = L[q]
        
        R[l] = 0
        L[q] = 0
        R[q] = lm
        L[lm] = q

        lm = q
        rm = l

    elif q == lm:
        r = R[q]
        L[r] = 0
        R[q] = 0
        L[q] = rm
        R[rm] = q
        lm = r
        rm = q

    else:
        l, r = L[q], R[q]
        L[q] = rm
        R[q] = lm
        
        R[l] = 0
        L[r] = 0
        
        L[lm] = q
        R[rm] = q
        
        rm = l
        lm = r

ans = []
while lm != 0:
    ans.append(lm)
    lm = R[lm]

print(*ans)


Measured memory_bytes: 21916
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main(){
	int n, m;
	long long sum = 0;
	vector<int>data[300000];
	priority_queue<int>que;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> m;
		for (int j = 0; j < m; ++j) {
			int x; cin >> x; data[i].push_back(x);
		}
	}
	for (int i = n-1; i >=0; --i) {
		for (int j = 0; j < data[i].size(); ++j) {
			que.push(data[i][j]);
		}
		if (!que.empty()) {
			sum += que.top();
			que.pop();
		}
	}
	cout << sum << endl;
	return 0;
}


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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	vector<ll> rsl;
	int mod = 100000;
	while(true) {
		int N, M, S;
		cin >> N >> M >> S;
		if(N == 0 and M == 0 and S == 0) break;

		int k = N * N;
		int n = S - k * (k + 1) / 2;
		int m = M - k;

		ll dp[k + 1][n + 1];
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;

		rep(i, 1, k + 1) rep(j, 0, n + 1) {
			if(j - i >= 0) {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % mod;
				if(j - i - m >= 0) (dp[i][j] -= dp[i - 1][j - i - m]) %= mod;
			} else dp[i][j] = dp[i - 1][j];
		}

		rsl.push_back(dp[k][n]);
	}

	rep(i, 0, rsl.size()) cout << rsl[i] << endl;

}



Measured memory_bytes: 3868
def main():
    n = int(input())
    # a, b, c, d = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    mx = 0
    result = 0
    for num in a:
        mx = max(mx, num)
        if mx > num:
            result += mx - num
    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 105192
#include<stdio.h>
#define INF 1000000
#define rep(i,x,n) for((i)=(x);(i)<=(int)(n);(i)++)
void warshall_floyd(void);
int min(int,int);
int graph[101][101];
int n,c,d;

int main(void){
  int k,i,j,x,e,a,b;

  while(1){

    scanf("%d %d",&n,&k);
    if(n==0 && k==0)break;
    
    rep(i,0,n)rep(j,0,n)
      graph[i][j] = (i==j?0:INF);
    
    for(i=0;i<k;i++){
      scanf("%d",&x);
      
      if(x){
	scanf("%d %d %d",&c,&d,&e);
	if(graph[c][d]>e){
	graph[c][d]=graph[d][c]=e;
	warshall_floyd();
	}
      }
      else{
	scanf("%d %d",&a,&b);
	if(graph[a][b]<INF)printf("%d\n",graph[a][b]);
	else printf("-1\n");
      }
    }
  }  
  return 0;
}

void warshall_floyd(void){
  int i,j;
  
  rep(i,1,n)rep(j,1,n)
    graph[i][j]=graph[j][i]=min(graph[i][j],graph[i][c]+graph[c][d]+graph[d][j]);
}

int min(int x,int y){
  return (x<y)?x:y;
}

Measured memory_bytes: 460
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;


int main(void) {

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

	ll x, k, d;
	cin >> x >> k >> d;

	x = abs(x);

	if (x == 0) {
		if (k % 2) cout << abs(d) << endl;
		else cout << 0 << endl;
		return 0;
	}
		
	ll c = x / d;
	if (k < c) {
		cout << x - d * k << endl;
		return 0;

	}
	k -= c;

	x -= d * c;
	ll ans = x;
	if (k % 2) ans = abs(x - d);

	cout << ans << endl;











	return 0;
}


Measured memory_bytes: 3684
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

void maxHeapify(vector<int>& heap, size_t i) {
  auto l = i * 2;
  auto r = i * 2 + 1;
  auto v = heap[i];
  auto lv = l < heap.size() ? heap[l] : numeric_limits<int>::lowest();
  auto rv = r < heap.size() ? heap[r] : numeric_limits<int>::lowest();
  if (v >= lv && v >= rv) {
    return;
  }
  auto largest = lv >= rv ? l : r;
  swap(heap[largest], heap[i]);
  maxHeapify(heap, largest);
}

void buildMaxHeap(vector<int>& heap) {
  for (size_t i = (heap.size() - 1) / 2; i >= 1; --i) {
    maxHeapify(heap, i);
  }
}

void printHeap(vector<int>& heap) {
  for (auto it = next(heap.begin()); it != heap.end(); ++it) {
    cout << " " << *it;
  }
  cout << endl;
}

int main() {
  int H;
  cin >> H;
  vector<int> heap;
  heap.push_back(0);
  for (int t, i = 0; i < H; ++i) {
    cin >> t;
    heap.push_back(t);
  }
  buildMaxHeap(heap);
  printHeap(heap);
}

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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	// freopen("input.in", "r", stdin);
	// freopen("input.out", "w", stdout);
	int n; cin >> n;
	ll ans = 0;
	FOR(i, 1, n) {
		ans += (n - 1) / i;
	}
	cout << ans << nl;
}

Measured memory_bytes: 3644
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = n; i <= 999; i++)
	{
		string str = to_string(i);
		if (str[0] == str[1] && str[0] == str[2]) cout << i << endl, exit(0);
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
    LL I,O,T,J,L,S,Z;
    LL flag=0;
    LL K,K1,K2;
    while(~scanf("%lld%lld%lld%lld%lld%lld%lld",&I,&O,&T,&J,&L,&S,&Z))
    {
        K=0;
        K1=0;
        K2=0;
        flag=0;
        LL MIN  = min(I,min(L,J));
        K   =(I/2)*4+(J/2)*4+(L/2)*4+(O*2);
        if(MIN==0)
        {

               printf("%lld\n",K/2);
            continue;
        }
        else
        {
            K1=(MIN*6)+(I-MIN)/2*4+(J-MIN)/2*4+(L-MIN)/2*4+(O*2);
            K2=(MIN-1)*6+(I-MIN+1)/2*4+(J-MIN+1)/2*4+(L-MIN+1)/2*4+(O*2);
            K=max(K,max(K1,K2));


            printf("%lld\n",K/2);
        }

    }
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Set as ST
import qualified Data.Sequence as SQ
import Data.Array
import Data.Array.Unboxed
import Data.Array.ST
import Data.Array.IO
import Data.Maybe
import Data.Ratio
import Data.Char
import Data.Bits
import Data.List
import Data.Tuple
import Data.Functor
import Data.IORef
import Data.STRef
import Control.Applicative
import Control.Monad
import Control.Monad.ST

main = do
  n <- readLn :: IO Int
  let s = floor $ sqrt $ fromIntegral n
  print $ minimum $ [i-1+j-1 | i <- [1..s], let j = n `div` i, let res = i * j, res == n]


Measured memory_bytes: 764