akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=1000010;

int n,d[maxn];
bool vis[maxn];
queue<int>q;
int main(){
    n=read();
    d[0]=n;for(int i=1;i<=n;i++)d[i]=i;
    for(int i=0;i<n;i++)q.push(i),vis[i]=1;
    while(!q.empty()){
    	int x=q.front();q.pop();
    	for(int i=0;i<10;i++){
			int cyc=(x*10+i)%n;
			if(d[cyc]>d[x]+i){
				d[cyc]=d[x]+i;
				if(!vis[cyc]){
					vis[cyc]=1;
					q.push(cyc%n);
				}
			}
		}
		vis[x]=0;
	}
	printf("%d",d[0]);
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  for( int i = 0; i < N; i++ ) cin >> L.at(i);
  sort(L.begin(),L.end());
  
  int total = 0;
  for( int i = 0; i < N-1; i++ ){
    total += L.at(i);
  }
  if( L.back() < total ) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back


#define L_B lower_bound
#define U_B upper_bound

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf (1000*1000*1000+5)
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll a,b,c;
	rl3(a,b,c);
	if((a==c&&a!=b)||((a==b)&&a!=c)||((b==c)&&c!=a))
		cout<<"Yes\n";
	else
		cout<<"No\n";
	
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll MOD = 1e9 + 7;
ll fact[100003];
bool fact_init = false;

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * pow(a, b - 1) % MOD;
	
	ll d = pow(a, b / 2) % MOD;
	return d * d % MOD; 
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2;i<=n;i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= pow(fact[k],MOD-2);
	ret %= MOD;
	ret *= pow(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}

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

	ll n;
	cin >> n;

	ll a[n+1];
	rep(i,n+1) cin >> a[i];

	ll p0, p1;
	ll b[n+1];
	rep(i,n+1) b[i] = -1;

	// 配列a[i]の中で2回出てくる項のindexを取得
	rep(i,n+1){
		if(b[a[i]] > -1){
			p0 = b[a[i]];
			p1 = i;
			break;
		}else{
			b[a[i]] = i;
		}
	}

	FOR(i,1,n+2){
		ll k = p0 + n - p1;
		cout << (MOD + comb(n + 1, i) - (k >= i-1 ? comb(k, i-1) : 0)) % MOD << endl;
	}
}

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

int n , m;
ll ans;
vector <pair <int , int> > v;
multiset <int> ms;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++){
        int a, b; cin >> a >> b;
        v.push_back({a , b});
    }
    sort(v.begin() , v.end());
    for (int i = 1 , j = 0; i <= m; i++){
        while (v[j].first <= i && j < n){
            ms.insert(-v[j].second);
            j++;
        }
        if (ms.size()){
            ans -= *ms.begin();
            ms.erase(ms.begin());
        }
    }
    cout << ans;
}


Measured memory_bytes: 5748
n = gets.to_i
a = gets.chomp.split(' ').map{|i| i.to_i}

m = 1000
k = 0

(n-1).times do |i|
    if a[i+1] > a[i]
        c = m/a[i]
        m -= c*a[i]
        k += c
    end

    if a[i+1] < a[i]
        m += k*a[i]
        k=0
    end
end

print(m + k*a[n-1])

Measured memory_bytes: 14292
import sys
sys.setrecursionlimit(10**6)
N,M,Q = map(int,input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,input().split())


sequences = []

def dfs(seq):
    if len(seq) == N+1:
        sequences.append(seq)
        return
    tail_num = seq[-1]
    for nxt_d in range(tail_num,M+1):
        dfs(seq+[nxt_d])
dfs([1])


ans = 0
for seq in sequences:
    score = 0
    for i in range(Q):
        if int(seq[b[i]]) - int(seq[a[i]]) == c[i]:
            score += d[i]
    ans = max(ans, score)
print(ans)




#     if len(seq) == N:
# TypeError: object of type 'NoneType' has no len()



# def dfs(s):
#     if len(s) == N:
#         sequences.append(s)
#         return
#     if s == '':
#         tail_num = 1
#     else:
#         tail_num = int(s[-1])
#     for nxt_d in range(tail_num,M+1):
#         dfs(s+str(nxt_d))
# dfs('')
## 10の時2桁追加されて停止条件飛び越す
## 10の時は0を追加して例外亭な処理する方針

Measured memory_bytes: 24428
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

int main(){
	int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    vector<int> perm(n);
    for(int i = 0; i < n; i++){
        int inp;
        cin >> inp;
        p.at(i) = inp;
        perm.at(i) = i + 1;
    }
    for(int i = 0; i < n; i++){
        int inp;
        cin >> inp;
        q.at(i) = inp;
    }

    int count = 0;
    int check = 0;
    int np = -1;
    int nq = -1;
    do{
        if(np >= 0 && nq >= 0) break;
        for(int i = 0; i < n; i++){
            if(perm.at(i) != p.at(i)) break;
            else if(i == n - 1) np = count;
        }
        for(int i = 0; i < n; i++){
            if(perm.at(i) != q.at(i)) break;
            else if(i == n - 1) nq = count;
        }
        count++;
    }while(next_permutation(perm.begin(), perm.end()));

    cout << abs(np - nq) << endl;
  	return 0;
}


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

typedef long int lint;
typedef long long int llint;

#define EACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i, s, e) for (int i = (s); i < (int)(e); ++i)
#define REP(i, n) FOR(i, 0, n)
#define endl "\n";

template<typename T>
void print(const std::vector<T>& v, char sep=' ') {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i != 0) cout << sep;
    cout << v[i];
  }
  cout << endl;
}

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

  int n, sum = 0;
  cin >> n;
  REP(i, n + 1){
    sum += i;
  }
  cout << sum << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, 0, n) cin >> p[i];
    int ans = 0;
    rep(i, 1, n - 1)
    {
        if ((max({p[i - 1], p[i], p[i + 1]}) != p[i]) && (min({p[i - 1], p[i], p[i + 1]}) != p[i]))
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll H,W,h,w;
  cin>>H>>W>>h>>w;
  cout<<H*W-W*h-w*H+h*w<<endl;
}

Measured memory_bytes: 3640
import random
import time

def down_score(d, c, last_d, score):
    sum = 0
    for i in range(26):
        sum = sum + c[i]*(d-last_d[i])
        
    return int(score - sum)


def main():
    D = int(input())

    c = list(map(int, input().split()))

    s = [list(map(int, input().split())) for i in range(D)]

    start = time.time()
    
    last_d = [0 for i in range(26)]
    
    ans = []
    
    score1 = 0
    
    for i in range(D):
        max = 0
        idx = 0
        for j in range(26):
            if max < (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] != 0:
                max = s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2
                idx = j
            elif max == (s[i][j] + c[j] * (i-last_d[j])*(i-last_d[j]+1)/2) and c[j] * (i-last_d[j])*(i-last_d[j]+1)/2 > c[idx]* (i-last_d[idx])*(i-last_d[idx]+1)/2:
                idx = j
            
        last_d[idx] = i+1
        score1 += s[i][j]
        score1 = down_score(i+1,c,last_d,score1)
        
        ans.append(idx)


    while time.time() - start < 1.9:
        idx = random.randint(0,25)
        d = random.randint(0,D-1)
        if c[idx] == 0 or ans[d-1] == idx:
            continue
        tmp = ans[d]
        ans[d] = idx
        last_d = [0 for i in range(26)]
        score2 = 0    
        for i in range(D):
            score2 += s[i][ans[i]-1]
            last_d[ans[i]-1] = i+1
            score2 = down_score(i+1, c, last_d, score2)
        
        if score1 > score2:
            ans[d] = tmp
    
    for i in range(D):
        print(ans[i]+1)  

if __name__ == "__main__":
    main()


Measured memory_bytes: 9716
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

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

  int N; cin >> N;
  ll ans = 0;
  vector<tuple<ll, ll, ll>> S(N);
  rep(i, N) {
    ll A, B; cin >> A >> B;
    S[i] = make_tuple(A + B, A, B);
  }
  sort(S.begin(), S.end());
  reverse(S.begin(), S.end());
  rep(i, N) {
      if(i%2 == 0) ans += get<1>(S[i]);
      else ans -= get<2>(S[i]);
  }
  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((int)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

void print(Vl v){
    rep(i, 0, sz(v)){
        if(i) cout << " ";
        cout << v[i];
    }
    cout << endl;
}

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


int main() {
	ll n, m, x; cin >> n >> m >> x;
	Vl c(n);
	vector<vector<ll>> a(n, vector<ll>(m));
	rep(i, 0, n){
		cin >> c[i];
		rep(j, 0, m) cin >> a[i][j];
	}

	ll ans = INF;

	for(int tmp = 1; tmp < (1 << n); tmp++){
		bitset<12> s(tmp);
		ll sum = 0;
	 	Vl cnt(m, 0);
		rep(i, 0, n){
			if(s.test(i)){
				sum += c[i];
				rep(j, 0, m) cnt[j] += a[i][j];
			}
		}
		// if(tmp == 7) {
		// 	co(s);
		// 	co(sum);
		// 	rep(j, 0, m) cout << cnt[j] << " ";
		// 	cout << endl;
		// }

		bool f = true;
		rep(i, 0, m){
			if(cnt[i] < x) f = false;
		}
		// //
		// co(sum << " ");
		// rep(i, 0, m) cout << cnt[i] << " ";
		// cout << endl;
		// //
		if(f){
			chmin(ans, sum);
		}
	}

	if(ans == INF) co(-1);
	else co(ans);

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

const int mod=1e9+7;
int pw(int a,int b,int p){
    if(b==0)return 1;
    int t=pw(a,b/2,p);
    if(b%2)return (((a*t)%p)*t)%p;
    else return ((t*t)%p);
}
int solve(){
    int n,a,b; cin>>n>>a>>b;
    int ans=pw(2,n,mod);
    ans=(ans-1+mod)%mod;
    int t1=1,t2=1;
    for(int i=1; i<=a; i++){
        t1=(((t1*(n-i+1))%mod)*pw(i,mod-2,mod))%mod;
    }
    for(int i=1; i<=b; i++){
        t2=(((t2*(n-i+1))%mod)*pw(i,mod-2,mod))%mod;
    }
    ans=(ans-t1+mod)%mod;
    ans=(ans-t2+mod)%mod;
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> P;
 
#define INF (1<<29)
#define INFL (1ll<<60)
#define EPS (1e-8)
#define PI (acos(-1))
const ll MOD = 1000000007ll;

int n;
ll a[112345];
ll sum[112345];

int main() {
	cin >> n;
	REP(i, n) scanf("%lld", a + i);
	sort(a, a + n);
	
	
	sum[0] = a[0];
	FOR(i, 1, n) sum[i] = sum[i - 1] + a[i];
	
	int ans = 1;
	for (int i = n - 2; i >= 0; i--) {
		if (a[i + 1] <= sum[i] * 2) {
			ans++;
		}
		else {
			break;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2424
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vector <int> v[N], temp;
int ch[N],n;
void dfs(int u, int p)
{
    ch[u]=1;
    for(auto to:v[u])
    {
        if(to==p)
        continue;
        dfs(to, u);
        ch[u]+=ch[to];
        //cout<<u<<" "<<to<<" "<<ch[to]<<" "<<n-ch[to]<<"\n";
        temp.pb((ch[to]*(n-ch[to])));
    }
    return;
}
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    int m=0,ans=0;
    for(int i=0;i<n;i++)
    {
        ans+=max(0ll, m-ar[i]);
        m=max(m, ar[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 7552
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

struct LowLink {
    const vector<vector<int>> &G;
    vector<bool> used;
    vector<int> ord,low,articulation;
    vector<pair<int, int>> bridge;

    LowLink (const vector<vector<int>> &G) : G(G) {}

    int dfs(int v, int k, int pv) {
        used[v] = true;
        ord[v] = k++;
        low[v] = ord[v];
        bool is_articulation = false;
        int cnt = 0;
        for (auto &nv : G[v]) {
            if (!used[nv]) {
                ++cnt;
                k = dfs(nv, k, v);
                low[v] = min(low[v],low[nv]);
                is_articulation |= ~pv && low[nv] >= ord[v];
                if (ord[v] < low[nv]) bridge.emplace_back(minmax(v, nv));
            } else if (nv != pv) {
                low[v] = min(low[v],ord[nv]);
            }
        }
        is_articulation |= pv == -1 && cnt > 1;
        if (is_articulation) articulation.emplace_back(v);
        return k;
    }

    virtual void build() {
        used.assign(G.size(), false);
        ord.assign(G.size(), 0);
        low.assign(G.size(), 0);
        int k = 0;
        for (int i = 0; i < G.size(); i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<vector<int>> G(N);
    rep(i,M) {
        int s,t; cin >> s >> t;
        G[s].emplace_back(t);
        G[t].emplace_back(s);
    }

    LowLink LL(G);
    LL.build();
    sort(all(LL.articulation));
    for (auto i : LL.articulation) cout << i << endl;
}



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

using namespace std;
using ll = long long;

const int N = 200005;

ll n;
int m, x;

int vis[N];

int main() {
	scanf("%lld %d %d", &n, &x, &m);

	ll ans = 0;
	ll ptr = x;
	for(int it = 1; n > 0 and !vis[ptr]; it++) {
		n--;
		vis[ptr] = it;
		ans += ptr;
		ptr = ptr * ptr % m;
	}

	if(!n) return printf("%lld\n", ans), 0;

	ll tot = 0;
	int size = 0;
	for(ll u = ptr; ; ) {
		tot += u;
		size++;
		u = u * u % m;
		if(u == ptr) break; 
	}

	ans += n / size * tot;
	n %= size;
	while(n--) {
		ans += ptr;
		ptr = ptr * ptr % m;
	}

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


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

bool devision(int N, int t[100001], int x[100001], int y[100001]) {
int dis;
  for(int i=0; i<N; ++i) {
    dis = t[i+1]-t[i]-abs(x[i+1]-x[i])-abs(y[i+1]-y[i]);
    if(!(dis >= 0 && dis % 2 == 0))
      return false;
  }
  return true;
}

int main(){
  int N, t[100001], x[100001], y[100001];
  cin >> N;
  t[0]=0, x[0]=0, y[0]=0;
  for(int i=1; i<N+1; ++i) cin >> t[i] >> x[i] >> y[i];

  if(devision(N, t, x, y))
    cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  int key;
  Node  *right,*left,*parent;
};

Node *root,*NIL;


void insert(int k){
  Node *y =NIL;
  Node *x =root;//`アドレががそのままxに入る`
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL)return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int Find(int k){
  Node *y =NIL;
  Node *x =root;//`アドレががそのままxに入る`
  Node *z;

  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }else if(z->key>x->key){
      x=x->right;
    }else{
      return 1;
    }
  }
return 0;
  /*
  z->parent=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
  */
}


/*
void Find(Node *u){
  while(1){
    if(u>x->key){
      x=x->left;
    }else if(u<x->key){
      x=x->right;
    }else if(u==x->key){
      printf("yes\n");
      break;
    }else if(u==NIL){
      printf("no\n");
      break;
    }
  }
}


*/
int main(){
  int n,i,x;
  string com;
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    cin>>com;
    if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n" );
    }else if(com=="find"){
      scanf("%d", &x);
      //printf("\n");
      if(Find(x)){
        printf("yes\n") ;
      }else{
        printf("no\n") ;
      };
    }
  }
  return 0;
}



Measured memory_bytes: 22016
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];
            for (int i = 0; i < values.length; i++) {
                values[i] = i + 1;
            }
            for (int i = 0; i < n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1; // aとbを使ってvaluesを操作しよう
                int swap;
                swap=values[a];
                values[a]=values[b];
                values[b]=swap;
            }
            for(int i=0;i<values.length;i++) {
                System.out.println(values[i]);
            }
        }
    }
}


Measured memory_bytes: 26196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    while(1)
    {
        char ch;
        ll sum=0;
        while((ch=getchar())!='\n')
        {
            sum+=ch-'0';
        }
        if(sum==0)
            break;
        else
        {
            cout<<sum<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<string.h>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<deque>
#include<queue>
#include<math.h>
#include<chrono>
#include<list>
#include<random>
#include<bitset>
#include<assert.h>
#include<ctime>
#include<cstdio>
#include <unordered_map>
using namespace std;
ifstream fi("zinput.txt");
ofstream fo("output.txt");
#define fast_input() {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); }
#define ll long long
#define For(i,n) for (int(i) = 0; (i)< (int)(n); (i)++)
#define For1(i,n) for (int(i) = 1; (i) <= (int)(n); (i)++)
#define Forlr(i,l,r) for (int(i) = (int)(l); (i) <= (int)(r); (i)++)
#define Forrl(i,r,l) for (int(i) = (int)(r); (i) >= (int)(l); (i)--)
#define all(a) a.begin(), a.end() 
#define pb push_back
#define pp pop_back
#define mp make_pair
#define PI 3.14159265
#define putno return cout <<"NO", 0;
#define putyes return cout <<"YES", 0;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef map<int, int> mii;
//const ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
//DSU
/*
int p[ N], r[N];
void init(int n) {
	For(i, n) {
		p[i] = i;
	}
}
int get(int x) {
	if (p[x] != x) {
		p[x] = get(p[x]);
	}
	return p[x];
}
bool uni(int x, int y) {
	x = get(x); y = get(y);
	if (x == y) {
		return false;
	}
	if (r[x] >= r[y]) {
		p[y] = x;
	}
	else {
		p[x] = y;
	}
	if (r[x] == r[y]) {
		r[x]++;
	}
	return true;
}
*/

// So mu
/*
int power(int x, unsigned int y, int p)
{
	int res = 1; // Initialize result

	x = x % p; // Update x if it is more than or
	// equal to p

	while (y > 0)
	{
		// If y is odd, multiply x with result
		if (y & 1)
			res = (res*x) % p;

		// y must be even now
		y = y >> 1; // y = y/2
		x = (x*x) % p;
	}
	return res;
}
*/

// ReadHexa
/*
bitset<16400> b[4101];
void readHexa()
{
	For(i, n)
	{
		string st;
		cin>> st;
		For(j, m/4)
		{
			int x;
			if (st[j] >= 'A' && st[j] <= 'F')
				x = st[j] - 'A' + 10;
			else x = st[j] - '0';
			for (int k = 4; k; --k, x >>= 1)
				b[i][j * 4 + k] = x & 1;
		}
	}
}
*/

// nChoosek
/*
ll nChoosek(ll n, ll k)
{
	if (k > n) return 0;
	if (k * 2 > n) k = n - k;
	if (k == 0) return 1;

	ll result = n;
	for (ll i = 2; i <= k; ++i) {
		result *= (n - i + 1);
		result /= i;
	}
	return result;
}
*/

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
MIKUNO - 15/02/1999
*/
int n, m, k, cnt, rs, q;
int x, y;
//	priority_queue <ll, vector<ll>, greater<ll> > q;
//ll n, m, q, k, pos, t, cnt, rs1, check;
ll maxx = -1e9, minn = 1e9;
int ma = -1e9, mi = 1e9;
const int maxn = 2*N;
const ll MOD = 1e9 + 7;
int a[100];
int main()
{
	fast_input();
	cin >> n;
	int ma = 0;
	For(i, n)
	{
		cin >> a[i];
		if (a[i] >= ma)
		{
			rs++;
			ma = a[i];
		}
	}
	cout << rs;
}

Measured memory_bytes: 256
object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ").map(d => if (d.size == 1) '0' + d else d)).toSeq
    println(in.flatMap(_.tail.grouped(2).map(x => x(0) + ':' + x(1))).sorted.distinct.map(s =>
        if (s(0) == '0' && s(2) == ':') s.tail else s
    ).mkString(" "))
}

Measured memory_bytes: 44784
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<int> X(N), L(N);
  vector<P> ps(N);
  REP(i, N) { cin >> X[i] >> L[i]; }

  // REP(i, N) ps[i] = P(X[i] - L[i], X[i] + L[i]);
  REP(i, N) ps[i] = P(X[i] + L[i], X[i] - L[i]);
  sort(ps.begin(), ps.end());

  ll ans = 0;
  ll cur = -INF;
  REP(i, N) {
    P p = ps[i];
    if (cur <= p.second) {
      ans++;
      cur = p.first;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int gcd(int p , int q){
	if(p%q == 0) return q ;
	return gcd(q, p%q) ;
}

int main(int argc, char const *argv[])
{
	//freopen("input.txt" , "r" , stdin) ;

	int a , b , k ;

	cin >> a >> b >> k ;

	int g = gcd(a , b) ;

	vector<int> V ;

	for(int i = g ; i >=1 ; i--){
		if(g % i == 0)V.push_back(i) ;
	}

	printf("%d\n", V[k-1]);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long long n, d, x, y;
	long long i, ans = 0;

	scanf("%lld%lld", &n, &d);
	d *= d;

	for (i = 0; i < n; i++)
	{
		scanf("%lld%lld", &x, &y);
		if ((x*x + y*y) <= d) ans++;
	}

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

	return 0;
}


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

using namespace std;

using lli = long long int;
using pii = pair<int,int>;

const int maxn = 3e3 + 5;
const int mod = 1e9 + 7;

int n,m;
char s[maxn],t[maxn];
int f[maxn][maxn]={};

int main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);
    //freopen("t.inp","r",stdin);freopen("t.out","w",stdout);
    cin>>n>>m>>(s+1);
    strcpy(t+1,s+1);
    for(int i=1,u,v;i<=m;i++){
        cin>>u>>v;
        sort(s+u,s+v+1);
        sort(t+u,t+v+1,greater<char>());
    }
    int cnt[2]={};
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        cnt[0]+=(s[i]=='1');
        cnt[1]+=(t[i]=='1');
        for(int j=cnt[0];j<=cnt[1];j++){
            f[i][j]=f[i-1][j];
            if (j) f[i][j]+=f[i-1][j-1];
            if (f[i][j]>=mod) f[i][j]-=mod;
        }
    }
    int res=0;
    for(int j=cnt[0];j<=cnt[1];j++){
        res+=f[n][j];
        if (res>=mod) res-=mod;
    }
    cout<<res;
    return 0;
}


Measured memory_bytes: 15828
#include <iostream>
using namespace std;
 
int main(){
	int a, b, c;
  
  	cin>>a>>b>>c;
  	
  	
  	if((a==b&&b==c)||(a!=b&&b!=c&&c!=a)){
    	cout<<"No"<<endl;
    }else {
    	cout<<"Yes"<<endl;;
    }
  
  return 0;
}

Measured memory_bytes: 256
def prime_factorize(n):
  # nの素因数分解
  a = []
  while n % 2 == 0:
    a.append(2)
    n = n // 2
  f = 3
  while f * f <= n:
    if n % f == 0:
      a.append(f)
      n = n // f
    else:
      f += 2
  if n != 1:
    a.append(n)
  return a

def abc052_c():
  n = int(input())
  if n == 1:
    print(1)
    return

  # 2...nを素因数分解してすべて集める
  primes = []
  for i in range(2, n+1):
    primes += prime_factorize(i)

  # N!の約数を生成する組合せ数
  # 各素因数の出現回数+1(何も使わないも含めて)を掛け合わせる
  div = 10**9 + 7
  ans = 1
  from collections import Counter
  for kv in Counter(primes).items():
    ans = ans * (kv[1] + 1) % div
  print(ans)

abc052_c()

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

int main() {
    int n, a[45] = { 1, 1 };
    cin >> n;
    for (int i = 2; i <= n; ++i) {
        a[i] = a[i - 1] + a[i - 2];
    }
    cout << a[n] << endl;

    return 0;
}


Measured memory_bytes: 3116
N = int(input())
A = list(map(int,input().split()))
#%%
D = [0]*(N+1)
for a in A:
    D[a] += 1

cmb = 0
for d in D:
    cmb += d*(d-1)//2

ans = []
for i in range(N):
    d = D[A[i]]
    tmp = cmb-(d*(d-1)//2)
    tmp += (d-1)*(d-2)//2
    
    ans.append(tmp)

for an in ans:
    print(an)

Measured memory_bytes: 90060
#include<bits/stdc++.h>
#include <math.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 lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  ll N;
  cin >>N;
  ll y=10*10*10*10*10*10*10*10*10+7;
  ll x=1;
  repl(i,1,N+1) {
    x*=i;
    x =x%y;
  }
  cout<< x<< endl;
}
    
 

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ARC083_D___Restoring_Road_Network
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(solver());
        }
        static long solver()
        {
            var N = int.Parse(Console.ReadLine());
            var distance = new long[N + 1, N + 1];
            long result = 0;
            for (int i = 0; i < N; i++)
            {
                var read = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                for (int j = 0; j < N; j++)
                {
                    distance[i + 1, j + 1] = read[j];
                    result += read[j];
                }
            }
            result /= 2;

            for (int from = 1; from < N + 1; from++)
            {
                for (int to = from + 1; to < N + 1; to++)
                {
                    var isDelete = false;
                    for (int via = 1; via < N + 1; via++)
                    {
                        if (via == from || via == to) continue;
                        var compare = distance[from, to].CompareTo(distance[from, via] + distance[via, to]);
                        if (compare > 0) return -1;
                        if (compare == 0) isDelete = true;
                    }
                    if (isDelete) result -= distance[from, to];
                }
            }
            return result;
        }
    }
}

Measured memory_bytes: 19416
#include <stdio.h>

int main(void)
{
	int a;
	int b;
	int c;
	int i;

	scanf("%d",& a);
	scanf("%d",& b);
	scanf("%d",& c);

	if (a == b){
		printf("%d", c);
	}
	if (b == c){
		printf("%d", a);
	}
	if (a == c){
		printf("%d", b);
	}
	
	return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
using namespace std;
const int tINF = (int)INT_MAX;
const long long lINF = (long long)LLONG_MAX;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef DEBUG
			assert(freopen("inp", "r", stdin));
			assert(freopen("out", "w",stdout));
	#else
			#define cerr if(false)cerr
	#endif
    string s1,s2;
    cin >> s1 >> s2;
    int a, b;
    cin >> a >> b;
    string c;
    cin >> c;
    if(c == s1)
        --a;
    if(c == s2)
        --b;
    cout << a << " " << b << '\n';

    cerr << "Time execute: " << (double)clock() / (double)CLOCKS_PER_SEC 
    << " sec" << endl;
}

Measured memory_bytes: 256
# 2018/06/02

from collections import deque

d = deque()
q = int(raw_input())

for i in range(q):
    query = [int(j) for j in raw_input().split()]
    if query[0] == 0:
        if query[1] == 0:
            d.appendleft(query[2])
        else:
            d.append(query[2])
    elif query[0] == 1:
        print  d[query[1]]
    elif query[0] == 2:
        if query[1] == 0:
            d.popleft()
        else:
            d.pop()


Measured memory_bytes: 30488
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double x1 = sc.nextDouble();
		double y1 = sc.nextDouble();
		double x2 = sc.nextDouble();
		double y2 = sc.nextDouble();
		double ans = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
		System.out.println(ans);
	}
}



Measured memory_bytes: 27924
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			
			char[][] board = new char[8][8];
			for (int y = 0; y < 8; y++) {
				board[y] = sc.next().toCharArray();
			}
			
			int sx = sc.nextInt() - 1;
			int sy = sc.nextInt() - 1;
			
			bomb(board, sx, sy);
			
			out.println("Data " + (i + 1) + ":");
			for (int y = 0; y < 8; y++) {
				for (int x = 0; x < 8; x++) {
					out.print(board[y][x]);
				}
				out.println();
			}
		}
		out.flush();
	}
	
	static void bomb(char[][] board, int bx, int by) {
		if (board[by][bx] == '1') {
			board[by][bx] = '0';
			for (int x = Math.max(0, bx - 3); x <= Math.min(7, bx + 3); x++) {
				bomb(board, x, by);
			}
			for (int y = Math.max(0, by - 3); y <= Math.min(7, by + 3); y++) {
				bomb(board, bx, y);
			}
		}
	}
	
}

Measured memory_bytes: 25852
#include<stdio.h>
int main(){
  int n,i,j;
  int data[6];
  for(i=0;i<5;i++){
    scanf("%d",&data[i]);
  }
  for(i=0;i<4;i++){
    for(j=0;j<4-i;j++){
      if(data[j]<data[j+1]){
	int temp;
	temp=data[j];
	data[j]=data[j+1];
	data[j+1]=temp;
      }
    }
  }
  for(i=0;i<5;i++){
    printf("%d",data[i]);
    if(i==4){
      printf("\n");
    } else{
      printf(" ");
    }
  }
  return(0);
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int h, w;
int a[80][80];
int b[80][80];

const int kMax = 80 * 80 * 2;
using bs = bitset<kMax * 2 + 1>;
bs dp[81][81];

int main() {
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> a[i][j];
  rep(i, h) rep(j, w) cin >> b[i][j];
  dp[0][1][kMax] = 1;
  rep(i, h) rep(j, w) {
    int d = abs(a[i][j] - b[i][j]);
    bs b = (dp[i][j + 1] | dp[i + 1][j]);
    dp[i + 1][j + 1] = (b << d) | (b >> d);
  }
  rep(i, 80 * 80 * 40 + 1) if (dp[h][w][i + kMax]) {
    out(i);
    return 0;
  }
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n,m,r;
  cin>>n>>m>>r;
  int g[300][300];
  vector<int> path(r);
  rep(i,r){
    cin>>path[i];
    path[i]--;
  }
  rep(i,n)rep(j,n)g[i][j]=(i==j?0:INF);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    if(g[a][b]>c)g[a][b]=g[b][a]=c;
  }
  rep(k,n)rep(i,n)rep(j,n)g[i][j]=min(g[i][j],g[i][k]+g[k][j]);

  int ans=INF;
  sort(path.begin(),path.end());
  do{
    int tmp=0;
    rep(i,r-1) tmp+=g[path[i]][path[i+1]];
    ans=min(ans,tmp);
  }while( next_permutation(path.begin(),path.end()) );

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vb vector<bool>
#define pii pair<int,int>
#define mii map<int,int>
#define all(c)  c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf (long long) 1e18
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define rep(i,n)  for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int N = 1e9 + 7;

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



void solve()
{
    int n,k;
    cin>>n>>k;
    vector<int> v(n);
    rep(i,n)
        cin>>v[i];
    vector<int> ans(n);
    ans[1]=abs(v[1]-v[0]);
    for(int i=2;i<n;i++)
    {
        ans[i]=inf;
        for(int j=i;j>=0&&j>=i-k;j--)
        {
            ans[i]=min(ans[i],ans[j]+abs(v[i]-v[j]));
        }
    }
    cout<<ans[n-1];
    return;
}



int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
   int t;
    t=1;
    while(t--)
   {
      solve();
   }
}

Measured memory_bytes: 4800
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cmath>
#include <algorithm>
using namespace std;
using LL = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; i++)
const int INF = 1e9;
const int E = numeric_limits<int>::min();

int main(void)
{
    char c;
    cin >> c;

    if (c >= 65 && c <= 90){
        cout << 'A' << endl;
    }else if (c >= 97 && c <= 122){
        cout << 'a' << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    int sm = 0;
    for(int i=0; i<N; i++){
            cin >> a[i];
            sm += a[i];
    }
    int ans = N-1;
    int opt = 1<<30;
    for(int i=N-1; i>=0; i--){
            int dist = abs(a[i]*N-sm);
            if(dist <= opt){
                    ans = i;
                    opt = dist;
            }
    }
    cout << ans << endl;
    return 0;
}


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,P> PP;

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n,f[100][10];
int p[100][11];
ll ans=-INF;

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

	cin>>n;
	REP(i,n) REP(j,10) cin>>f[i][j];
	REP(i,n) REP(j,11) cin>>p[i][j];

	FOR(i,1,1<<10) {
		ll sum=0;
		int cnt[n];
		REP(j,n) {
			cnt[j]=0;
			REP(k,10) if((i>>k)&f[j][k]) cnt[j]++;
		}
		REP(j,n) sum+=p[j][cnt[j]];
		//cout<<"i,sum "<<BIT(i,10)<<' '<<sum<<endl;
		ans=max(ans,sum);
	}
	cout<<ans<<endl;


	return 0;
}


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

const int mod = 1000000007, mod2 = 998244353, inf = 0x3f3f3f3f;
const int maxn = 1e6 + 5;

int main()
{
//    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size() - 1; ++i){
        if (s[i] == s[i + 1]){
            if (s[i + 1] == '0') s[i + 1] = '1';
            else s[i + 1] = '0';
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 3E5 + 100;
int n, a[N];

int main() {
    cin >> n;
    FOR (i, 0, 3 * n) cin >> a[i];
    sort(a, a + 3 * n, greater<int>());
    LL s = 0;
    FOR (i, 0, n) s += a[i * 2 + 1];
    cout << s << endl;
}

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

int main()
{	
	int m, d, c = 0;

	cin >> m >> d;

	if (m > 3 && d > 21) {
		for (int i = 4; i <= m; i++)
			for (int j = 22; j <= d; j++)
				if ((j % 10 > 1) && (j / 10) * (j % 10) == i)
					c++;
	}

	cout << c << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cstdio>
#include<string>
#include<vector>
#include<math.h>
#include<time.h>
#include<utility>
#include<cstdlib>
#include<sstream>
#include<cstring>
#include<stdio.h>
#include<iomanip>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,product=1;
	cin>>n;
	while(product<=n){
		product*=2;
	}
	cout<<product/2;
	return 0;
}

Measured memory_bytes: 256