akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

multiset<lint> decomp(lint N){
    multiset<lint> res;
    lint num=N;
    for(lint i=2;i*i<=num;i++){
        while(N%i==0) N/=i,res.insert(i);
        if(N==1) break;
    }
    if(N!=1) res.insert(N);
    return res; 
}

int main(void){
    int N;
    cin >> N;
    lint ans=0;
    for(int i=1;i<=N;i++){
        lint num=N-1;
        lint add=num/i;
        ans+=add;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;


void solve()
{
	int n;
	cin>>n;
	ll sum=0;
	rep(i,n){
		int k=i+1;
		if(k%3==0 or k%5==0){

		}else{
			sum+=k;
		}
	}
	cout<<sum<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

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

       double a =scan.nextDouble();
       double b =scan.nextDouble();
       double c1 =scan.nextDouble();
       double C = c1*Math.PI/180;

       double s = 0.5*a*b*Math.sin(C);
       double c = Math.sqrt(a*a+b*b-2*a*b*Math.cos(C));
       double l = a+b+c;
       double h = b*Math.sin(C);

       System.out.println(s+" "+l+" "+h);

       }
   }


Measured memory_bytes: 27884
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n;
  int cnt = 0;
  cin>>n;
  RE (i, n) {
    int k;
    cin>>k;
    if (k % 2) {
      cnt++;
    }
  }
  if (cnt % 2 == 0) {
    cout<<"YES\n";
  } else {
    cout<<"NO\n";
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 256
func gcd(_ a: Int, _ b: Int) -> Int {
  if b == 0 {
    return a
  }
  return gcd(b, a % b)
}

let input = readLine()!.split(separator: " ").map { Int($0)! }
let a = input[0] - 1
let b = input[1]
let c = input[2]
let d = input[3]

let lcm = c * d / gcd(c, d)

let canDivides = b / c - a / c + b / d - a / d - (b / (lcm) - a / (lcm))
print(b - a - canDivides)

Measured memory_bytes: 8312
import java.util.Scanner;

class Main {

	public static int[] b;
	public static int[] f;
	public static int[] s;
	public static boolean ok;

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		while(n--!=0){
			b = new int[10];
			
			for(int i=0;i<10;i++){
				b[i]=scan.nextInt();
				}
			
			f = new int[10];
			s = new int[2];
			ok = false;
			
			dfs(0);
			
			System.out.println(ok?"YES":"NO");
		}
	}
	
	public static boolean check(){
		s[0] = s[1] = 0;
		
		for(int i=0;i<10;i++){
			if(s[f[i]]>=b[i])return false;
			s[f[i]] = b[i];
		}
		return true;
	}

	public static void dfs(int k){
		if(k==10){
			ok |= check();
		}else{
			f[k] = 0;
			dfs(k+1);
			f[k] = 1;
			dfs(k+1);
		}
	}
}

Measured memory_bytes: 27544
N, M, X = map(int, input().split())
C = [0] * N
A = [[] for _ in range(N)]
for i in range(N):
    c_a = list(map(int, input().split()))
    C[i] = c_a[0]
    A[i] = list(c_a[1:])

INF = 9999999999
ans = INF
for i in range(2 ** N):
    price = []
    rikaido = [0] * M
    for j in range(N):
        if (i >> j) & 1:
            price.append(C[j])
            for k in range(M):
                rikaido[k] += A[j][k]
    for l in range(M):
        if rikaido[l] < X:
            break
    else:
        ans = min(ans, sum(price))

if ans == INF:
    ans = -1
print(ans)

Measured memory_bytes: 9244
import bisect
N = int(input())
s = []
for i in range(N):
    s_i = ''.join(sorted(input()))
    s.append(s_i)

s.sort()
ans = 0
for i in range(N):
    ans += bisect.bisect_right(s, s[i])-i-1
    # for j in range(i+1, N):
    #     if s[i] == s[j]:
    #         ans += 1
    #     elif s[i] < s[j]:
    #         break
print(ans)

Measured memory_bytes: 58456
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
struct data{int to,next,wi;}e[maxn*2];
int head[maxn];
int cnt=0;
int du[maxn];
queue<int> q;
bool vis[maxn];
void ins(int u,int v,int ww)
{
	e[++cnt].to=v;
	e[cnt].next=head[u];
	e[cnt].wi=ww;
	head[u]=cnt;
}
int n,m;
int dis[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		ins(x,y,z);
		du[y]++;
	}
	for(int i=1;i<=n;i++)dis[i]=1e9+10;
	for(int s=1;s<=n;s++)
	{
		if(du[s]==0)
		{
			dis[s]=0;
			vis[s]=1;
			q.push(s);
			while(!q.empty())
			{
				int x=q.front();
				q.pop();
				for(int i=head[x];i;i=e[i].next)
				{
					int u=e[i].to;
					if(vis[u]==1&&dis[u]!=dis[x]+e[i].wi)
					{
						puts("No");
						return 0;
					}
					if(vis[u]==0)
					{
						vis[u]=1;
						dis[u]=min(dis[u],dis[x]+e[i].wi);
						q.push(u);
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++)if(vis[i]==0){puts("No");return 0;}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;

namespace CompetitiveProgramming
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split('/');
            int y = int.Parse(s[0]);
            int m = int.Parse(s[1]);
            int d = int.Parse(s[2]);

            if(y<=2019)
            {
                if(y<2019 || (y==2019&&m<=4))
                {
                    Console.WriteLine("Heisei");
                }else{
                    Console.WriteLine("TBD");
                }
            }else{
                Console.WriteLine("TBD");
            }
        }

    }
}


Measured memory_bytes: 11092
import scala.io.StdIn

object Main extends App {

  private val N = 1000
  
  def lcs(x: String, y: String): Int = {
    val a = Array.fill(N+1, N+1)(0)
    val m = x.length
    val n = y.length
    var maxl = 0
    var tempX = " " + x
    var tempY = " " + y

    (1 to m).foreach{ i =>
      (1 to n).foreach{ j =>
        if(tempX(i) == tempY(j)){
          a(i)(j) = a(i-1)(j-1) + 1
        } else {
          a(i)(j) = scala.math.max(a(i-1)(j), a(i)(j-1))
        }
        maxl = scala.math.max(maxl, a(i)(j))
      }
    }
    maxl
  }

  val cnt = StdIn.readLine().toInt
  val result = (0 until cnt).map{ _ =>
    lcs(StdIn.readLine(), StdIn.readLine())
  }

  result.foreach(println)
}


Measured memory_bytes: 437740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    int x, y, z;
    
    cin >> x >> y >> z;
    
    swap(x, y);
    swap(x, z);
    
    cout << x << " "<< y << " "<< z << endl;
    
    
    
}


Measured memory_bytes: 256
def main():
  s = list(map(lambda x:ord(x)-97, list(input())))
  ls = len(s)
  ss = set(s)
  t = list(map(lambda x:ord(x)-97, list(input())))
  lt = len(t)
  st = set(t)
  td = [list() for _ in range(26)]
  if not st.issubset(ss):
    print(-1)
    exit()
  for i in range(lt-1):
    td[t[i]].append(t[i+1])
  md = [None for _ in range(ls)]
  cd = [0]*26
  for i in range(ls-1,-1,-1):
    cd[s[i]] = i + ls
  for i in range(ls-1,-1,-1):
    md[i] = cd.copy()
    cd[s[i]] = i
  ans = 0
  cur = cd[t[0]]
  for i in range(lt-1):
    cur = md[cur][t[i+1]]
    ans += (cur//ls)
    cur %= ls
  print(1 + ans*ls+cur)

if __name__ == "__main__":
  main() 

Measured memory_bytes: 37604
import math
n = int(input())

a = list(map(int, input().split()))
b = list(map(int, input().split()))

d1 = d2 = d3 = d4 = 0
l = []
for a, b in zip(a, b):
    d1 += math.pow(abs(a - b), 1)
    d2 += math.pow(abs(a - b), 2)
    d3 += math.pow(abs(a - b), 3)
    l.append(abs(a-b))

d1 = math.pow(d1, 1)
d2 = math.pow(d2, 1/2)
d3 = math.pow(d3, 1/3)
d4 = max(l)
print(d1)
print(d2)
print(d3)
print(d4)



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

typedef long long ll;

const int N = 2001;
int n, x, y;
int dist[N];

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

    cin >> n >> x >> y;

    for (int i = 1; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            int d = min(j - i, abs(x - i) + 1 + abs(j - y));
            dist[d] ++;
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << dist[i] << endl;
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
      	
		int A = sc.nextInt();
      	int B = sc.nextInt();
      	if(B%A ==0){
        	System.out.println(A+B);
        }else{
        	System.out.println(B-A);
        }
		
    }
}

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

int main(){

  int n,d,i,j,k;
  int z[13][13];
  int disi;
  double disd;
  int cnt = 0;
  double check;
  double sum = 0;

  scanf("%d %d", &n, &d);

  for(i = 1;i <= n;i++){
    for(j = 1;j <= d;j++){
      scanf("%d", &z[i][j]);
    }
  }

  for(i = 1;i <= n - 1;i++){
    for(j = i + 1;j <= n;j++){
      sum = 0;
      for(k = 1;k <= d;k++){
        sum += pow(z[j][k] - z[i][k],2);
      }
      disd = (double)sqrt(sum);
      disi = (int)sqrt(sum);
      check = (double)(disd - disi);

      if(check == 0.0) cnt++;
    }
  }

  printf("%d\n", cnt);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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


		int count = 1;
		for (int i = 1; i < s.length(); i++) {
			if (s.charAt(i - 1) != s.charAt(i)) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 27696
class Point:
    def __init__(self, x , y):
        self.x = x
        self.y = y
    def __sub__(self, p):
        x_sub = self.x - p.x
        y_sub = self.y - p.y
        return Point(x_sub, y_sub)

class Vector:
    def __init__(self, p):
        self.x = p.x
        self.y = p.y
    def norm(self):
        return (self.x ** 2 + self.y ** 2) ** 0.5

def cross(v1, v2):
    return v1.x * v2.y - v1.y * v2.x

def dot(v1, v2):
    return v1.x * v2.x + v1.y * v2.y

def ccw(p0, p1, p2):
    a = Vector(p1 - p0)
    b = Vector(p2 - p0)
    cross_ab = cross(a, b)
    if cross_ab > 0:
        return 1
    elif cross_ab < 0:
        return -1
    elif dot(a, b) < 0:
        return 1
    elif a.norm() < b.norm():
        return -1
    else:
        return 0

def intersect(p1, p2, p3, p4):
    if (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0) and \
       (ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0):
        print('1')
    else:
        print('0')

import sys

file_input = sys.stdin

sq = file_input.readline()

for line in file_input:
    x_p0, y_p0, x_p1, y_p1, x_p2, y_p2, x_p3, y_p3 = map(int, line.split())
    p0 = Point(x_p0, y_p0)
    p1 = Point(x_p1, y_p1)
    p2 = Point(x_p2, y_p2)
    p3 = Point(x_p3, y_p3)
    intersect(p0, p1, p2, p3)

Measured memory_bytes: 7996
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

template <typename T> void max_self(T& a, T b) {
    a = max(a, b);
}

// dp[n][m]

bool first_row_or_column(pair<int,int> p) {
    return p.first == 0 || p.second == 0;
}

const int INF = 1e9 + 5;

int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<pair<int,pair<int,int>>>> dp(a.length() + 1,
        vector<pair<int,pair<int,int>>>(b.length() + 1, {-INF,{0,0}}));
    dp[0][0] = {0, {0,0}};
    // dp[i][j] - the max total length so far
    for(int i = 0; i < (int) a.length(); ++i) {
        for(int j = 0; j < (int) b.length(); ++j) {
            if(a[i] == b[j]) {
                max_self(dp[i+1][j+1], make_pair(dp[i][j].first + 1, make_pair(i,j)));
            }
            max_self(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i,j)));
            max_self(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }
    pair<int,pair<int,int>> answer = {0,{0,0}};
    for(int i = 0; i <= (int) a.length(); ++i) {
        for(int j = 0; j <= (int) b.length(); ++j) {
            max_self(answer, make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }
    string s;
    pair<int,int> cur = answer.second;
    while(!first_row_or_column(cur)) {
        int i = cur.first;
        int j = cur.second;
        pair<int,int> previous = dp[i][j].second; // a cell from which we came to (i,j)
        debug() << imie(cur) imie(previous);
        if(previous == make_pair(i - 1, j - 1)) {
            assert(a[i-1] == b[j-1]);
            s += a[i-1];
        }
        cur = previous;
    }
    //~ debug() << answer;
    reverse(s.begin(), s.end());
    cout << s << endl;
}


Measured memory_bytes: 105984
#include <stdio.h>

int main() {

   int a, b;

   scanf ("%d %d", &a, &b);

   if (a < b) {
      printf ("a < b\n");
   } else if (a > b) {
      printf ("a > b\n");
   } else {
      printf ("a == b\n");
   }

   return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1, 1, -1, -1, 2, 2, -2, -2}; //knight moves
///int ky[]={2,-2,  2, -2, 1,-1,  1, -1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};//eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};//eight direction
 
///using namespace __gnu_pbds;
using namespace std;
 
///inline double toRad(double deg){return deg*PI/180;}
///inline double toDeg(double rad){return rad*180/PI;}
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=223456;
int main()
{
    #ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    #endif
    int n,k;
    while(sf("%d",&n)==1)
    {
        set<int>st;
        map<int,int>mp;
        for(int i=0;i<n;i++)
        {
            int x;
            sf("%d",&x);
            st.insert(x);
            mp[x]++;
        }

        int ans=0;
        for(int x:st)
        {
            if(mp[x]>=x)ans+=(mp[x]-x);
            else ans+=mp[x];
        }
        pf("%d\n",ans);
    }
    return 0;
}
 









 




























Measured memory_bytes: 9216
n, a = gets.split.map(&:to_i)
x = gets.split.map(&:to_i)
max = [x.max, a].max

dp = Array.new(n + 1) { Array.new(n + 1) { Array.new(max * n + 1) } }

0.upto(n) do |i|
  0.upto(n) do |j|
    0.upto(max * n) do |k|
      dp[i][j][k] =
        if i == 0 && j == 0 && k == 0
          1
        elsif i >= 1 && j >= 1 && k >= x[i - 1]
          dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]]
        elsif i >= 1 && k < x[i - 1]
          dp[i - 1][j][k]
        else
          0
        end
    end
  end
end

ans = 0
1.upto(n) do |j|
  ans += dp[n][j][a * j]
end

puts ans

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

int main(){
  ll N; cin >> N;
  vector<ll> a(N);
  ll sum = 0;
  for(ll i = 0; i < N; i++){
    cin >> a[i];
    sum += a[i];
  }
  
  
  ll su = a[0];
  ll ans = abs(sum - 2 * su);
  for(ll i = 1; i < N-1; i++){
    su+=a[i];
    ans = min(ans, abs(sum - 2 * su));
  }
  cout << ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define maxn (int)1e5+1000
#define up(i,x,y) for(int i=x;i<=y;i++)
#define down(i,x,y) for(int i=x;i>=y;i--)
#define bug cout<<""-----------""<<endl
#define pb push_back
#define SZ(x) ((int)x.size())
#define All(x)  (x.begin()), (x.end())

typedef long long ll;

ll a[maxn];
int main()
{
    ll n,va,vb;  cin>> n >> va >> vb;

    up(i,1,n)scanf("%lld",&a[i]);
    ll res = 0;
    up(i,1,n-1)
    res += min( (a[i+1] - a[i]) * va, vb);
    cout << res <<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j) vector<vector<ll>> name(i,vector<ll>(j))
#define vec2f(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k)))
#define vec3f(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define vec4(name,i,j,k,l) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l))))
#define vec4f(name,i,j,k,l,m) vector<vector<vector<vector<ll>>>> name(i,vector<vector<vector<ll>>>(j,vector<vector<ll>>(k,vector<ll>(l,m))))
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> p(n);
    REP(i,n) cin >> p[i];
    sort(p.begin(),p.end());
    ll ans = 0;
    REP(i,k) ans+=p[i];
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
map<int,int> mp;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
		mp[x]=i+1; 
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++)
		cout<<mp[a[i]]<<" ";
	return 0;
}

Measured memory_bytes: 5880
#include <bits/stdc++.h>
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define FASTIO ios_base::sync_with_stdio(NULL); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define MOD 1000000007

using namespace std;

void init(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin) ;
  freopen("output.txt", "w", stdout) ;
  #endif
}

// code from below

ll dp[3001][3001];
void solve(){
	ll n;
    cin>>n;
    vector<ll> arr(n);
    FOR(i,n)
        cin>>arr[i];
    // dp[i][j] stores the x-y value if both players play optimally, considering subarr from i to j of arr
    // thus we have n^2 sub array thus dp is of n^2 size
    for(int L=n-1;L>=0;L--){
        for(int R=L;R<n;R++){
            if(L==R)
                dp[L][R]=arr[R];
            else{
                dp[L][R]=max(arr[L]-dp[L+1][R],arr[R]-dp[L][R-1]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}

int main(){
    int t=1;
    //cin>>t;
    // cin.ignore(numeric_limits<streamsize>::max(),'\n'); 
    while(t--)
        solve();
}

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

using namespace std;

int main(){
  string s, t; cin >> s >> t;
  vector<vector<int> > dp(s.size() + 1, vector<int>(t.size() + 1, 0));
  for(int i = s.size() - 1; i >= 0; i--){
    for(int j = t.size() - 1; j >= 0; j--){
      if(s[i] == t[j]){
        dp[i][j] = 1 + dp[i + 1][j + 1];
      }
      else{
        dp[i][j] = max(dp[i + 1][j], dp[i][j + 1]);
      }
    }
  }
  string ans;
  int i = 0, j = 0;
  while(i < s.size() && j < t.size()){
    if(s[i] == t[j]){
      ans += s[i];
      ++i;
      ++j;
    }
    else{
      if(dp[i + 1][j] >= dp[i][j + 1]) ++i;
      else ++j;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35584
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int Max(int a,int b){return a>b?a:b;}
struct edge{
    int next,to,fr;
}e[4005];
int n,k,cnt,h[2005],now,ans;
void ins(int x,int y){e[++cnt].next=h[x];h[x]=cnt;e[cnt].to=y;e[cnt].fr=x;}
void dfs(int x,int fa,int dep){
    now++;
    if(!dep) return;
    for(int i=h[x];i;i=e[i].next) if(e[i].to!=fa) dfs(e[i].to,x,dep-1);
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1,a,b;i<n;i++)scanf("%d%d",&a,&b),ins(a,b),ins(b,a);
    if(k&1) for(int i=1;i<=cnt;i+=2) now=0,dfs(e[i].fr,e[i].to,k/2),dfs(e[i].to,e[i].fr,k/2),ans=Max(ans,now);
    else for(int i=1;i<=n;i++) now=0,dfs(i,-1,k/2),ans=Max(ans,now);
    printf("%d",n-ans);
}

Measured memory_bytes: 384
i = 1
flag = True
n = int(input())
l = []

while flag:
    x = i
    if x % 3 == 0:
        l.append(i)

    else:
        flag2 = True
        while flag2:
            if x % 10 == 3:
                l.append(i)
                break

            else:
                x //= 10
                if x < 1:
                    flag2 = False

    i += 1
    if i > n:
        flag = False

m = map(str, l)
print(" ", end = "")
print(" ".join(m))



Measured memory_bytes: 6104
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >


using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=1e2+10,mod=1e9+7;


int main ()
{
    FASTIO
    ll a , b , c , d;
    cin >> a >> b >> c >> d;
    ll ans=0;
    ans += min(a,d);
    d -= min(d,a);
    d -= min(b,d);
    ans -= min(d,c);
    cout << ans << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 3624
def solve(a, b, c, ans):
    if (a, b, c) in s:
        return -1
    if (a % 2) or (b % 2) or (c % 2):
        return ans
    s.add((a, b, c))
    a >>= 1
    b >>= 1
    c >>= 1
    return solve(b + c , c + a, a + b, ans + 1)

if __name__ == '__main__':
    a, b, c = map(int, input().split())
    s = set()
    print(solve(a, b, c, 0))



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

#define int long long

using namespace std;

int a[100010];

int32_t main()
{
    int n,x;
    cin >> n >> x;

    a[n] = x;

    for(int i=0;i<n;i++)
        cin >> a[i];

    sort(a,a+n+1);

    int ans = 0;

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

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int MAX = 2e5+4;
const ll INF = 1e18;
int dp[3001][3001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s,t;
	cin >> s >> t;
	for(int i=1;i<=s.size();i++)
	{
		for(int j=1;j<=t.size();j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(s[i-1]==t[j-1])
			{
				dp[i][j]=max(dp[i-1][j-1]+1,dp[i][j]);
			}
		}
	}
	int n=s.size(),m=t.size();
	string res;
	while(n>0 && m>0)
	{
		if(dp[n][m]==dp[n-1][m])
		n--;
		else if(dp[n][m]==dp[n][m-1])
		m--;
		else
		{
			res+=s[n-1];
			n--;
			m--;
		}
	}
	reverse(res.begin(),res.end());
	cout << res;
	return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<stdio.h>
#include<math.h>

int main()
{
	int l[10], v[2];
	while( scanf( "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v[0], &v[1] ) != EOF ){
		int sum = 0;
		for( int i = 0; i < 10; i++ ) sum += l[i];
		
		int p = ceil( (double)sum * v[0] / ( v[0] + v[1] ) );
		
		int i = 0, j = 0;
		while( j < p ){
		 	j += l[i++];
		}
		
		std::cout << i << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1212
#include<stdio.h>
#include<string.h>

int main(){
  char s[1000];
  scanf("%s",&s);
  
  int n;
  n=strlen(s);
  
  for(int i=0;i<n;i++){
    if(s[i]!=s[n-1-i]){
      printf("No");
      return 0;
    }
  }
  
  for(int i=0;i<(n-1)/2;i++){
    if(s[i]!=s[(n-1)/2-1-i]){
      printf("No");
      return 0;
      
    }
  }
  
  printf("Yes");
  return 0;
}

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

long first(long n) 
{ 
    while (n >= 10)  
        n /= 10; 
    return n; 
} 
  
long last(long n) 
{ 
    return (n % 10); 
} 

int main(){

long n;
cin>>n;
vector<vector <long> > vec(10, vector<long> (10, 0));
for(long i=1; i<=n; i++){
  vec[first(i)][last(i)]++;
}

long long ans=0;
for(long i=1; i<=9; i++){
  for(long j=i; j<=9; j++){
    if(i==j){
    ans+=((vec[i][j])*(vec[i][j]));
    //cout<<vec[i][j]<<" ";
    }else{
    ans+=(2*((vec[i][j])*(vec[j][i])));
    }
  }
  //cout<<endl;
}
cout<<ans;

}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N), B(N);
	REP(i, N) cin >> A[i];
	REP(i, N) cin >> B[i];

	vector<ll> husoku, amari;
	REP(i, N){
		if(A[i]>B[i]) amari.push_back(A[i]-B[i]);
		if(A[i]<B[i]) husoku.push_back(B[i]-A[i]);
	}
	ll res = 0;
	ll husokusum = 0;
	REP(i, husoku.size()) husokusum += husoku[i];
	res += husoku.size();
	sort(amari.rbegin(), amari.rend());
	REP(i, amari.size()){
		if(husokusum<=0) break;
		husokusum -= amari[i];
		res++;
	}
	if(husokusum>0){
		cout << -1 << endl;
	}else{
		cout << res << endl;
	}
    return 0;
}

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

const int N = 1e5 + 100 , mod = 1e9 + 7;

int n , k , a[N] , dp[3][N] , cs[3][N];

int yes(int a , int b){
	return (a+mod - b)%mod;
}

int main(){
	scanf("%d%d" , &n , &k);
	for(int i=0 ; i<n ; i++) scanf("%d" , a+i);
	dp[n&1][k] = 1;
	for(int i = n-1 ; i >= 0 ; i--){
		for(int c = k ; c >= 0 ; c--)
			dp[i&1][c] = yes(dp[(i+1)&1][min(k , c+a[i])] , (!c ? 0:dp[(i+1)&1][c-1]));
		for(int c = 1 ; c<=k ; c++) 
			dp[i&1][c] = (dp[i&1][c-1] + dp[i&1][c])%mod;
		
	}
	printf("%d" , dp[0][0]);
}



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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

const int MOD = (int)1e9 + 7, MAXN = (int)1e5 + 10;
int n;
VI A;

int mul(int a, int b) {
	return (1ll * a * b) % MOD;
}

int sub(int a, int b) {
	a -= b;
	return a < 0 ? a + MOD : a;
}


int fact[MAXN], finv[MAXN], inv[MAXN];
void precalc()
{
	fact[0] = fact[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(LL i = 2; i < MAXN; ++i) {
		inv[i] = sub(MOD, mul(inv[MOD % i], MOD / i));
		fact[i] = mul(fact[i - 1], i % MOD);
		finv[i] = mul(finv[i - 1], inv[i]);
	}
}

int comb(int n, int r)
{
	if(n < r) return 0;
	return mul(fact[n], mul(finv[r], finv[n - r]));
}

void solve()
{
	precalc();

	int dist;
	VI pos(MAXN + 1, -1);
	for(int i = 0; i < n + 1; ++i) {
		if(pos[A[i]] != -1) {
			dist = i - pos[A[i]];
			break;
		}
		pos[A[i]] = i;
	}
	
	for(int len = 1; len <= n + 1; ++len) {
		int whole = comb(n + 1, len), remain = comb(n - dist, len - 1);
		cout << sub(whole, remain) << '\n';
	}
	cout << flush;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> n;

	A = VI(n + 1, 0);
	REP(i, 0, n + 1) cin >> A[i];

	solve(); 

	return 0;
}

Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		String p = kb.next();
		String q = kb.next();
		int i = kb.nextInt();
		int j = kb.nextInt();
		String r = kb.next();
		if (r.equals(p)) {
			i -= 1;
		} else if (r.equals(q)) {
			j -= 1;
		}
		System.out.println(i + " " + j);
		kb.close();
	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
  IO;

  string origin;
  string news;

  cin>>origin>>news;

  if(origin==news.substr(0,origin.length()))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;


  return 0;


}


Measured memory_bytes: 3612
s = gets.chomp
t = gets.chomp

def kaiten(str)
  tmp = str[-1]
  str.insert(0, tmp)
  str[-1] = ""
end

flag = false
s.length.times do |i|
  if s==t
    flag = true
    break
  end
  kaiten(s)
end

if flag
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define Nmax 200005
#define OFF 100001
using namespace std;

int a,b;

int main()
{
    cin >> a >> b;
    if (a > 0) cout << "Positive\n";
    else if (b < 0) cout << (( b - a + 1) % 2 ? "Negative\n" : "Positive\n");
    else cout << "Zero\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int a, b;
	cin >> a >> b;
	double ans = 0;
	rep(i, a) {
		int tmp = i + 1;
		double cnt = (double)1 / a;
		while (tmp < b) {
			tmp *= 2;
			cnt /= 2;
		}
		ans += cnt;
	}
	printf("%.15f\n", ans);
	return 0;
}

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

using namespace std;

int main()
{
    int n;
    long long la, lb;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        long long a, b;
        scanf("%lld%lld", &a, &b);
        if (!i) { la = a; lb = b; }
        else {
            long long dva = (la+a-1)/a;
            long long dvb = (lb+b-1)/b;
            if (dva > dvb) {
                la = dva * a;
                lb = dva * b;
            }
            if (dva < dvb) {
                la = dvb * a;
                lb = dvb * b;
            }
            if (dva == dvb) {
                la = dva * a;
                lb = dvb * b;
            }
        }
        /* printf("%lld %lld\n", la, lb); */
    }
    /* printf("%lld %lld\n", la, lb); */
    printf("%lld\n", la+lb);
    return 0;
}


Measured memory_bytes: 384
from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def nextLine(): return next(stdin)
def nextStrList(): return nextLine().split()
def nextIntList(): return [int(_) for _ in nextStrList()]


def main():
	n,k=nextIntList()
	x=n%k
	x1=abs(x-k)
	print(min(x,x1))

if __name__=="__main__":
	main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define M_PI 3.14159265358979323846
#define MOD 998244353
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
    
/*
    Author: Koushik Sahu
    Created: 19 Sep 2020 17:57:27
*/

int n, k;
array<ipair, 10> lr;
array<ll, 200001> dp, prefix_sum; 

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>n>>k;
    for(int i=0; i<k; i++){
        cin>>lr[i].first>>lr[i].second;
    }
    dp.fill(0);
    prefix_sum[0] = 0;
    dp.at(1) = prefix_sum.at(1) =  1;
    for(int i=2; i<=n; i++){
        dp.at(i) = 0;
        for(int j=0; j<k; j++){
            ipair p = lr[j];
            ipair tmp(i-p.second, i-p.first);
            tmp.first = max(tmp.first, 1);
            tmp.second = min(tmp.second, i-1);
            if(tmp.first>=1 && tmp.second>=1 && tmp.second>=tmp.first){
                dp[i] += (((prefix_sum[tmp.second] - prefix_sum[tmp.first-1])%MOD)+MOD)%MOD;
                dp[i] %= MOD;
            }
        }
        prefix_sum[i] = (dp[i] + prefix_sum[i-1])%MOD;
    }
    cout<<dp[n]<<"\n";
    return 0;
}

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

int main(){
    int a,b;
    cin>> a >> b;
    int ans=0;
    for(int i=0;i<2;i++){
        if(a>=b){
            ans+=a;
            a--;
        }
        else {
            ans+=b;
            b--;
        }
    }
    cout << ans <<endl;
}

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

int main() {

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

  if(N == K) {
    for(int i = 0;i < N;i++) {
      cout << S << " ";
    }
    cout << endl;
  }else if(S == 1 || S == 1000000000) {
    for(int i = 0;i < N;i++) {
      if(i < K) cout << S << " ";
      else cout << 3 << " ";
    }
    cout << endl; 
  }else {
    for(int i = 0;i < N;i++) {
      if(i < K+1) {
        if(i%2 == 0) cout << S-1 << " ";
        else cout << 1 << " ";
      }else {
        cout << S+1 << " "; 
      }
    }
    cout << endl;
  }

  
}



Measured memory_bytes: 1280
N = [int(n) for n in list(input())]
d = int(input())
p = 10**9+7
DP = [[0]*d, [0]*d]
DP[1][0] = 1
for n in N:
    DP_ = [[0]*d, [0]*d]
    for i in range(2):
        for j in range(d):
            for k in range(n+i):
                DP_[i][j] += DP[1][(j-k) % d] % p
            for k in range(n+i, 10):
                DP_[i][j] += DP[0][(j-k) % d] % p
            DP_[i][j] %= p
    DP = DP_
print((DP[1][0] + p - 1) % p)


Measured memory_bytes: 45532
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

import GHC.Exts

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, m ] <- readInts
	as :: [Integer] <- map fromIntegral . sort <$> readInts
	cs <- map fromIntegral . take n . concat . reverse . map ( \( b, c ) -> replicate b c ) . sortWith snd . map mp <$> replicateM m readInts
	print $ sum $ take n $ reverse $ sort $ as ++ cs

Measured memory_bytes: 70012
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
     
#define pb emplace_back
#define fi first
#define se second
     
using namespace std;
     
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ ll x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
int l[210];

int ans;

int main(){

  n = in();
  REP( i , 2*n ){
    l[i] = in();
  }

  sort( l , l+2*n );
  REP( i , n ){
    ans += l[i*2];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof a)
#define  For(i,a,b) for(int i=a,i##end=b;i<=i##end;++i)
#define rFor(i,a,b) for(int i=a,i##end=b;i>=i##end;--i)
using namespace std;
typedef long long LL;
const int N=200010;
template<typename T>inline T chkmax(T _A,T _B){return _A>_B?_A:_B;}
template<typename T>inline T chkmin(T _A,T _B){return _A<_B?_A:_B;}
template<typename T>void read(T&x)
{
    x=0;int _f(0);char ch=getchar();
    while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
    while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
    x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
}
int n;
LL a[N],sum,ret,ans;
int main()
{
	read(n);
	For(i,1,n)
	{
		read(a[i]);
		sum+=a[i];
	}
	ans=1e16;
	For(i,1,n-1)
	{
		ret+=a[i];
		ans=chkmin(ans,abs(ret-(sum-ret)));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, x[51] = {}, y[51] = {}, cost0 = 0;

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			ll counter = 0;
			for (int k = 1; k <= N; k++) {
				for (int l = k + 1; l <= N; l++) {
					if ((k == i && l == j) || (k == j && l == i))continue;
					if ((x[j] - x[i] == x[l] - x[k] && y[j] - y[i] == y[l] - y[k]) || (x[j] - x[i] == x[k] - x[l] && y[j] - y[i] == y[k] - y[l]))counter++;
				}
			}
			cost0 = max(cost0, counter + 1);
		}
	}
	cout << N - cost0 << endl;
	return 0;
}

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

using namespace std;

int main(){
	vector<int> A;
	string input;

	while (cin >> input){
		if (input[0] == '+'){
			int m = A[A.size() - 1];
			A.pop_back();
			int n = A[A.size() - 1];
			A.pop_back();
			A.push_back(m + n);
		}
		else if (input[0] == '-'){
			int m = A[A.size() - 1];
			A.pop_back();
			int n = A[A.size() - 1];
			A.pop_back();
			A.push_back(n - m);
		}
		else if (input[0] == '*'){
			int m = A[A.size() - 1];
			A.pop_back();
			int n = A[A.size() - 1];
			A.pop_back();
			A.push_back(m * n);
		}
		else{
			A.push_back(stoi(input));
		}
	}

	cout << A[0] << endl;

	return 0;
}

Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,K;

int main(){
  cin >>  A >> B >> C >> K;
  if(K>=A+B){
    cout << A-(K-A-B) << endl;
  }
  else if(K>=A){
    cout << A <<  endl;
  }
  else{
    cout << K << endl;
  }
}

Measured memory_bytes: 3628