akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint p(n);
    REP(i,n){
         cin >> p[i];
         p[i]--;
    }
    int cnt = 0;
    REP(i,n){
        if(p[i]!=i){
            cnt++;
            if(p[p[i]]!=i){
                cout << "NO\n";
                return 0;
            }else if(cnt>1){
                cout << "NO\n";
                return 0;
            }
            p[p[i]] = p[i];
            p[i] = i;
        }
    }
    cout << "YES\n";
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

ll n,k;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[400005],R[400005];
void make(){
	F[0] = 1;
	for(int i=1;i<400005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<400005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int main(){
	cin>>n>>k;
	ll ans = 0;
	make();
	for(int zero=0;zero<=min(n-1,k);zero++){
		int zan = n-zero;
		ans += C(n,zero) * C(n-1,zan-1) % mod;
	}
	cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    n=1,x=1;
    while(1){
    cin>>n>>x;
    if(n==0&&x==0) return 0;
    REP(i,1,n-1){
        REP(j,i+1,n){
            REP(k,j+1,n+1){
                if(i+j+k==x) sum++;
        
    } 
    }
    }
    cout<<sum<<endl;
    sum=0;
    }

    return 0;
}


Measured memory_bytes: 3176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		
		int[] a = new int[n];
		int[] b = new int[m];

		int mina = 999999999;
		int minb = 999999999;
		int ans;
		
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextInt();
			mina = Math.min(a[i], mina);
		}
		
		for(int i = 0; i < m; i++)
		{
			b[i] = sc.nextInt();
			minb = Math.min(b[i], minb);
		}
		ans = mina + minb;
		
		for(int i = 0; i < k; i++)
		{
			int ca = sc.nextInt()-1;
			int cb = sc.nextInt()-1;
			int c = sc.nextInt();
			ans = Math.min(ans, a[ca]+b[cb]-c);
		}
		System.out.println(ans);

	}

}


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

#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for (int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);

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

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

    int N, H, W;
    cin >> H >> W >> N;

    int x, y;
    cin >> x >> y;

    int ans = 0;

    REP(i, N - 1)
    {
        int inx, iny;
        cin >> inx >> iny;

        if((x <= inx && iny <= y) || (inx <= x && y <= iny))
        {
            ans += abs(x - inx) + abs(y - iny);
        }
        else
        {
            int dx = abs(inx - x), dy = abs(iny - y);

            ans += min(dx, dy) + abs(dx - dy);
        }
        
        x = inx;
        y = iny;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3120
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	size := int(scanInt(sc))
	ns := make([]int64, size)
	for i := 0; i < size; i++ {
		ns[i] = scanInt(sc)
	}

	possible := "Yes"
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		} else if max-ns[i] > 1 {
			possible = "No"
			break
		}
	}

	fmt.Println(possible)
}

func scanInt(sc *bufio.Scanner) int64 {
	sc.Scan()
	v, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return v
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define eps 1e-9
#define all(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

const int INF = 1000000;
 
struct Edge 
{
    int to, cap, rev;
    Edge(int to, int cap, int rev) : to(to), cap(cap), rev(rev) {}
};
 
vector<Edge> G[410];
bool h[410];
 
void add_edge(int from, int to, int cap) 
{
    G[from].pb(Edge(to, cap, G[to].size()));
    G[to].pb(Edge(from, 0, G[from].size() - 1));
}
 
int dfs(int v, int t, int f) 
{
    if (v == t) return f;
    h[v] = true;
    for (int i = 0; i < G[v].size(); i++) 
    {
        Edge &e = G[v][i];
        if (!h[e.to] && e.cap > 0) 
        {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) 
            {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
 
int max_flow(int s, int t) 
{
    int flow = 0;
    while (1) 
    {
        memset(h, 0, sizeof(h));
        int f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}
 
int main() 
{
	int H, W;
	H = read();
	W = read();
	rep(i, 0, H - 1)
	{
		string a;
		cin >> a;
		rep(j, 0, W - 1)
		{
			if (a[j] == 'S') 
			{
				add_edge(0, i + 1, INF);
				add_edge(0, H + j + 1, INF);
			}
			else if (a[j] == 'T')
			{
				add_edge(i + 1, H + W + 1, INF);
				add_edge(H + j + 1, H + W + 1, INF);
			} 
			else if (a[j] == 'o') 
			{
				add_edge(i + 1, H + j + 1, 1);
				add_edge(H + j + 1, i + 1, 1);
			}
		}
	}
	int ans = max_flow(0, H + W + 1);
	cout << (ans >= INF ? -1 : ans) << endl;
	return 0;
}


Measured memory_bytes: 896
#!/usr/bin/env python3
import sys

MOD = 5  # type: int
YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(A: int, B: int, C: int):
    from fractions import gcd
    return YES if C % gcd(A, B) == 0 else NO


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    print(solve(A, B, C))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 5972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
// const ll MOD=998244353;

int main(){
  int N; cin>>N;
  int V[N]; rep(i,N) cin>>V[i];
  sort(V,V+N);
  double ans=V[0];
  rep(i,N-1){
    ans=(ans+V[i+1])/2;
  }
  cout<<setprecision(15);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
         
        using namespace std;
		#define INF 100000000997
        typedef long long ll;
		
        int main(){
          ll n,w;
          cin>>n>>w;
          ll a[n][2];
          ll sum=0;ll mv=0;
          for(int i=0;i<n;i++){cin>>a[i][0]>>a[i][1];mv+=a[i][1];}
          ll dp[n+1][mv+1];
          for(int i=0;i<=n;i++){
			for(int j=0;j<=mv;j++){if(j==0){dp[i][j]=0;continue;}dp[i][j]=INF;}}
          
          for(int i=1;i<=n;i++){
			for(int j=0;j<mv+1;j++){
              if(j==0){dp[i][j]=0;continue;}
              	if(j<a[i-1][1])dp[i][j]=dp[i-1][j];
              else{
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-a[i-1][1]]+a[i-1][0]);}
            }
          }
          ll in;
          for(int i=0;i<mv+1;i++){
			if(dp[n][i]<=w)in=i;
          }
          cout<<in<<endl;
        }

Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 要素の入力、格納
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		// 出力
		if((B-A)%2==0){
			System.out.println("Alice");
		}else{
			System.out.println("Borys");
		}
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,m;cin >> n >>m;
    ll ans=0;
    rep(i,m){
        ll a;cin >> a;
        ans+=a;
    }
    if(n-ans>=0)cout << n-ans <<endl;
    else cout << -1 <<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, j, maxi = 0, cnt = 0, cnt1 = 0;
    scanf("%d", &n);
    int a[n];
    for (i=0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (i=0; i<n; i++) {
        if (a[i] % 2 == 0) {
            if ((a[i] % 3) && (a[i] % 5)) {
                printf("DENIED\n");
                return 0;
            }
        }
    }
    printf("APPROVED\n");
    return 0;
}


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(n: usize, a: [usize1; n - 1]);

    let mut tree = vec![vec![]; n];
    for i in 0..(n - 1) {
        tree[a[i]].push(i + 1);
    }

    println!("{}", dfs(0, &tree) - 1);
    // println!("{:?}", tree);
}

fn dfs(v: usize, tree: &Vec<Vec<usize>>) -> usize {
    let mut children = vec![];
    for &child in tree[v].iter() {
        let child = dfs(child, tree);
        children.push(child);
    }
    children.sort();
    children.reverse();
    let max = children.iter().enumerate().map(|(i, c)| c + i + 1).max();
    match max {
        Some(max) => max,
        _ => 1,
    }
}


Measured memory_bytes: 32764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<typename T>
struct Doubling {
private:
    const int LOG;
    vector<vector<T>> table;
    
public:
    Doubling(int n, long long mv) : LOG(64 - __builtin_clzll(mv)) {
        table.resize(LOG, vector<T>(n, -1));
    }
    
    void set_next(int k, T x) {
        table[0][k] = x;
    }
    
    void build() {
        for(int k = 0; (k + 1) < LOG; k++) {
            for(int i = 0; i < table[k].size(); i++) {
                if (table[k][i] == -1) {
                    table[k + 1][i] = -1;
                }
                else {
                    table[k + 1][i] = table[k][table[k][i]];
                }
            }
        }
    }
    
    T query(int k, long long t) {
        for(int i = LOG - 1; i >= 0; i--) {
            if ((t >> i) & 1) {
                k = table[i][k];
            }
        }
        return k;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    Doubling<ll> dbl(n, k);
    rep(i, n) dbl.set_next(i, a[i] - 1);
    dbl.build();
    cout << (dbl.query(0, k) + 1) << endl;
    return 0;
}


Measured memory_bytes: 100028
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll i, temp,t, n,j, a[200600], ans, k;
bool cond;
list<char>L;
list<char>::iterator it;
string s;
char c;
int main()
{
    //I am Monim, a tiny creature of Allah
    cin >> s;
    temp = s.size();
    for(i=0;i<temp;i++)
    {
        L.push_back(s[i]);
    }
    cin >> n;
    cond = true;
    for(i=0;i<n;i++)
    {
        cin >> j;
        if(j==2)
        {
            cin >> k >> c;
            if(cond)
            {
                if(k==1)
                    L.push_front(c);
                else
                    L.push_back(c);
            }
            else{
                if(k==1)
                    L.push_back(c);
                else
                    L.push_front(c);
            }
        }
        else{
            cond = 1-cond;
        }
    }
    if(!cond)
        reverse(L.begin(), L.end());
    for(it=L.begin();it!=L.end();it++)
            cout << *it;
    return 0;
}


Measured memory_bytes: 13060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//long longのシフト演算には気をつけよう

int main(){
    int N, K; cin >> N >> K;
    vector<pair<ll, ll>> A(N);
    for(int i=0; i<N; i++){
        ll t; cin >> t;
        ll d; cin >> d;
        A[i] = {d, t};
    }

    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    ll dsum = 0;
    map<ll, ll> ma;

    for(int i=0; i<K; i++){
        dsum += A[i].first;
        ma[A[i].second]++;
    }

    ll ans = dsum + ma.size()*ma.size();
    int r = K-1;
    for(int i=K; i<N; i++){
        if(ma[A[i].second] != 0) continue;

        while(ma[A[r].second] == 1 && r >= 0) r--;
        if(r == -1) break;

        ma[A[r].second]--;
        ma[A[i].second]++;
        dsum = dsum + A[i].first - A[r].first;
        ll tmp = dsum + ma.size()*ma.size();
        ans = max(ans, tmp);
        r--;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long N, std::vector<long long> A)
{
    ll minus = 0;
    ll minimum = LONG_MAX;
    ll absMax = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] < 0)
        {
            minus++;
        }
        minimum = min(minimum, abs(A[i]));
        absMax += abs(A[i]);
    }

    if (minus % 2 == 0)
    {
        cout << absMax << endl;
    }
    else
    {
        cout << absMax - (minimum * 2) << endl;
    }
}

int main()
{
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

typedef long long ll;
//{
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define sysp system("pause")
//}

#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}
inline long long digitsum(long long v){long long d=0;while(v){d+=v%10;v/=10;}return d;}
inline long long digitnumbersum(long long a){long long b=0;while(a){a/=10;b++;}return b;}
inline long long mysqrt(long long a){long long i=0;for(i=1;a>0;i++){a-=i*2+1;}return i-1;}
//}

long long n,ans,sum;

int main(){
	ans=999999999999999;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=-100;i<=100;i++){
		sum=0;
		for(int j=0;j<n;j++){
			sum+=(a[j]-i)*(a[j]-i);
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
	system("pause");
}
 

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

stack<int>B;

void func(int x, int n) {
    for (int i = 0; i < n; i++) {
        B.push(x%2);
        x = x / 2;
    }
}

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int>C(N);
    vector<vector<int>>A(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        cin >> C.at(i);
        for (int j = 0; j < M; j++) {
            cin >> A.at(i).at(j);
        }
    }
    vector<int>s(M);
    int c, ans = -1;
    bool check;
    for (int i = 0; i < pow(2, N); i++) {
        for (int j = 0; j < M; j++) {
            s.at(j) = 0;
        }
        c = 0;
        check = true;
        func(i, N);
        for (int j = 0; j < N; j++) {
            if (B.top() == 0) {
                for (int k = 0; k < M; k++) {
                    s.at(k) += A.at(j).at(k);
                }
                c += C.at(j);
            }
            B.pop();
        }
        for (int j = 0; j < M; j++) {
            if (s.at(j) < X) {
                check = false;
                break;
            }
        }
        if (check) {
            if (ans != -1) {
                ans = min(ans, c);
            }
            else {
                ans = c;
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010
int f[MAXN];
int a[MAXN];
int n;
int main()
{
	cin>>n;
	memset(f,0x3f,sizeof f);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	f[0]=0;
	for(int i=1;i<n;i++)
	{
		f[i]=min(f[i],f[i-1]+abs(a[i]-a[i-1]));
		if(i>1) f[i]=min(f[i],f[i-2]+abs(a[i]-a[i-2]));
	}
	if(n<=2) cout<<abs(a[0]-a[1]);
	else cout<<f[n-1];
//	for(int i=0;i<n;i++) cout<<f[i]<<' ';
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(ll i=(a);i<ll(b);i++)
#define rep(i,b) loop(i,0,b)
#define eb emplace_back

typedef int Weight;
struct Edge {
    int src, dst;
    int event;
    Edge(int src_, int dst_, int event_) :
        src(src_), dst(dst_), event(event_) { }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

int const inf = 1e8;

int N,M,E,S,T,R;
int ev[110];
Graph g;

int bfs(){
    typedef tuple<int,int,int,int> State;
    queue<State> q;
    q.emplace(0,0,S,0);
    static int dp[111][111][111];
    fill((int*)dp,(int*)dp+111*111*111,inf);
    dp[0][S][0] = 0;
    q.emplace(0,0,S,0);
    int ans = -1;
    while(q.size()){
        int d1,d2,v,e;
        tie(d1,d2,v,e) = q.front();
        q.pop();
        if(v==T){
            ans = d1;
            break;
        }
        int nxe = e;
        if(ev[v]!=-1) nxe |= 1<<ev[v];
        for(auto & edge : g[v]){
            if(edge.event!=-1 && ~nxe>>edge.event&1) continue;
            int nxd1 = d1+1;
            int nxd2 = edge.dst==S ? 0 : d2+1;
            if(nxd2 > R) continue;
            if(dp[nxd2][edge.dst][nxe] > nxd1){
                dp[nxd2][edge.dst][nxe] = nxd1;
                q.emplace(nxd1,nxd2,edge.dst,nxe);
            }
        }
    }
    return ans;
}

int main(){
    cin >> N >> M >> E >> S >> T >> R;
    g.assign(N,{});
    rep(i,M){
        int a,b;
        cin >> a >> b;
        g[a].eb(a,b,-1);
        g[b].eb(b,a,-1);
    }
    rep(i,N) ev[i] = -1;
    rep(i,E){
        int a,b,c;
        cin >> a >> b >> c;
        g[a].eb(a,b,i);
        g[b].eb(b,a,i);
        ev[c] = i;
    }
    rep(i,N){
        if(i==S) continue;
        g[i].eb(i,S,-1);
    }
    cout << bfs() << endl;
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

ll n, m;
vector<ll> a, dp;

ll f(ll v) {
    ll ans = 0;
    rep(i, n) {
        ans += n - (lower_bound(all(a), v - a[i]) - a.begin());
    }
    return ans;
}

ll g(ll v) {
    ll ans = 0;
    rep(i, n) {
        ll idx = lower_bound(all(a), v - a[i]) - a.begin();
        ans += dp[n] - dp[idx] + (n - idx) * a[i];
    }
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n >> m;
    a.resize(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    dp.resize(n + 1);
    rep(i, n) dp[i + 1] = dp[i] + a[i];
    ll l = 0, h = LONG_LONG_MAX / 2 - 1;
    while((l + 1) < h) {
        ll x = (l + h) / 2;
        if (f(x) > m) l = x;
        else h = x;
    }
    ll ans = g(h) + (m - f(h)) * l;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
int main(void)
{
        //aとbを格納
        int a,b;
        //scanfでaとbを取得
        scanf("%d %d",&a, &b);
        //bよりaの方が大きければ、a > bを出力
        if(a > b){
        	printf("a > b\n");
        } 
		//bよりaの方が小さければ、a > bを出力
        else if(a < b){
        	printf("a < b\n");
        }
		//aとbが等しければ、 a == bと出力
        else{
        	printf("a == b\n");
        }
        return 0;
}


Measured memory_bytes: 2112
#!/usr/bin/env python3

def main():
    N, Ma, Mb = map(int, input().split())
    a = [None] * N
    b = [None] * N
    c = [None] * N
    for i in range(N):
        a[i], b[i], c[i] = map(int, input().split())

    INF = 10**12
    dp = [[[INF] * 401 for _ in range(401)] for _ in range(N+1)]
    dp[0][0][0] = 0

    for i in range(N):
        for j in range(400,-1,-1):# 後ろから更新すること
            for k in range(400,-1,-1):
                dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k])
                if j - a[i] >= 0 and k - b[i] >= 0:
                    dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j-a[i]][k-b[i]]+c[i])
    
    ans = INF
    for j in range(400):
        for k in range(400):
            if j*Mb == k*Ma != 0:
                ans = min(ans,dp[N][j][k])
    print(ans) if ans < INF else print(-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 127232
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;

int main(){
  ll n;cin>>n;
  int mod=1000000007;
  ll dp[n+1];
  dp[0]=1;
  dp[1]=n;
  dp[2]=n*n %mod;
  rep(i,n-2){
    dp[i+3]=(2*dp[i+2]-dp[i+1]+dp[i]-1)%mod;
    if(dp[i+3]<0)dp[i+3]+=mod;
    }
  cout<<dp[n]<<endl;
  return 0;
  }

  
    


Measured memory_bytes: 8064
#include<stdio.h>
#define MAX 2000000
#define MIN -1

void swap(int A[],int a,int b){
int temp;

temp=A[a];
A[a]=A[b];
A[b]=temp;

return;
}


void insert(int A[],int last){
int i=last;

while(i!=1){
 if(A[i]>A[i/2]){swap(A,i,i/2); i=i/2;}
 else{return;}
}

return;
}




void sort(int A[],int i){
if(i*2>MAX){return;}
if(A[i]>A[2*i]&&A[i]>A[2*i+1])return;

else if(A[2*i]>A[2*i+1]){swap(A,i,2*i);i=i*2;sort(A,i);}
else if(A[2*i]<A[2*i+1]){swap(A,i,2*i+1);i=i*2+1;sort(A,i);}
else if(A[2*i]==A[2*i+1]&&A[i]<A[2*i]){swap(A,i,2*i);i=i*2;sort(A,i);}
return;
}



void deletemax(int A[],int *last){
int i=1;

printf("%d\n",A[1]);

swap(A,1,(*last));
A[*last]=MIN;
(*last)--;

sort(A,1);

return;
}





int main(){
int n,i;
int A[MAX];
int last;
char com[6];
int a;


for(i=0;i<=MAX;i++)A[i]=MIN;

a=1;
last=0;

while(a>0){
 scanf("%s",com);

 switch(com[2]){
  case 'd':/*end*/
           a=0;
           break;

  case 's':/*insert*/
           last++;
           scanf("%d",&A[last]);
           insert(A,last);
           break;

  case 't':/*extract*/
           deletemax(A,&last);
           break;
 }/*switch end*/

}/*for end*/



return 0;
}


Measured memory_bytes: 9612
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int d, n;
    cin >> d >> n;

    if (n != 100)
    {
        cout << n * (int)pow(100, d) << "\n";
    }
    else
    {
        cout << 101 * (int)pow(100, d) << "\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

int used[100001] = {0};
vector<pair<int,int>> m1[100001];
int ans[100001];
int q,k;

void get_r(int x,int d){
    ans[x] = d;
    if(m1[x].size() == 0)return;
    for(auto v : m1[x]){
        if(used[v.fi] == 0){
            used[v.fi] = 1;
            get_r(v.fi,d + v.se);
        } 
    }
}



signed main(){

    //vector<pair<int,int>> m2[10001];

    int n;
    cin >> n;
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        m1[a].pb(MP(b,c));
        m1[b].pb(MP(a,c));
    }
    rep(i,100001) ans[i] = INF;

    cin >> q >> k;

    used[k] = 1;
    get_r(k,0);

    rep(i,q){
        int X,Y;
        cin >> X >> Y;
        cout << ans[X] + ans[Y] <<endl;
    }







    

    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 13568
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, sum = 0;
ll A[500000] = {}, B[500000] = {}, C[500000] = {}, dp[100][10] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S, T;
bool check = false, check2 = false;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int main() {

	//Code Line
	cin >> n;
	for (int i = 0; i < n; i++)cin >> A[i];
	for (int i = 0; i < n; i++)cin >> B[i];
	for (int i = 0; i < n - 1; i++)cin >> C[i];

	for (int i = 0; i < n; i++) {
		sum += B[A[i] - 1];
			if (A[i + 1] == A[i] + 1 && i < n-1)sum += C[A[i]-1];
			
	}
	cout << sum << endl;

	return 0;
}




Measured memory_bytes: 4352
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = n - 1; i>= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;

const int MAXN = 100005;
ll mod=1000000007;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(s.size() > n){
		cout<<s.substr(0,n)<<"..."<<nl;
	}
	else{
		cout<<s<<nl;
	}
	return 0;
}



Measured memory_bytes: 3616
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1-i):
        k = N-i-j
        if Y - (i * 10000 + j * 5000 + k * 1000) == 0:
            print(i, j, k)
            exit()
print(-1, -1, -1)

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

using namespace std;

int main()
{   
 	int n;
 	cin>>n;
 	int score1=0,score2=0;
 	for(int i=1;i<=n;i++)
 	{
 		string a,b;
 		cin>>a>>b;
 		
 			if(a>b){score1+=3;}
 			if(a<b){score2+=3;}
 			if(a==b){score1++;score2++;}
 		
	 	
  	} 
  	cout<<score1<<" "<<score2<<endl;

	return 0;
}


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

char s[32][32];
int cnt;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

void dfs(int y, int x)
{
	cnt++;
	s[y][x]=0;
	for(int i=0; i<4; i++)
	{
		int ny=y+dy[i];
		int nx=x+dx[i];
		if(s[ny][nx]=='.')
			dfs(ny,nx);
	}
}

int main()
{
	int w,h;
	while(cin >> w >> h, w||h)
	{
		cnt = 0;
		memset(s,0,sizeof(s));
		for(int i=1; i<=h; i++)
		{
			cin >> s[i]+1;
		}

		for(int i=1; i<=h; i++)
		for(int j=1; j<=w; j++)
		if(s[i][j]=='@')
		{
			dfs(i,j);
			break;
		}
		cout << cnt << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdbool.h>
#define LEN 3

int are_all_positive(int a[LEN], int b[LEN])
{
	return ((a[0] >= 0) && (a[1] >= 0) && (a[2] >= 0) && (b[0] >= 0) && (b[1] >= 0) && (b[2] >= 0));
}

int is_matched(int a[LEN], int b[LEN], int c[LEN][LEN])
{
	return ((c[0][1] == a[0] + b[1]) && (c[0][2] == a[0] + b[2]) && (c[1][2] == a[1] + b[2]) && (c[2][0] == a[2] + b[0]));
}

int main()
{
	int c[LEN][LEN];
	int a[LEN], b[LEN];
	bool is_correct = false;

	for (int i = 0; i < LEN; i++) {
		scanf("%d %d %d", &c[i][0], &c[i][1], &c[i][2]);
	}

	a[0] = 0;
	while (1) {
		if (a[0] > c[0][0]) goto RESULT;
		b[0] = c[0][0] - a[0];
		a[1] = c[1][0] - b[0];
		b[1] = c[1][1] - a[1];
		a[2] = c[2][1] - b[1];
		b[2] = c[2][2] - a[2];

		if (!is_matched(a, b, c)) goto INCREMENT;
		if (are_all_positive(a, b)) {
			is_correct = true;
			goto RESULT;
		}
		INCREMENT:a[0]++;
	}

	RESULT:if (is_correct == true) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m,a,b,c,d,e,g,i,j,k,f,t;
int A,B,C,X,Y,Z;
long long MIN ,ans,mid;
char str[3];

int main()
{
	a=0;
	b=0;
	scanf("%s",str);
	for(i=0;i<3;i++)
	{
		if(str[i]=='A') a=1;
		if(str[i]=='B') b=1;
	}
	if(a==1&&b==1) printf("Yes\n");
	else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    A=[list(map(int,input().split())) for _ in range(h)]
    B=[list(map(int,input().split())) for _ in range(h)]

    d=abs(A[0][0]-B[0][0])
    ofs=12800
    dp=[[0]*w for _ in range(h)]
    dp[0][0]=(1<<(ofs+d))|(1<<(ofs-d))

    from itertools import product
    for i,j in product(range(h),range(w)):
        if(i==0 and j==0): continue
        d=abs(A[i][j]-B[i][j])
        if(i>0):
            dp[i][j]|=(dp[i-1][j]<<d)|(dp[i-1][j]>>d)
        if(j>0):
            dp[i][j]|=(dp[i][j-1]<<d)|(dp[i][j-1]>>d)

    for i in range(ofs):
        if((dp[-1][-1]>>(i+ofs))&1):
            print(i)
            return
resolve()

Measured memory_bytes: 56412
import functools
n, x = map(int, input().split())
a = [0] + list(map(int, input().split()))

result = 0

def f(a, b):
    global result
    d = max(0, (b + a) - x)
    result += d
    return max(0, b - d)

functools.reduce(f, a)
print(result)


Measured memory_bytes: 14652
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
vector<ll> vectorprime(ll x){
    vector<bool> is_prime(x+1);
    vector<ll> prime;
    rep(i,x+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(ll i=2;i<=x;i++){
        if(is_prime[i]){
            prime.pb(i);
        }
        for(int j=i*2;j<=x;j+=i) is_prime[j]=false;
    }
    return prime;
}
map<ll,ll> prime_factor(ll x){
    map<ll,ll> m;
    ll sq=(ll)sqrt(x) + 1;
    vector<ll> v_prime=vectorprime(sq);
    
    ll tmp=x;
    rep(i,sz(v_prime)){
        ll count=0;
        while(tmp % v_prime[i] == 0){
            tmp /= v_prime[i];
            count++;
        }
        if(count != 0) m[v_prime[i]]=count;
        if(tmp==1) break;
    }
    
    if(tmp != 1) m[tmp]=1;
    return m;
}


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll A,B; cin>>A>>B;
    ll L=gcd(A,B);
    map<ll,ll> m=prime_factor(L);
    cout<<sz(m)+1<<endl;
}



Measured memory_bytes: 4260
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;

int main(){
  int n;
  cin >> n;
  cout << (1000-((n-1)%1000+1));
  
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define ld long double
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

int modpow(int a, int n, int mod) {
    int res=1;
    while(n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int x,y; cin >> x >> y;
    if((x+y)%3!=0){
        cout<<0<<endl;

        return 0;
    }

    if(2*x-y<0 || 2*y-x<0){
        cout<<0<<endl;
        return 0;
    }

    int a=(2*y-x)/3;
    int b=(2*x-y)/3;

    int res=1;

    //cout<<a<<' '<<b<<endl;
    /*
    for(int i=1; i<=(a+b); i++){
        res=res*(i%MOD);
        res%=MOD;
    }
    for(int i=1; i<=min(a,b); i++){
        res*=modpow(i,MOD-2,MOD);
        res%=MOD;
    }
    for(int i=1; i<=max(a,b); i++){
        res*=modpow(i,MOD-2,MOD);
        res%=MOD;
    }
    */

   for(int i=b+1; i<=a+b; i++){
       res=res*(i%MOD);
       res%=MOD;
   }
   for(int i=1; i<=a; i++){
       res*=modpow(i,MOD-2,MOD);
       res%=MOD;
   }
    
    cout<<res<<endl;
}

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

string get_ans(string sd, string t, int offset)
{
    string res = "";
    rep(i, 0, sd.size())
    {
        if (offset <= i and i < offset + t.size())
            res += t[i - offset];
        else
        {
            if (sd[i] == '?') res += 'a';
            else res += sd[i];
        }
    }
    return res;
}

int main()
{
    string sd, t;
    cin >> sd;
    cin >> t;

    string ans = "";
    rep(i, 0, sd.size() - t.size() + 1)
    {
        bool ok = true;
        rep(j, 0, t.size())
            ok &= sd[i + j] == t[j] or sd[i + j] == '?';

        if(ok)
        {
            string cand = get_ans(sd, t, i);

            if (ans.size() == 0)
                ans = cand;
            else if (ans == cand)
            {
                ans = "";
                break;
            }
            else if (ans > cand) 
                ans = cand;
        }
    }

    if (ans == "")
        cout << "UNRESTORABLE" << endl;
    else
        cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ld long double
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactive problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main(){ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);

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

    reverse(b, b+n);

    ll c=-1;
    for (int i = 0; i < n; ++i)
    {
        if(a[i]==b[i]){
            c=b[i];
            break;
        }
    }

    if(c==-1){
        cout<<"Yes"<<endl;
        for (int i = 0; i < n; ++i)
        {
            cout<<b[i]<<" ";
        }
        cout<<endl;
        return 0;
    }

    ll l=-1;
    for (int i = 0; i < n; ++i)
    {
        if(a[i]==c && b[i]==c){
            l=i;
            break;
        }
    }

    ll r = -1;
    for (int i = 0; i < n; ++i)
    {
        if(a[i]==c && b[i]==c){
            r=i;
        }
    }


    for (int i = 0; i < n; ++i) {
        if (a[i] != c && b[i] != c && l <= r) {
            swap(b[i], b[l]);
            ++l;
        }
    }

    if(l<=r){
        cout<<"No";
        return 0;
    }

    cout<<"Yes"<<endl;
    for (int i = 0; i < n; ++i)
    {
        cout<<b[i]<<" ";
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 6776
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        n: u64,
        p:[u64;n]
    }
    let mut c :u64 = 1;
    let mut m: u64 = p[0];
    for &i in &p[1..] {
        if i < m || i == m {
            c += 1;
            m = i;
        }
    }
    println!("{}", c)
}


Measured memory_bytes: 8444