akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std; 
int m(int y)
{
	if(y<0)
		y=y*(-1);
return y;}
  int fuc(int *a,int l,int k)
  {
	  int b[l];
	  int i,j;
	  b[0]=0;
	  b[1]=m(a[1]-a[0]);
	  for(i=2;i<l;i++)
	  {
		  b[i]=1000000000;
		  for(j=i-k;j<i;j++)
		  {
			  if(b[j]+m(a[i]-a[j])<b[i])
			  { b[i]=m(a[i]-a[j])+b[j];
		  //cout<<b[i]<<endl;
		  }
		  }
	  }	  
  return b[l-1];		  
  }
  

int main() 
{   
ios::sync_with_stdio(false);
  cin.tie(0);
    //SieveOfEratosthenes(900000);
	int t,k,i;
  k=2;
	cin>>t;
	int a[t];
	i=0;
	while(i<t)
	{
		cin>>a[i];
		i++;
	}
	int cost=fuc(a,t,k);
	cout<<cost<<endl;
    return 0; 
} 

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

using namespace std;

using ll = int64_t;

/// <summary>
/// 単純なcoutの時に使う
/// </summary>
#define co(a) cout<<a<<"\n"


/// <summary>
/// [beg, end)の範囲を，添え字indexでループするfor文に置換します
/// </summary>
#define rep(i,a) for(ll i=0; i<a; ++i)
#define reps(i, a, b) for(ll i = a; i < b; ++i)

/// <summary>
/// 迷路等で使う方向のベクトル
/// </summary>
const vector<ll> dx = { 0, 1, 0, -1 }, dy = { 1, 0, -1, 0 };

/// <summary>
/// デバッグ時に使う
/// </summary>
#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

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

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

	ll N;
	cin >> N;

	vector<double> A (N);

	rep (i, N) {
		cin >> A[i];
	}

	for (; A.size () > 1;) {
		sort (A.begin (), A.end ());

		double hoge1 = A[0], hoge2 = A[1];
		A.erase (A.begin ());
		A[0] = (hoge1 + hoge2) / 2;
	}

	cout << A[0] << endl;
}



Measured memory_bytes: 256
num = input().split()
num = [int(x) for x in num]

if num[1] < num[2] or num[3] < num[0]:
    print(0)
elif num[1] > num[2]:
    print(min(num[1], num[3])-max(num[2], num[0]))
else:
    print(min(num[3],num[1]) - max(num[0], num[2]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N;
    cin >> N;
    int A[N][N];
    rep(i,N){
        rep(j,N){
            cin >> A[i][j];
        }
    }
    bool ok[N][N]{};
    rep(k,N){
        rep(i,N){
            rep(j,N){
                if(i == j || i == k || j == k) continue;
                if(A[i][j] > A[i][k] + A[k][j]){
                    cout << -1 << endl;
                    return 0;
                }
                else if(A[i][j] == A[i][k] + A[k][j]){
                    ok[i][j] = true;
                }
            }
        }
    }
    int ans = 0;
    rep(i,N){
        rep(j,N){
            if(!ok[i][j]) ans += A[i][j];
        }
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  // ll n, m;
  // cin >> n >> m;
  ll n, m, l;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;
  l = lcm(n, m);
  // string u(l, ' ');
  map<int, char> u;
  fi(0, n) {
    u[i * l / n] = s[i];
  }
  fi(0, m) {
    char c = u[i * l / m];
    if(c != '\0' && c != t[i]) {
      cout << "-1\n";
      return 0;
    }
  }
  
  cout << l << endl;
  return 0;
}



Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <cstdlib>  
#include <algorithm>
#include <string>

using namespace std;
 
int main() {
    int a,b;cin>>a>>b;
    if((a*b)%2 == 0){
      cout<<"No";
    }
    else cout<<"Yes";
    return 0;
}

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

vector<int> par(100010);

int root(int x)
{
    if (par[x] == x)
        return x;
    else
        return par[x] = root(par[x]);
}

void unite(int x, int y)
{
    x = root(x);
    y = root(y);
    if (x == y)
        return;
    par[x] = y;
}

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

    int n, x, a = 0;
    cin >> n >> x;
    int t = 0;
    a = n + 1;
    rep(i, n)
    {
        int l;
        cin >> l;

        if (t + l > x)
        {
            a = i + 1;
            break;
        }
        t += l;
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int E = sc.nextInt();
		int K = sc.nextInt();

		if(E-A <= K){
			System.out.println("Yay!");
		}else{
			System.out.println(":(");

		}

		

	}


}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}




Measured memory_bytes: 23764
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int[] A = new int[N];
    int[] order = new int[N];
    StringBuilder sb = new StringBuilder();
    for(int i=0;i<N;i++){
      order[Integer.parseInt(sc.next())-1] = i+1;
    }
    sb.append(order[0]);
    for(int i=1;i<N;i++){
      sb.append(' ');
      sb.append(order[i]);
    }
    System.out.print(sb.toString());
    System.out.flush();
  }
}


Measured memory_bytes: 47584
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test1 cout << "test1" << endl;
#define test2 cout << "test2" << endl;
#define fixprecision(n) fixed; cout << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define iikae auto&
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

int main(){
  kyopro;
  ll a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if(max({a, b, c, d, e}) - min({a, b, c, d, e}) <= k) cout << "Yay!" << rt;
  else cout << ":(" << rt;
}

Measured memory_bytes: 256
#include <iostream>
    using namespace std;
    int an[5000],bl[5000];
    int main() {
    // you
    int A,B;
    cin >> A >> B;
     
    for(int i=0;i<A;i++){
    cin >>an[i];
    }
    for(int i=0;i<B;i++){
    cin >> bl[i];
    }
    
    int maxer=0;
    for(int i=0;i<B;i++){
  	int now=i;
  		for(int j=0;j<A;j++){
  			if(bl[now]==an[j])
  			now++;
  		}
  		maxer=max(now-i,maxer);
    }
    
    cout << maxer << endl;
    return 0;
    }

Measured memory_bytes: 1204
S = input()
n = S.count('N')
s = S.count('S')
e = S.count('E')
w = S.count('W')
if (n > 0 and s > 0 and e == 0 and w == 0) or (n == 0 and s == 0 and e > 0 and w > 0) or (n > 0 and s > 0 and e > 0 and w > 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

	int h, w;
	int i, j;

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

		if (h == 0 && w == 0){
			break;
		}

		for (i = 0; i < h; i++){
			
			for (j = 0; j < w; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");

	} 
	return 0;
}

Measured memory_bytes: 572
/*方針
悪い展望台の番号を選ぶ
展望台の番号は0~N-1とする(インデックスにそのまま使えるようにするため)

Aj＜Bjであるとき、その時点でAjは絶対に良い展望台にはなり得ない、よって悪い展望台
その逆もまた同様
Aj==Bjであるとき、その時点でAjもBjも悪い展望台
悪い展望台の番号を配列に追加していく

最後にすべての展望台の数から悪い展望台の数を引くと、良い展望台の数が出てくる
*/
import Foundation
let nm = readLine()!.split(separator:" ").map{Int($0)!}
let hill = readLine()!.split(separator:" ").map{Int($0)!}
var ans: Set<Int> = []
for _ in 1...nm[1]{
  let ab = readLine()!.split(separator:" ").map{Int($0)!}
  if hill[ab[0]-1] < hill[ab[1]-1]{
    ans.insert(ab[0]-1)
  }
  else if hill[ab[0]-1] > hill[ab[1]-1]{
    ans.insert(ab[1]-1)
  }
  else{
    ans.insert(ab[0]-1)
    ans.insert(ab[1]-1)
  }
}
print(nm[0]-ans.count)

Measured memory_bytes: 19116
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}


void func(void)
{
//DEBUG_OUT("----\n");
    struct T{
        int32 cnt;
        string dir;
    };
    int32 sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    int32 dy = ty-sy;
    int32 dx = tx-sx;
    vector<T> root(12);
    
    //// for ty,tx 1 ////
    root[0].cnt = dy; root[0].dir = "U";   // up
    root[1].cnt = dx; root[1].dir = "R";   // right

    //// for sy,sx 1 ////
    root[2].cnt = dy; root[2].dir = "D";   // down
    root[3].cnt = dx; root[3].dir = "L";   // left

    //// for ty,tx 2 ////
    root[4].cnt = 1; root[4].dir = "L";   // left
    root[5].cnt = dy+1; root[5].dir = "U";   // up
    root[6].cnt = dx+1; root[6].dir = "R";   // right
    root[7].cnt = 1; root[7].dir = "D";   // down
    
    //// for sy,sx 2 ////
    root[8].cnt = 1; root[8].dir = "R";   // right
    root[9].cnt = dy+1; root[9].dir = "D";   // down
    root[10].cnt = dx+1; root[10].dir = "L";   // left
    root[11].cnt = 1; root[11].dir = "U";   // up
    
    for(int32 i=0; i<12; i++){
        for(int32 j=0; j<root[i].cnt; j++){
            cout << root[i].dir;
        }
    }

    cout << endl;
    return;
}



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

public class Main{

	
	static int MOD=(int)1e9+7;
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner();
		PrintWriter out=new PrintWriter(System.out);
		int n=sc.nextInt(),k=sc.nextInt();
		int []a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		int [][]dp=new int [n+1][k+1],pre=new int [n+1][k+1];
		pre[n][k]=dp[n][k]=1;
		for(int idx=n-1;idx>=0;idx--) {
			int sum=0;
			for(int eaten=0;eaten<=k;eaten++)
			{
				int ans=pre[idx+1][Math.min(k, eaten+a[idx])];
				if(eaten>0) {
					ans=ans-pre[idx+1][eaten-1];
					if(ans<0)
						ans+=MOD;
				}
				dp[idx][eaten]=ans;
				sum=sum+ans;
				if(sum>=MOD)
					sum-=MOD;
				pre[idx][eaten]=sum;
			}
		}
		out.println(dp[0][0]);
		out.close();
	}
	
	static class Scanner
	{
		BufferedReader br;
		StringTokenizer st;
		Scanner(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		Scanner(String fileName) throws FileNotFoundException{
			br=new BufferedReader(new FileReader(fileName));
		}
		String next() throws IOException {
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		String nextLine() throws IOException {
			return br.readLine();
		}
		int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		long nextLong()  throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}
		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}
	}
}


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

n, m = map(int, input().split())
ks = [[0]*(m+1) for _ in range(m)]
ans = 0
for i in range(m):
    ks[i] = list(map(int, input().split()))
p = list( map(int, input().split()))

ans = 0
for i in range(2**n):
    isConflict = False

    for j in range(m):
        tmp = 0
        for k in ks[j][1:]:
            k -= 1
            tmp += (i >> k)
        if tmp%2 != p[j]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 39664
n = int(input())
w = list(map(int,input().split()))
ans = float('inf')
for i in range(1,len(w)):
    w_1 = w[:i]
    w_2 = w[i:]
    abs_w = abs(sum(w_1)-sum(w_2))
    ans = min(ans, abs(sum(w_1)-sum(w_2)))
print(ans)

Measured memory_bytes: 3060
left, right = gets.chomp.split.map(&:to_i)
MOD = 2019

if right - left >= MOD then
    puts 0
else
    ans = 1 << 40
    (left..right).each do |i|
        (left..right).each do |j|
            next if i == j
            tmp = i % MOD * j % MOD
            ans = tmp if tmp < ans
        end
    end
    puts ans
end

Measured memory_bytes: 14396
from functools import reduce

n, X = map(int, input().split())
x = list(map(int, input().split()))
for i in range(n):
    x[i] -= X
    x[i] = abs(x[i])

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def gcd_list(n):
    return reduce(gcd, n)

print(gcd_list(x))

Measured memory_bytes: 14596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node
{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key)
{
  NodePointer  i;
  for(i=nil;i->next!=nil;i=i->next)
   if(i->next->key==key)return i->next;
  return NULL;
}

void init()
{
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList()
{
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t)
{
  t->next->prev = t->prev;
  t->prev->next = t->next;
}

void deleteFirst()
{
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast()
{
  NodePointer i;
  i=nil->prev;
  deleteNode(i);
}

void delete(int key)
{
  NodePointer i;
  i=listSearch(key);
  if(i!=NULL)deleteNode(i);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;

  scanf("%d", &n);

  init();

  for ( i = 0;i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' )
    {
      insert(key);
      np++;
      size++;
    }
    else if ( com[0] == 'd' )
    {
      if (strlen(com) > 6)
      {
	      if ( com[6] == 'F' ) deleteFirst();
	      else if ( com[6] == 'L' ) deleteLast();
      }
      else
      {
	      delete(key);
        nd++;
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 36092
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	if 2 * K - 1 > N:
		print(-1)
	else:
		if N % 2 == 1:
			ans = [[0, 0, 0] for i in range(N)]
			for i in range(N):
				ans[i][2] = K + 2 * N + i
			for i in range(N):
				ans[(2 * i) % N][(2 * i) // N] = K + i
				ans[(2 * i + 1) % N][(2 * i + 1) // N] = K + N + i
		else:
			ans = [[0, 0, 0] for i in range(N)]
			for i in range(N):
				ans[i][2] = K + 2 * N + i
			n = N // 2
			for i in range(n):
				ans[2 * i][0] = K + i
				ans[2 * i + 1][0] = K + N + i
			for i in range(n, N):
				ans[2 * i - N][1] = K + N + i
				ans[2 * i + 1 - N][1] = K + i
		for i in range(N):
			print(" ".join(list(map(str, ans[i]))))

if __name__ == '__main__':
	main()

Measured memory_bytes: 25192
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int [] a = new int[n];
		int d;
		for ( int i=0; i<n-1; i++) {
			d = sc.nextInt();
			a[d-1]++;
		}
		sc.close();
		for ( int i=0; i<n; i++) {
			System.out.println(a[i]);
		}

	}
}


Measured memory_bytes: 55868
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static class Knapsack {

		int n, w;
		int wt[];
		long value[];
		long dp[][];

		Knapsack(int n, int w) {

			this.n = n;
			wt = new int[n];
			value = new long[n];

			dp = new long[n][w + 1];

			for (int i = 0; i < n; i++) {
				for (int j = 0; j <= w; j++)
					dp[i][j] = -1L;
			}
		}

		long maxprofit(int i, int j) {

			if (i == n || j == 0)
				return 0;

			if (dp[i][j] != -1L)
				return dp[i][j];

			if (wt[i] <= j) {

				long left = value[i] + maxprofit(i + 1, j - wt[i]);
				long right = maxprofit(i + 1, j);

				return dp[i][j] = Math.max(left, right);
			}

			else
				return dp[i][j] = maxprofit(i + 1, j);
		}
	}

	public static void main(String args[]) throws Exception {

		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);
		int n = sc.nextInt();
		int w = sc.nextInt();

		Knapsack a = new Knapsack(n, w);

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

			a.wt[i] = sc.nextInt();
			a.value[i] = sc.nextLong();
		}

		pr.println(a.maxprofit(0, w));
		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

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

Measured memory_bytes: 127864
S = list(input())
 
count = 0
s1 = S[:]
for i in range(1, len(S)):
    if s1[i - 1] == s1[i]:
        s1[i] = '0' if s1[i-1] == '1' else '1'
        count += 1
 
count2 = 0
s2 = S[:]
for i in reversed(range(len(S)-1)):
    if s2[i] == s2[i +1]:
        s2[i] = '0' if s2[i+1] == '1' else '1'
        count2 += 1
 
print(min(count, count2))

Measured memory_bytes: 5544
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

long int pow_long(int n, int i) {
    return (long int) round(pow(n, i));
}

bool check(long int N, int i) {
    if (N < 0) return false;
    if (i == 0) return ((N + 1) / 2 % 2 == 1);
    long int remainder = N % pow_long(2, i + 1);
    return !(remainder < pow_long(2, i) || remainder % 2 == 1);
}

int main() {
    long int A, B;
    scanf("%ld %ld", &A, &B);

    long int ans = 0;
    int i = 0;
    while (pow_long(2, i) <= A || pow_long(2, i) <= B) {
        bool a = check(A-1, i);
        bool b = check(B, i);
        if ((!a && b) || (a && !b)) ans += pow_long(2, i);
        i++;
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, ans = 10000,hu=0;
vector<int> da(8);

int abs(int a, int b) {
	if (a > b)
		return a - b;
	else
		return b - a;
}

void calc(vector<int> ch) {
	int A = 0, B = 0, C = 0, x = 0;
	bool ju = true;
	for (int i = 1;i < 4;i++) {
		int gg = 0;
		for (int j = 0;j < n;j++) {
			if (ch[j] == i)
				gg++;
		}
		if (gg == 0)
			ju = false;
		x += (gg - 1) * 10;
	}
	for (int i = 0;i < n;i++) {
		if (ch[i] == 1)
			A += da[i];
		else if (ch[i] == 2)
			B += da[i];
		else if (ch[i] == 3)
			C += da[i];
	}
	x += abs(A, a) + abs(B, b) + abs(C, c);
	if (ju) {
		/*for (int i = 0;i < n;i++) {
			cout << ch[i] << ' ';
		}*/
		ans = min(x, ans);
		//cout << x << endl;
		hu++;
	}
	return;
}

void dfs(int de, vector<int> ch) {
	if (de == n)
		calc(ch);
	else {
		for (int i = 0;i < 4;i++) {
			ch[de] = i;
			dfs(de + 1, ch);
		}
	}
}

int main() {
	cin >> n >> a >> b >> c;
	for (int i = 0;i < n;i++) {
		cin >> da[i];
	}
	vector<int> ch(8, 0);
	dfs(0, ch);
	cout << ans << endl;
	//cout << hu << endl;
}

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

typedef long long ll;
typedef long double ld;

const int N=1e5+10;

bool p[N];
int a[N];

int main(){
    //freopen("a.txt", "r", stdin);
    //freopen("answers.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    for(int i=2;i<N;i++){
        if(!p[i]){
            if(i!=2 && !p[(i+1)/2]) a[i]=1;
            for(int j=i+i;j<N;j+=i){
                p[j]=true;
            }
        }
    }
    for(int i=2;i<N;i++){
        a[i]+=a[i-1];
    }
    int q;
    cin>>q;
    while(q--){
        int l,r;
        cin>>l>>r;
        cout<<a[r]-a[l-1]<<endl;
    }

    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  cout << 1-N << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        char[] s = in.ns().toCharArray();
        char[] t = in.ns().toCharArray();
        long[][] dp = new long[s.length+1][t.length+1];
        for (int i = 1; i <= s.length; i++) {
            for (int j = 1; j <= t.length; j++) {
                if(s[i-1]==t[j-1]){
                    dp[i][j] = dp[i-1][j-1]+1;
                }else{
                    dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
                }
            }
        }
        StringBuilder sb = new StringBuilder();
        int i = s.length-1, j = t.length-1;
        while(i>=0&&j>=0){
            if(s[i]==t[j]){
                sb.append(s[i]);
                i--;
                j--;
            }else{
                if(dp[i+1][j] >= dp[i][j+1]) j--;
                else i--;
            }
        }
        out.println(sb.reverse());
    }
    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 128972
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int,readline().split()))
s = a[0]+a[1]
if n == 2:
  if a[0] < a[1] or s%2 == 1:
    print(-1)
  else:
    print(a[0]-s//2)
  exit()
  
c = 0
for i in a[2:]:
  c ^= i

sc = (s-c)//2
if s < c or (s-c)%2 == 1 or c&sc != 0:
  print(-1)
  exit()

bb = a[0].bit_length()
x = ''
chk = 0
for i in range(bb-1,-1,-1):
  if (c>>i&1)|(sc>>i&1) == 0:
    x += '0'
  elif c>>i&1 == 0 and sc>>i&1 == 1:
    x += '1'
    chk += 2**i
  else:
    x += 'p'
    
if chk > a[0]:
  print(-1)
  exit()
  
for i in range(bb):
  if x[i] == 'p':
    if a[0] >= chk+2**(bb-1-i):
      chk += 2**(bb-1-i)
      
if chk == 0:
  print(-1)
else:
  print(a[0]-chk)

Measured memory_bytes: 62256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        int ans = N;
        int che = 0;
        for (int i = 1; i < (N + 1); i++) {
            che = String.valueOf(i).length();
            if (che % 2 == 0) {
                ans--;
            }
        }
            System.out.print(ans);
    }
}


Measured memory_bytes: 30292
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  ll n;
  cin >> n;
  bool ans = false;
  REP(i,26){
    REP(j,16){
      if(i*4+j*7==n){
        ans = true;
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No"  << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//TrainTicket.cpp (C)
#include <iostream>
#include <string>
using namespace std;


int main(){
  string S,Ans;
  cin >> S;
  int A[4],sum;
  for(int i = 0; i < 4; i++) A[i] = S[i] - '0';
  for(int x = 0; x < 8; x++){
    sum = A[0];
    Ans = '0' + A[0];
    for(int i = 0; i < 3; i++){
      if(x&(1<<i)){
        sum += A[i+1];
        Ans += '+';
        Ans += '0' + A[i+1];
      }else{
        sum -= A[i+1];
        Ans += '-';
        Ans += '0' + A[i+1];
      }
    }
    if(sum == 7){
      cout << Ans << "=7" <<  endl;
      return 0;
    }

  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int rank[10000],parent[10000];

int find(int x){
	if (x == parent[x]){
	    return x;
	}
	else{
		return parent[x] = find(parent[x]);
	}
}

bool isSame(int x,int y){
	return find(x) == find(y);
}

void unite(int x,int y){
	x = find(x);
	y = find(y);
	if(x == y){
	    return;
	}
	if(rank[x] < rank[y]){
		parent[x] = y;
	}
	else{
		parent[y] = x;
		if(rank[x] == rank[y]){
		    rank[x]++;
		}
	}
}

int main(){
    int com, x, y, n, q;
    cin >> n >> q;
	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}
	for(int i = 0; i < q; i++){
		cin >> com >> x >> y;
		if(com == 1){
			if(isSame(x,y)){
			    cout << 1 << endl;
			}
			else{
				cout << 0 << endl;
			}
		}
		else{
			if(isSame(x,y)){
			    continue;
			}
			unite(x,y);
		}
	}

	return 0;
}





Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num;
    while(1)
    {
        for(int i=1;i<=5;i++)
        {
            cin>>num;
          if(num==0)
          {
            cout<<i<<endl;
            break;
          }
        }
      break;
    }
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main() {
	int k,a,b;
	cin >> k >> a >> b;
	int val = a%k;
	a = a-val+k;
	if(a<=b || val==0) {
		cout << "OK";
	} else {
		cout << "NG";
	}
}

Measured memory_bytes: 3636
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    res = num2alpha(n)

    return res

def num2alpha(num):
    if num<=26:
        return chr(96+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(122)
    else:
        return num2alpha(num//26)+chr(96+num%26)

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31212
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    ArrayList<Integer> d = new ArrayList<Integer>();
    for (int i=0; i<N; i++) {
      d.add(sc.nextInt());
    }
    int ans = new HashSet<>(d).size();
    System.out.println(ans);
  }
}

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

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {
    int N;
    cin >> N;
    string S, T;
    cin >> S >> T;
    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << endl;
    
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.Trans.State
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- sortOn fst <$> replicateM n readPair
  print $ solve m ps

solve :: Int -> [Pair] -> Int
solve m = fst . foldl' f e
  where
    e = (0,0)
    f (!s,!n) (a,b)
      | n == m    = (s,n)
      | c > m     = (s+a*(m-n),m)
      | otherwise = (s+a*b,c)
      where
        c = n+b

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = head . unfoldr readT <$> C8.getLine
  where
    readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)
    readInt = C8.readInt . C8.dropWhile isSpace

Measured memory_bytes: 39292
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int M = Math.max(A, Math.max(B, C));

		if((A+B+C)%2 == M%2) {
			System.out.println((3*M-(A+B+C))/2);
		}else {
			System.out.println(((3*M+3)-(A+B+C))/2);
		}

	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iterator>
typedef long long int ll;
typedef long double ld;
using namespace std;
typedef pair<int,int> pii;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 2e5+50;
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define f first
#define s second
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)
#define rep0(i,l,r) for(int i=l;i<r;++i
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}

void solve(){
    ll n,k,count=0;
    cin>>n>>k;
    for(int i=0;i<n;++i){
        ll x,y;
        cin>>x>>y;
        if(pow(x,2)+pow(y,2)<=pow(k,2)){
            count++;
        }
    
    }
    cout<<count<<endl;  
}
int main(){
 
   ios::sync_with_stdio(false);
  cin.tie(0);
     solve();
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(I,0,n){cout<<(I ? " ":"")<<A[I]x;}cout<<endl;
#define pprint(A,y,m,n) rep(J,0,m){print(A[J],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int N; long A,B,C,D; cin>>N>>A>>B>>C>>D;
    if(C == 0 && D == 0){
        cout<<(A == B ? "YES" : "NO")<<endl;
        return 0;
    }
    long k = abs(A - B);
    long x = (k + D*(N-1)) / (C+D);
    long y = (k + C*(N-1) + (C+D-1)) / (C+D);
    if(y <= x && y < N) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll n,h,a[1000005],b[1000005],sum,maxi,rez,reztot;
int main(){
    cin >> n >> h;
    for(ll i=1;i<=n;i++) cin >> a[i] >> b[i];
    for(ll i=1;i<=n;i++) if(maxi<a[i]) maxi=a[i];
    sort(b+1,b+n+1);
    for(ll i=n;i>=1;i--){
        if(b[i]<=maxi) break;
        if(b[i]>maxi){h-=b[i]; rez++;}
        if(h<=0){ cout<<rez; return 0;}
    }
    while(h>0){h-=maxi; rez++;}
    cout<<rez;
}

Measured memory_bytes: 5120
#include <iostream>
#include<map>
using namespace std;
 
int main(){
    map<string,int> m;
 
    int n;cin>>n;
 
    for(int i=0; i<n; i++){
        string x;cin>>x;
        m[x]+=1;
    }
 
    int maxv=0;
    for(auto &x: m){
        if(x.second>maxv)maxv=x.second;
    }
 
    for(auto &x: m){
        if(x.second==maxv)
        cout<<x.first<<'\n';
    }
 
}

Measured memory_bytes: 25216
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make([]int64, n)
	ss := make([][61]int64, n+1)
	mod := int64(1e9 + 7)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		for j := 0; j < 61; j++ {
			ss[i+1][j] = ss[i][j] + (aa[i] >> uint(j) & 1)
		}
	}

	var ans int64
	for i := 0; i < n-1; i++ {
		for j := 0; j < 61; j++ {
			if aa[i]>>uint(j)&1 == 0 {
				ans += ((1 << uint(j)) % mod) * ((ss[n][j] - ss[i+1][j]) % mod)
			} else {
				ans += ((1 << uint(j)) % mod) * ((int64(n-i-1) - (ss[n][j] - ss[i+1][j])) % mod)
			}
			ans %= mod
		}
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}


Measured memory_bytes: 161792
import itertools
K, S = map(int, input().split())

ans = 0
for x, y in itertools.product(range(K + 1), range(K + 1)):
    z = S - (x + y)
    if z >= 0 and z <= K:
        # print('{} + {} + {} = {}'.format(x, y, z, S))
        ans += 1

print(ans)


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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===




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

	Vi L(M), R(M);
	for (int i = 0; i < M; ++i) {
		cin >> L[i] >> R[i];
		--L[i]; --R[i];
	}

	Vi p(Q), q(Q);
	for (int i = 0; i < Q; ++i) {
		cin >> p[i] >> q[i];
		--p[i]; --q[i];
	}

	vector<Vi> ans(N + 1, Vi(N + 1));
	for (int i = 0; i < M; ++i) {
		++ans[0][R[i]];
		--ans[L[i] + 1][R[i]];
		--ans[0][N];
		++ans[L[i] + 1][N];
	}
	for (int i = 0; i < N + 1; ++i) {
		for (int j = 0; j < N; ++j) {
			ans[i][j + 1] += ans[i][j];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N + 1; ++j) {
			ans[i + 1][j] += ans[i][j];
		}
	}

	for (int i = 0; i < Q; ++i) {
		cout << ans[p[i]][q[i]] << endl;
	}

	return 0;
}

Measured memory_bytes: 4352
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 200001;


vl A,B,ind;

vl B2, CS;

ll extra(ll t){
    ll l = 0;
    ll r = sz(CS);
    if(t >= CS.back())return r-1;
    while(l < r-1){
        ll mid = (l+r)/2;
        if(t >= CS[mid]){
            l = mid;
        }
        else{
            r = mid;
        }
    }
    return l;
}

bool comp(ll i, ll j){
    ll a = A[i];
    ll b = B[i];
    ll c = A[j];
    ll d = B[j];

    ll P = (c+1) * (a+b+2) + d;
    ll Q = (a+1) * (c+d+2) + b;

    return P > Q;

    if(A[i] == A[j]){
        return B[i] > B[j];
    }
    return A[i] < A[j];
}

const int MAXL = 65;

ll DP[MAXN][MAXL] = {0};
bool DPC[MAXN][MAXL] = {0};

ll dp(ll i, ll L){
    if(i == sz(ind)){
        if(L == 0)return 0;
        return big;
    }
    if(DPC[i][L])return DP[i][L];
    if(L == 0)return 0;
    ll ans = dp(i+1,L);

    ll temp = dp(i+1,L-1) + 1;
    if(temp <= T){
        ll ans2 = temp + A[ind[i]] * temp + B[ind[i]];
        ans = min(ans, ans2);
    }
    DPC[i][L] = 1;
    DP[i][L] = ans;
    return ans;
}

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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,d,e;

    cin >> n;
    cin >> T;
   // n = 20000;
  //  T = 1000000000;
    rep(c1,0,n){
        cin >> a >> b;
       // a = rand()%2;
       // b = rand()%1000000000;
        if(a == 0){
            B2.push_back(b+1);
        }
        else{
            A.push_back(a);
            B.push_back(b);
            ind.push_back(sz(ind));
        }
    }

    sort(all(B2));
    CS.push_back(0);
    rep(c1,0,sz(B2)){
        CS.push_back(B2[c1] + CS[c1]);
    }
    sort(all(ind), comp);
    //reverse(all(ind));

    ll ans = 0;
    rep(c1,0,MAXL-1){
        //cerr << c1 << ": " << dp(0,c1)  << "\n";

        if(dp(0,c1) <= T){
            ans = max(ans, c1 + extra(T - dp(0,c1)));
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 128852
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    priority_queue<double> que;
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        que.emplace(static_cast<double>(a));
    }

    for (int i = 0; i < M; ++i) {
        double a = que.top();
        que.pop();

        a /= 2;

        que.emplace(a);
    }

    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        double a = que.top();
        que.pop();

        ans += static_cast<ll>(a);
    }

    cout << ans << endl;

    return 0;
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

int calc(int n) {
    int cnt = 0;
    while (n % 100 == 0) {
        n /= 100;
        cnt++;
    }

    return cnt;
}

void solve() {
    int d, n;
    cin >> d >> n;

    int val = 0, cnt = 0;
    while (cnt < n) {
        val++;
        if (calc(val) == d) cnt++;
    }

    cout << val << endl;
}

int main() {
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll x,r,d,last;
int32_t main(){
CODE_START;
cin>>r;
cin>>d;
cin>>x;
last=x;
for(ll i=0;i<10;i++){
    cout<<last*r-d<<endl;
    last=last*r-d;
}
}



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

int main(void)
{
  int n;
  char c[4];
  int sum[4]={0};
  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%s",c);
    if(c[0]=='A') sum[0]++;
    if(c[0]=='W') sum[1]++;
    if(c[0]=='T') sum[2]++;
    if(c[0]=='R') sum[3]++;
  }

  printf("AC x %d\n",sum[0]);
  printf("WA x %d\n",sum[1]);
  printf("TLE x %d\n",sum[2]);
  printf("RE x %d\n",sum[3]);

  return 0;
}

Measured memory_bytes: 1736