akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
#define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

int n;
void dfs(string s, char m){
    if(s.size()==n)fin(s);
    else {
        for(char i='a'; i <=m+1; i++){
            dfs(s+(char)i, max(i,m));
        }
    }
}

int main() {
    
    cin>>n;
    dfs("a",'a');


}



Measured memory_bytes: 1536
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import itertools as ite
import math
import random
import sys
import codecs
from collections import defaultdict

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

n = input()
A = map(int, raw_input().split())
for i in range(n - 1):
    n1, n2 = map(int, raw_input().split())
    A += [n2]
DP = [[INF] * n for i in range(n)]
for i in range(n):
    DP[i][i] = 0

for L in range(1, n):
    for i in range(n - L):
        for j in range(L):
            DP[i][i + L] = min(DP[i][i + L], DP[i][i + j] + DP[i + j + 1][i + L] + A[i] * A[i + j + 1] * A[i + L + 1])
print DP[0][n - 1]



Measured memory_bytes: 7032
from bisect import bisect_right

N, D, A = map(int, input().split())
xh = sorted([list(map(int, input().split())) for _ in range(N)])
ds = [0]*(N+2)
b = 0
for i, (x, h) in enumerate(xh, 1):
  ds[i] += ds[i-1]
  d = ds[i]
  if d>=h:
    continue
  h -= d
  times = h//A if h%A==0 else h//A+1
  ds[i] += times*A
  ds[bisect_right(xh, [x+2*D, float('inf')])+1] -= times*A
  b += times
print(b)

Measured memory_bytes: 59944
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
#define mod(int)(1000000007)
using namespace std;
string test[2000];
int ok[213456];
signed main() {
	int n, m, a = 0, ans = 0; string s, t; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> s; int b = 0;
		for (int i = 0; i < a; i++) {
			if (test[i] == s) { ok[i]++; b = 1; }
		}
		if (b == 0) { test[a] = s; ok[a] = 1; a++; }
	}
	cin >> m;
	for (int h = 0; h < m; h++) {
		cin >> t;
		for (int i = 0; i < a; i++) {
			if (test[i] == t) { ok[i]--; }
		}
	}
	for (int h = 0; h < a; h++) {
		ans = max(ans, ok[h]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
name=[0]*5
ans=0
for _ in range(N):
    ini=list(input())
    if ini[0]=="M":
        name[0]+=1
    elif ini[0]=="A":
        name[1]+=1
    elif ini[0]=="R":
        name[2]+=1
    elif ini[0]=="C":
        name[3]+=1
    elif ini[0]=="H":
        name[4]+=1
for i in range(3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            if name[i]+name[j]+name[k]>=3:
                ans+=name[i]*name[j]*name[k]
print(ans)

Measured memory_bytes: 3064
#2-5 Knoapsack problem
while True:
    try:
        N, W = map(int,input().split())
        v=[]
        w=[]

        for i in range(N):
            temp1, temp2 = map(int, input().split())
            v.append(temp1)
            w.append(temp2)

        dp = [[0]*(W+1) for j in range(N+1)]

        for i in range(N-1,-1,-1):
            for j in range(W+1):
                if j < w[i]:
                    dp[i][j] = dp[i+1][j]
                else:
                    dp[i][j] = max(dp[i+1][j],dp[i+1][j-w[i]]+v[i])
        print(dp[0][W])
        
    except:
        break



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

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

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

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    const int MOD = 1e9+7;

    int n;
    cin>>n;
    int ans=0;
    rep(i,1,n+1){
        ans+=i*(n/i)*(n/i+1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
ll n,m,k;
int ok(ll x,ll k){
    m=x;
    while(m%k==0) m/=k;
    return m%k==1;
}


int main(){
    cin>>n;
    ll ans=1, sz=sqrt(n-1);
    rep(i,2,sz){
        if((n-1)%i==0){
            if(n%i) ++ans;
            if((n-1)/i!=i && n%((n-1)/i)) ++ans;
        }
    }
    if(n%(n-1)) ++ans;

    sz=sqrt(n);
    rep(i,2,sz){
        if(n%i==0){
            if(ok(n,i)) ++ans;
            if(n/i!=i && ok(n,n/i)) ++ans;
        }
    }
    cout<< ans<<endl;
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void) {
 
    string S;
    cin >> S;

    size_t n = S.length();
    string a = S.substr(0, (n-1)/2);
    string b = S.substr((n+3)/2-1);

    int ans=0;

    for(size_t i=0;i<S.length()/2;i++)
    {
        if (S[i]!=S[S.length()-1-i])
        {
            ans=1;
            break;
        }
    }
    for(size_t i=0;i<a.length()/2;i++)
    {
        if (a[i]!=a[a.length()-1-i])
        {
            ans=1;
            break;
        }
    }
    for(size_t i=0;i<b.length()/2;i++)
    {
        if (b[i]!=b[b.length()-1-i])
        {
            ans=1;
            break;
        }
    }
    if (ans==0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,q; cin>>n>>m>>q;
    vector<vi> t(n);
    rep(i,m){
        int l,r; cin>>l>>r; l--; r--;
        t[l].pb(r);
    }
    rep(i,n) sort(all(t[i]));
    while(q--){
        int a,b; cin>>a>>b; a--; b--;
        int ans=0;
        FOR(i,a,b){
            ans+=upper_bound(all(t[i]), b)-t[i].begin();
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    vl L(N);
    rep(i, N) cin >> L[i];

    ll ans = 0;
    rep(i, N) repe(j, i + 1, N) repe(k, j + 1, N) {
        if (L[i] == L[j] or L[j] == L[k] or L[i] == L[k]) continue;
        vl A = {L[i], L[j], L[k]};
        if (A[0] + A[1] > A[2] and A[0] + A[2] > A[1] and A[1] + A[2] > A[0]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(long long N, long long K, std::vector<long long> h){
  int sum = 0;
  REP(x, N) {
    if(K <= h.at(x)) sum++;
  }
  cout << sum << endl;
}

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


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

using namespace std;

vector<int> to[200005];
vector<int> ans;

void dfs(int v, int p=-1){
    for(int u: to[v]){
        if(u == p) continue;
        ans[u] += ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin >> n >> q;

    for(int i=0; i<n-1; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    for(int i=0; i<q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0);

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

Measured memory_bytes: 23552
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<int,string> mp;
  mp[0] = "Sunny";
  mp[1] = "Cloudy";
  mp[2] = "Rainy";
  string s;cin>>s;
  if(s=="Sunny")cout<<"Cloudy"<<endl;
  if(s=="Cloudy")cout<<"Rainy"<<endl;
  if(s=="Rainy")cout<<"Sunny"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename Q_temp>
using smaller_queue = priority_queue <Q_temp, vector<Q_temp>, greater<Q_temp> >;

const int INF = (int) 1e9;
const ll LINF = (ll) 4e18;
const ll MOD = (ll) (1e9 + 7);
const double PI = acos(-1.0);
const int limit = 200010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); ++i)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbg2(x_) for(auto a_ : x_) cerr << a_ << " "; cerr << endl;
#define dbg3(x_ , sx_) rep(i, sx_) cerr << x_[i] << " "; cerr << endl;
vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int l[n];
    rep(i, n) cin >> l[i];
    sort(l, l + n);
    int sum = 0;
    rep(i, n - 1) sum += l[i];
    Yes(sum > l[n - 1]);
    return 0;
}

Measured memory_bytes: 256
import math
import decimal
a,b,x = map(int, input().split(" "))
if a * a * b * 0.5 < x:#多い
  print(math.atan((2 * b - (2 * x / a / a))/a) * 180 / math.pi)
else:#少ない
  print(90 - math.atan(2 * x / (a * b * b)) * 180 / math.pi)

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

int main(){
    long long X, now=100;

    cin >> X;

    for(int i=0;i<10010010010010;i++){
        now = 1.01 * now;
        if(now>=X){
            cout << i + 1 << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
require 'openssl'
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=998244353
n = gets.chomp.to_i
d = gets.chomp.split.map(&:to_i)

if d[0] != 0
  puts 0
  exit
end

h = Hash.new(0)
d.each do |num|
  h[num] += 1
end

if h[0] != 1
  puts 0
  exit
end

ans = 1

ha = h.sort_by{|k,v| k}
(ha.size-1).times do |i|
  if ha[i][0] + 1 != ha[i+1][0]
    puts 0
    exit
  end
  # p [ha[i][1], ha[i+1][1], ha[i][1].to_bn.mod_exp(ha[i+1][1], MOD)]
  a = ha[i][1].to_bn.mod_exp(ha[i+1][1], MOD)
  ans = (ans * a) % MOD
  # ans = (ans * (ha[i][1] ** ha[i+1][1])) % MOD
end

puts ans


Measured memory_bytes: 31540
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans;
	ans=a*c;
	
	if(a*d>ans)
	{
		ans=a*d;
	}
	if(b*c>ans)
	{
		ans=b*c;
	}
	if(b*d>ans)
	{
		ans=b*d;
	}
	cout<<ans;



	return 0;
}

Measured memory_bytes: 3568
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int N, K;
	string S;

	cin >> N >> K >> S;

	if (S[K - 1] == 'A')S[K - 1] = 'a';
	else if(S[K - 1] == 'B')S[K - 1] = 'b';
	else S[K - 1] = 'c';

	cout << S;
}

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
#define MAXNM 2010
lli sumTable[MAXNM][MAXNM];
lli S[MAXNM];
lli T[MAXNM];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  REPS(i, N) { cin >> S[i]; }
  REPS(i, M) { cin >> T[i]; }

  sumTable[0][0] = 1;
  REPS(i, N) { sumTable[i][0] = 1; }
  REPS(i, M) { sumTable[0][i] = 1; }

  REPS(i, N) {
    REPS(j, M) {
      sumTable[i][j] = sumTable[i - 1][j] + sumTable[i][j - 1];
      if (S[i] != T[j]) {
        sumTable[i][j] -= sumTable[i - 1][j - 1];
      }
      sumTable[i][j] = (sumTable[i][j] + MOD) % MOD;
    }
  }
 
  cout << sumTable[N][M] << "\n";
}


Measured memory_bytes: 31744
import sys
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline

N = int(readline())
S = np.array([list(i) for i in read().split()], np.int64)
edges = np.where(S == 1)

# 二部グラフかを判定する。隣り合う頂点の色が被らないように白黒で塗り分ける
graph = [[] for _ in range(N)]
start = None
for i, j in zip(edges[0].tolist(), edges[1].tolist()):
    graph[i].append(j)
    graph[j].append(i)
    start = i


def judge(start):
    colors = [-1] * N
    colors[start] = 0
    queue = deque([(start, 0)])
    while queue:
        V, c = queue.popleft()
        c ^= 1
        for v in graph[V]:
            if colors[v] == -1:
                colors[v] = c
                queue.append((v, c))
            else:
                if colors[v] != c:
                    return False
    return True


if judge(start):
    d = floyd_warshall(S)
    print(int(np.max(d)) + 1)
else:
    print(-1)


Measured memory_bytes: 29592
//Hey u r far away to know this
#include <bits/stdc++.h>
using namespace std;
#define     ff      	    	first
#define     pb 	         	push_back
#define     ss          		second
#define     ll      	    	long long
#define     MAX  	       	5000
#define     mpi         		map<int, int>
#define     mpll        		map<ll, ll>
#define     pll         		pair<ll, ll>
#define     plld        		pair<ll, double>
#define     SKILLER     		ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     vi          		std::vector<int>
#define     vll         		std::vector<ll>
#define     vs          		std::vector<string>
#define     vvi         		std::vector<std::vector<int>>
#define     vvll        		std::vector<std::vector<ll>>
#define     all(v)      		v.begin(), v.end()
#define     allr(v)      		v.rbegin(), v.rend()
#define     loop(i, a, b) 	for(int i = a; i < b; i++)
#define 	  debug(x) 		cout << x <<" " <<"\n";
#define 	  debug1(x, y) 	cout << x << " " << y  << "\n";
#define 	  debug2(x, y, z) 	cout << x << " " << y << " " << z<<"\n";
#define 	  int 			ll
const   int N = 1e6+5, Mod = 1e9 + 7;
int32_t main(){
    	SKILLER;
    	
     ll n, k; cin >> n >> k;
     vector<int> v(n+1);
     for(int i = 1; i <= n; i++)
     	cin >> v[i];
     int cycle = 1;
     int i = 1;
     if(k <= n){
     	i = 1;
     	while(k){
     		i = v[i];
     		k--;
     	}
     	cout << i;
     	return 0;
     }
     i = 1;
     set<int> s;
     while(true){
     	if(s.find(i) != s.end()){
     		cycle = i;
     		break;
     	}
     	s.insert(i);
     	i = v[i];
     }
     int x = cycle;
     cycle = 1;
     i = 1;
     int before = 0;
     while(x != i){

     	i = v[i];
     	before++;
     }
     while(x != v[i]){
     	i = v[i];
     	cycle++;
     }
     k -= before;
     k = k%cycle;
     i = x;
     while(k){
     	i = v[i];
     	k--;
     }
     cout << i;
    	return 0;
}

Measured memory_bytes: 12084
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<pair<ll,ll>> b(m);
    rep(i, m){
        cin >> b[i].second >> b[i].first;
    }
    sort(b.begin(), b.end());
    /*rep(i, m){
        cout << b[i].first << " " << b[i].second << endl;
    }*/

    vector<ll> a_sum(n + 1);
    a_sum[0] = 0;
    _rep(i, 1, n + 1){
        a_sum[i] = a_sum[i - 1] + a[i - 1];
    }
    ll num = 0;
    ll c_num = 0;
    ll ans = a_sum[n];
    while(true){
        if(a[num] < b[m - 1].first){
            ans += b[m - 1].first - a[num];
        }
        c_num++;
        num++;
        if(c_num == b[m - 1].second){
            m--, c_num = 0;
        }

        if(num == n || (m == 1 && c_num == b[0].second))break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

int n, m, ca[1000000];
vector<int> v;

int dp(int k) {
        if (k== m) return 1;
        if (k> m) return 0;

        int &ret= ca[k];
        if (ret!= -1) return ret;
        else ret= 0;

        lp(i, v.size()) {
               if (v[i]>= 3) ret+= ( dp(k+ v[i])% mod );
        }
        return ret% mod;
}

void solve() {
        cin >> n;
        m= n;
        lp(i, 2111) ca[i]= -1;
        for (int i= 3; i<= n; i++) {
                v.push_back(i);
        }
        cout << dp(0);
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        //freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
        int t = 1, tc= 1;
        //cin >> t;
        while ( t-- ) {
                //cout << "Case #"<< tc++<< ": ";
                solve();
        }
return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>
#include<math.h>
#define N 10000
int main(){
  int ary[N];
  int i,j,n,flag=0,scount=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&ary[i]);
  }
  for(i=0;i<n;i++){
    flag=0;
    for(j=2;j<=sqrt(ary[i]);j++){
      if(ary[i]%j==0){
	flag=1;
      }
    }
    if(flag==0)scount++;
  }
  printf("%d\n",scount);
  return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    int H, W; cin >> H >> W;
    vector<string> s(H);
    REP(i, H) cin >> s[i];

    mat t(H + W + 1, vec(H + W + 1, 0));
    REP(i, H){
        REP(j, W){
            if(s[i][j] == '#')
            t[i + j + 1][i - j + 1 + W] = 1;
        }
    }
    mat tsum = t;
    REP(i, H + W + 1) REP(j, H + W) tsum[i][j + 1] += tsum[i][j];
    REP(j, H + W + 1) REP(i, H + W) tsum[i + 1][j] += tsum[i][j];

    int ans = 0;
    REP(i, H + W){
        REP(j, H + W){
            if(t[i + 1][j + 1] == 0) continue;
            FOR(j2, j + 1, H + W){
                if(t[i + 1][j2 + 1] == 0) continue;
                int n = j2 - j;
                if(i - n >= 0) ans += tsum[i - n + 1][j2 + 1] - tsum[i - n + 1][j] - tsum[i - n][j2 + 1] + tsum[i - n][j];
                if(i + n < H + W) ans += tsum[i + n + 1][j2 + 1] - tsum[i + n + 1][j] - tsum[i + n][j2 + 1] + tsum[i + n][j];
            }
            FOR(i2, i + 2, H + W){
                if(t[i2 + 1][j + 1] == 0) continue;
                int n = i2 - i;
                if(j - n >= 0) ans += tsum[i2][j - n + 1] - tsum[i + 1][j - n + 1] - tsum[i2][j - n] + tsum[i + 1][j - n];
                if(j + n < H + W) ans += tsum[i2][j + n + 1] - tsum[i + 1][j + n + 1] - tsum[i2][j + n] + tsum[i + 1][j + n];
            }
        }
    }
    cout << ans;
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

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

ll n, w;

const ll V_MAX = 100000+10;
const ll N_MAX = 100+10;

ll value[N_MAX], weight[N_MAX];
ll dp[N_MAX][V_MAX]; // dp[i][j] = i番目までの品物を選んだ時の価値j以下における重さの最小値

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

    cin >> n >> w;
    ll sum = 0;
    REP(i,n){
        cin >> weight[i+1] >> value[i+1];
        sum += value[i+1];
    }

    for(ll j=0;j<=sum;j++){
        if(j==0) dp[0][j] = 0;
        else dp[0][j] = LINF;
    }

    for(ll i=1;i<=n;i++){
        for(ll j=0;j<=sum;j++){
            if(j<value[i]) dp[i][j] = dp[i-1][j];
            else dp[i][j] = min(dp[i-1][j],dp[i-1][j-value[i]]+weight[i]);
        }
    }

    while(1){
        if(dp[n][sum]<=w){
            cout << sum << endl;
            break;
        }
        sum--;
    }

    
    return 0;
}



Measured memory_bytes: 82520
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
x, y = map(int, input().split())
if x in A and y in A:
    print("Yes")
elif x in B and y in B:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
//404 Not Found {=}7 (o)7 (x)7
#include<bits/stdc++.h>
using namespace std;
#define append push_back
#define endl "\n"
#define dbug(x) cout<<#x<<"="<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;

const ll maxn = 5e5+10, inf = 1e9, mod= 1e9+7;
ll a[maxn];
vector<ll> v;
ll b[maxn];
ll fen[maxn+10];
ll par[maxn];
ll get(ll id)
{
    ll sum = 0;
    for(;id;id -= id&-id)
        sum += fen[id];
    return sum;
}
void add(ll id)
{
    for(;id<maxn;id += id&-id)
        fen[id] ++;
}
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    
    ll n;
    cin >> n;
    for(ll i = 0;i<n;i++){
        cin >> a[i];
        v.append(a[i]);
    }
    sort(v.begin(),v.end());
    ll l=0,r=n;
    while(l+1 < r)
    {
        ll mid = (l+r) / 2;
        
        for(ll i = 0;i<n;i++)
            b[i] = (a[i]<v[mid]?1ll:-1ll);
        b[0] += n+2;
        for(ll i = 1 ;i<n;i++)
            b[i] += b[i-1];

        ll ans = 0;
        add(n+2);
        ans += get(b[0]-1);
        add(b[0]);
        for(ll i = 1;i < n;i++)
        {
            ans += get(b[i]-1);
            add(b[i]);
        }                                   
        if(ans > (n*(n+1))/4)
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
        for(ll i = 0;i<maxn;i++)
            fen[i] =0;
    }
    cout << v[l];
    
    return 0;
}

Measured memory_bytes: 13428
#include<stdio.h>
#include<string.h>
int main(){
	char key[15];
	scanf("%s", key);
	char temp[15];
	int len=strlen(key);
	int newindex=0, index=0;
	while(len--){
		if(key[index]=='B'){
			if(newindex>0){
				newindex--;
			}
			temp[newindex]=' ';
			index++;
		}
		else{
			temp[newindex]=key[index];
			index++;
			newindex++;
		}
		
	}
	temp[newindex] = '\0';
	printf("%s\n", temp);

	
	return 0;
}

Measured memory_bytes: 1604
N, C = map(int, input().split())
#D[X][Y] = (X+1)→(Y+1)に塗り替えたときの違和感
D = [list(map(int, input().split())) for i in range(C)]
#C[i][j] = (i+1,j+1)の色
c = [list(map(int, input().split())) for i in range(N)]
#import pdb; pdb.set_trace()
ans = float('inf')
#c0: (i+1)+(j+1) \equiv 0 なるマスに色1, 色2, ..., 色Cがそれぞれ何個書かれているか
c0 = [0] * C
c1 = [0] * C
c2 = [0] * C
for i in range(N):
    for j in range(N):
        if (i + j) % 3 == 0:
            c0[c[i][j] - 1] += 1
        if (i + j) % 3 == 1:
            c1[c[i][j] - 1] += 1
        if (i + j) % 3 == 2:
            c2[c[i][j] - 1] += 1


for x in range(C):
    for y in range(C):
        for z in range(C):
            if (x-y)*(y-z)*(z-x) != 0:
                iwakan = sum(D[i][x] * c0[i] for i in range(C)) + sum(D[j][y] * c1[j] for j in range(C))+sum(D[k][z] * c2[k] for k in range(C))                
                ans = min(ans, iwakan)
print(ans)


Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define MOD 1000000007
#define ALL(a) begin((a)),end((a))
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
struct edge
{
	int from, to, 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;
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int dp[1 << 15][15];
int d[15][15];
int V, E;
vector<vector<edge>> es(15);

int bitDP(int s, int v)
{
	if (dp[s][v] >= 0) return dp[s][v];
	if (s == (1 << V) - 1 && v == 0)
	{
		return dp[s][v] = 0;
	}
	int res = INF;
	REP(i, V)
	{
		if (!(s >> i & 1))
		{
			res = min(res, bitDP(s | 1 << i, i) + d[v][i]);
		}
	}
	return dp[s][v] = res;
}

int main()
{
	cin >> V >> E;
	REP(i, V)REP(j, V)
	{
		d[i][j] = (i == j ? 0 : INF);
	}
	REP(i, E)
	{
		int s, t, c;
		cin >> s >> t >> c;
		d[s][t] = c;
	}
	MS(dp, -1);
	cout << (bitDP(0, 0) >= INF ? -1 : bitDP(0, 0)) << endl;
	return 0;
}

Measured memory_bytes: 3128
n=int(input())
a=list(map(int,input().split()))

a=sorted(a)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
c=make_divisors(a[0])


d=sorted(c)
f=[]
for y in range(len(d)):
  e=d[y]
  ch=0
  for x in range(1,n):
    if not a[x]%e==0:
      continue
    ch+=1
  if ch==n-1:
    f.append(e)
    
print(max(f))

Measured memory_bytes: 20000
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	vector<ll> a(n);vector<ll> b(m);
	vector<ll> prefa(n+2);vector<ll> prefb(m+2);
	prefa[0]=0;prefb[0]=0;
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		prefa[i+1]=prefa[i]+a[i];
	}
	for(ll i=0;i<m;i++)
	{
		cin>>b[i];
		prefb[i+1]=prefb[i]+b[i];
	}
	ll ans=0;ll j=m;
	for(ll i=0;i<n+1;i++)
	{
		if(prefa[i]>k){
			break;
		}
		while(j>=0&&prefb[j]>(k-prefa[i]))
		{
			j--;
		}
		ans=max(ans,i+j);
		
	}
	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 9484
#include<stdio.h>

int n, a, i;
int p[20];
int main(void){
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", p+i);
	}
	for(i=1; i<n-1; i++){
		if(p[i-1]<p[i] && p[i]<p[i+1]){
			a++;
		}else if(p[i-1]>p[i] && p[i]>p[i+1]){
			a++;
		}
	}
	printf("%d\n", a);
}


Measured memory_bytes: 128
use std::io::*;
const MOD: u64 = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: u64 = itr.next().unwrap().parse().unwrap();
    let k: u64 = itr.next().unwrap().parse().unwrap();

    let mut ans = 0;
    for i in k..n + 2 {
        let low = i * (i - 1) / 2;
        let high = (n * 2 - i + 1) * i / 2;
        if high >= low {
            ans = (ans + high - low + 1 + MOD) % MOD;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2120
#include <iostream>
#include <algorithm>	
using namespace std;
#define ll long long

ll r[99], p[99];

ll ps(int n, ll k) {
	if (k == 0) return 0;
	if (n == 0) return 1;
	if (k == 1) return 0;
	if (k <= r[n - 1] + 1)
		return ps(n - 1, k - 1);
	else if (k == r[n - 1] + 2)
		return p[n - 1] + 1;
	else if (k <= r[n - 1] * 2 + 2)
		return p[n - 1] + ps(n - 1, k - r[n - 1] - 2) + 1;
	else
		return p[n - 1] * 2LL + 1;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n; ll k; cin >> n >> k;
	r[0] = p[0] = 1;
	for (int i = 1; i <= n; i++) {
		r[i] = r[i - 1] * 2 + 3; p[i] = p[i - 1] * 2 + 1;
	}
	cout << ps(n, k) << '\n';
	return 0;
}

Measured memory_bytes: 256
from sys import stdin

N = int(stdin.readline().rstrip())
p = [int(x) for x in stdin.readline().rstrip().split()]

cnt = 0
for k in range(len(p)):
    if p[k] != k + 1:
        cnt += 1

if cnt == 2 or cnt == 0:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() {
  int n, y;
  cin >> n >> y;

  int sum_yen, sum_num, ten_thousand_yen, five_thousand_yen, thousand_yen;
  FOR(i, 0, n + 1)
  {
    FOR(j, 0, n + 1)
    {
      ten_thousand_yen = i * 10000;
      five_thousand_yen = j * 5000;
      if (ten_thousand_yen + five_thousand_yen + (1000 * (n - i - j)) == y && (n - i - j) >= 0)
      {
        cout << i << " " << j << " " << n - i - j << "\n";
        return(0);
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << "\n";

  return(0);
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;

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

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

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

	for (int i = 0; i < N - 1; i++)
	{
		if (A.at(i) == A.at(i + 1))
		{
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long a[] = new long[n];
		int ans = 0;
		
		for(int i=0;i<n;i++){
		    a[i] = sc.nextLong();
		    for(long j=0; j<n; j++){
		        if(a[i]%2==0){
		            a[i] = a[i]/2;
		            ans++;
		        }
		    }
		}
		
        System.out.println(ans);
	}
}


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

int main() {
  int N; cin >> N;
  int m = 1, n = 0;
  int long long sum = 0;
  
  vector<int> a(N);
  for( int i = 0; i < N; i++ ) {
    cin >> a.at(i);
    if( a.at(i) < 0 ) {
      n++;
      a.at(i) *= -1;
    }
  }
  
  for( int i = 0; i < N; i++ )
    sum += a.at(i);
  int min = *min_element(a.begin(), a.end());
  sum = sum - 2 * min * ( n % 2 );
  cout << sum << endl;
  
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  while(1){
    int n,p;
    vector <int>an;
    int so[101];
    cin>>n>>p;
    if(n==-1&&p==-1)break;
    int c=0;
    for(int i=n+1;c<=p;i++){
      int f=0;
      if(i==1)continue;
      for(int j=2;j*j<=i;j++){
	if(i%j==0){f=1;break;}
      }
      if(f==0){so[c]=i;c++;}
    }
    for(int i=0;i<p;i++)
      for(int j=i;j<p;j++)
	an.push_back(so[i]+so[j]);
    sort(an.begin(),an.end());
    cout<<an[p-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
#define N 100
#define INF 1<<25
int n,p[N+1],m[N+1][N+1];
int matrixchainmultiplication(){
  for(int i=1;i<=n;i++) m[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=INF;
      for(int k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  return m[1][n];
}
int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>p[i]>>p[i+1];
  cout<<matrixchainmultiplication()<<endl;
  return 0;
}
/*
verified on 2017/04/26
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_B
*/

Measured memory_bytes: 3100
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] x = new int[m];
        int[] y = new int[m];
        int[] num = new int[n];
        Arrays.fill(num, 1);
        boolean[] flag = new boolean[n];
        Arrays.fill(flag, false);
        flag[0] = true;
        for(int i=0;i<m;i++){
        	x[i] = sc.nextInt()-1;
        	y[i] = sc.nextInt()-1;
        }

        for(int i=0;i<m;i++){
        	if(num[x[i]]==1 && flag[x[i]]){
        		num[x[i]]--;
        		flag[y[i]] = true;
        		num[y[i]]++;
        		flag[x[i]] = false;
        	}
        	else if(num[x[i]]>1 && flag[x[i]]){
        		num[x[i]]--;
        		num[y[i]]++;
        		flag[y[i]] = true;
        	}
        	else{
        		num[x[i]]--;
        		num[y[i]]++;
        	}
        }

        int count = 0;
        for(int i=0;i<n;i++){
        	if(flag[i]){
        		count++;
        	}
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 83788
N=int(input())
s=''
point=0
q1,q2,q3=0,0,0 #q1はBA q2はBの最初のみ q3はAの末尾のみ
for j in range(N):
    n=str(input())
    point+=n.count("AB")
    if n[0]=="B" and n[len(n)-1]=="A":
      q1+=1  
    elif n[0]=="B":
      q2+=1
    elif n[len(n)-1]=="A":
      q3+=1
    else:
      pass
if q1>=1:
  if q2==0 and q3==0:
    print(q1-1+point)
  elif q2==0 or q3==0:
    print(q1-1+1+point)
  else:
    print(q1-1+point+2+min(q2-1,q3-1))
else:
  print(min(q2,q3)+point)

Measured memory_bytes: 44136
//config = { input: 'tmp', newline: '\r\n' }; // win
config = { input: '/dev/stdin', newline: '\n' }; // linux

line = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline);

const MAXSIZE = 1000;
max = new Array(MAXSIZE);
for (i = 0; i < MAXSIZE; i++) {
  max[i] = new Array(MAXSIZE);
  for (j = 0; j < MAXSIZE; j++) max[i][j] = 0;
}

function lcs(X, Y, max) {
  var idx0, i, j;

  idx0 = X.indexOf(Y[0]);
  if (idx0 === -1) idx0 = X.length;
  for (i = 0; i < idx0; i++) max[i][0] = 0;
  for (i = idx0; i < X.length; i++) max[i][0] = 1;

  idx0 = Y.indexOf(X[0]);
  if (idx0 === -1) idx0 = Y.length;
  for (j = 1; j < idx0; j++) max[0][j] = 0;
  for (j = idx0; j < Y.length; j++) max[0][j] = 1;

  for (i = 1; i < X.length; i++) {
    for (j = 1; j < Y.length; j++) {
      max[i][j] = Math.max(max[i-1][j], max[i][j-1]);
      if (X[i] === Y[j])
        max[i][j] = Math.max(max[i][j], max[i-1][j-1]+1);
    }
  }
  return max[X.length-1][Y.length-1];
}

for (i = 1; i < line.length; i += 2) {
  console.log(lcs(line[i], line[i+1], max));
}

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

int main(){
  vector<int> cnt(4);
  for(int i = 0;i < 3;i++){
    int a,b;
    cin >> a >> b;
    cnt[a-1]++;
    cnt[b-1]++;
  }
  string ret = "YES";
  for(int i = 0;i < 4;i++){
    if(cnt[i] >= 3){
      ret = "NO";
    }
  }

  cout << ret << endl;
}


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;
#pragma GCC optimize("O3")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000*1000+5;
const ll N2      = 2000*1000*10;
const ld PI  = 3.141592653589793;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> tree_set;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n,m;
    cin>>n>>m;

    n==m ? cout<<"Yes" : cout<<"No" ; 
    printclock;
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt() - (i + 1);
        }
        Arrays.sort(array);
        long median = 0;
        if(n % 2 == 0) {
            median = (array[n / 2] + array[n / 2 - 1]) / 2;
        } else {
            median = array[(int)Math.floor(n/2)];
        }
        long min = 0;
        for(int i = 0; i < n; i++) {
            min += Math.abs(array[i] - median);
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 65016
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, m; cin >> n >> m;
  vector<vector<ll>> G(n);
  rep(i, m) {
    ll a, b; cin >> a >> b; --a, --b;
    G[a].pb(b);
    G[b].pb(a);
  }
  if (m % 2 == 1) {
    cout << -1 << endl;
    return;
  }
  vector<bool> used(n, false);
  vector<ll> cnt(n, 0);
  vector<P> ans;
  function<void(ll,ll)> dfs = [&](ll v, ll pv) {
    used[v] = true;
    each(to, G[v]) if (to != pv && used[to]) {
      ans.eb(v, to);
      ++cnt[v];
    }
    each(to, G[v]) if (to != pv && !used[to]) dfs(to, v);
    if (pv < 0) {
      assert(cnt[v] % 2 == 0);
    }
    else if (cnt[v] % 2 == 0) {
      ans.eb(pv, v);
      ++cnt[pv];
    }
    else {
      ans.eb(v, pv);
      ++cnt[v];
    }
  };
  dfs(0, -1);
  each(p, ans) cout << p.first+1 << " " << p.second+1 << endl;
}


Measured memory_bytes: 17136