akhauriyash/Code-Regression huggingface dataset:
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define printx(x) printf("%lld\n",x);
#define printxy(x,y) cout << x << y <<endl;
#define printxyz(x,y,z) cout << x << y << z <<endl;
#define deba(a) cout << #a << a << endl;
#define debab(a,b) cout << #a << a << #b << b << endl;
int main()
{
	fast;
	ll n;
	cin >> n;
	cout << (n * (n + 1)) / 2;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>

using namespace std;

int main(){
  string S;
  cin >> S;

  char c;
  int flg = 0;
  for (int i = 0; i < 26; i++){
    c = 'a' + i;
    if (S.find(c) == string::npos) break; 
    if (i==25) flg=1;
  }

  if (flg == 1){
    printf("None\n");
  }else{
    printf("%c\n", c);
  }
  
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-12;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
#define db(x) cerr << #x << " = " << (x) << " ";
#define endln cerr << "\n";

void solve() {
    int n; cin >> n;
    map<int, int> hs;
    FOR(i, 0, n) {
        int x; cin >> x;
        hs[x]++;
    }
    int m; cin >> m;
    FOR(i, 0, m) {
        int x; cin >> x;
        if (!hs[x]) {
            cout << "NO\n";
            return;
        }
        hs[x]--;
    }
    cout << "YES\n";
}

int main() {
    int JUDGE_ONLINE = 1;
    if (fopen("in.txt", "r")) {
        JUDGE_ONLINE = 0;
        assert(freopen("in.txt", "r", stdin));
        //assert(freopen("out.txt", "w", stdout));
    }
    else {
        ios_base::sync_with_stdio(0), cin.tie(0);
    }
    solve();
    if (!JUDGE_ONLINE) {
        //cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    }
    return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int main(void){
  char S[11], T[12];
  scanf("%s", &S);
  scanf("%s", &T);
  
  for(int i=0; S[i] !='\0'; i++){
  	if(S[i]!=T[i]){
      printf("No\n");
      return 0;
    }

      
  }
      
      printf("Yes\n");
    
    
  return 0;
}



Measured memory_bytes: 1644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll i,j,k,n,m=1,t,y,mx,x,g;
    scanf("%lld",&n);
    ll a[n+3],b[n+3],c[n+3];
    for(i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    } b[1]=a[1],c[n]=a[n];
    for(i=2;i<=n;i++) b[i]=__gcd(b[i-1],a[i]);
    for(i=n-1;i>=0;i--) c[i]=__gcd(c[i+1],a[i]);
    mx=max(c[2],b[n-1]);
    for(i=2;i<n;i++){
        mx=max(mx,__gcd(b[i-1],c[i+1]));
    } cout<<mx;
}


Measured memory_bytes: 6008
def make753(n):
    ns = str(n)
    l = len(ns)* -1
    flg = True
    while flg:
        for i in range(-1, l-1, -1):
            if ns[i] == '3' or ns[i] == '5':
                ii = (i+1)*-1
                n += 10**ii*2
                flg = False
                break
            if ns[i] == '7':
                ii = (i+1)*-1
                n -= 10**ii*4
                flg = False
                continue
    ns = str(n)
    for j in range(len(ns)):
        if not ns[j] == '3':
            break
        if j == len(ns) - 1:
            n = 10*n+3
    return n


def check753(n):
    ns = str(n)
    l = len(ns)
    a = []
    for i in range(l):
        a.append(int(ns[i]))
    a = list(set(a))
    if len(a) == 3:
        return True
    else:
        return False

n = int(input())
a = 333
cnt = 0

while a <= n:
    if check753(a):
        cnt += 1
    a = make753(a)
print(cnt)

Measured memory_bytes: 9208
#include <iostream>
#include <string>
#include <cctype>

using namespace std;

bool check(int A, int B, string S) {
	if (S[A] != '-') return false;
	for (int i = 0; i < A; i++)
		if (!isdigit(S[i]))
			return false;
	for (int i = A + 1; i < A + B + 1; i++)
		if (!isdigit(S[i]))
			return false;

	return true;
}

int main(int argc, char *argv[]) {
	int A, B;
	string S;
	cin >> A >> B >> S;

	if (check(A, B, S)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import numpy as np
import math

N = int(input())

# -10^9 <= N <= 10^9

k = 0

ret = ''

rest = N

while True:
    # print('ret=', ret)
    # print('rest=', rest)
    # print('rest%2', rest % 2)
    if rest % 2 == 1:
        ret += '1'
        if k % 2 == 0:
            rest -= 1
        else:
            rest += 1
    else:
        ret += '0'
    k += 1

    if rest == 0:
        break
    rest = int(rest / (2))
    

print(ret[::-1])


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_d() {
	ll n, m, x;
	ll ans = 0;
	cin >> x;

	ll ansa = 0, ansb = 0;
	rep2(a, -205, 205) rep2(b, -205, 205) {
		if (a * a * a * a * a - b * b * b * b * b == x) {
			ansa = a;
			ansb = b;
			break;
		}
	}

	cout << ansa << " " << ansb << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import deque

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)
q = deque()
done = [-1]*N
done[0] = 1
q.appendleft(0)
while q:
    now = q.pop()
    for to in G[now]:
        if done[to] != -1: continue
        done[to] = now+1
        q.appendleft(to)
print("Yes")
print(*done[1:], sep="\n")


Measured memory_bytes: 38428
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

short checkTable[1001][1001];

int tmp_max=0;


void calc(int index,char pattern[],char to_search[],int to_search_length){

	for(int i=to_search_length-1;i>=0;i--){
		if(to_search[i]==pattern[index]){
			checkTable[index][i]=1;
			if(pattern[index+1]!='\0' && i < to_search_length-1){
				checkTable[index][i] = checkTable[index+1][i+1] + checkTable[index][i];
			}
		}else{
			if(i != to_search_length-1){
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>checkTable[index][i+1])
							?checkTable[index+1][i]:checkTable[index][i+1];

				}else{
					checkTable[index][i]=(checkTable[index][i+1]>0)?checkTable[index][i+1]:0;
				}
			}else{
				if(pattern[index+1] != '\0'){
					checkTable[index][i]=(checkTable[index+1][i]>0)?checkTable[index+1][i]:0;
				}else{
					checkTable[index][i] = 0;
				}
			}
		}
		tmp_max = (tmp_max >= checkTable[index][i])?tmp_max:checkTable[index][i];
	}
}

int main(){

	int q,left_length,right_length;
	char left[1001],right[1001];

	scanf("%d",&q);

	for(int i=0;i<q;i++){
		left_length=0;
		right_length=0;
		scanf("%s %s",left,right);
		for(int k=0;left[k]!='\0';k++)left_length++;
		for(int k=0;right[k]!='\0';k++)right_length++;

		if(right_length>=left_length){

			for(int k=left_length-1;k>=0;k--)calc(k,left,right,right_length);
		}else{

			for(int k=right_length-1;k>=0;k--)calc(k,right,left,left_length);
		}
		printf("%d\n",tmp_max);
		tmp_max=0;
	}

    return 0;
}

Measured memory_bytes: 5172
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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


def ex_square(n,k): #n^k
	if k == 0:
		ans = 1
	elif k % 2 == 0:
		ans = ex_square(n, k//2) ** 2
	else:
		ans = ex_square(n,k-1) * n
	ans %= mod
	return ans

S = list(input())

aa = [0]
bb = [0]
cc = [0]
qq = [0]
Sa = Sb =Sc = Sq = 0
for s in S:
	if s == 'A':
		Sa += 1
	elif s == 'B':
		Sb += 1
	elif s == 'C':
		Sc += 1
	elif s == '?':
		Sq += 1
	aa.append(Sa)
	bb.append(Sb)
	cc.append(Sc)
	qq.append(Sq)

ans = 0
for i,s in enumerate(S):
	if s == 'B':
		SUMq = Sq
	elif s == '?':
		SUMq = Sq-1
	elif s == 'A' or s == 'C':
		continue

	Lq = qq[i]
	Rq = SUMq-Lq
	La = aa[i]
	Rc = Sc - cc[i]

	if SUMq == 0:
		ex = 1
		exx = exxx = 0
	elif SUMq == 1:
		ex = 3
		exx = 1
		exxx = 0
	else:
		exxx= ex_square(3,SUMq-2)
		exx = exxx*3%mod
		ex = exx*3%mod

	ans1 = (ex  * (La*Rc)%mod)%mod
	ans2 = (exx * (Lq*Rc)%mod)%mod
	ans3 = (exx * (La*Rq)%mod)%mod
	ans4 = (exxx * (Lq*Rq)%mod)%mod
	ans += (ans1+ans2+ans3+ans4)%mod
	ans %= mod

print(ans)

Measured memory_bytes: 11428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

int main () {
  int N;
  cin >> N;
  int S = 0;
  for(int d = 1e9, M = N; d >= 1; d/=10) {
    S += M / d;
    M = M % d;
  }
  cout << (N % S ? "No" : "Yes") << endl;
  return 0;
}


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

long long A, B, C, D;
map<long long, long long> dp;
long long f(long long N) {
  if (dp[N] != 0) return dp[N];
  if (N == 0) return dp[N] = 0;
  if (N == 1) return dp[N] = D;
  
  long long res = 1e18;
  if (N < res / D) res = min(res, N * D);
  
  int num[] = {2, 3, 5};
  int cost[] = {A, B, C};
  for (int i = 0; i < 3; ++i) {
    if (N % num[i] == 0) {
      res = min(res, f(N/num[i]) + cost[i]);
      continue;
    }
    
    int d = N % num[i];
    res = min(res, f((N-d) / num[i]) + cost[i] + D * d);
    d = num[i] - d;
    res = min(res, f((N+d) / num[i]) + cost[i] + D * d);
  }
  
  return dp[N] = res;
}

int main() {
  int T;
  cin >> T;
  
  for (int i = 0; i < T; ++i) {
    long long N;
    cin >> N >> A >> B >> C >> D;
    dp.clear();
    cout << f(N) << endl;
  }
}


Measured memory_bytes: 4500
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>

int main(void) {
	int n;

	std::cin >> n;

	while (n < 1000) {
		if (n / 100 == (n / 10) % 10 && n / 100 == n % 10) {
			std::cout << n << std::endl;
			return 0;
		}
		n++;
	}
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

ll dp[100][100][5000];
ll n, k, x[100];

int main() {
   cin >> n >> k;
   rep (i, n) {
      cin >> x[i];
   }

   dp[0][0][0] = 1;
   rep (i, n) {
      rep (j, n) {
         rep (k, 5000) {
            if (dp[i][j][k] == 0) continue;
            dp[i+1][j+1][k+x[i]] += dp[i][j][k];
            dp[i+1][j][k] += dp[i][j][k];
         }
      }
   }
   ll sum = 0;
   for (int i = 1; i <= n; i++) {
      sum += dp[n][i][k*i];
   }
   cout << sum << endl;

   return 0;
}

Measured memory_bytes: 151936
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;


int main(){
   int n, m, R;
   cin >> n >> m >> R;
   VEC(int, r, R);

   ll d[n+10][n+10];
   rep(i, n + 10){
       rep(j, n + 10){
           if(i == j)d[i][j] = 0;
           else d[i][j] = INF * INF;
       }
   }

   rep(i, m){
       int a, b, c;
       cin >> a >> b >> c;
       d[a][b] = c;
       d[b][a] = c;
   }

   //warshall_floyd
   rep(k, n + 1){
       rep(i, n + 1){
           rep(j, n + 1){
               d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
           }
       }
   }

   ll res = INF * INF;
  sort(ALL(r));
   do{
       ll sum = 0;
       rep(i, R - 1){
           sum += d[ r[i] ][ r[i + 1] ];
       }

       res = min(res, sum);
   }while( next_permutation( ALL(r) ) );
   cout << res << endl;
}



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

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

template<typename T>
void chmax(T&a,const T& b){if(a<b)a=b;}
template<typename T>
T gcd(T a,T b){
  while(1){
    swap(a,b);
    if(a==0)return b;
    if(b==0)return a;
    a%=b;
  }
}
template<typename T>
T func(const T&a,const T&b){return gcd(a,b);}

template<typename T>
struct Segment_Tree{

  private:
    int n;
    vector<T> node;

  public:
    Segment_Tree(vector<T> v){
      int sz=v.size();
      n=1;
      while(n<sz)n<<=1;
      node.resize(2*n-1,0);
      rep(i,sz)node[i+n-1]=v[i];
      for(int i=n-2;i>=0;--i)
        node[i]=func(node[2*i+1],node[2*i+2]);
    }

    void update(int x,T val){
      x+=(n-1);
      node[x]=val;
      while(x){
        x=((x-1)>>1);
        node[x]=func(node[2*x+1],node[2*x+2]);
      }
    }

    T query(int a,int b,int k=0,int l=0,int r=-1){
      if(r<0)r=n;
      if(r<=a || b<=l)return 0;
      if(a<=l && r<=b)return node[k];
      T vl=query(a,b,2*k+1,l,(l+r)/2);
      T vr=query(a,b,2*k+2,(l+r)/2,r);
      return func(vl,vr);
    }

    void debg(){
      for(const auto& x:node)
        cout<<x<<" ";
      cout<<endl;
    }
};

main(){
  ll n;
  cin>>n;
  vector<ll> a(n);
  for(auto&x:a)cin>>x;
  Segment_Tree<ll> seg(a);

  ll ans=0;
  rep(i,n){
    seg.update(i,0);
    auto tmp=seg.query(0,n);
    chmax(ans,tmp);
    seg.update(i,a[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3840
#include <stdio.h>

int area(int n){
    int sum=2,i;
    if(n==1)
        return sum;
    for(i=1;i<n;i++){
        sum+=(i+1);
    }
    return sum;
}

int main(int argc, const char * argv[]) {
    int n,a;
    
    while(scanf("%d",&n)!=EOF){
        a=area(n);
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
  string s;
  cin >> s;
  int n=s.size();
  int a=2200000;
  int b=0;

  rep(i,n){
     if(s.at(i)=='A'){
        a=min(a,i);
     }
     else if(s.at(i)=='Z'){
        b=max(b,i);
     }
  }
  cout << b-a+1 << endl;

}

Measured memory_bytes: 3736
// A - Shik and Stone

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

char grid[9][9];

int main() {
	int H, W;
	cin >> H >> W;

	int all_cnt = 0;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			cin >> grid[i][j];
			if (grid[i][j] == '#') all_cnt++;
		}
	}

	int r = 0;
	int c = 0;
	int cnt = 0;

	while (1) {
		cnt++;

		if (r == H-1 && c == W-1) break;

		if (grid[r+1][c] == '#') {
			r++;
		} else if (grid[r][c+1] == '#') {
			c++;
		} else {
			break;
		}
	}

	string ans;

	if (cnt == all_cnt) ans = "Possible";
	else ans = "Impossible";

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3616
import java.lang.Math

fun main(args: Array<String>) {
    val (N, K) = readInputLine().split(" ").map { it.toInt() }

    val points = Array(N) { val (x, y) = readInputLine().split(" ").map { it.toLong() }; Pair(x, y) }

    val (xs, ys) = points.unzip().let { Pair(it.first.sorted().toLongArray(),
                                             it.second.sorted().toLongArray()) }

    val pointsSumBase = Array(N) { IntArray(N) }

    for (p in points) {
        val xIndex = xs.indexOf(p.first)
        val yIndex = ys.indexOf(p.second)

        pointsSumBase[yIndex][xIndex]++
    }

    var ans = Long.MAX_VALUE

    for (xIndex in 0 until N) {
        for (yIndex in 0 until N) {
            val pointsSum = Array(N) { pointsSumBase[it].copyOf() }

            for (y in 0 until yIndex) {
                for (x in 0 until N) {
                    pointsSum[y][x] = 0
                }
            }

            for (y in 0 until N) {
                for (x in 0 until xIndex) {
                    pointsSum[y][x] = 0
                }
            }

            for (y in 0 until N) {
                for (x in 0 until N) {
                    if (x != 0) {
                        pointsSum[y][x] += pointsSum[y][x - 1]
                    }
                }
            }

            for (y in 0 until N) {
                for (x in 0 until N) {
                    if (y != 0) {
                        pointsSum[y][x] += pointsSum[y - 1][x]
                    }
                }
            }

            for (y in yIndex until N) {
                for (x in xIndex until N) {
                    if (pointsSum[y][x] >= K) {
                        ans = Math.min(ans, (ys[y] - ys[yIndex]) * (xs[x] - xs[xIndex]))
                        break
                    }
                }
            }
        }
    }

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main() {
	int H,A;
	cin >> H >> A;
  cout << (H+A-1)/A << endl;
}

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

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int N;
  cin >> N;
  string S[N];
  rep(i,N) cin >> S[i];

  bool flag = false;
  rep(i,N){
    if (S[i] == "Y") flag = true;
  }
  if (flag) cout << "Four" << endl;
  else cout << "Three" << endl;
}


Measured memory_bytes: 3608
#include <iostream>
using namespace std;
int main() {
	int x, y;
	cin >> x >> y;
	int group[13] = {-1, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
	if(group[x] == group[y]){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

const int mod = 1000000007;
class mint {
public:
	long long x;
	mint(long long x = 0) : x((x%mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	mint n = mint(N);
	mint a = mint(A);
	mint b = mint(B);
	mint res = mint(2).pow(N);
	res -= 1;
	mint bunbo = a;
	mint bunshi = n;
	mint cnt = mint(1);
	while (1) {
		if (a.x == cnt.x)break;
		bunbo *= (a - cnt);
		bunshi *= (n - cnt);
		cnt += mint(1);
	}
	res -= bunshi / bunbo;
	bunbo = b;
	bunshi = n;
	cnt = mint(1);
	while (1) {
		if (b.x == cnt.x)break;
		bunbo *= (b - cnt);
		bunshi *= (n - cnt);
		cnt += mint(1);
	}
	res -= bunshi / bunbo;
	pv(res)
}

Measured memory_bytes: 256
use std::collections::HashSet;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn usize() -> usize {
    read()
}

fn main() {
    let n = usize();
    let mut ns = HashSet::new();
    for _ in 0..n {
        let i = usize();
        if ns.contains(&i) {
            ns.remove(&i);
        } else {
            ns.insert(i);
        }
    }
    println!("{}", ns.len());
}

Measured memory_bytes: 8444
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
LL read(){
    LL f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
    return f*x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int cnt[10];
LL a[MAXN+5],b[MAXN+5];
int main(){
	//freopen("circle.in","r",stdin);
	//freopen("circle.out","w",stdout);
	int T=1;
	while(T--){
		int n=read();
		memset(cnt,0,sizeof(cnt));
		bool f=1;
		for(int i=1;i<=n;i++){
			b[i]=a[i]=read();
			if(a[i]) f=0; 
		}
		if(f){
			puts("Yes");
			continue;
		}
		sort(b+1,b+n+1);
		int m=unique(b+1,b+n+1)-(b+1);
		if(m>=4){
			puts("No");
			continue;
		}
		for(int t=1;t<=m;t++)
			for(int i=1;i<=n;i++)
				if(b[t]==a[i])
					cnt[t]++;
		sort(cnt+1,cnt+m+1);
		if(m==1)
			puts("No");
		if(m==2){
			if(n%3==0){
				if(cnt[1]==n/3&&cnt[2]==n/3*2&&b[1]==0)
					puts("Yes");
				else puts("No");
			}
			else puts("No");
		}
		if(m==3){
			if(n%3==0){
				if(cnt[1]==n/3&&cnt[2]==n/3&&cnt[3]==n/3&&(b[1]==(b[2]^b[3])))
					puts("Yes");
				else puts("No");
			}
			else puts("No");
		}
	}
    return 0;
}


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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;

    int p[n], sum= 0;

    for(int i=0; i<n; i++)
    {
        cin>> p[i];
        sum+= p[i];
    }

    sum-= (*max_element( p, p+n))/2;

    cout << sum;
    nl;

    return 0;
}




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

int main(){
  int N;cin>>N;
  vector<string> S(N);
  for(int i=0;i<N;i++) cin>>S.at(i);
  int M;cin>>M;
  vector<string> T(M);
  for(int i=0;i<M;i++) cin>>T.at(i);
  priority_queue<int> A;
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    if(i>0 && S.at(i)==S.at(i-1)) continue; 
    string X=S.at(i);
    int count=0;
    for(int j=i;j<N;j++){
      if(X==S.at(j)) count++;
    }
    for(int j=0;j<M;j++){
      if(X==T.at(j)) count--;
    }
    A.push(count);
  }
  if(A.top()<0) cout<<0<<endl;
  else cout<<A.top()<<endl;
}


Measured memory_bytes: 3564
#include <stdio.h>
#define MAX 300000
int main(){
    int N;
    char S[MAX+1];
    int anwx=0;
    int anwy=0;
    int ANW=0;
    scanf("%d",&N);
    scanf("%s",S);
    for(int i=1;i<N;i++) if(S[i]!='W') anwy++;
    for(int i=0;i<N;i++){
        if(i!=0) {
        if(S[i-1]!='E') anwx++;
        if(S[i]!='W') anwy--;
        }
        if(i==0) ANW=anwx+anwy;
        if(ANW>anwx+anwy) ANW=anwx+anwy;
    }
    printf("%d",ANW);
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 998244353 
#define pb push_back
//#define mp make_pair
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define eps 1e-9
#define pp pair < pair<ll,ll> , ll> 
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define foll(i,j,k) for(ll i=j;i<=k;i++)
#define clr(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>
#define sz(a) a.size()
#define len(a) a.length()
#define all(a) a.begin(),a.end()
#define io_file freopen("Contest/input_file.in", "r", stdin); freopen("Contest/output_file.in", "w", stdout)

const int MAXN = 2e5+5;
using namespace std;
ll power(ll x, ll y)
{
  ll res = 1;
  while(y>0)
  {
    if(y&1)
       {
         res = (res*x)%mod;
        }
     x = (x*x)%mod;
     y = y>>1;
  }
    return res;
}
// std::vector<ll> divi[100004];
// void divisor(int n)
// {
//    for(ll i=1;i<=n;i++)
//    {
//      for(ll j=i;j<=n;j+=i)
//      {
//        divi[j].pb(i);
//      }
//    }
// }

string s;
int K;
int dp[305][305][305];

ll solve(int i, int j, int k)
{
	if(i > j) return 0;
	if(i==j) return dp[i][j][k]=1;
	if(dp[i][j][k]!=-1) return dp[i][j][k];
	if(i+1==j){
		if(s[i]==s[j])
		{
			return dp[i][j][k] = 2;
		}
		else {
			if(k==0)
				return dp[i][j][k] = 1;
			else  if(k > 0) return dp[i][j][k] = 2;
		} 
	}
	ll ans=max(solve(i+1,j,k),solve(i,j-1,k));
	if(s[i]==s[j])
	{
		ans  = max(ans, 2 + solve(i+1,j-1,k));
	
	}
	else if(k>0){
		ans = max(ans,2 + solve(i+1,j-1,k-1));
	}
	return dp[i][j][k] =  ans;
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>s;
    cin>>K;
    
    cout<<solve(0,s.length()-1,K)<<endl;
    return 0;

}
	

Measured memory_bytes: 111232
import bisect
N =int(input())
lisA =list(map(int,input().split()))
lisB = list(map(int,input().split()))
lisC = list(map(int,input().split()))

lisA.sort()
lisB.sort()
lisC.sort()
cnt = 0

for b in lisB:
    cnt += bisect.bisect_left(lisA,b)*(N-bisect.bisect_right(lisC,b))

print(cnt)

Measured memory_bytes: 23360
import collections

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

A=list(collections.Counter(A).items())
#print(A)
ans=len(A)


tmp=0
for a in A:
  tmp+=1 if a[1]%2==0 else 0
ans-=1 if tmp%2 else 0

print(ans)

Measured memory_bytes: 21468
#include <stdio.h>
#include <vector>
#include <map>
using namespace std;

map<long long, int> chk[44];
int N,X,Y,Z;

vector<int> reduce(vector<int> o)
{
	vector<int> r;
	for (int i=0;i<o.size();i++){
		bool good = 1;
		int u[3] = {X,Y,Z},C=0,s=0;
		for (int j=i;j<o.size();j++){
			s += o[j];
			if (u[C] == s) C++, s = 0;
			else if (u[C] < s){
				good = 0; break;
			}
			if (C == 3){
				return vector<int>(1,-1);
			}
		}
		if (good){
			r = vector<int>(o.begin()+i,o.end());
			break;
		}
	}
	return r;
}

const int mod = 1000000007;
int add[44];

long long hash1(vector<int> &a)
{
	long long r = 0;
	for (int x : a) r = r * 257 + x;
	return r;
}

int go(vector<int> &a, int n)
{
	if (n == 0) return 0;
	long long h = hash1(a);
	if (chk[n].count(h)) return chk[n][h];
	int &r = chk[n][h];
	for (int i=1;i<=10;i++){
		vector<int> o = a;
		o.push_back(i);
		o = reduce(o);
		if (!o.empty() && o[0] == -1){
			r = (r + add[n]) % mod;
		}
		else{
			r = (r + go(o,n-1)) % mod;
		}
	}
	return r;
}

int main()
{
	add[1] = 1;
	for (int i=2;i<=40;i++){
		add[i] = ((long long)add[i-1] * 10) % mod;
	}

	scanf ("%d %d %d %d",&N,&X,&Y,&Z);
	vector<int> emp;
	printf ("%d\n",go(emp,N));

	return 0;
}

Measured memory_bytes: 34176
//  https://www.spoj.com/problems/CPCRC1C/


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#include <set>
#include <iterator>
using namespace std;
using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF INT_MAX
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )

typedef tree<pll, null_type, less<pll>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
const int N=1e5+10, M=(ll)1e9+1 ;
const int mod = 1e9+7;

void work(){
  ll n;
  cin >> n;
  ll p,q;
  p=q=0;
  vl a(n);
  for(ll i=0;i<n;i++){
    cin >> a[i];
    if(a[i]<0)
        q++;
    else
        p++;
  }
  sort(a.begin(),a.end());
  ll x=q-1;
  if(q==0)
    x=0;
  if(p==0)
    x=n-2;
  ll prev=a[0],z;
  vll ans;
  for(ll i=x+1;i<n-1;i++){
    ans.pb({prev,a[i]});
    prev-=a[i];
  }
  z=prev;
  prev=a[n-1];
  for(ll i=1;i<=x;i++){
    ans.pb({prev,a[i]});
    prev-=a[i];
  }
  ans.pb({prev,z});
  cout << prev-z << "\n";
  for(ll i=0;i<ans.size();i++)
    cout << ans[i].f << " " << ans[i].s << "\n";
  }
int main(){
 ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t,z;
//     cin >> t;
    // z=t;
    t=1;
    while(t--){
            // cout << "Case #" << z-t << ": ";
            work();
    }
   return 0;

}


Measured memory_bytes: 4336
n = int(input())
a = list(map(int, input().split()))
even = []

for i in a:
    if i % 2 == 0:
        even.append(i)

ele = 0

for x in even:
    if  not (x % 3 == 0 or x % 5 == 0):
        print("DENIED")
        break
    else:
        ele += 1

if ele == len(even):
    print("APPROVED")


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

int main() {
  int n;
  cin>>n;
  int a[n];
  for (int i=0; i<n; i++) {
    cin>>a[i];
  }
  if (n <= 2) {
    cout<<1<<endl;
    return 0;
  }
  int idx = 0;
  int cnt = 0;
  while (idx < n) {
    ++cnt;
    ++idx;
    bool ascending = true;
    while (idx < n) {
      if (a[idx-1] == a[idx]) {
        ++idx;
      } else if (a[idx-1] < a[idx]) {
        break;
      } else {
        ascending = false;
        break;
      }
    }
    while (idx < n) {
      if (ascending) {
        if (a[idx-1] <= a[idx]) {
          ++idx;
        } else {
          break;
        }
      } else {
        if (a[idx-1] >= a[idx]) {
          ++idx;
        } else {
          break;
        }
      }
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int d, t, s; cin >> d >> t >> s;
    if (d <= t*s) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3648
N = input()
n = int(N)
if len(N)==6:
    print(9+900+90000)
elif len(N)==5:
    print(n-9999+9+900)
elif len(N)==4:
    print(9+900)
elif len(N)==3:
    print(n-99+9)
elif len(N)==2:
    print(9)
else:
    print(N)

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

inf = float('inf')

def main():
	N = input()
	N = N[:-1]
	N = "0" + N
	N = N[::-1]

	dp = [[inf,inf] for i in range(len(N)+2)]
	dp[0][0] = 0
	#print(dp)

	cnt = 0
	for ii in N:
		i = int(ii)
		cnt += 1
		#print(dp)
		for j in range(10):
			if i > j:
				tmp = j + 10 - i
				dp[cnt][1] = min(dp[cnt][1], dp[cnt-1][0] + tmp + j)
			else:
				tmp = j - i
				dp[cnt][0] = min(dp[cnt][0], dp[cnt-1][0] + tmp + j)

			tmptmp = j-1
			if i > tmptmp:
				tmp = tmptmp + 10 - i
				dp[cnt][1] = min(dp[cnt][1], dp[cnt-1][1] + tmp + j)
			else:
				tmp = tmptmp - i
				dp[cnt][0] = min(dp[cnt][0], dp[cnt-1][1] + tmp + j)

	#print(dp)
	print(dp[len(N)][0])

if __name__ == "__main__":
	main()


Measured memory_bytes: 188392
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {
  int N, D; std::cin >> N >> D;
  std::vector<std::vector<int>> V;
  V.resize(N); for(int i=0; i<N; i++) V[i].resize(D);
  for(int i=0; i<N; i++) for(int j=0; j<D; j++) std::cin >> V[i][j];

  int ans = 0;
  for(int i=0; i<N; i++) {
    for(int j=i+1; j<N; j++) {
      int kk = 0;
      for(int k=0; k<D; k++) kk += (V[i][k]-V[j][k])*(V[i][k]-V[j][k]);
      int sq = std::floor(std::sqrt((double) kk));
      if ( sq*sq == kk ) ans++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

 

int main(){
    int N;cin >> N;
    int a[N],x=1,s=0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        s+=a[i];
    }
    bitset<4000001> b;
    b[0]=1;
    for (int i = 0; i < N; i++) {
        b=b|(b<<a[i]);
    }
    int c=0;
    for (int i = 0; i < 4000001; i++) {
        if(b[i]) c++;
    }
    c/=2;
    for (int i = 1; i < 4000001; i++) {
        if(b[i]) c--;
        if(c==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 2176
#include <cstdio>

int
main(void)
{
  int i, x;

  i = 1;
  while (std::scanf("%d", &x) != EOF) {
    if (x > 0) {
      std::printf("Case %d: %d\n", i, x);
      i++;
    }
  }

  return 0;
}



Measured memory_bytes: 2572
N = int(input())
FB = [i for i in range(1,N+1)]
f = [i for i in range(3,N+1,3)]
b = [i for i in range(5,N+1,5)]
fb = [i for i in range(15,N+1,15)]
l = sum(FB)
m = sum(f)
n = sum(b)
o = sum(fb)
print(l-m-n+o)

Measured memory_bytes: 72368
from sys import stdin


def main():
    N, L = [int(x) for x in stdin.readline().rstrip().split()]

    apple_list = []

    for i in range(N):
        apple_list.append(L+i)

    s = sorted(apple_list, key=abs)
    s.pop(0)
    print(sum(s))


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;


class Program {
    internal static void Main(string[] args)
    {

        var N = int.Parse(ReadLine());
        var A = new List<int>();
        A.Add(0);
        A.AddRange(ReadLine().Split(' ').Select(s => int.Parse(s)).ToList());
        A.Add(0);
        var ans = 0L;
        var now = 0;

        for (int j = 0; j < N + 2; j++) {
            ans += Math.Max(A[j], now) - Math.Min(A[j], now);
            now = A[j];
        }

        for (int i = 1; i < N + 1; i++) {
            var bef = A[i - 1];
            var aft = A[i + 1];

            if (bef >= aft) {
                if (bef < A[i]) {
                    WriteLine(ans - Math.Abs((A[i] - bef) * 2));
                } else if (aft > A[i]) {
                    WriteLine(ans - Math.Abs((A[i] - aft) * 2));
                } else {
                    WriteLine(ans);
                }
            } else if (bef <= aft) {
                if (bef > A[i]) {
                    WriteLine(ans - Math.Abs((A[i] - bef) * 2));
                } else if (aft < A[i]) {
                    WriteLine(ans - Math.Abs((A[i] - aft) * 2));
                } else {
                    WriteLine(ans);
                }
            }
        }
    } 
}

Measured memory_bytes: 27228
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll X;
	cin>>X;
	ll div=X/100;
	if(div==0){
		cout<<"0"<<endl;
		return 0;
	}
	ll mod=X%100;
	ll num;
	if((double)mod/5==mod/5)num=mod/5;
	else num=mod/5+1;
	if(div>=num){
		cout<<"1"<<endl;
	}else{
		cout<<"0"<<endl;
	}
	return 0;
}


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

#define len(x)  (int((x).size()))
#define append push_back
#define pp make_pair
#define ff(a, b)    for (int a = 0; a < int(b); ++a)
#define kk(n)    ff(k, n)
#define xx(n)    ff(x, n)
#define yy(n)    ff(y, n)
#define ii(n)    ff(i, n)
#define fff(a, b, c) for (int a = int(b); a < int(c); ++a)
#define kkk(a, b) fff(k, a, b)
#define xxx(a, b) fff(x, a, b)
#define yyy(a, b) fff(y, a, b)
#define iii(a, b) fff(i, a, b)
#define bb begin()
#define ee end()
#define uu first
#define vv second
#define all(x)  (x).bb, (x).ee
#define ite(v)   decltype((v).bb)
#define fe(i, v) for(ite(v) i = (v).bb; i != (v).ee; ++i)
#define err(...)    { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#define zz(array, byte)   memset(array, byte, sizeof(array));

using LL = long long;
using DD = long double;
using pii = pair<int, int>;


const LL  INFLL  = 0x7f7f7f7f7f7f7f7fLL;
const int INFint = 0x7f7f7f7f;  //Works with memset(..).
   




int main() {
    //ios_base::sync_with_stdio(false);     cin.tie(NULL);
    //cout << '\n';     //Avoid flushing with endl.
    cout.precision(16);

    LL a, b, c;
    cin >> a >> b >> c;
    ii (10111000) {
        if ((a & 1) == 1
        ||  (b & 1) == 1
        ||  (c & 1) == 1) {
            cout << i << '\n';
            return 0;
        }

        LL d = a / 2 + b / 2;
        LL e = b / 2 + c / 2;
        LL f = a / 2 + c / 2;
        a = d;
        b = e;
        c = f;

    }

    cout << "-1\n";
    

    return 0;
}



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

const int N = 100010;
typedef std::pair <int, int> pii;

int x, k, q;
int r[N], ans[N];
std::pair <pii, int> query[N];

int main(){
	scanf("%d%d", &x, &k);
	for (int i = 0; i < k; ++ i){
		scanf("%d", &r[i]);
	}
	scanf("%d", &q);
	for (int i = 0, t, a; i < q; ++ i){
		scanf("%d%d", &t, &a);
		query[i] = {{t, a}, i};
	}
	std::sort(query, query + q);
	pii one = {0, 0}, two = {x, x};
	for (int i = 0, j = 0; i < q; ++ i){
		while (j < k && query[i].first.first >= r[j]){
			int dif = r[j] - (j ? r[j - 1] : 0);
			if (j & 1){
				if (two.second + dif <= x){
					one.second += dif;
					two.second += dif;
				}
				else if (one.second + dif < x){
					one.second += dif;
					two = {two.first - dif + x - two.second, x};
				}
				else{
					one = {0, x};
					two = {0, x};
				}
			}
			else{
				if (one.second >= dif){
					one.second -= dif;
					two.second -= dif;
				}
				else if (two.second > dif){
					one = {one.first + dif - one.second, 0};
					two.second -= dif;
				}
				else{
					one = {0, 0};
					two = {0, 0};
				}
			}
			++ j;
		}
		if (query[i].first.second <= one.first){
			ans[query[i].second] = one.second;
		}
		else if (query[i].first.second >= two.first){
			ans[query[i].second] = two.second;
		}
		else{
			ans[query[i].second] = one.second + query[i].first.second - one.first;
		}
		int xx = j ? r[j - 1] : 0;
		ans[query[i].second] += j & 1 ? query[i].first.first - xx : xx - query[i].first.first;
		if (ans[query[i].second] < 0){
			ans[query[i].second] = 0;
		}
		if (ans[query[i].second] > x){
			ans[query[i].second] = x;
		}
	}
	for (int i = 0; i < q; ++ i){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[10010],a[10010];
    int i,j,k,l,w;

    cin>>s;
    cin>>w;

    l=strlen(s);

    j=0;
    for(i=0;i<l;i+=w)
    {
        a[j++]=s[i];
    }
    a[j]='\0';

    printf("%s",a);
}


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

int main(){

	string S, T, U;
	cin >> S >> T;

	int A, B;
	cin >> A >> B >> U;

	if (U == S){cout << A-1 << ' ' << B << endl;}
	else{cout << A << ' ' << B-1 << endl;}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

const int MAX = 5100000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n=MOD-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%MOD,a=a*a%MOD,n>>=1;
	return r;
}

int main() {
  int n, m, k; cin >> n >> m >> k;

  COMinit();

  ll sum = 0;
  for(int i=0; i<=k; i++){
    sum += COM(n-1, i)*m%MOD*modpow(m-1, n-i-1)%MOD;
  }


  cout << sum%MOD << endl;
  return 0;
}


Measured memory_bytes: 123172
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    char c[6][6];
    
    rep(i, 3){
        scanf("%s", c[i]);
    }
    
    printf("%c%c%c", c[0][0], c[1][1], c[2][2]);
    
    return 0;
}



Measured memory_bytes: 1732