akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<bits/stdc++.h>
#define ll long long
#define inf 1e9
using namespace std;

struct item
{
    int wt;
    int val;
};

ll solve(vector<item> ar, int n, int W)
{
    ll dp[n+1][W+1];

    for(int w = 0; w <= W; w++)
        dp[1][w] = 0;
    
    dp[1][ar[1].wt] = ar[1].val;
    
    for(int i = 2; i <= n; i++)
    {
        for(int w = 0; w <= W; w++)
        {
            dp[i][w] = dp[i-1][w];
            if(ar[i].wt > w)
                continue;
            dp[i][w] = max(dp[i][w], ar[i].val + dp[i-1][w - ar[i].wt]);
        }
    }
    return *max_element(dp[n], dp[n] + W + 1);
}

int main() {
    int n, w;
    cin >> n >> w;
    vector<item> ar(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i].wt >> ar[i].val; 
    }
    cout << solve(ar, n, w);
}


Measured memory_bytes: 78336
def main():
  N = int(input())
  A = list(map(int, input().split()))
    
  m = A[0]
  S = 0

  for a in A:
      if m - a > 0:
          S += m - a
      if m < a:
          m = a

  print(S)


if __name__ == "__main__":
  main()


Measured memory_bytes: 32124
n = int(input())
d = list(map(int, input().split()))
MOD = 998244353

if d[0] != 0:
    ans = 0
else:
    d.sort()
    d.append(d[-1] + 1)
    if d[1] == 0:
        ans = 0
    else:
        x = 1
        cnt_prev = 1
        cnt = 0
        ans = 1
        for i in range(1, n + 1):
            if d[i] == x:
                cnt += 1
            elif d[i] == x + 1:
                # print(x, cnt, cnt_prev)
                ans *= cnt_prev**cnt
                ans %= MOD
                cnt_prev = cnt
                cnt = 1
                x += 1
            else:
                ans = 0
                break

print(ans)


Measured memory_bytes: 13908
a, op, b = 0, '', 0
while op != '?':
    a, op, b = input().split()
    if op == '+':
        print(int(a) + int(b))
    if op == '-':
        print(int(a) - int(b))
    if op == '*':
        print(int(a) * int(b))
    if op == '/':
        print(int(a) // int(b))


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

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

	int n;
	cin >> n;

	int ans = 0;
	vector<int> v(n), c(n);

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

	for (int i = 0; i < n; i++) {
		cin >> c[i];
		if (c[i] < v[i])
			ans += (v[i] - c[i]);
	}

	cout << ans << "\n";
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p) {
    int res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}

int32_t main() {
    nitin;
    int n,p;
    cin>>n>>p;
    int even=0;
    int odd=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        if(a&1) odd++;
        else even++;
    }
    if(odd>=1)
        cout<<(1LL<<even)*(1LL<<(odd-1));
    else
    {
        if(p==0)
            cout<<(1LL<<even);
        else
            cout<<0<<endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;


int main(){
  int n, u, v, m;
  cin >> n >> u >> v >> m;
  map<int, pair<int,int> > U, N;
  int t;
  if(n == 1){
    if(u > 1){
      u += 5;
    }
    if(v > 1){
      v += 5;
    }
  }
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin >> t;
      U[t] = make_pair(i+1,j+1);
    }
  }
  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      cin >> t;
      N[t] = make_pair(i+1,j+1);
    }
  }
  
  int T[m];
  vector< vector<int> > U_(2,vector<int>(n+1,n)), N_(2,vector<int>(n+1,n));
  for(int i = 0; i < m; ++i) cin >> T[i];
  for(int i = 0; i < m; ++i){
    int k = T[i], s = U[k].first, t = U[k].second;
    if(s&&t){
      --U_[0][s];
      --U_[1][t];
      if(s == t) --U_[0][0];
      if(s + t == n+1) --U_[1][0];
      if(!U_[0][s]){
	--u;
	--U_[0][s];
      }
      if(!U_[1][t]){
	--u;
	--U_[1][t];
      }
      if(!U_[0][0]){
	--u;
	--U_[0][0];
      }
      if(!U_[1][0]){
	--u;
	--U_[1][0];
      }
    }
    s = N[k].first, t = N[k].second;
    if(s&&t){
      --N_[0][s];
      --N_[1][t];
      if(s == t) --N_[0][0];
      if(s + t == n+1) --N_[1][0];
      if(!N_[0][s]){
	--v;
	--N_[0][s];
      }
      if(!N_[1][t]){
	--v;
	--N_[1][t];
      }
      if(!N_[0][0]){
	--v;
	--N_[0][0];
      }
      if(!N_[1][0]){
	--v;
	--N_[1][0];
      }
    }
    if(u <= 0 && v <= 0){
      cout << "DRAW" << endl;
      return 0;
    }else if(u <= 0){
      cout << "USAGI" << endl;
      return 0;
    }else if(v <= 0){
      cout << "NEKO" << endl;
      return 0;
    }
  }
  cout << "DRAW" << endl;
  return 0;
}

Measured memory_bytes: 22688
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import copy
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():

    N = I()
    XY = LLIN(N)
    if N == 1:
        print(1)
        exit()
    XY.sort()

    count = defaultdict(int)
    for i, (x1, y1) in enumerate(XY):
        for j, (x2, y2) in enumerate(XY[i+1:]):
            dx, dy = x1 - x2, y1 - y2
            count[(dx, dy)] += 1
    maxim = -inf
    for v in count.values():
        maxim = max(maxim, v)
    print(N - maxim)
    
    
                        
if __name__ == '__main__':
    main()

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

#define int int_fast64_t

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

  int n; cin >> n;
  vector<int> v;
  copy_n(istream_iterator<int>(cin), n, back_inserter(v));

  auto friendly = [&](int x) {
    return (v[x]-1 != x &&
            v[v[x]-1]-1 == x);
  };
  int s=0;
  for (int i=0; i<n; ++i) s += friendly(i);
  cout << s/2 << '\n';
}

/*
 * Local variables:
 * compile-command:"g++ -D_GLIBCXX_DEBUG -g3 -ggdb3 -O0 -Wall -Wextra -std=c++14 b.cc -o b && for f in *.in; do echo \"--- $f -------------\"; ./b <$f; done"
 * end:
 */



Measured memory_bytes: 1400
#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() {
    double n;
    cin >> n;
    vector<int> a(n);
    double bunsi = 1;
    double bunbo = 0;
    rep(i, n) cin >> a[i];
    rep(i, n) {
        double tmp = 1;
        rep(j, n) {
            if(i != j)
                tmp *= a[j];
        }
        bunbo += tmp;
        bunsi *= a[i];
    }
    // cout << "bunsi:" << bunsi << ",bunbo:" << bunbo << endl;
    cout << fixed << setprecision(5) << bunsi / bunbo << endl;
    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
  
  // 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

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

  // 初期化 (最小化問題なので INF に初期化)
  for (int i = 0; i < 100010; ++i) dp[i] = INF;

  // 初期条件
  dp[0] = 0;

  // ループ
  for (int i = 1; i < N; ++i) {
    for(int j = 0; j < K; ++j) {
      if (i > j) chmin(dp[i], dp[i - 1 - j] + abs(h[i] - h[i - 1 - j]));
    }
  }

  // 答え
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 5104
//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 1e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

bool debug = 0;
const int MAXN = 3e5 + 100;
const int LOG = 21;
const int mod = 998244353;
const int MX = (2e7 + 100);


pii dp[128][128];
char a[128][128];

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int e = 1; e <= m; ++e) {
            cin >> a[i][e];
        }
    }
    if (a[1][1] == '#')
        dp[1][1] = {1, 1};
    else
        dp[1][1] = {0, 0};
    for (int i = 1; i < 128; ++i) {
        dp[i][0] = {inf_int, 0};
        dp[0][i] = {inf_int, 0};
    }
    dp[1][0] = {0, 0};
    for (int i = 1; i <= n; ++i) {
        for (int e = 1; e <= m; ++e) {
            if (a[i][e] == '#') {
                auto val1 = dp[i][e - 1];
                if (val1.se == 0) {
                    val1.fi++;
                    val1.se++;
                }
                auto val2 = dp[i - 1][e];
                if (val2.se == 0) {
                    val2.fi++;
                    val2.se++;
                }
                dp[i][e] = min(val1, val2);
            } else {
                dp[i][e] = min(dp[i - 1][e], dp[i][e - 1]);
                dp[i][e].se = 0;
            }
        }
    }
    cout << dp[n][m].fi << "\n";
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {
#ifdef zxc
    freopen("../input.txt", "r", stdin);
//    freopen("../output.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    int t = 1;
    while (t--) {
        solve();
    }
    debug(1.0 * clock() / CLOCKS_PER_SEC);
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[100001];
	int n,i,cnt;
	scanf("%d",&n);
	scanf("%s",s);
	cnt=0;
	for(i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			cnt++;
			i++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 2144
from collections import defaultdict
n, m = map(int, input().split())

d = defaultdict(list)
for i in range(m):
    p, y = map(int, input().split())
    d[p].append([i, y])

for i in range(1, n + 1):
    tmp = d[i]
    tmp.sort(key=lambda x: x[1])
    for i, j in enumerate(tmp):
        j.append(i + 1)

ans = []
for a, b in d.items():
    for i in b:
        i.append(a)
        ans.append(i)

for _, _, c, p in sorted(ans):
    print("{:06}{:06}".format(p, c))

Measured memory_bytes: 48824
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
    string s;
    cin >> s;
    string t;
    cin >> t;
    s = s + s;

    if(s.find(t) != s.npos){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def g(A, n):
    if A == -1:
        return 0
    return A // (2 * n) * n + max(A % (2 * n) - (n - 1), 0)


def f(A, B):
    result = 0
    for i in range(48):
        t = 1 << i
        if (g(B, t) - g(A - 1, t)) % 2 == 1:
            result += t
    return result


A, B = map(int, input().split())

print(f(A, B))


Measured memory_bytes: 3060
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
int n , m ;
int dp[1001][1<<12] ;
int a[1001] ;
int p[1001] ;

int go(int idx, int mask){
	if(idx == m){
		if(mask == (1<<n)-1){
			return 0 ;
		}
		return INF ;
	}
	int& ans = dp[idx][mask] ;
	if(~ans){
		return dp[idx][mask] ;
	}
	ans = go(idx+1,mask) ;
	ans = min(ans, p[idx]+go(idx+1,mask|a[idx])) ;
	return ans ;
}

void solve(){
	cin >> n >> m ;
	for(int i = 0 ; i < m ; i++){
		int x , y ;
		cin >> x >> y ;
		for(int j = 0 ; j < y ; j++){
			int z ; cin >> z ;
			--z ;
			a[i] |= 1<<z ;
		}
		p[i] = x ;
	}
	ms(dp,-1) ;
	int ans = go(0,0) ;
	if(ans == INF) ans = -1 ;
	cout << ans ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
}


Measured memory_bytes: 35692
#include <bits/stdc++.h>
using namespace std;
double ans[200005];
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int lli;
int main()
{
    fio;
    int n,k;
    cin>>n>>k;
    vector<lli> dp(n,INT_MAX);
    lli a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=k;j++)
            if(i>=j)
        dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,a[maxn],k;
int sum,ans;
int cur;
vector<int> d;

int main(){
    ans=1;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    for(int i=(int)sqrt(sum);i>=2;i--){
        if(sum%i==0){
            d.push_back(i);
            if(i*i!=sum){
                d.push_back(sum/i);
            }
        }
    }
    d.push_back(sum);
    for(int x:d){
        vector<int> b;
        for(int i=1;i<=n;i++){
            b.push_back(a[i]%x);
        }
        sort(b.rbegin(),b.rend());
        while(!b.empty()&&b.back()==0){
            b.pop_back();
        }
        reverse(b.begin(),b.end());
        int pt=0;
        cur=0;
        for(int i=0;i<(int)b.size();i++){
            while(b[i]>0){
                if(b.empty())break;
                if(x-b.back()==b[i]){
                    cur+=(x-b.back());
                    b[i]=0;
                    b.pop_back();
                    break;
                }
                if(b[i]>x-b.back()){
                    cur+=(x-b.back());
                    b[i]-=(x-b.back());
                    b.pop_back();
                }
                else if(b[i]<x-b.back()){
                    cur+=(b[i]);
                    b.back()+=b[i];
                    b[i]=0;
                }
            }
        }
        if(cur<=k){
            ans=max(ans,x);
        }
    }
    printf("%d\n",ans);
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
typedef long long lli;
typedef vector<lli> vec;
typedef vector<vec> mat;
 
const lli N = 6;
 
lli n, M, L;
 
mat mul(mat &A, mat &B){
  mat C(A.size(), vec(B[0].size()));
  for(lli i=0;i<A.size();i++){
    for(lli k=0;k<B.size();k++){
      for(lli j=0;j<B[0].size();j++){
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
      }
    }
  }
  return C;
}
 
mat pow(mat A, lli n){
  mat B(A.size(), vec(A.size()));
  for(lli i=0;i<A.size();i++){
    B[i][i] = 1;
  }
  while(n > 0){
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
 
lli dy[6] = {-1, -1, 0, 0, 1, 1};
lli dx[6] = {-1, 0, -1, 1, 0, 1};
 
int main(){
  int time = 0;
  while(cin >> n >> M >> L && (n|M|L)){
    int size = (2 * n - 1);
    mat dat(size, vec(size, -1));
    int d = 0;
    int t_size = n;
    for(int i=0;i<2*n-1;i++){
      int in;
      if(i >= n) d++;
      for(int j=0;j<t_size;j++){
        cin >> dat[i][j+d];
      }
      if(i + 1 < n) t_size++;
      else t_size--;
    }
    mat A(size*size, vec(size*size, 0));
    for(int i=0;i<size;i++){
      for(int j=0;j<size;j++){
        if(dat[i][j] == -1) continue;
        A[i*size+j][i*size+j] = 1;
        for(int k=0;k<6;k++){
          int ny = i + dy[k];
          int nx = j + dx[k];
          if(ny < 0 || ny >= size) continue;
          if(nx < 0 || nx >= size) continue;
          if(dat[ny][nx] == -1) continue;
          A[i*size+j][ny*size+nx] = 1;
        }
      }
    }
    mat B(size*size, vec(1, 0));
    for(int i=0;i<size;i++){
      for(int j=0;j<size;j++){
        B[i*size+j][0] = max(0LL, dat[i][j]);
      }
    }
    A = pow(A, L);
    A = mul(A, B);
    lli ans = 0;
    for(int i=0;i<A.size();i++){
      for(int j=0;j<A[i].size();j++){
        ans += A[i][j];
      }
    }
    cout << "Case " << ++time << ": " << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1696
n, ao, bo, co = map(int, input().split())
l = [int(input()) for _ in range(n)]

def solve(ln, a, b, c):
    if len(l) <= ln:
        if a * b * c > 0:
            return abs(ao - a) + abs(bo - b) + abs(co - c)
        else:
            return float("inf")
    
    x = l[ln]
    return min([
        solve(ln + 1, a, b, c),
        solve(ln + 1, a + x, b, c) + (10 if a > 0 else 0),
        solve(ln + 1, a, b + x, c) + (10 if b > 0 else 0),
        solve(ln + 1, a, b, c + x) + (10 if c > 0 else 0)
    ])
print(solve(0, 0, 0, 0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
#define mod ll(10e8+7)
using namespace std;
int main()
{
    ll n,k;
    cin>>n;
    vll vec(n);
    for(ll &x:vec) cin>>x;

    ll mean=0;
    for(ll x:vec) mean+=x;

    mean/=n;
    ll st1=0,st2=0;
    for(ll x:vec)
    {
        st1+=(x-mean)*(x-mean);
        st2+=(x-mean-1)*(x-mean-1);
    }
    cout<<min(st1,st2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
    #include <ext/pb_ds/assoc_container.hpp> // Common file  
    #include <ext/pb_ds/tree_policy.hpp>  
    #include <functional>
    #include <unistd.h>
    using namespace std; 
    using namespace std::chrono; 
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag,  
                tree_order_statistics_node_update>  
        ordered_set;  
    #define ll long long int 
    ll brr[200005];
    void addEdge(vector<ll> adj[], ll u, ll v) 
    { 
        adj[u].push_back(v); 
        adj[v].push_back(u); 
    } 
     
int main() 
{ 
	long double n;
	cin>>n;
	n/=3;
	 cout << fixed << setprecision(20)<<pow(n,3)<< endl; 
  return 0; 
} 


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,l;
    cin >> l >> n;

    vector<ll> a(n);

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

    vector<ll> reversea(n);

    for(int i = 0; i < n; i++){
        reversea[i] = l - a[n-i-1];
    }

    vector<ll> suma(n+1,0),sumr(n+1,0);

    for(int i = 1; i < n+1; i++){
        suma[i] = suma[i-1] + a[i-1];
        sumr[i] = sumr[i-1] + reversea[i-1];
    }

    ll ans = 0;

    for(int i = 0; i < n; i++){
        ll t = n-i;
        if(t%2 == 0){
            ll tmp = (suma[i + (t/2)] - suma[i])*2 + (t/2 - 1 < 0? 0 : sumr[t/2 - 1])*2 + (t/2 - 1 < 0? 0 :reversea[t/2-1]);
            ans = max(ans,tmp);
            tmp = (sumr[i + (t/2)] - sumr[i])*2 + (t/2 - 1 < 0? 0 : suma[t/2 - 1])*2 + (t/2 - 1 < 0 ? 0 : a[t/2-1]);
            ans = max(ans,tmp);
        }else{
            ll tmp = (suma[i + (t/2)] - suma[i])*2 + sumr[t/2]*2 + a[i + t/2];
            ans = max(ans,tmp);
            tmp = (sumr[i + (t/2)] - sumr[i])*2 + suma[t/2]*2 + reversea[i + t/2];
            ans = max(ans,tmp);
        }
    }

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

Measured memory_bytes: 6528
N = int(input())
w = list(map(int, input().split()))
c = [0]
for ww in w:
    c.append(c[-1] + ww)

ans = float('inf')
for i in range(N - 1):
    ans = min(ans, abs((c[-1] - c[i + 1]) - c[i + 1]))
print(ans)


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

int main(){
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i,n){
    cin >> w[i];
  }
  
  int ans = 1e9;
  for(int i=1;i<n;i++){
    int l = 0, r = 0;
    for(int j=0;j<i;j++) l += w[j];
    for(int k=i;k<n;k++) r += w[k];
    ans = min(ans,abs(l-r));
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = [a[i] - i - 1 for i in range(n)]

b = sorted(a)
if n % 2 != 0:
    b = b[n // 2]
else:
    b = (b[n // 2] + b[n // 2 - 1]) // 2

a = [abs(a[i] - b) for i in range(n)]
ans = sum(a)
print(ans)


Measured memory_bytes: 26020
#ABC137-B
#K, X = input().split()
#K = int(K)
#X = int(X)
K, X = map(int, input().split())#複数整数入力はこれ!
print(*list(range(X-(K-1), X+K) ))#複数出力はリストにして*つけて返す。/ range(a,b) = [a, a+1,...b-1]なので注意

Measured memory_bytes: 3060
#include <cstdio>
#include <vector>

using namespace std;

const int MAXN=2e5+10;

typedef long long int ll;

int color[MAXN];
ll N;
vector<int> graph[MAXN];

ll sizes[MAXN];
ll cnt[MAXN];
ll ans[MAXN];

void DFS(int cur,int parent){
    sizes[cur]=1;
    ll temp=cnt[color[cur]];

    for(auto adj:graph[cur]){
        if (adj==parent) continue;
        ll temp=cnt[color[cur]];
        DFS(adj,cur);
        sizes[cur]+=sizes[adj];
        ll diff=cnt[color[cur]]-temp;
        ll sz=sizes[adj]-diff;
        ans[color[cur]]-=sz*(sz-1)/2;
    }

    cnt[color[cur]]=temp+sizes[cur];

}

int main(){
    scanf("%lld",&N);
    for(int i=1;i<=N;i++) scanf("%d",color+i),ans[i]=N*(N-1)/2;

    for(int i=1;i<=N-1;i++){
        int s,e;
        scanf("%d%d",&s,&e);
        graph[s].push_back(e);
        graph[e].push_back(s);
    }

    DFS(1,1);

    for(int c=1;c<=N;c++){
        ll nxt=N-cnt[c];
        ans[c]-=nxt*(nxt-1)/2;
    }

    for(int i=1;i<=N;i++) ans[color[i]]++;

    for(int c=1;c<=N;c++) printf("%lld\n",ans[c]);

    return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

int n;
vector<int> dp(100001, -1);
vector<int> a;

int ans(int s) {
    if (s < a[0])
        return 0;
    else if (dp[s] != -1)
        return dp[s];

    for (int i = 0; i < n; i++) {
        if (a[i] <= s) {
            if (ans(s - a[i]) == 0) {
                dp[s] = 1;
                return 1;
            }
        }
    }
    dp[s] = 0;
    return 0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int k;
    cin >> k;
    for (int i = 0; i < n; i++) {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    if (ans(k))
        cout << "First";
    else
        cout << "Second";
    return 0;
}

Measured memory_bytes: 5376
import sys
from collections import deque
N = int(sys.stdin.readline())
lines = sys.stdin.readlines()

l = deque()
for i in range(N):
    command = lines[i].split()
    if command[0] == 'deleteFirst':
        l.popleft()
    elif command[0] == 'deleteLast':
        l.pop()
    elif command[0] == 'insert':
        l.appendleft(command[1])
    else:
        if command[1] in l:
            l.remove(command[1])
            
print(' '.join(map(str, l)))
    


Measured memory_bytes: 212256
#include <stdio.h>

typedef struct
{
	char enc;
	char dec;
} ENCODE;

ENCODE encode[100000000];

int main(void)
{
	int n, m;
	int i, j;
	char c;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
		for (i = 0; i < n; i++){
			scanf(" %c %c", &encode[i].enc, &encode[i].dec);
		}
		
		scanf("%d", &m);
		for (i = 0; i < m; i++){
			scanf(" %c", &c);
			
			for (j = 0; j < n; j++){
				if (c == encode[j].enc){
					c = encode[j].dec;
					break;
				}
			}
			printf("%c", c);
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 572
/* author: Tarek */ 
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
//typedef pair<int, int> pii;
//typedef pair<ll, int> pli;
//typedef pair<ll, ll> pll;
//typedef long double ld;
//#define mp make_pair
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++){
   cin>>a[i];
}
sort(a,a+n);
long  d=0;
for(int j=0;j<n-k;j++){
  d+=a[j];
}
cout<<d<<endl;
	return 0;
}



Measured memory_bytes: 1024
// B - Contest with Drinks Easy
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	vector<int> T(N+1);
	int all = 0;
	for(int i=1; i<N+1; i++){
		cin>>T[i];
		all += T[i];
	}

	int M; cin>>M;
	for(int i=1; i<M+1; i++){
		int p,x; cin>>p>>x;
		cout<< all-T[p]+x <<endl;;
	}
}


Measured memory_bytes: 256
import collections


if __name__ == '__main__':
    s = input()
    t = input()

    s_freq_values = list(collections.Counter(s).values())
    s_freq_values.sort()

    t_freq_values = list(collections.Counter(t).values())
    t_freq_values.sort()

    if t_freq_values == s_freq_values:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 4144
// Placing Marbles

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
	char s[3];
	for (int i = 0; i < 3; ++i){
		cin >> s[i];
	}
	cout << s[0]+s[1]+s[2] - 3*'0' << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  cin >> N;
  vector<int64_t> a(N + 1);
  irep(i, N) { cin >> a[i]; }

  vector<int64_t> U(N + 1), L(N + 1);
  U[N] = L[N] = a[N];
  rrep(i, N) {
    U[i] = a[i] + U[i + 1];
    L[i] = a[i] + (L[i + 1] + 1) / 2;
    if (U[i] < L[i]) {
      cout << -1 << endl;
      return 0;
    }
  }

  if (L[0] > 1 || U[0] < 1) {
    cout << -1 << endl;
    return 0;
  }

  L[0] = U[0] = 1;
  rep(i, N) {
    U[i + 1] = min(U[i + 1], 2 * (U[i] - a[i]));
    L[i + 1] = max(L[i + 1], L[i] - a[i]);
    if (U[i + 1] < L[i + 1]) {
      cout << -1 << endl;
      return 0;
    }
  }

  int64_t result = 0;
  irep(i, N) { result += U[i]; }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
 
 
int main(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
}

Measured memory_bytes: 256
N=int(input())
s = [input() for i in range(N)]

atama=[]
oshiri=[]

def is_unique(seq):
    return len(seq) == len(set(seq))



for i in s:
    atama.append(i[0])
    oshiri.append(i[-1])



oshiri=oshiri[-1:]+oshiri[:-1]

atama.pop(0)
oshiri.pop(0)

if oshiri==atama and is_unique(s)==True:
    print("Yes")
else:
    print("No")


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

int cps(string a, string b){
	int la = a.size();
	int lb = b.size();
	int m = min(la, lb);
	for(int i=0; i<m; i++){
		if(a[i] > b[i]) return 1;
		if(a[i] < b[i]) return -1;
	}
	if(la > lb) return 1;
	if(la < lb) return -1;
	return 0;
}

int main(){
	int n;
	cin >> n;
	
	int pt = 0, ph = 0;
	
	for(int i=0; i<n; i++){
		string a, b;
		cin >> a >> b;
		switch(cps(a, b)){
		case 1:
			pt += 3;
			break;
		case 0:
			pt++;
			ph++;
			break;
		case -1:
			ph += 3;
			break;
		}
	}
	cout << pt << " " << ph << endl;
	return 0;
}


Measured memory_bytes: 3224
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 2002;
const int S_MAX = 4000000;

int n;

int a[N_MAX];

bitset <S_MAX> dp;

int sum;

bitset <S_MAX> aux;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++)
        sum += a[i];
    dp[0] = true;
    for(int i = 1; i <= n; i++)
    {
        aux = dp;
        aux <<= a[i];
        dp |= aux;
    }
    for(int j = (sum + 1) / 2; j <= S_MAX; j++)
        if(dp[j] == true)
        {
            cout << j << "\n";
            return 0;
        }
    return 0;
}


Measured memory_bytes: 4644
N = int(input())
S = [input() for _ in range(N)]
S_ = [''.join(sorted(list(s))) for s in S]

from collections import Counter
c = Counter(S_)

ans = 0
for k,v in c.items():
  #print(k,v)
  ans += v*(v-1)//2

  
print(ans)

Measured memory_bytes: 26900
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
#define ll long long int
#define inf 999999999
#define maxn 100003
const ll mod = 1e9+7;
using namespace std;
int n, ar[maxn];
void code()
{
	string a;cin >> a;
	string b; cin >> b;
	int maxmatch = INT_MIN, n = a.length(),m = b.length(), j =0;
	while(j<= n - m)
	{
		int cnt = 0;
		for(int i = j, k=0; i < j+m && k<m ; i++,k++)
		{
			//no of matching
			if(a[i]==b[k])
			{
				cnt++;
			} 
		}
		maxmatch = max(maxmatch, cnt);
		j++;
	}
	cout << m-maxmatch << "\n";
}
int main()
{
	SPEED
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	int t = 1;
	while(t--)
	{
		code();
	}
}

Measured memory_bytes: 3636
#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>;
const ll INF = ll(1e18) + 1;

int main(){
  int n;ll k;
  cin >> n >> k;
  vector<ll>a(n);
  rep(i, n)cin >> a[i];
  sort(a.begin(), a.end());
  ll l = -INF, r = INF;
  while(l + 1 < r){
    ll x  = (l + r)/ 2;
    bool ok = [&]{
      ll tot = 0;
      rep(i, n){
        if (a[i] < 0){
          int l = -1, r = n;
          while(l + 1 < r){
            int c = (l + r)/ 2;
            if (a[c]*a[i] < x) r = c; else l = c;
          }
          tot += n - r;
        }else{
          int l = -1, r = n;
          while ( l+1 < r){
            int c = (l+r)/2;
            if (a[c]*a[i] < x) l = c; else r = c;
          }
          tot += r;
        }
        if (a[i]*a[i] < x) tot--;
      }
      tot /= 2;
      return tot < k;
    }();
    if (ok) l = x; else r = x;
  }
  cout << l << endl;
  return 0;
}

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

using namespace std;

#define LL long long int
#define FASTIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int oo = 1e9;
// const LL oo = 1e18;
// const int MOD = 1e9 + 7;
const int MOD = 998244353;
const int N = 5e5;
// const long double PI = acos(-1);

int v[N], cnt[N];
void solve() {
    int n, i;
    cin >> n;
    cout << (n-1)/2 << '\n';
}

int main() {
    // FASTIO; 
    int t = 1; 
    // cin >> t;
    for (int tc = 1; tc <= t; ++tc) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=100005;

void solve()
{
    string s;
    cin>>s;
    int n=s.length();
    int x=0;
    for(int i=0;i<n;i++)
    {
        x=x+s[i]-'0';
    }
    if(x%9)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
}
int32_t main()
{
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}





Measured memory_bytes: 3796
/*
    AUTHOR:shivam51
    IIESTS
*/
  #include<bits/stdc++.h>
  using namespace std;
  //
  #define add accumulate
  #define ll long long int
  #define ff first
  #define ss second
  #define pb push_back
  #define mp make_pair
  #define vll vector<ll>
  #define lb lower_bound
  #define ub upper_bound
  #define pll pair<ll,ll>
  #define vpll vector<pll>
  #define all(v) v.begin(), v.end()
  #define rep(i,k,n) for(int i=k;i<n;i++)
  #define hs ios_base::sync_with_stdio(false);cin.tie(NULL);
  const int md=1e8;
  const int MAX=1e5+1;
  //
  //
  int main(){
  	ll n,k;
  	cin>>n>>k;
  	int arr[n];
  	rep(i,0,n)
  		cin>>arr[i];
  	ll ans=-1*MAX;
   	priority_queue<int,vector<int>,greater<int>> q;
  	for(int i=0;i<=min(n,k);i++){
  		for(int j=0;i+j<=min(n,k);j++){
  			rep(p,0,i)
  				q.push(arr[p]);
  			rep(p,0,j)
  				q.push(arr[n-1-p]);
  			ll kk=k-i-j;
  			while(kk&&!q.empty()){
  				--kk;
  				if(q.top()>0)
  					break;
  				q.pop();
  			}
  			ll temp=0;
  			while(!q.empty()){
  				temp+=q.top();
  				q.pop();
  			}
  			ans=max(ans,temp);
  		}
  	}
  	cout<<ans;
  	return 0;
  }

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 200000
#define NO return puts("No"),0
#define YES return puts("Yes"),0
char str[MAXN+5];

int main(){
    int N=read(),A=read(),B=read(),C=read(),D=read();
    scanf("%s",str+1);
    for(int i=A;i<=max(C,D)-1;i++)
        if(str[i]=='#'&&str[i+1]=='#')
            NO;
    if(C<D)
        YES;
    for(int i=B-1;i<=D-1;i++)
        if(str[i]=='.'&&str[i+1]=='.'&&str[i+2]=='.')
            YES;
    NO;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;

#define LL long long
#define INF 0x3f3f3f3f3f3f3f3f
#define N 420000

LL n,m,x,y,f,ans,a[N],mn1[N*2],mn2[N*2],tag[N*2];

void pushdown(LL cur){
	mn1[cur<<1]+=tag[cur]; mn1[cur<<1|1]+=tag[cur];
	mn2[cur<<1]+=tag[cur]; mn2[cur<<1|1]+=tag[cur];
	tag[cur<<1]+=tag[cur]; tag[cur<<1|1]+=tag[cur];
	tag[cur]=0;
}

void update(LL cur){
	mn1[cur]=min(mn1[cur<<1],mn1[cur<<1|1]);
	mn2[cur]=min(mn2[cur<<1],mn2[cur<<1|1]);
}

void add(LL cur,LL l,LL r,LL L,LL R,LL k){
	if (l>=L && r<=R){mn1[cur]+=k; mn2[cur]+=k; tag[cur]+=k; return;}
	pushdown(cur); LL mid=(l+r)>>1;
	if (L<=mid) add(cur<<1,l,mid,L,R,k);
	if (R>mid) add(cur<<1|1,mid+1,r,L,R,k);
	update(cur);
}

LL min1(LL cur,LL l,LL r,LL L,LL R){
	if (l>=L && r<=R) return mn1[cur];
	pushdown(cur); LL mid=(l+r)>>1,tmp=INF;
	if (L<=mid) tmp=min(tmp,min1(cur<<1,l,mid,L,R));
	if (R>mid) tmp=min(tmp,min1(cur<<1|1,mid+1,r,L,R));
	return tmp;
}

LL min2(LL cur,LL l,LL r,LL L,LL R){
	if (l>=L && r<=R) return mn2[cur];
	pushdown(cur); LL mid=(l+r)>>1,tmp=INF;
	if (L<=mid) tmp=min(tmp,min2(cur<<1,l,mid,L,R));
	if (R>mid) tmp=min(tmp,min2(cur<<1|1,mid+1,r,L,R));
	return tmp;
}

void modify(LL cur,LL l,LL r,LL x,LL k){
	if (l==r){mn1[cur]=min(mn1[cur],k-x); mn2[cur]=min(mn2[cur],k+x); return;}
	pushdown(cur); LL mid=(l+r)>>1;
	if (x<=mid) modify(cur<<1,l,mid,x,k);
	if (x>mid) modify(cur<<1|1,mid+1,r,x,k);
	update(cur);
}

LL getans(LL cur,LL l,LL r){
	if (l==r) return mn1[cur]+l;
	pushdown(cur); LL mid=(l+r)>>1;
	return min(getans(cur<<1,l,mid),getans(cur<<1|1,mid+1,r));
}

int main(){
	scanf("%lld%lld%lld%lld",&n,&m,&a[1],&a[2]);
	memset(mn1,0x3f,sizeof mn1); memset(mn2,0x3f,sizeof mn2); modify(1,1,n,a[1],0);
	for (LL i=3;i<=m+2;i++){
		scanf("%lld",&a[i]);
		f=min(min1(1,1,n,1,a[i])+a[i],min2(1,1,n,a[i],n)-a[i]);
		add(1,1,n,1,n,abs(a[i]-a[i-1]));
		modify(1,1,n,a[i-1],f);
	}
	printf("%lld\n",getans(1,1,n));
	
	return 0;
}
			

Measured memory_bytes: 22784
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int k; cin>>k;

    queue<ll> que;
    for(int i=1; i<=9; i++) que.emplace(i);
    vector<ll> ans;
    while(ans.size() < k){
        ll cur = que.front(); que.pop();
        ans.emplace_back(cur);
        int rem = cur % 10;
        for(int i=0; i<=9; i++){
            if(abs(rem - i) <= 1){
                que.emplace(cur * 10 + i);
            }
        }
    }

    sort(all(ans));

    cout << ans[k-1] << endl;

    return 0;
}

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

int main() {
    int a, b;

    for (;;) {
        cin >> a >> b;
        if (a == 0 && b == 0) {
            return 0;
        }
        if (a > b) {
            cout << b << " " << a << endl;
        } else {
            cout << a << " " << b << endl;
        }
    };
}

Measured memory_bytes: 3076
///
// File:  alds1_6_b.cpp
// Author: ymiyamoto
//
// Created on Mon Oct  9 21:27:59 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
static vector<uint32_t> array;

static uint32_t partition(uint32_t p, uint32_t r)
{
  uint32_t index = 0;
  for (uint32_t i = p; i < r; i++) {
    if (array[i] <= array[r]) {
      swap(array[index], array[i]);
      index++;
    }
  }

  swap(array[index], array[r]);

  return index;
}
int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    uint32_t val;
    cin >> val;
    array.push_back(val);
  }

  uint32_t index = partition(0, array.size() - 1);
  for (uint32_t i = 0; i < array.size(); i++) {
    if (i != 0) cout << " ";
    if (i == index) {
      cout << "[" << array[i] << "]";
    } else {
      cout << array[i];
    }
  }

  cout << endl;

  return 0;
}

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

using namespace std;
int minEl, n;
vector<int> dp1, dp2;
bool play2(int k, vector<int> &A);
bool play1(int k, vector<int> &A){
    if(k < minEl) return 0;
    if(dp1[k] != -1) return dp1[k];
    for(int i = 0; i < A.size();++i){
        bool ans = play2(k - A[i], A);
        if(k - A[i] >= 0 && ans == 1) dp1[k] = 0;
        else if(k - A[i] >= 0 && ans == 0){
            dp1[k] = 1;
            break;
        }
    }
    if(dp1[k] != 0) return dp1[k] = 1;
    else return 0;
}
bool play2(int k, vector<int> &A){
    if(k < minEl) return 0;
    if(dp2[k] != -1) return dp2[k];
    for(int i = 0; i < A.size();++i){
        bool ans = play1(k - A[i], A); 
        if(k - A[i] >= 0 && ans == 1) dp2[k] = 0;
        else if(k - A[i] >= 0 && ans == 0){
            dp2[k] = 1;
            break;
        }
    }
    if(dp2[k] != 0) return 1;
    else return 0;
}
int main() {
   int n, k;
   cin >> n >> k;
   vector<int> A(n);
   minEl = INT_MAX;
   for(int i = 0;i < n;++i){
       cin >> A[i];
       minEl = min(minEl, A[i]);
   }
   dp1.clear(); dp2.clear();
   dp1.resize(k + 1, -1); dp2.resize(k + 1, -1);
   play1(k, A);
   if(dp1[k] == 1) cout << "First" << endl;
   if(dp1[k] == 0) cout << "Second" << endl;
   return 0;
}

Measured memory_bytes: 5760
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        int N = sc.nextInt();
        int A[] = new int[N];
        for(int i= 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        long allGcd = A[0];
        for(int i = 1; i < N; i++) {
            if(allGcd > A[i])
                allGcd = gcd(A[i], allGcd);
            else
                allGcd = gcd(allGcd, A[i]);
        }
        if(allGcd == 1) {
            Set<Integer> primeSet = new HashSet<>();
            for(int i = 0; i < N; i++) {
                Set<Integer> primes = primes(A[i]);
                for(Integer prime : primes) {
                    if(primeSet.contains(prime)){
                        os.println("setwise coprime");
                        return;
                    }
                    primeSet.add(prime);
                }
            }
            os.println("pairwise coprime");
        } else {
            os.println("not coprime");
        }
    }

    static public long gcd(long a, long b) {
        while(a > 0) {
            long tmpa = a;
            a = b % a;
            b = tmpa;
        }
        return b;
    }

    static public Set<Integer> primes(int A) {
        Set<Integer> ret = new HashSet<>();
        if (A % 2 == 0) {
            ret.add(2);
            while (A % 2 == 0) {
                A /= 2;
            }
        }
        for(int i = 3; i <= Math.sqrt(A); i+=2) {
            if (A % i == 0) {
                ret.add(i);
                while (A % i == 0) {
                    A /= i;
                }
            }
        }
        if(A != 1)
            ret.add(A);
        return ret;
    }
}

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

void solve() {
    ll k;
    cin>>k;
    queue<ll> q;
    for(int i=1; i<=9; ++i) q.push(i);
    k--;
    while(k--) {
        ll x=q.front();
        q.pop();
        if(x%10!=0) q.push(10*x + x%10 - 1);
        q.push(10*x + x%10);
        if(x%10!=9) q.push(10*x + x%10 + 1);
    }
    cout<<q.front()<<"\n";
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
    return 0;
}

Measured memory_bytes: 1792
import math
import sys
sys.setrecursionlimit(1000000)
dp = [-1]*(100*1000+1)
tab = [[] for x in range(100*1000+1)]

def get_max(root):
    if(dp[root] > -1): return dp[root]
    
    mi = 0
    for nei in tab[root]:
        mi = max(mi,get_max(nei)+1)
    dp[root] = mi
    return dp[root]
def main():
    n,m = map(int,input().split())
    
    for x in range(m):
        a,b = map(int,input().split())
        a-=1;b-=1
        tab[a].append(b)
    
    for x in range(n):
        get_max(x) 
    
    print(max(dp))
main()

Measured memory_bytes: 135628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int A,B;
    cin >> A >> B;
    vector<vector<char>> ret(100,vector<char>(100));
    for(int i = 0;i < 100;i++) {
        for(int j = 0;j < 100;j++) {
            if(i % 2 == 0) {
                ret.at(i).at(j) = '#';
            }
            else {
                ret.at(i).at(j) = '.';
            }
        }
    }
    for(int i = 0;i < 100;i++) {
        ret.at(i).at(0) = '#';
    }
    for(int i = 0;i < 100;i++) {
        ret.at(i).at(99) = '.';
    }
    int cntb = 0;
    for(int i = 1;i < 100;i += 2) {
        bool count = true;
        for(int j = 2;j < 99;j += 2) {
            if(cntb == A - 1) {
                count = false;
                break;
            }
            ret.at(i).at(j) = '#';
            cntb++;
        }
        if(count == false) {
            break;
        }
    }
    int cnta = 0;
    for(int i = 98;i >= 0;i -= 2) {
        bool count = true;
        for(int j = 97;j > 0;j -= 2) {
            if(cnta == B - 1) {
                count = false;
                break;
            }
            ret.at(i).at(j) = '.';
            cnta++;
        }
        if(count == false) {
            break;
        }
    }
    cout << 100 << " " << 100 << endl;
    for(int i = 0;i < 100;i++) {
        for(int j = 0;j < 100;j++) {
            cout << ret.at(i).at(j);
        }
        cout << endl;
    }
}

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

int main()
{
	int N =0;
	std::cin >> N;

	std::vector<int> a(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a.at(i);
	}

	int cnt = 0;
	bool odd = false;
	while (1) {
		for (int x : a) {
			x = x % 2;
			if (x != 0) {
				odd = true;
			}
		}

		if (odd == true) {
			break;
		}

		for (int &x : a) {
			x /= 2;
		}

		cnt++;

	}

	std::cout << cnt << std::endl;
	
	return 0;
}

Measured memory_bytes: 256