akhauriyash/Code-Regression huggingface dataset:
import scala.io.StdIn._
import scala.collection._

object Main {
  def main(args: Array[String]) {
    val cardNum = readInt()
    val sList, hList, cList, dList = mutable.ArrayBuffer.range(1, 13 + 1)
    val cardListMap = mutable.Map("S" -> sList, "H" -> hList, "C" -> cList, "D" -> dList)

    checkCards(readLine(), cardNum)
    missingCards

    def checkCards(input: String, limit: Int, i: Int = 0): Unit ={
      if(i < limit) {
        val Array(suit, num) = input.split(" ")
        suit match {
          case "S" => deleteFindCard("S", num)
          case "H" => deleteFindCard("H", num)
          case "C" => deleteFindCard("C", num)
          case "D" => deleteFindCard("D", num)
        }
        checkCards(readLine(), limit, i + 1)
      }
    }

    def deleteFindCard(suit: String, n: String): Unit ={
      cardListMap(suit)(n.toInt - 1) = 0
    }

    def missingCards: Unit = {
      val sMissingCards = findMissingCards("S")
      val hMissingCards = findMissingCards("H")
      val cMissingCards = findMissingCards("C")
      val dMissingCards = findMissingCards("D")

      missingCardsPrintln("S", sMissingCards)
      missingCardsPrintln("H", hMissingCards)
      missingCardsPrintln("C", cMissingCards)
      missingCardsPrintln("D", dMissingCards)
    }

    def findMissingCards(suit: String): Seq[Int] = {
      val notFindCards = cardListMap(suit).filter(i => i > 0)
      if(notFindCards.nonEmpty) notFindCards else Seq()
    }

    def missingCardsPrintln(m: String, s: Seq[Int]): Unit = {
      s.foreach(i => println(s"$m $i"))
    }
  }
}

Measured memory_bytes: 44264
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def check(A, operations):
    c = A[:]
    for o in operations:
        if o == 1:
            A = A[1:]
        elif o == len(A):
            A = A[:len(A) - 1]
        else:
            o -= 1
            A = A[:o - 1] + [A[o - 1] + A[o + 1]] + A[o + 2:]

    if len(A) != 1:
        print(c)
        print(operations)
    assert(len(A) == 1)
    return A[0]


def solve(N, A):
    ans1 = 0
    del1 = []
    ok1 = False
    start1, end1 = None, None
    for i in range(0, N, 2):
        if A[i] >= 0:
            ans1 += A[i]
            ok1 = True
            if start1 is None:
                start1 = i
            end1 = i
        else:
            if ok1:
                del1.append(i)

    ans2 = 0
    del2 = [1]
    ok2 = False
    start2 = None
    end2 = None
    for i in range(1, N, 2):
        if A[i] >= 0:
            ans2 += A[i]
            ok2 = True
            if start2 is None:
                start2 = i
            end2 = i
        else:
            if ok2:
                del2.append(i)

    ans, dele, start, end = None, None, None, None
    if ok1 and ok2:
        if ans1 > ans2:
            ans, dele, start, end = ans1, del1, start1, end1
        else:
            ans, dele, start, end = ans2, del2, start2, end2
    elif ok1:
        ans, dele, start, end = ans1, del1, start1, end1
    elif ok2:
        ans, dele, start, end = ans2, del2, start2, end2

    if not ok1 and not ok2:
        ans = max(A)
        idx = A.index(ans)
        a = []
        for i in range(N, idx + 1, -1):
            a.append(i)
        for i in range(1, idx + 1):
            a.append(1)
        return ans, a

    else:
        a = []
        num = 0
        for i in range(end + 1, N):
            a.append(N - num)
            num += 1

        for i in dele[::-1]:
            if start < i < end:
                a.append(i + 1)
                num += 2

        for i in range(start):
            a.append(1)
            num += 1

        for i in range((N - num) // 2) :
            a.append(2)

        return ans, a


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans, ope = solve(N, A[:])
    print(ans)
    print(len(ope))
    print(*ope, sep="\n")

    
if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
N,M = map(int, input().split())

X = set()
Y = set()
for i in range(M):
    a,b = map(int, input().split())
    if a == 1:
        X.add(b)
    if b == N:
        Y.add(a)

if (X & Y) == set():
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')
    

Measured memory_bytes: 19024
#include <stdlib.h>
#include <assert.h>
#include <iostream>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <complex>
#include <iomanip>
#include <bitset>
#include <random>
#include <vector>
#include<string>

using namespace std;

int main() {
	int a, p, max = 0, ans=0;
	for (int i = 0; i < 5; i++) {
		cin >> a;
		if (a % 10 == 0) {
			ans += a;
		}
		else {
			if (10-a % 10 > max)
				max = 10-a % 10;
			ans += a / 10 * 10 + 10;
		}
	}
	ans -= max;
	cout << ans << endl;
}


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

using namespace std;

int main() {
  constexpr int f[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (int i = 0; i < M; ++i) cin >> A[i];
  sort(A.begin(), A.end(), greater<int>());

  // ちょうどi本のマッチ棒で整数を作れないケースを INT_MIN とする.
  vector<int> dp(N + 1, numeric_limits<int>::min());
  dp[0] = 0;
  for (int i = 0; i <= N; ++i) {
    for (int j = 0; j < M; ++j) {
      const int k = i - f[A[j]];
      if (k < 0) continue;
      dp[i] = max(dp[i], dp[k] + 1);
    }
  }

  string ans = "";
  int rem = dp[N];
  int budget = N;
  while (budget > 0) {
    for (auto a : A) {
      if (budget - f[a] < 0) continue;
      if (dp[budget - f[a]] == rem - 1) {
        ans += to_string(a);
        budget -= f[a];
        rem--;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream> //cinなど
#include<string> //文字列
#include<algorithm> //sort など
#include<math.h> //paw(冪乗など)
#include<set> // 集合
#include<map> //写像
#include<stdio.h> //printf
#include<stack>

using namespace std;
int main(){
  string a,s,c;
  cin>>a>>s>>c;
  cout<<"A"<<s[0]<<"C"<<endl;

return 0;
}


Measured memory_bytes: 256
#abc126b

s=raw_input()
s1=s[:2]
s2=s[2:]
if 0<int(s1)<13 and 0<int(s2)<13:
 print 'AMBIGUOUS'
elif 0<int(s1)<13:
 print 'MMYY'
elif 0<int(s2)<13:
 print 'YYMM'
else:
 print 'NA'


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

using namespace std;


bool funcao(int a, int b){
    return (a < b);
}

int main(){

    vector<int> vet(3, 0);

    cin >> vet[0] >> vet[1] >> vet[2];

    sort(vet.begin(), vet.end(), funcao);

    cout << vet[0] + vet[1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100000
long long n,l;
long long fl=0;
long long a[MAXN+5];
long long read()
{
	long long x=0,f=1;
	char c=getchar();
	while('0'>c||c>'9'){if(c=='-') f=-1;c=getchar();}
	while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	n=read(),l=read();
	for(int i=1;i<=n;i++)
	a[i]=read();
	for(int i=1;i<n;i++)
	{
		if(a[i]+a[i+1]>=l)
		{
			fl=i;
			break;
		}
	}
	if(!fl)
	{
		printf("Impossible\n");
	}
	else 
	{
		printf("Possible\n");
		for(int i=1;i<=fl-1;i++)
			printf("%d\n",i);
		for(int i=n-1;i>=fl;i--)
			printf("%d\n",i);
	}
}
//

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
#define fi first
#define se second
int k;
char s[110];
int dp[110][4];
int dfs(int step, bool pre, bool limit, int kk) { 
  if(kk > k) return 0;
  if(!s[step]) return kk == k;
  if(!pre && !limit && ~dp[step][kk]) return dp[step][kk];
  int r = limit ? s[step]-'0' : 9;
  int temp = 0;
  for(int i = 0; i <= r; i++) {
    temp += dfs(step+1, pre && i ==0, limit && i == s[step]-'0', kk + (i==0?0:1));
  }
  if(!limit && !pre) dp[step][kk] = temp;
  return temp;
}
 
int main() { 
  scanf("%s %d", s, &k);
  memset(dp, -1, sizeof dp);
  cout << dfs(0, true, true, 0);
} 

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

using namespace std;

long d[222222][5];
int main() {
	int l;
	cin >> l;
	for (int i = 0; i < l; i++) {
		int a;
		scanf("%d", &a);
		d[i + 1][0] = d[i][0] + a;
		d[i + 1][1] = min(d[i][0], d[i][1]) + a % 2 + !a * 2;
		d[i + 1][2] = min({ d[i][0],d[i][1],d[i][2] }) + 1 - a % 2;
		d[i + 1][3] = min({ d[i][0],d[i][1],d[i][2],d[i][3] }) + a % 2 + !a * 2;
		d[i + 1][4] = min({ d[i][0],d[i][1],d[i][2],d[i][3],d[i][4] }) + a;
	}
	cout << min({ d[l][0],d[l][1],d[l][2],d[l][3],d[l][4] }) << endl;
	return 0;
}


Measured memory_bytes: 8448
N, K = [int(s) for s in input().split()]
P = [int(s) for s in input().split()]

# Piの期待値 (1 + Pi) // 2
E = list(map(lambda x: (x + 1) / 2, P))
E_SUMS = [E[0]]
for i in range(1, N):
    E_SUMS.append(E_SUMS[i - 1] + E[i])

m = E_SUMS[K - 1]
for i in range(K, N):
    m = max(m, E_SUMS[i] - E_SUMS[i - K])

print(m)

Measured memory_bytes: 33784
import java.util.*; import java.math.*; import java.awt.Point;
import static java.util.Arrays.*; import static java.util.Collections.*;
import static java.lang.Math.*; import static java.lang.System.*;
class Main extends Lib {
  long[] fromLeft(int n, long[] a) {
    long[] r = new long[n+1];
    PriorityQueue<Long> q = new PriorityQueue<>();
    long s = 0;
    for (int i=0; i<n; i++) {
      q.add(a[i]);
      s += a[i];
    }
    r[0] = s;
    for (int i=n; i<2*n; i++) {
      q.add(a[i]);
      s += a[i];
      s -= q.poll();
      r[i-n+1] = s;
    }
    return r;
  }
  long[] fromRight(int n, long[] a) {
    long[] r = new long[n+1];
    PriorityQueue<Long> q = new PriorityQueue<>(Collections.reverseOrder());
    long s = 0;
    for (int i=0; i<n; i++) {
      q.add(a[3*n - i - 1]);
      s += a[3*n - i - 1];
    }
    r[n] = s;
    for (int i=0; i<n ; i++) {
      int j = 2 * n - 1 - i;
      q.add(a[j]);
      s += a[j];
      s -= q.poll();
      r[n-i-1] = s;
    }
    return r;
  }
  long solve(int n, long[] a) {
    //    println(Arrays.toString(fromLeft(n, a)));
    //    println(Arrays.toString(fromRight(n, a)));
    long[] p = fromLeft(n, a);
    long[] q = fromRight(n, a);
    long max = p[0] - q[0];
    for (int i=1; i<=n; i++)
      max = max(max, p[i] - q[i]);
    return max;
  }
  void solve() {
    int n = _Int();
    long[] a = new long[3*n];
    for (int i : until(3*n)) {
      a[i] = sc.nextLong();
    }
    println(solve(n, a));
  }
  public static void main(String[] args) { new Main().solve(); }
}
class Lib {
  void println(Object o) { out.println(o); }
  void ln() { out.println(); }
  void print(Object o) { out.print(o); }
  void printf(String f, Object...o) { out.printf(f, o); }
  Scanner sc = new Scanner(in);
  int _Int() { return sc.nextInt(); }
  long _Long() { return sc.nextLong(); }
  String _Next() { return sc.next(); }
  char _Char() { return sc.next().charAt(0); }
  String _Line() { return sc.nextLine(); }
  boolean _HasInt() { return sc.hasNextInt(); }
  boolean _HasNext() { return sc.hasNext(); }
  boolean _HasLine() { return sc.hasNextLine(); }
  int[] until(int n) { int[] t = new int[n]; for (int i=0; i<n; i++) t[i] = i; return t; }
  int[] until(int fr, int to) { int[] t = new int[to-fr]; for (int i=fr; i<to; i++) t[i-fr] = i; return t; }
  int[] to(int fr, int to) { return until(fr, to+1); } int[] to(int n) { return until(0, n); }
}


Measured memory_bytes: 99328
{-# 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

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

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

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ m, d ] <- readInts
	print $ length $ do
		x <- [ 1 .. m ]
		y <- [ 1 .. d ]
		guard $ 10 <= y
		let
			[ dd1, dd2 ] = map digitToInt $ show y
		guard $ 2 <= dd1 && 2 <= dd2 && dd1 * dd2 == x
		return ()

Measured memory_bytes: 892
#include <stdio.h>
#include <math.h>

int main(void) {

  int d,t;
  double x=0.0,y=0.0;
  int ang=90.0;

  while(1) {

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

    if(d==0 && t==0) break;
    
    x+=(double)d*cos((double)ang*M_PI/180.0);
    y+=(double)d*sin((double)ang*M_PI/180.0);

    ang-=(double)t;
  }

  printf("%d\n%d\n",(int)x,(int)y);

  return 0;
}

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

int main()
{
  int N ;
  cin>>N ;
  vector<int64_t>a(N),sum(N) ;
  for(int i=0;i<N;i++){
    cin>>a.at(i) ;
    if(i==0) sum.at(i)=a.at(i) ;
    else sum.at(i)=sum.at(i-1)+a.at(i) ;
  }
  
  int64_t ans_right=0,ans_R ;
  int64_t ans_left=0,ans_L ;
  for(int i=0;i<N;i++){
    int64_t right_value=sum.at(i)+ans_right ;
    int64_t left_value=sum.at(i)+ans_left ;
    if(i%2==0){
      if(right_value==0){
        ans_right++ ;
        ans_R++ ;
      }else if(right_value<0){
        ans_right+=1-right_value ;
        ans_R+=1-right_value ;
      }
      
      if(left_value>0){
        ans_left-=left_value+1 ;
        ans_L+=left_value+1 ;
      }else if(left_value==0){
        ans_left-- ;
        ans_L++ ;
      }
    }else{
      if(right_value>0){
        ans_right-=1+right_value ;
        ans_R+=1+right_value ; 
      }else if(right_value==0){
        ans_right-- ;
        ans_R++ ;
      }
      
      if(left_value<0){
        ans_left+=1-left_value ;
        ans_L+=1-left_value ;
      }else if(left_value==0){
        ans_left++ ;
        ans_L++ ;
      }
    }
  }
  
  cout<<(ans_R<ans_L?ans_R:ans_L)<<endl ;
  
  return 0 ;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair 
# define all(x) x.begin(),x.end()                                                      
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main(){
	ll n;
	cin>>n;
	int h[n+1];
	for(ll i=1;i<=n;i++){
		cin>>h[i];
	}
	ll x[n+1];
	ll y[n+1];
	for(ll i=1;i<n+1;i++){
		x[i]=i+h[i];
	}
	map<ll,ll> m;
	for(ll j=1;j<n+1;j++){
		y[j]=j-h[j];
		m[y[j]]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		m[y[i]]--;
		if(m[y[i]]==0)m.erase(y[i]);
		ans+=m[x[i]];
	}
	cout<<ans<<'\n';
}

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> array(n);    
    
    for(int i=0; i<n;i++){
        cin >> array[n-i-1];
    }

    cout << array[0];
    
    for(int i = 1;i<n;i++){
        cout  << " "<< array[i] ;
    }
    
    cout << "\n";

    return 0;   
}


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

using namespace std;

int main (void) {
    int N, K;
    string S;
    cin >> N >> K >> S;

    assert((int)S.size() == N);

    int n_group = 1;
    for ( int i = 1; i < N; i++ ) {
        if ( S.at(i) != S.at(i-1) )
            n_group++;
    }

    int ans = (N - 1) - (n_group - 1);
    while ( n_group > 0 && K > 0 ) {
        n_group--;
        K--;
        ans += 2;
    }

    cout << min(ans, N-1) << endl;
    return 0;
}


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

struct UF{
  vector<int> par; //親
  vector<int> depth; //木の深さ

  vector<int> size;
  int ans;

  void init(int n){
    depth.resize(n,0);
    size.resize(n,1);
    par.resize(n);
    for(int i = 0; i < n; i++){
      par[i] = i;
    }
  }

  //木の根を求める
  int root(int x){
    if(par[x] == x){
      return x;
    }
    else {
      return par[x] = root(par[x]);
    }
  }

  //xとyの属する集合を併合
  void unite(int x,int y){
    x = root(x);
    y = root(y);
    if(x == y) return;

    ans -= (size[x])*(size[y]);

    if(depth[x] < depth[y]) swap(x,y);
    par[y] = x;
    size[x] += size[y];
    if(depth[x] == depth[y]) depth[x]++;
  }
}uf;

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

  int n,m; cin >> n >> m;
  vector< pair<int,int> > v(m);
  for(int i = 0; i < m; i++){
    cin >> v[i].first >> v[i].second;
  }
  uf.init(n+1);

  vector<int> ans(m);
  uf.ans = n*(n-1)/2;
  for(int i = m-1; i >= 0; i--){
    ans[i] = uf.ans;
    uf.unite(v[i].first,v[i].second);
  }

  for(int i : ans){
    cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 6016
# -*- coding: utf-8 -*-
n, m = map(int, input().split())

sc_list = []

for i in range(m):
    sc_list.append(list(map(int, input().split())))

ans_list = [-1] * n

for item in sc_list:
    s = item[0]
    c = item[1]
    if ans_list[s-1] != -1 and ans_list[s-1] != c:
        print(-1)
        exit()
    else:
        ans_list[s-1] = c

if n > 1 and ans_list[0] == 0:
    print(-1)
    exit()

for i in range(len(ans_list)):
    if ans_list[i] == -1:
        if i == 0 and len(ans_list) > 1:
            ans_list[i] = 1
        else:
            ans_list[i] = 0

print("".join(list(map(str, ans_list))))


Measured memory_bytes: 38676
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
int a[200010]={},ans[200010]={};
int main(){
    int n;
    ll sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n+1;i++)sum+=abs(a[i]-a[i-1]);
    for(int i=1;i<=n+1;i++){
        ans[i]=sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]);

    }
    for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
    //cout<<sum;

}


Measured memory_bytes: 4420
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <utility>
#define ll long long int
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

using namespace std;

int main(){
	int a,b,N;
	cin >> N >> a >> b;
	cout << min(a*N,b) << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,n,u,k,v,a[100][100];
  scanf("%d",&n);
  for(i=0;i<100;i++)
    for(j=0;j<100;j++)
      a[i][j]=0;
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      a[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",a[i][j]);
      if(j==n-1)
	printf("\n");
      else
	printf(" ");
    }
  }
  return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
    int N, K;
    cin >> N >> K;
    long int a[N], dp[K + 1][N];//intでは若干ケタが足らずWAが出る
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for(int j = 0; j < N; j++) {
        dp[0][j] = 1;
    }
    for(int i = 1; i <= K; i++) {
        if(i <= a[0]) {
            dp[i][0] = 1;
        } else {
            dp[i][0] = 0;
        }
        for(int j = 1; j < N; j++) {
            if(a[j] == 0) {
                dp[i][j] = dp[i][j - 1];
            } else {
                if(i <= a[j]) {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007);
                } else {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007);
                }
            }
        }
    }
    cout << dp[K][N - 1] << endl;
    return 0;
}
 

Measured memory_bytes: 78336
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b,c,d,e,f;
  std::cin >> a >> b >> c >>d;
  if(a<b) e=a;
  else e=b;
  if(c<d) f=c;
  else f=d;
  std::cout << e+f << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<functional>
#include<stack>
#include<queue>
#include<cmath>
# define MOD 1000000000+7
# define INF 1e9
# define LINF 1e18
typedef long long ll;

using namespace std;
int gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
 

bool broken[100000] = {false};
int dp[100010] = {};

int a[100010] = {}, b[100010] = {};

int main() {
/*
	int n = 0, m = 0;
	cin >> n >> m;

	for (int i = 0; i < m; i++) {
		int temp;
		cin >> temp;
		broken[temp] = true;
	}

	dp[0] = 1;

	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= min(i + 2, n); j++) {

			if (broken[j] == false) {
				dp[j] += dp[i];
				dp[j] %= MOD;
			}

		}
	}

	cout << dp[n] << endl;

	return 0;
	*/

	int n = 0;
	ll ans = 0,memo = 0;
	cin >> n;
	for (int i = 0; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

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

		ans += min(a[i], b[i]);
		if (a[i] < b[i]) {
			memo = a[i + 1];
			a[i + 1] = max(0, a[i+1] - (b[i] - a[i]));
			ans += (memo - a[i + 1]);
		}


	}

	cout << ans << endl;

}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  
  vector<int> v(n);
  for(int i; i < n; i++)
    cin >> v.at(i);
  
   vector<int> w(n);
  for(int i; i < n; i++)
    cin >> w.at(i);
  
   vector<int> x(n-1);
  for(int i; i < n-1; i++)
    cin >> x.at(i);
  
  int s = 0;
  
  for(int i; i < n; i++){
    s += w.at(v.at(i) - 1);
    if(i > 0){
      if((v.at(i) - v.at(i-1)) == 1)
        s += x.at(v.at(i)-2);
    }
  }
  cout << s << endl;
}
      

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<int>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
#define MOD 1000000007
using namespace std;
typedef long long ll;



int main(void) {

	ll n; cin >> n;
	vint a(n);
	map<ll, ll> w;
	map<ll, ll> s;
	rep(i, n) {
		int x;
		cin >> x;
		w[x + i]++;
		s[x - i]++;
	}
	ll ans=0;
	for (auto itr:s) {
		if (w[-1*itr.first] != 0) {
			ans += itr.second*w[-1*itr.first];
		}
	}

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


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e3 + 5);
const int MAX_H = (int)(1e4 + 5);

int h, n;

int a[MAX_N], b[MAX_N];

ll dp[MAX_N][MAX_H];

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &n);

  for (int i = 0; i < n; ++i) {
    scanf("%d %d", &(a[i]), &(b[i]));
  }

  for (int j = 0; j <= h; ++j) {
    for (int i = 0; i <= n; ++i) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0LL;

  for (int j = 0; j <= h; ++j) {
    for (int i = 0; i < n; ++i) {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);

      int target_index = j + a[i];
      target_index = target_index >= h ? h : target_index;

      dp[i + 1][target_index] =
          min(dp[i + 1][target_index], dp[i + 1][j] + b[i]);
    }
  }

  // for (int j = 0; j <= h; ++j) {
  //   printf("%15lld ", j);
  // }
  // printf("\n");

  // for (int i = 0; i <= n; ++i) {
  //   for (int j = 0; j <= h; ++j) {
  //     printf("%15lld ", dp[i][j]);
  //   }
  //   printf("\n");
  // }

  ll ans = dp[n][h];

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

  return 0;
}


Measured memory_bytes: 78464
from operator import mul
from functools import reduce

def combination(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N, K = tuple(map(int, input().split()))
mod = 10**9+7
for i in range(K):
    if i <= N-K:
        print( ( combination(K-1,i)*combination(N-K+1,i+1) ) % mod )
    else:
        print(0)

Measured memory_bytes: 3944
N, D= map(int,input().split())
arr = [list(map(int,input().split())) for _ in range(N)]
count=0
for i in range(N):
    for j in range(i+1,N):
        tmp = 0
        for k in range(D):
            if i != j:
                tmp += (arr[i][k]-arr[j][k])**2
        tmp = tmp**0.5
        if tmp.is_integer():
            count = count+1
print(count)

Measured memory_bytes: 3060
//
// Created by Myabu on 2020/01/23.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    string A,B;

    cin>>A>>B;

    char temp = A[0];
    A[0] = A[2];
    A[2] = temp;

    if(A==B){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{int a,b,c,d = 0,n;
    scanf("%d %d %d",&a,&b,&c);
    for(n = a;n <= b;n++)
    {if(c % n == 0)
    {d++;
    }
    }
    printf("%d\n",d);
}


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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

LL A[4];

int main()
{
    rep(i , 1 , 3) read(A[i]);
    rep(i , 1 , 3) if(A[i] % 2 == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    LL Ans = A[1] * A[2];
    rep(i , 1 , 3)
        rep(j , i + 1 , 3)
        {
            chkmin(Ans , A[i] * A[j]);
        }
    cout << Ans << endl;
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >>D;
  
  int nameL ,nameR;
  nameL = A + B;
  nameR = C + D;
  
  if(nameL > nameR){
    cout << "Left" <<endl;
  }
  
  if(nameL == nameR){
    cout << "Balanced" <<endl;
  }
  
  if(nameL < nameR){
    cout << "Right" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K;
    cin >> N;
    cin >> K;

    vector<int> h(N,0);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    int ans = 0;

    for (int i=0; i<N; i++){
        if(h[i] >= K){
            ans += 1;
        }
    }

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

    return 0;
}

Measured memory_bytes: 640
// B - Snake Toy
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int solve(int N, int K, vi &L){
	sort(allr(L));
	int sumL = 0;
	rp(i, 0, K) sumL += L[i];
	return sumL;
}

int main(){
	int N,K; cin>>N>>K;
	vi L(N); rp(i, 0, N) cin>>L[i];
	cout<< solve(N, K, L) <<endl;
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i = (a); i >= (b); i--)
#define FORR(i,a,b) for (int i = (a); i > (b); i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

    int n;
    cin >> n;

    if(n==5 || n==3 || n==7)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}

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

int main(){
  //map < char , int > count;
  int count [500] = {};
  string str;
  while( cin >> str ){
      for(int i = 0;i < str.size();i++){
        if(isupper(str[i])) str[i] = tolower(str[i]);
      }
      for(int i = 0;i < str.size();i++){
        count [ str[i] ]++;
      }
  }
  for(char ch = 'a';ch <= 'z';ch++){
    cout << ch << " : " << count[ch] << endl;
  }
  return 0;
}



Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
typedef long long ll;
int main()
{
  int n;cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll res = 0;
  map<int,ll> mp;
  rep(i,n) {
    int x = i - a[i];
    int y = a[i] + i;
    res += mp[x];
    mp[y]++;
  }

  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 26688
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string S;
	cin>>S;
	for(int i=S.length();i>0;i--)
		for(int j=0;j<S.length()-i+1;j++)
		{
			bool ok=true;
			for(int k=j;k<j+i;k++)
				if(S[k]!='A'&&S[k]!='C'&&S[k]!='G'&&S[k]!='T')
					ok=false;
			if(ok)
			{
				cout<<i<<endl;
				return 0;
			}
		}
	puts("0");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
a = 0
b = 0
A = [0] * (N - 1)
A[N - 2] = 1
for i in range(N):
    for j in range(i,N):
        if P[j] > P[i]:
            P[j] -= 1
    for j in range(i,N):
        if Q[j] > Q[i]:
            Q[j] -= 1
for i in range(1,N -1):
    A[N - 2 - i] = (i + 1)* A[N - 2 - i + 1]
for i in range(N -1):
    a += P[i]*A[i]
    b += Q[i]*A[i]
print(abs(a-b))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdlib>
#include <utility>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>

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

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    int h, w;
    cin >> h >> w;
    cout << (H - h) * (W - w) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;

int a[10000];
int main(){
  int n,i;
  long long z,r;
  for(;scanf("%d",&n),n;printf("%lld\n",r)){
    for(i=0;i<n;i++)scanf("%d",a+i);
    sort(a,a+n);
    for(z=r=i=0;i<n-1;i++)z+=a[i],r+=z;
  }
}

Measured memory_bytes: 1080
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#include <bitset>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> x(n),y(n),h(n);
    int i,j;
    int maxh=-INF;
    int imaxh=0;
    for(i=0; i<n; i++) {
        scanf("%d%d%d", &x[i], &y[i], &h[i]);
        if(h[i]>maxh) {
            maxh=h[i];
            imaxh=i;
        }
    }

    for(i=0; i<=100; i++) {
        for(j=0; j<=100; j++) {
            int H=abs(x[imaxh]-i)+abs(y[imaxh]-j)+h[imaxh];

            int k;
            for(k=0; k<n; k++) {
                int H0=MAX(H-abs(x[k]-i)-abs(y[k]-j),0);
                if(H0!=h[k]) {
                    break;
                }
            }
            if(k==n) {
                printf("%d %d %d\n", i, j, H); return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int h1 = Integer.parseInt(sc.next());
		int m1 = Integer.parseInt(sc.next());
		int h2 = Integer.parseInt(sc.next());
		int m2 = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		System.out.println((h2 - h1) * 60 + m2 - m1 - k);
	}
}


Measured memory_bytes: 35756
N_list = []

for i in range(1,10):
    for j in range(1,10):
        N_list.append(i*j)
A_B = list(map(int, input().split()))
if A_B[0] < 10 and A_B[1] < 10:
    s = A_B[0]*A_B[1]
    if s in N_list:
        print(s)
    else :
        print("-1")
else :
    print("-1")


Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
import java.util.stream.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		ArrayList<Integer> list = new ArrayList<Integer>();
		int num = 0;
		int sumsa = 0;
		int maxsa = 0;
		for(int i = 0;i < 5;i++){
			num = saori.saori_hayami();
			list.add(num);
			if(num % 10 != 0){
				sumsa += 10 - (num % 10);
				maxsa = Math.max(maxsa, 10 - (num % 10));
			}
		}
		System.out.println(list.stream().mapToInt(Integer::intValue).sum() + sumsa - maxsa);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 25940
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n, d =map(int,input().split())
    ans = 0
    for i in range(n):
        x, y = map(int,input().split())
        if x**2 + y**2 <= d**2:
            ans += 1
    print(ans)

if __name__=='__main__':
    main()

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

int main(){
#define int int64_t
  int N,x;
  cin >> N;
  cin >> x;

  vector<int> a;
  for(int i = 0;i < N;i++){
    int aa;
    cin >> aa;
    a.push_back(aa);
  }

  int ans = 0;
  for(int i = 1;i < N - 1;i++){
    int sum1 = a[i - 1] + a[i];
    int sum2 = a[i] + a[i + 1];
    bool _1 = sum1 > x;
    bool _2 = sum2 > x;
    if(_1 && _2){
      int b = sum1 - x;
      if(a[i] >= b) a[i] -= b;
      else a[i] = 0;
      ans += b;
    }else if(_1){
      int b = sum1 - x;
      if(a[i] >= b) a[i] -= b;
      else a[i] = 0;
      ans += b;
    }
  }
  if(a[N - 2] + a[N - 1] > x){
    ans += a[N - 2] + a[N - 1] - x;
  }

  std::cout << ans << std::endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll putere(ll val,ll k){
    if(k == 0)return 1;
    else{
        ll a = 1;
        for (int i = 0; i!=k;i++){
            a*=val;
        }
        return a;
    }
}

ll cifre(ll aux){
    ll cifre= 0;
    while(aux!=0){
        cifre++;
        aux/=10;
    }
    return cifre;
}

void backtrack(ll nr,ll *sum,int aux_val){
    if(nr == 0) return;
    ll cifr = cifre(nr);
    for(int i = 1; i<cifr; i++){
        ll val = putere(10,i);
        (*sum) =(*sum)+nr/val+aux_val+nr%val;
        backtrack(nr/val,sum,aux_val+nr%val);
    }
}

int main()
{
    ll nr;
    cin>>nr;
    ll sum = 0;
    backtrack(nr,&sum,0);
    cout<<sum+nr<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,s[100],d=-1000,f=1000000,g,h,j,i,z=2100000000,flg;
	scanf("%d",&a);
	for(i=0;i<a;i++){
		scanf("%d",&s[i]);
		if(d<s[i])
			d=s[i];
		if(f>s[i])
			f=s[i];
	}
	for(i=f;i<=d;i++){
		h=i;
		g=0;
		flg=0;
		/*if(h<0){
			 h*=-1;
			 flg=1;
		}*/
		for(j=0;j<a;j++){
			g=(h-s[j])*(h-s[j])+g;
		}
		if(z>g)
			z=g;
	}
	printf("%d\n",z);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  ll a[N];
  for(int i=0;i<N;i++) cin >> a[i];

  ll dp[N][N+1];
  for(int len = 1; len <= N; len++){
    for(int l = 0; l <= N - len; l++){
      int r = l + len;
      if(l + 1 == r){
        if((N - len) % 2 == 0) dp[l][r] = a[l];
        else dp[l][r] = -a[l];
      }
      else{
        if((N - len) % 2 == 0){
          dp[l][r] = max(dp[l+1][r] + a[l], dp[l][r-1] + a[r-1]);
        }
        else dp[l][r] = min(dp[l+1][r] - a[l], dp[l][r-1] - a[r-1]);
      }
    }
  }

  cout << dp[0][N] << endl;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<int,int> > ab(N);
    for(int i=0;i<N;i++){
        cin >> ab.at(i).second >> ab.at(i).first;
    }
    int now = 0;
    sort(ab.begin(),ab.end());
    for(int i=0;i<N;i++){
        now+=ab.at(i).second;
        if(now > ab.at(i).first){
            cout << "No" << endl;
            break;
        }
        if(i==N-1){
            cout << "Yes" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int t[2000],n,m,a,ans,pos;
void init(){
  for(int i=0;i<2000;i++)t[i]=0;
}
int main(){
  while(cin>>n>>m&&n&&m){
    init();
    for(int i=0;i<n;i++)cin>>t[i];
    ans=-1,pos=0;
    for(int i=0;i<m;i++){
      cin>>a;
      if(ans==-1){
	pos+=a;
	if(pos>=n-1&&ans==-1)ans=i+1;
	pos+=t[pos];
	if(pos>=n-1&&ans==-1)ans=i+1;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1168
import sys
readline = sys.stdin.readline
read = sys.stdin.read

S = input()
Q = int(input())

u = ''
t = ''

r = False
for _ in range(Q):
    q = readline().split()
    if q[0] == '1':
        u, t = t, u
        r = not r
    else:
        if q[1] == '1':
            t += q[2]
        else:
            u += q[2]
            
if r:
    print(t[::-1]+S[::-1]+u)
else:
    print(t[::-1]+S+u)

Measured memory_bytes: 4468
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            long i = sc.nextLong();
            long count = 0;
            boolean left = false;
            while (i-- > 0) {
                long x = sc.nextLong();
                if (left == true && x!=0) {
                    x++;
                }
                count+=x/2;
                if (x % 2 == 1) {
                    left = true;
                } else {
                    left=false;
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 22772
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd              double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define vdd             vector<double>
#define vpii            vector<pair<int,int>>
#define vpll            vector<pair<long long,long long>>
#define vvi             vector<vector<int>>
#define vvl             vector<vector<long long>>
#define mii             map<int,int>
#define mll             map<long long,long long>
#define umii            unordered_map<int,int>
#define umll            unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep2(i,a,b)     for(int i=a;i<b;i++)
#define rev(i,n)        for(int i=n;i>=0;i--)
#define rev2(i,a,b)     for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define fio             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl            '\n'
#define all(x)          x.begin(),x.end()
#define d0(x)           cout <<x<<" "
#define d1(x)           cout <<x<<endl
#define d2(x,y)         cout <<x<<" "<<y<<endl
#define d3(x,y,z)       cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)     cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define read2(x,y)      cin>>x>>y
#define read3(x,y,z)    cin>>x>>y>>z
#define read4(x,y,z,w)  cin>>x>>y>>z>>w
#define read5(x,y,z,w,a)cin>>x>>y>>z>>w>>a
#define sz(a)           (int)a.size()
const ll mod=1e9+7;
const double PI = 3.14159265359;
const ll MOD=998244353;
void i_o()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
}

int help(vi& A,int k){
   int n=sz(A);
   vi dp(n);
   dp[0]=0;
   rep2(i,1,n){
      int x=INT_MAX;
      for(int j=max(0,i-k);j<=i-1;j++) x=min(x,dp[j]+abs(A[i]-A[j]));
      dp[i]=x;
   }
   return dp[n-1];
}
int main() {
   fio
  // i_o();
   int n,k;
   cin>>n>>k;
   vi h(n);
   rep(i,n) cin>>h[i];
   d1(help(h,k));
   return 0;
}



Measured memory_bytes: 1024
from collections import defaultdict

N, K = map(int, input().split())
A = list(map(int, input().split()))

d = defaultdict(int)
for key in A:
    d[key] += 1
ans = 0
for key, i in sorted(d.items(), key = lambda x:x[1])[:-K]:
    ans += i
print(ans)

Measured memory_bytes: 39312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 1000000000;

int main() {
  ll n = pow(10, 9) + 7;
  int N; cin >> N;
  ll p = 1;
  rep2(i, 1, N+1) {
    p *= i;
    p %= n;
  }
  cout << p << endl;
}

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

using namespace std;

int main()
{
    bool arr[102];
    fill(arr, arr+102, false);
    int x, n;
    cin >> x >> n;
    int tmp;
    for(int i=0; i<n; i++){
        cin >> tmp;
        arr[tmp] = true;
    }
    int i = x;
    int j = x;
    while(arr[i]){
        i--;
    }
    while(arr[j]){
        j++;
    }
    if(i == j){
        cout << i << '\n';
    }
    else{
        if(x - i == j - x){
            cout << i << '\n';
        }
        else if( x - i < j - x){
            cout << i << '\n';
        }
        else{
            cout << j << '\n';
        }
    }
    
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
#define PB push_back
#define MP make_pair
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<long long>;
using ld = long double;

#define unordered_map __fast_unordered_map
template<class Key, class Value, class Hash = std::hash<Key>>
using unordered_map = __gnu_pbds::gp_hash_table<Key, Value, Hash>;

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 TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);

  string s;
  cin >> s;
  const int n = SZ(s);

  string last;
  int ans = 0;
  int i = 0;

  while (i < n) {
    string nxt(1, s[i]);
    if (nxt == last) {
      if (i == n - 1) { break; }
      ++i;
      nxt += s[i];
    }
    last = nxt;
    ++ans;
    ++i;
  }

  cout << ans << "\n";

}



Measured memory_bytes: 1228