akhauriyash/Code-Regression huggingface dataset:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    NI = lambda : int(sys.stdin.readline())

    N = NI()
    S = [[int(x) for x in sys.stdin.readline().rstrip()] for _ in range(N)]

    max_k = 0

    for i in range(N):
        node = [-1] * N
        q = collections.deque()
        q.append((i,1))
        node[i] = 1
        f = True
        while q:
            v,d = q.popleft()
            for j in range(N):
                if S[v][j] == 0: continue
                if node[j] == d+1 or node[j] == d-1: continue
                if node[j] < 0:
                    node[j] = d+1
                    q.append((j,d+1))
                else:
                    f = False
                    break
            else:
                continue
            break
        if f: max_k = max(max_k,max(node))
    if max_k == 0:
        print(-1)
    else:
        print(max_k)

if __name__ == '__main__':
    main()

Measured memory_bytes: 42200
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define MAX_N 1000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)

typedef long long ll;

ll A[MAX_N + 1], B[MAX_N + 1], C[MAX_N + 1];
ll AB[MAX_N * MAX_N + 1];
ll ABC[MAX_N * 3000 + 1];

int main()
{
  int x, y, z, k;
  cin >> x >> y >> z >> k;

  REP(i, x) cin >> A[i];
  REP(i, y) cin >> B[i];
  REP(i, z) cin >> C[i];

  for (int i = 0; i < x; i++) {
    for (int j = 0; j < y; j++) {
      AB[i * y + j] = A[i] + B[j];
    }
  }
  sort(AB, AB + (x * y), std::greater<ll>());
  ll lab = min(x * y, k);
  // AB だけ上位k個だけ
  for (int i = 0; i < lab; i++) {
    for (int j = 0; j < z; j++) {
      ABC[i * z + j] = AB[i] + C[j];
    }
  }
  sort(ABC, ABC + (lab * z), std::greater<ll>());
  for (int i = 0; i < k; i++) {
    cout << ABC[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if(a>b)
        swap(a, b);
    if ((b - a) % 2 == 1) cout << "IMPOSSIBLE" << endl;
    else cout << (b + a) / 2 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int mod = 1e9 + 7;
using namespace std;

ll N,K;
struct node
{
	ll M[55][55];
};
node xi,ans;

node mul(const node & A,const node & B){
	node ans;
	memset(ans.M,0,sizeof ans.M);
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=N;j++){
			for(int k = 1;k<=N;k++){
				ans.M[i][j] += A.M[i][k] * B.M[k][j]%mod; ans.M[i][j] %= mod;
			}
		}
	}
	return ans;
}

int main(){
	// debug;
	ios;

	cin>>N>>K;
	for(int i = 1;i<=N;i++) for(int j = 1;j<=N;j++) cin>>xi.M[j][i];
	for(int i = 1;i<=N;i++) ans.M[i][1] = 1;
	while(K){
		if(K & 1) ans = mul(xi,ans);
		xi = mul(xi,xi);
		K >>= 1;
	}
		
	ll res = 0;
	for(int i = 1;i<=N;i++) res = (res + ans.M[i][1]) %mod;
	cout<<res<<'\n';
	
	return 0;
}


Measured memory_bytes: 384
-- ABD042 C - こだわり者いろはちゃん / Iroha's Obsession

import Control.Monad
import Data.List

main :: IO()
main = do
    [n,k] <- map read . words <$> getLine
    tabooLs <- map read . words <$> getLine
    print $ payVal n tabooLs
    


barabara :: Int -> [Int]
--数字をばらばらにする。1230は[1,2,3,0]になる。
barabara num
    | num < 10				= [num]
    | otherwise				= (barabara (div num 10)) ++ [(mod num 10)]

payVal :: Int -> [Int] -> Int
payVal num tabooLs
    | intersect (barabara num) tabooLs == []	= num
    | otherwise									= payVal (succ num) tabooLs


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
  
    int a,b,k;
    cin>>a>>b>>k;

    for(int i=a;i<a+k;i++){
      if(i<=b){
        cout<<i<<endl;
      }
    }

    for(int i=b-k+1;i<=b;i++){
      if(i<=b && i>=a+k){
        cout<<i<<endl;
      }
    }
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<string> vs;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
map<ll, ll> mp;

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (a <= c && c <= b) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
#define ALL(a)  (a).begin(),(a).end()
#define SZ(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(int i= (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N, M; cin >> N >> M;
    int ans = (1900 * M + 100 * (N - M)) * pow(2, M);
    cout << ans << "\n";
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

    ll s;
    cin >> s;

    ll sq = ceil(sqrt(s));
    ll x1 = sq, x3 = 0, y2 = sq, y1 = 0;
    ll extra = sq*sq-s;
    ll x2=sq-1, y3 = extra;

    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,d;
  int a;
  
  scanf("%d %d",&n,&d);
  
  a=n/(2*d+1);
  
  if(n==(2*d+1)*a)
    printf("%d",a);
  else
    printf("%d",a+1);
  
  return 0;
}

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

using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll n;
    cin >> n;

    if (n % 2 == 1 || n < 10) {
        cout << 0 << EOL;
    } else {
        ll ans = 0;
        ll p = 10;
        while (p <= n) {
            ans += n / p;
            p *= 5;
        }
        cout << ans << EOL;

    }
}


Measured memory_bytes: 256
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


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


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


x, a, b = inl()

if a - b >= 0:
    print('delicious')
elif a - b >= -x:
    print('safe')
else:
    print('dangerous')


Measured memory_bytes: 3572
def dijkstra(node, edge, check):
    """
    nodeを含む連結グラフの中で、
    矛盾が発生しないか確認する
    矛盾が発生しない場合、
    nodeを0としたときの各ノードのスコアを返す
    """
    # 到達距離
    d = dict()
    st = [(node, 0)]
    curr_min = float('inf')
    curr_max = -float('inf')
    while st:
        curr_node, curr_d = st.pop()
        # 到達済みであれば矛盾が発生しないか確認する
        if curr_node in d.keys():
            if d[curr_node] != curr_d:
                # 矛盾が発生した
                return None, None, None, check
            else:
                continue
        # 到達した距離を記録
        d[curr_node] = curr_d 
        check[curr_node] = True
        if curr_d < curr_min:
            curr_min = curr_d
        if curr_max < curr_d:
            curr_max = curr_d

        # 隣接ノードを積む
        for nxt, diff in edge[curr_node]:
            st.append((nxt, curr_d + diff))
    
    return d, curr_min, curr_max, check


def submit():
    n, m = (int(e) for e in input().split())
    
    # グラフを構成
    edge = {i : [] for i in range(1, n + 1)}
    for _ in range(m):
        l, r, d = (int(e) for e in input().split())
        edge[l].append((r, d))
        edge[r].append((l, -d))

    check = {i: False for i in range(1, n + 1)}
    curr_max = -float('inf')

    for i in range(1, n + 1):
        if not check[i]:
            d, sub_min, sub_max, check = dijkstra(i, edge, check)

            if d == None:
                print('No')
                return
            # sub_minを0としたときのsub_maxを計算する
            sub_max -= sub_min
            if sub_max > curr_max:
                curr_max = sub_max

    if curr_max > 10 ** 9:
        print('No')
    else:
        print('Yes')


submit()

Measured memory_bytes: 108660
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, a, b, c, x);

  int ans = 0;
  for (int i = 0; i <= a; ++i) {
    for (int j = 0; j <= b; ++j) {
      // 500*i + 100*j + 50*? = x
      // 10*i + 2*j + ? = x/50
      int k = x / 50 - 10 * i - 2 * j;
      if (0 <= k && k <= c) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import std.stdio;

enum conv = [
    'I':1,
    'V':5,
    'X':10,
    'L':50,
    'C':100,
    'D':500,
    'M':1000
];

void main()
{
    foreach(input; stdin.byLine())
    {
        int arabia = 0;
        if(input.length == 1) arabia = conv[input[0]];
        else
        {
            foreach(i; 1 .. input.length)
            {
                if(conv[input[i - 1]] < conv[input[i]])
                {
                    arabia -= conv[input[i - 1]];
                }
                else
                {
                    arabia += conv[input[i - 1]];
                }
            }
            arabia += conv[input[$ - 1]];
        }
        arabia.writeln;
    }
}

Measured memory_bytes: 1236
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
auto solve(string S) {
    immutable N = S.length.to!int();
    immutable s = S.map!(c=>(c-'0').to!long()).array();
    auto v = new long[][](N,N);
    v[0][]=s;
    foreach(i;1..N)
        foreach(j;0..N-i)
            v[i][j]=v[i-1][j]*10+s[i+j];
    long t=0;
    foreach(i;0..N)
        foreach(j;0..i+1)
            t+=v[N-1-i][j]*(1L<<max(0,j-1))*(1L<<max(0,i-j-1));
    return t;
}
void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 256
#include <iostream>

int main ()
{

    int n, a1, a2;
    int i1 = 0, i2 = 1;
    std::cin >> n >> a1 >> a2;
    if (a1 < a2)
    {
        i1 = 1;
        i2 = 0;
        int t = a1;
        a1 = a2;
        a2 = t;
    }
    for (int i = 2; i < n; i++)
    {
        int v;
        std::cin >> v;
        if (v > a1)
        {
            a2 = a1;
            i2 = i1;
            a1 = v;
            i1 = i;
        }
        else if (v > a2)
        {
            a2 = v;
            i2 = i;
        }
    }

    for (int i = 0; i < n; i++)
    {
        std::cout << ((i == i1)?(a2):(a1))<< std::endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int count = 0;
  for (int i=1;i<=n;i++){
    if (to_string(i).length()%2 == 1){
      count++;
    }
  }
  cout << count << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

vector<int>v,v1;


int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == 'A') {
            v.push_back(i);
        }
        if (s[i] == 'Z') {
            v1.push_back(i+1);
        }
    }
    cout << v1[v1.size()-1] - v[0] << endl;
    return 0;
}


Measured memory_bytes: 1428
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string s;
  cin>>N>>s;
  int c=0;
  for(int i=0;i<N-2;i++){
    if(s.substr(i,3)=="ABC") c++;
  }
  cout<<c<<endl;
}
      

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
 
    ll n,d;
    cin>>n>>d;
    ll ans = 0;
    ll now =0, p = 0, ti = 0;
    for(int i=0;i<n;i++){
        int t,f;
        cin>>t>>f;
        f--;
        if(abs(now-f) > t-ti){
            cout << -1 << endl;
            return 0;
        }
        if(now + f <= t-ti){
            ans += now * p;
            p = 1, now = f, ti = t;
        }
        else{
            if(p==d){
                cout << -1 << endl;
                return 0;
            }
            ans += (t-ti) * p;
            p++;
            now = f;
            ti = t;
        }
    }
    ans += now*p;
    cout << ans << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N,P;
    cin>>N>>P;
    int num = 0;
    for(int i=0;i<N;i++){
        int bis;
        cin >> bis;
        if(bis%2==1 ){
            num++;
        }
    }
    if(num==0){
        cout<<(P == 0 ? (1LL << N) : 0 );
    }
    else cout <<(1LL <<(N - 1));
    
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;  
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)  
#define fn1 for( int i =1;i<=n; i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
#define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;  
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
  IOS;
  int T=1;
  // cin >> T;
  while(T--){
    int n;
    cin >> n;
    string s;
    cin >>s;
    map<char,int>mp;
    for(char x:s)mp[x]++;
    int ans= min(mp['R'],mp['W']);
    int i =0 ,ans2=0, j = s.size()-1;
    while(i<j){
      while(i<j&&s[i]=='R')i++;
      while(i<j&&s[j]=='W')j--;
      if(i<j){
        ans2++;
        swap(s[i],s[j]);
      }
    }
    ans=min(ans,ans2);
    cout <<ans;
  
  
  }
  return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5 + 5;
int n;
ll L, a[maxn];
int main() {
    scanf("%d%lld",&n,&L);
    ll sum = 0;
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    int x = -1;
    for(int i=1;i<=n-1;i++) {
        if(a[i]+a[i+1]>=L) x = i;
    }
    if(x==-1) printf("Impossible");
    else {
        printf("Possible\n");
        for(int i=1;i<x;i++) printf("%d\n",i);
        for(int i=n-1;i>=x;i--) printf("%d\n",i);
    }
}


Measured memory_bytes: 1664
// "header" {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair

constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod1 = 1000000007;
constexpr long long mod2 = 998244353;

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

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){ return ((n + d -1) / d); }
inline int64_t square(int64_t a){ return a * a; }
// }}}

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

    int n,m;
    cin >> n >> m;

    int x=1,y=1;
    reps(i,n){
        (x *= i) %= mod1;
    }
    reps(i,m){
        (y *= i) %= mod1;
    }

    if(abs(n - m) > 1){
        cout << 0 << '\n';
    }else if(n - m == 0){
        cout << (x * y * 2) % mod1 << '\n';
    }else{
        cout << x * y % mod1 << '\n';
    }

    return 0;
}

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

bool dpx[8008][16061], dpy[8008][16061];

int main() {
    string S;
    int X,Y;
    cin >> S >> X >> Y;

    // init
    int cnt = 0;
    vector<int> move;
    for(char s : S) {
        if(s == 'F') ++cnt;
        else {
            move.push_back(cnt);
            cnt = 0;
        }
    }
    if(cnt > 0) move.push_back(cnt);

    // calc
    // start (8000, 8000)
    int N = (int)move.size();

    dpx[0][8000] = true, dpy[0][8000] = true;
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= 16000; ++j) {
            if(i % 2 == 0) {
                dpx[i + 1][j + move[i]] |= dpx[i][j];
                if(i != 0 && j - move[i] >= 0) dpx[i + 1][j - move[i]] |= dpx[i][j];

                // not move to y direction
                dpy[i + 1][j] |= dpy[i][j];
            } else {
                dpy[i + 1][j + move[i]] |= dpy[i][j];
                if(j - move[i] >= 0) dpy[i + 1][j - move[i]] |= dpy[i][j];

                // not move to x direction
                dpx[i + 1][j] |= dpx[i][j];
            }
        }

    }

    cout << (dpx[N][8000+X] && dpy[N][8000+Y] ? "Yes" : "No") << '\n';
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int aans,bans;
    vector<int> a(n),b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    vector<int> array(n);
    rep(i,n) array[i] = i+1;
    int cnt = 1;
    do{
        if(a == array) aans = cnt;
        if(b == array) bans = cnt;
        cnt++;
    }while(next_permutation(array.begin(),array.end()));
    
    cout << abs(aans - bans) << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));

$sum = array_sum($a_li);
$sunuke = 0;
$min = 10**10+1;
//print_r($a_li);
for($i=0;$i<$n-1;$i++){
  $sunuke+=$a_li[$i];
  $arai = $sum-$sunuke;
  //echo $sunuke." ",$arai."\n";
  $diff = abs($sunuke-$arai);
  $min = min($diff,$min);
}
printf("%s", $min);

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 10000000000000000
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b)
{
    ll ans=1;
    while(b!=0)
    {
        if(b&1)
        {
            ans*=a;
            ans%=mod;
        }
        a=(a*a);
        a%=mod;
        b>>=1;
    }
    return ans%mod;
}
void solve()
{
    ll n;
    cin>>n;
    VL a(n+1),ans(n+1,0);
    fr(i,1,n+1)
        cin>>a[i];
    ll b=0;
    //VL ans;
    map<ll,ll> mp;
    for(ll i=n;i>=1;i--)
    {
        ll ct=0;
        for(ll j=i+i;j<=n;j+=i)
        {
            ct+=ans[j];
        }
        if(a[i]!=ct%2)
        {
            b++;
            ans[i]=1;
            //a[i]+=1
        }
    }
    cout<<b<<endl;
    fr(i,1,n+1)
    {
        if(ans[i]==1)
            cout<<i<<" ";
        //cout<<ans[i]<<" ";
    }
    cout<<"\n";
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

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



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
#define double long double
const int mod=1000000007,MAX=35,INF=1<<29;
pair<int,int> dp[MAX][MAX][MAX][MAX];
bool seen[MAX][MAX][MAX][MAX];
int H,W,need;

struct ruirui{
    vector<vector<ll>> T;
    
    void init(vector<vector<ll>> &S){
        T.clear();
        int H=S.size(),W=S[0].size();
        T.resize(H+1);
        for(int i=0;i<=H;i++) T[i].resize(W+1);
        
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                T[i][j]=S[i-1][j-1];
            }
        }
        for(int i=0;i<=H;i++){
            for(int j=1;j<=W;j++){
                T[i][j]+=T[i][j-1];
            }
        }
        for(int j=0;j<=W;j++){
            for(int i=1;i<=H;i++){
                T[i][j]+=T[i-1][j];
            }
        }
    }
    
    ll query(int u,int d,int l,int r){
        return T[d+1][r+1]+T[u][l]-T[d+1][l]-T[u][r+1];
    }//u<=i<=d,l<=j<=rの和を返す
};

ruirui T;

pair<int,int> solve(int u,int d,int l,int r){
    if(seen[u][d][l][r]) return dp[u][d][l][r];
    
    seen[u][d][l][r]=1;
    
    pair<int,int> ret;
    
    if(T.query(u,d-1,l,r-1)>=need) ret={1,T.query(u,d-1,l,r-1)};
    else ret={0,0};
    
    if(d-u>=2){
        for(int i=u+1;i<d;i++){
            auto a=solve(u,i,l,r),b=solve(i,d,l,r);
            auto c=make_pair(a.fi+b.fi,min(a.se,b.se));
            if(ret.fi<c.fi) ret=c;
            else if(ret.fi==c.fi) chmax(ret.se,c.se);
        }
    }
    
    if(r-l>=2){
        for(int j=l+1;j<r;j++){
            auto a=solve(u,d,l,j),b=solve(u,d,j,r);
            auto c=make_pair(a.fi+b.fi,min(a.se,b.se));
            if(ret.fi<c.fi) ret=c;
            else if(ret.fi==c.fi) chmax(ret.se,c.se);
        }
    }
    
    return dp[u][d][l][r]=ret;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        int S=0,sum=0;
        cin>>H>>W>>S;
        if(H+W==0) break;
        vector<vector<ll>> A(H,vector<ll>(W));
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>A[i][j];
                sum+=A[i][j];
            }
        }
        T.init(A);
        need=sum-S;
        memset(dp,0,sizeof(dp));
        memset(seen,0,sizeof(seen));
        
        auto a=solve(0,H,0,W);
        cout<<a.fi<<" "<<a.se-need<<endl;
    }
}





Measured memory_bytes: 16264
import java.util.Scanner;
import java.util.LinkedList;
import java.lang.Math;
import java.util.Arrays;
import java.util.Collections;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next(),
            t = sc.next();
        int a=sc.nextInt(),
            b=sc.nextInt();
        String u = sc.next();

        sc.close();
        if(u.equals(s)){
            a--;
        }else{
            b--;
        }
        System.out.print(a+" "+b);
        
    }
}

Measured memory_bytes: 23636
def find_gcd(x, y):   
    while(y): 
        x, y = y, x % y 
    return x 
          
t = int(input())       
l = [int(i) for i in input().split()] 
  
num1 = l[0] 
num2 = l[1] 
gcd = find_gcd(num1, num2) 
  
for i in range(2, len(l)): 
    gcd = find_gcd(gcd, l[i]) 
      
print(gcd) 

Measured memory_bytes: 14252
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>	
using namespace std;
int a[35];
int main() {
	int n,cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
	}
	for(int i=2;i<n;i++) {
		if((a[i-1]<a[i]&&a[i]<a[i+1])||(a[i-1]>a[i]&&a[i]>a[i+1])) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <utility>
#include <set>
 
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(1)
#define lli long long int

using namespace std;

string lower(string str) {
  rep (i, str.size()) {
    if (str[i] >= 'A' && str[i] <= 'Z') {
      str[i] += 0x20;
    }
  }
  return str;
}

int main() {
  
  string strkey;
  string text;
  
  cin >> strkey;
  int ans = 0;
  
  loop {
    
    cin >> text;
    if (text == "END_OF_TEXT") {
      break;
    }
    else if (lower(text) == strkey) {
      ans += 1;
    }
  }
  cout << ans << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  set<int> s;
  rep(i,n) s.insert(a[i]);
  if (s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <set>

using namespace std;

int main()
{
  int N;
  cin >> N;

  int d;
  set< int > s;
  for(int i = 0; i < N; i++) {
    cin >> d;
    s.insert(d);
  }

  cout << s.size() << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#define x_ real()
#define y_ imag()
#define cross(a, b) (conj(a)*(b)).imag()
#define dot(a, b) (conj(a)*(b)).real()
#define PI acos(-1)
#define F first
#define S second
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define fileIO freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef complex<ld> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
typedef pair<double, double> pd;
pair<int, int> dirs[] = { {1, 2}, {-1, 2}, {2, 1}, {2, -1}, {-2, 1}, {-2, -1}, {1, -2}, {-1, -2} };

int N = 1e3 + 7;


int main() {
	fastIO;
	int n, k;
	cin >> n >> k;
	vector<ll> v;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	ll mn = 1e9;
	for (int i = 0; i <= n-k; i++) {
		mn = min(mn, abs(v[i]-v[i+k-1]));
	}
	cout << mn;


}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int sum_v[2005][2005] = {};
int sum_e[2][2005][2005] = {};
int N, M, Q;
string S[2005];

inline int f(int sum[2005][2005], int x1, int y1, int x2, int y2){
	return sum[x2][y2] - sum[x1][y2] - sum[x2][y1] + sum[x1][y1];
}

int main(){
	ios_base::sync_with_stdio(false);

	cin >> N >> M >> Q;
	rep(i,N) cin >> S[i];

	rep(i,N) rep(j,M){
		sum_v[i+1][j+1] = sum_v[i+1][j] + sum_v[i][j+1] - sum_v[i][j];
		rep(k,2) sum_e[k][i+1][j+1] = sum_e[k][i+1][j] + sum_e[k][i][j+1] - sum_e[k][i][j];
		if( S[i][j] == '1' ){
			sum_v[i+1][j+1]++;
			if( i>0 && S[i-1][j] == '1' ) sum_e[0][i+1][j+1]++;
			if( j>0 && S[i][j-1] == '1' ) sum_e[1][i+1][j+1]++;
		}
	}

	int ans[Q];
	rep(i,Q){
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int v  = f(sum_v, x1-1, y1-1, x2, y2);
		int e0 = f(sum_e[0], x1, y1-1, x2, y2);
		int e1 = f(sum_e[1], x1-1, y1, x2, y2);
		//cout << v << " " << e0 << " " << e1 << endl;
		ans[i] = v - e0 - e1;
	}

	rep(i,Q) cout << ans[i] << '\n';

	return 0;
}

Measured memory_bytes: 53888
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[])
{
	int a, b, c;
	vector<int> v;
	cin >> a >> b >> c;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(),v.end());
	int ans = v[0] + v[1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int _=600+7;
int n,D[2],num[2],cnt[2][2];
bool col[_][_][2],t1,t2;
void init(){
  scanf("%d%d%d",&n,&D[0],&D[1]);
  //printf("%d %d %d\n",n,D[0],D[1]);
  for(int i=0;i<=1;i++)
    while(!(D[i]&1)){
      num[i]++;
      D[i]>>=1;
      //printf("num[%d]: %d\n",i,num[i]);
    }
}
void dye(int t){
  for(int i=0;i<2*n;i++)
    for(int j=0;j<2*n;j++)
      if(!(num[t]&1)) col[i][j][t]=((i+j)>>(num[t]>>1))&1;
      else col[i][j][t]=(i>>(num[t]>>1))&1;
}
void calc(){
  for(int i=0;i<2*n;i++)
    for(int j=0;j<2*n;j++)
      cnt[col[i][j][0]][col[i][j][1]]++;
  for(int i=0;i<=1;i++)
    for(int j=0;j<=1;j++)
      if(cnt[i][j]>cnt[t1][t2]){ t1=i; t2=j; }
}
void print(){
  int cnt=0;
  for(int i=0;i<2*n;i++)
    for(int j=0;j<2*n;j++)
      if(col[i][j][0]==t1&&col[i][j][1]==t2){
	printf("%d %d\n",i,j);
	cnt++;
	if(cnt==n*n) return;
      }
}
int main(){
  /*
#ifndef ONLINE_JUDGE
  freopen("x.in","r",stdin);
  freopen("x.out","w",stdout);
#endif
  */
  init();
  //printf("%d %d\n",num[0],num[1]);
  dye(0);
  dye(1);
  calc();
  print();
  return 0;
}


Measured memory_bytes: 1664
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#include <cassert>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    multiset<int, greater<int>> s;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (s.empty()) {
            s.insert(a);
        }
        else {
            auto biter = s.begin();
            auto eiter = s.end();
            eiter--;
            if (a > *eiter) {
                //at least one element in the set can be overwritten
                auto iter = s.upper_bound(a);
                s.erase(iter);
                s.insert(a);
            }
            else {
                s.insert(a);
            }
        }
    }
    cout << s.size() << endl;
    sysp;
}

Measured memory_bytes: 8256
#include <iostream>
#include <algorithm>
#include <vector>

int main(void){
  int n;
  int k;
  std::cin >> n >> k;
  
  std::vector<int> snk_have;
  for(int i=0; i<k; i++){
    int d;
    std::cin >> d;
    for(int j=0;j<d;j++){
      int a;
      std::cin >> a;
      snk_have.push_back(a);
    }
  }
  std::sort(snk_have.begin(), snk_have.end());
  snk_have.erase(std::unique(snk_have.begin(), snk_have.end()), snk_have.end());
  int snk_nohave = n - snk_have.size();
  std::cout << snk_nohave << std::endl;
  
  return 0;
}

Measured memory_bytes: 3644
import sys

DBG_FLAG = 0

def p_dbg(str):
    if(DBG_FLAG == 1):
        sys.stdout.flush()
        print str

in_text = raw_input()
N = int(in_text)
array = map(int,list(in_text))

p_dbg(array)

sum = 0

while len(array) > 0:
    item = array.pop()
    sum = sum + item

p_dbg(sum)

if (N % sum) == 0:
    print 'Yes'
else:
    print 'No'


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

using namespace std;
typedef long long ll ;
const int N = 3007, OO = 0x3f3f3f3f ;
int mem[N][N];
string s , t;
int solve(int idx1 , int idx2){
    if(idx1 == s.size() || idx2 == t.size()) return 0;
    int &ret = mem[idx1][idx2];
    if(~ret)
        return ret;
        ret = max(solve(idx1 + 1 , idx2) , solve(idx1 , idx2 + 1));
    if(s[idx1] == t[idx2])
        ret = max(ret , 1 + solve(idx1 + 1 , idx2 + 1));
    return ret;
}
void print(int idx1 , int idx2){
     if(idx1 == s.size() || idx2 == t.size()) return;
     int c1 = solve(idx1 , idx2);
     int c2 = solve(idx1 + 1 , idx2);
     int c3 = solve(idx1 , idx2 + 1);
     if(s[idx1] == t[idx2]){
        cout << s[idx1];
        return print(idx1 + 1 , idx2 + 1);
     }
     if(c1 == c2){
       return print(idx1 + 1 , idx2);
     }
     else if(c1 == c3){
        return print(idx1 ,idx2 + 1);
     }
}

int main()
{   ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> s >> t;
    memset(mem , -1 , sizeof mem);
    solve(0 , 0);
    print(0 , 0);

    return 0;
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int n, k;

ll const INF = 3e18;
int const MAX = 1e5 + 41;

ll w[MAX];
int d[MAX];

ll calc(ll h) {
	ll res = 0;
	fi(1, n) {
		if (h < w[i]) continue;
		res += 1 + (h - w[i]) / d[i];
		res = min(res, INF);
	}	
	return res;
}

void solve() {
	ll l = 0;
	ll r = INF;
	while (r - l > 1) {
		ll h = (l + r) / 2;
		ll resp = calc(h);
		if (resp >= k) {
			r = h;
		} else {
			l = h;
		}
	}
	printf("%lld\n", r);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d %d", &n, &k);
  fi(1, n) {
  	scanf("%lld %d", &w[i], &d[i]);
  }
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


class Card(object):

    def __init__(self, card):
        self.card = card
        self.suit = card[0]
        self.value = int(card[1:])

    def __str__(self):
        return str(self.card)


def print_array(a):
    print(" ".join(map(str, a)))


def bubblesort(cards, n):
    c = cards[::]
    for i in range(0, n):
        for j in range(n - 1, i, -1):
            if c[j].value < c[j - 1].value:
                (c[j], c[j - 1]) = (c[j - 1], c[j])
    return c


def selectionsort(cards, n):
    c = cards[::]
    for i in range(0, n):
        minj = i
        for j in range(i, n):
            if c[j].value < c[minj].value:
                minj = j
        (c[i], c[minj]) = (c[minj], c[i])
    return c


def main():
    n = int(input())
    cards = list(map(Card, input().split()))
    b = bubblesort(cards, n)
    print_array(b)
    print("Stable")
    s = selectionsort(cards, n)
    print_array(s)
    if b == s:
        print("Stable")
    else:
        print("Not stable")


if __name__ == "__main__":
    main()

Measured memory_bytes: 7796
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int H, N;
int dp[10010];
int A[10010], B[10010];

void solve() {
	cin >> H >> N;
	rep(i, 0, N) cin >> A[i] >> B[i];
	rep(j, 0, H) dp[j] = inf;
	dp[0] = 0;
	int res = inf;

	rep(i, 0, N) {
		rep(j, 0, H) {
			if(j + A[i] < H) {
				MIN(dp[j + A[i]], dp[j] + B[i]);
			}
			else {
				MIN(res, dp[j] + B[i]);
			}
		}
	}
	cout << res << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	x := input()
	y := input()
	if x < y {
		fmt.Print("<")
	} else if x > y {
		fmt.Print(">")
	} else {
		fmt.Print("=")
	}
}

func input() string {
	if sc.Scan() {
		return sc.Text()
	}
	return ""
}


Measured memory_bytes: 640
// Grid Repainting 2
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    string s[50];
    for (int i = 0; i < H; i++) cin >> s[i];

    bool can = true;
    int dx[4] = {0, 0, -1, 1};
    int dy[4] = {-1, 1, 0, 0};
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int count = 0;
            if (s[i][j] == '.') continue;
            for (int k = 0; k < 4; k++) {
                int x = j + dx[k];
                int y = i + dy[k];
                if (0 > x || x >= W) continue;
                if (0 > y || y >= H) continue;
                if (s[y][x] == '#') count++;
            }
            if (count == 0) {
                can = false;
                break;
            }
        }
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

void solv(int curr,
          std::vector<std::vector<std::pair<int, int>>> const& tree,
          std::vector<int>& ans) {
  for (auto n: tree[curr]) {
    auto v = n.first;
    auto w = n.second;

    if (ans[v] > 1) {
      if (w % 2 == 0) {
        ans[v] = ans[curr];
      } else {
        ans[v] = (ans[curr]+1)%2;
      }
      solv(v, tree, ans);
    }
  }
}

int main() {
  int N;

  std::cin >> N;

  std::vector<std::vector<std::pair<int, int>>> tree(N);

  for (int i=0; i<N-1; i++) {
    int u, v, w;
    std::cin >> u >> v >> w;
    u--; v--;
    tree[u].emplace_back(v, w);
    tree[v].emplace_back(u, w);
  }

  std::vector<int> ans(N, 8);
  ans[0] = 0;
  solv(0, tree, ans);

  for (int a: ans) {
    std::cout << a << '\n';
  }

  return 0;
}


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

int main(){
  int n;
  cin >> n;
  int count = 0;
  int after,point;
  for(int i=1;i<=n;i++){
    cin >> point;
    if(point==i){
      count++;
      if(i<n){
	cin >> point;
	i++;
      }
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
typedef long long ll;
const int INF = 1<<30;
const ll MOD = 1e9+7;
const double EPS = 1e-9;


int main(int argc, const char * argv[]) {
  int N; cin >> N;
  vector<int> L(N);
  set<int> s;
  for(int i=0; i<N; i++){
    cin >> L[i];
    s.insert(L[i]);
  }
  
  sort(L.begin(), L.end());
  
  ll ans = 0;
  for(int i=N-1; i>=0; i--){
    for(int j=i-1; j>=0; j--){
      ll tmp = (ll)distance(upper_bound(L.begin(), L.end(), L[i]-L[j]), L.end()) - (ll)(N-j);
      ans += max(0LL, tmp);
    }
  }

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

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

using namespace std;

// #define TEST

int isdigit(string s){
    for (int i = 0; i < 10; ++i)
        if (s[0] == i + '0')
            return i;
    return -1;
}

int ptr = 0; // next line
int calc(vector<string>& q, int d = 0){
    string op = q[ptr++].substr(d, 1);
    int t = isdigit(op);
    if (t >= 0) return t;
    vector<int> tmp;
    while (ptr < q.size() && q[ptr].size() > d && q[ptr].substr(d, 1) == "."){
        string node = q[ptr].substr(d + 1, 1);
        int res = isdigit(node);
        if (res < 0)
            res = calc(q, d + 1);
        else ++ptr;
        tmp.push_back(res);
    }
    int ans = 0;
    if (op == "+"){
        for (auto i : tmp)
            ans += i;
    }
    else{
        ans = 1;
        for (auto i : tmp)
            ans *= i;
    }
#ifdef TEST
    cout << op << " ";
    for (auto i : tmp) cout << i << " ";
    cout << endl;
#endif
    return ans;
} 

int main(){
    int line; cin >> line;
    while (line){
        vector<string> q;
        while (line--){
            string s; cin >> s;
            q.push_back(s);
        }
        ptr = 0;
        cout << calc(q) << endl;
        cin >> line;
    }
    return 0;
}


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

int  main(){
  int n,sum=0; cin>>n;
  vector<int> v(n);
  rep(i,n){
    cin>>v.at(i);
    sum+=v.at(i);
  }
  sort(v.begin(),v.end());
  if(sum>2*v.at(n-1)){cout<<"Yes";}
  else{cout<<"No";}
}

Measured memory_bytes: 256
import sys
n=int(input())
t=[]
x=[]
y=[]
t.append(0)
x.append(0)
y.append(0)
for i in range(1,n+1):
    a,b,c=map(int,input().split())
    t.append(a)
    x.append(b)
    y.append(c)
for j in range(1,n+1):
    S = abs(x[j]-x[j-1])+abs(y[j]-y[j-1])  #1つの移動最短距離
    T =t[j]-t[j-1] #その所用時間
    if S>T: #もし所用時間よりも距離が長ければ無理
        print("No")
        sys.exit()
    elif S%2==0: #もしも距離が偶数であれば
        if T%2==0: #時間も偶数であればOK
            continue
        else: #距離が偶数で時間が奇数ならダメ
            print("No")
            sys.exit()
    elif T%2!=0: #距離が奇数で、時間も奇数ならOK
        continue
    else:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 11800
def main():
    n=int(input())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    c=[]
    minus=0
    ans=0
    if sum(a)<sum(b):
        print(-1)
    else:
        for i in range(n):
            dif=a[i]-b[i]
            if dif>0:
                c.append(dif)
            elif dif<0:
                ans+=1
                minus+=dif
        c.sort(reverse=True)
        i=0
        while minus<0:
            minus+=c[i]
            i+=1
        print(ans+i)
if __name__=="__main__":
    main()

Measured memory_bytes: 18524