akhauriyash/Code-Regression huggingface dataset:
/**
    Sweet!
**/
#include <bits/stdc++.h>

#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define pp pop_back()
#define ll long long
#define ld long double
#define OK puts("OK");
#define sz(s) (ll)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

inline ll min(ll a, ll b) {
    return (a > b) ? b : a;
}

inline ll max(ll a, ll b) {
    return (a > b) ? a : b;
}

const int N = 2e5 + 10;
const int inf = 1e9+10;
const ll linf = 1e18+9;

ll n, m, a, b;
ll x[N];
ll ans = linf, del;
ll k[4*N], k2[4*N];

void eq(ll *t, ll v, ll tl, ll tr, ll pos, ll x) {
    if(tl == tr) {
        t[v] = x;
        return;
    }
    ll tm = (tl + tr) >> 1;
    if(pos <= tm)
        eq(t, v + v, tl, tm, pos, x);
    else
        eq(t, v + v + 1, tm + 1, tr, pos, x);
    t[v] = min(t[v + v], t[v + v + 1]);
}

ll get(ll *t, ll v, ll tl, ll tr, ll l, ll r) {
    if(l > r) return linf;
    if(l == tl && tr == r) {
        return t[v];
    }
    ll tm = (tl + tr) >> 1;
    return min(get(t, v + v, tl, tm, l, min(tm, r)),
               get(t, v + v + 1, tm + 1, tr, max(l, tm + 1), r));
}

int main() {
    scanf("%d%d%d%d", &n, &m, &a, &b);
    for(ll i = 1; i <= m; i++)
        scanf("%d", &x[i]);

    for(ll i = 1; i < 4*N; i++)
        k[i] = linf, k2[i] = linf;

    eq(k, 1, 1, n, a, abs(x[1] - b) - a);
    eq(k, 1, 1, n, b, abs(x[1] - a) - b);
    eq(k2, 1, 1, n, a, abs(x[1] - b) + a);
    eq(k2, 1, 1, n, b, abs(x[1] - a) + b);

    for(ll i = 2; i <= m; i++)
    {
        ll a = get(k, 1, 1, n, 1, x[i]) + del + x[i];
        ll b = get(k2, 1, 1, n, x[i], n) + del - x[i];
        a = min(a, b);
        del += abs(x[i] - x[i - 1]);
        eq(k, 1, 1, n, x[i - 1], a - x[i - 1] - del);
        eq(k2, 1, 1, n, x[i - 1], a + x[i - 1] - del);
    }
    for(ll i = 1; i <= n; i++)
        ans = min(ans, get(k, 1, 1, n, i, i) + del + i);
    printf("%lld\n", ans);
}


Measured memory_bytes: 14336
#include <iostream>
#define lli long long int
using namespace std;
int main()
{
    lli n;
    cin >> n;
    lli sum = 0;
    if(n == 1)
        cout << 0 << endl;
    else if(n == 2)
    {
        cout << 1 << endl;
    }
    else
    {
        
        cout << n*(n-1)/2 << endl;
    }

    return 0;
}


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

int main() {
  string s;cin>>s;
  string t="CODEFESTIVAL2016";
  int cnt=0;
  rep(i,s.size()){
    if(s[i]!=t[i])cnt++;
  }
  cout<<cnt<<endl;
}

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

int main()
{
  int n, l;
  cin >> n >> l;
  vector < pair<int, int> > apples;
  for (int i = 0; i < n; i++)
    apples.push_back({abs(l + i), l + i});
  sort(apples.begin(), apples.end());
  int ans = 0;
  for (int i = 1; i < n; i++)
    ans += apples[i].second;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	char in[201], tmp[201];
	int m, n, i, j;

	while (1) {
		scanf("%200s ", in);
		if (in[0] == '-')
			break;

		scanf("%d ", &m);
		while (m--) {
			scanf("%d ", &n);
			for (i = 0; in[i+n] != '\0'; i++) {
				tmp[i] = in[i+n];
			}
			for (j = 0; j < n; j++) {
				tmp[i+j] = in[j];
			}
			tmp[i+j] = '\0';
			for (i = 0; tmp[i] != '\0'; i++) {
				in[i] = tmp[i];
			}
		}
		puts(in);
	}
	return 0;
}


Measured memory_bytes: 2044
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    ll ans = 0;
    rep(i,N-1) {
        if (A[i] > A[i+1]) {
            ans += A[i]-A[i+1];
            A[i+1] = A[i];
        }
    }

    cout << ans << ln;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool path[10][10]; //隣接行列
bool visited[10];  //訪問したかどうか

int dfs(int depth, int from)
{
    if (depth == 0)
    {
        return 1;
    }

    int ans = 0;

    for (int v = 0; v < 10; v++)
    {
        if (v == from)
        {
            continue;
        }
        if (path[from][v] && !visited[v])
        {
            visited[v] = true;
            ans += dfs(depth - 1, v);
            visited[v] = false;
        }
    }

    return ans;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
    {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--; // 0-indexedに変える
        path[a[i]][b[i]] = true;
        path[b[i]][a[i]] = true;
    }

    visited[0] = true;

    cout << dfs(n - 1, 0) << endl;
}

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


int main(void){
    string s;
    int k;
    cin>>s>>k;
    int n = s.size();
    set<string> st;
    rep1(l,min(n,5)){
        rep(i,n-l+1){
            string sub = s.substr(i,l);
            st.insert(sub);
        }
    }
    for(auto str : st){
        k--;
        if(k==0){
            cout<<str<<endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll total =0;
    map<ll,ll>mp;
    REP(i,100000){
        mp[i]=0;
    }
    REP(i,n){
        int tmp;
        cin >> tmp;
        total+=tmp;
        mp[tmp]++;
    }
    
    int q;
    cin >> q;
    vector<int>b(q),c(q);
    REP(i,q){
        cin >> b[i] >> c[i];
    }
    REP(i,q){
        total-=b[i]*mp[b[i]];
        total+=c[i]*mp[b[i]];
        cout << total << endl;
        mp[c[i]]+=mp[b[i]];
        mp[b[i]]=0;
    }
    return 0;
}


Measured memory_bytes: 10332
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int dp[N],vis[N];
vector<int>e[N],p;
void dfs(int v)
{
	vis[v]=1;
	for(int i=0;i<e[v].size();i++)	
		if(!vis[e[v][i]])
			dfs(e[v][i]);
	p.push_back(v);
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		e[x].push_back(y);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	reverse(p.begin(),p.end());
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int v=p[i];
		for(int j=0;j<e[v].size();j++)
			dp[e[v][j]]=max(dp[e[v][j]],dp[p[i]]+1);
		ans=max(ans,dp[v]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 8440
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int n, m;
int main(void) {
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
    return 0;
}

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

int main() {
  int A, B, C, tmp = 0;
  cin >> A >> B >> C;
  tmp = B;
  B = A;
  A = tmp;

  tmp = C;
  C = A;
  A = tmp;

  cout << A << " " << B << " " << C << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int money1 = sc.nextInt();
          int money2 = sc.nextInt();
          int pro = sc.nextInt();
          if(money1 + money2 - pro >= 0) {
            System.out.println("Yes");
          } else {
            System.out.println("No");
          }      
          }
  }

Measured memory_bytes: 23892
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
//”次”の広義単調増加数列 size()=n,max<=m
void next_vec(vector<ll> &ans,ll m,ll n,bool &aaa){
   for(ll i=n-1;i>=0;i--){
     if(ans[i]!=m){
       ans[i]++;
       for(ll j=i;j<n;j++)ans[j]=ans[i];//後ろがans[i]にあわせる
       aaa=true;
       return;
     }
   }
  aaa=false;
  return;
}
 
int main(){
  ll n,m,q;
  cin >> n >> m >> q;
  vector<ll> a(q),b(q),c(q),d(q);
  ll MAX=0;
  rep(i,q){cin >> a[i] >> b[i] >> c[i] >> d[i];MAX+=d[i];}
  vector<ll> ans(n,1);
  ll M=0;
  bool aaa=true;
  while(aaa){
    ll cnt=0;
    rep(i,q)
    if(ans[b[i]-1]-ans[a[i]-1]==c[i])cnt+=d[i];
    M=max(M,cnt);
    //if(cnt==10)rep(i,n)cout << ans[i] << endl;
    if(M==MAX)break;
    //rep(i,n)cout<<ans[i]<<" ";
    //cout<<endl;
    //cout<<e<<endl;
    next_vec(ans,m,n,aaa);
  }
  cout << M << endl;
}

Measured memory_bytes: 3640
//BISMILLAHIR RAHMANIR RAHEEM
                                                //ALLAH IS WATCHING ME

//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█


#include<bits/stdc++.h>
using namespace std;

#define ull    unsigned long long
#define ll    long long
#define ios    ios::sync_with_stdio(0);cin.tie(0);
#define ses   "\n"

string digit="0123456789";
string small="abcdefghijklmnopqrstuvwxyz";

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};

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

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

//main function is here.........

int main()
{
    //ios
ll initial=1,multiple=1;
ll n;
cin>>n;
while(n>1){
    n/=2;
    multiple*=2;
    initial+=multiple;
}
cout<<initial;
}




//Alhamdulillah


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[100005], b[100005], c[100005], d[100005][3];
int main() {
  	cin >> n;
  	for (int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
  	for (int i = 1; i <= n; i++) {
      	d[i][0] = max(d[i - 1][1], d[i - 1][2]) + a[i];
      	d[i][1] = max(d[i - 1][0], d[i - 1][2]) + b[i];
      	d[i][2] = max(d[i - 1][0], d[i - 1][1]) + c[i];
    }
  	cout << max({d[n][0], d[n][1], d[n][2]}) << '\n';
}

Measured memory_bytes: 5528
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
//const int mod = 1000000007ll;
long ggd(long a, long b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}
long lcm(long number1,long number2){
	return number1/ggd(number1,number2)*number2;	
}

int main(){
    int n;
    std::cin >> n;
    itn ans=0;
    rrep(i,1,n+1)rrep(j,1,n+1)rrep(k,1,n+1){
        int d=ggd(i,j);
        d=ggd(d,k);
        ans+=d;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long int
#define fo(i, n) for (ll i = 0; i < n; i++)
#define fo1(i, n) for (ll i = 1; i <= n; i++)
#define pi (double)3.14159265359
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define vect vector<ll>
#define pb push_back
#define mod (ll) pow(10, 9) + 7
#define prq priority_queue <int, vector<int>, greater<in1t>>
#define scan(x) scanf("%lld",&x);
#define print(x) printf("%lld\n",x);
using namespace std;

void solve(){
	ll n;
	cin>>n;
	if(n%1000==0)
      cout<<"0"<<endl;
    else
    cout<<(1000-(n%1000))<<endl;	
}
int main(){
	int t=1;
	while (t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m,x;
  cin >> n >> m >> x;
  ll a[m];
  rep(i,m) cin >> a[i];
  ll k=lower_bound(a,a+m,x)-a;
  pr(min(k,m-k));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 256
/*
[abc148] F - Playing Tag on Tree
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5 + 5;
const int MAX_V = MAX_N;
const int MAX_LOG_V = 32;

vector<int> g[MAX_V];
int par[MAX_LOG_V][MAX_V];
int dep[MAX_V];

void dfs_lca(int v, int p = -1, int d = 0) {
    par[0][v] = p;
    dep[v] = d;
    for (int to : g[v]) {
        if (to == p) {
            continue;
        }
        dfs_lca(to, v, d + 1);
    }
}

int lca(int u, int v) {
    if (dep[u] > dep[v]) {
        swap(u, v);
    }
    for (int k = 0; k < MAX_LOG_V; k++) {
        if (((dep[v] - dep[u]) >> k) & 1) {
            v = par[k][v];
        }
    }
    if (u == v) {
        return u;
    }
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
        if (par[k][u] != par[k][v]) {
            u = par[k][u];
            v = par[k][v];
        }
    }
    return par[0][u];
}

void init(int root) {
    dfs_lca(root);
    for (int k = 1; k < MAX_LOG_V; k++) {
        for (int v = 0; v < MAX_V; v++) {
            par[k][v] = (par[k - 1][v] < 0) ? -1 : par[k - 1][par[k - 1][v]];
        }
    }
}

int N;
int TK, AO;

ll solve() {
    init(AO);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int w = lca(i, TK);
        if (dep[w] > dep[TK] - dep[w]) {
            ans = max(ans, dep[i] - 1);
        }
    }

    return ans;
}

int main() {
    cin >> N >> TK >> AO;
    TK--, AO--;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    cout << solve() << endl;

    return 0;
}


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


void solve(long long N, long long K){
    ll cnt = 0;

    while(N > 0) {
        cnt++;
        N /= K;
    }

    cout << cnt << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 764
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
b = list(li())

num_ofst = [[bi, (i+1) - bi] for i, bi in enumerate(b)]
ans = []

ok = True
while ok and num_ofst:
    cur = -1
    cur_idx = -1
    for i in range(len(num_ofst)-1, -1, -1):
        if num_ofst[i][1] == 0:
            cur = num_ofst[i][0]
            cur_idx = i
            break

        else:
            num_ofst[i][1] -= 1

    if cur != -1:
        num_ofst = num_ofst[:i] + num_ofst[i+1:]
        ans.append(cur)
    else:
        ok = False

if ok:
    print("\n".join(map(str, ans[::-1])))
else:
    print(-1)

Measured memory_bytes: 3064
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


#define rep(i,n) for(int i=0; i<n; i++)
#define mp make_pair

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

//BIT bit(16384);みたいな感じで生成する
struct BIT {
	typedef int T;
	T n;
	vector<T> bit;

	// 各要素の初期値は 0
	BIT(T num) : bit(num+1, 0) { n = num; }

	// a_i += w
	void add(T i, T w) {
		for (T x = i; x <= n; x += x & -x) {
			bit[x] += w;
		}
	}

	// [1, i] の和を計算.
	T sum(T i) {
		T ret = 0;
		for (T x = i; x > 0; x -= x & -x) {
			ret += bit[x];
		}
		return ret;
	}

	//[iより大きい]の和を計算
	T sum_above(T i) {
		T ret = 0;
		for (T x = i; x > 0; x -= x & -x) {
			ret += bit[x];
		}
		return sum(n) - ret;
	}

};

int n;
int a[200005];

ll inversion_count(){
	ll cnt = 0;
	set<pii> s;

	rep(i,n) s.insert(mp(a[i],i));
	int cnttmp = 1;
	for(auto x : s) {
		a[x.second] = cnttmp;
		cnttmp++;
    }

	BIT bit(200005);

	rep(i,n){
		cnt += bit.sum_above(a[i]);
		bit.add(a[i],1);
	}
	return cnt;
}


int main(){
	cin >> n;
	rep(i,n)cin >> a[i];
	ll ans = inversion_count();
	prints(ans);

	return 0;
}



Measured memory_bytes: 13596
n = int(input())
w = [input() for i in range(n)]
bool = True
for i in range(1,n):
    if w[i][0] != w[i-1][len(w[i-1]) - 1]:
        bool = False
    for j in range(0,i):
        if w[i] == w[j]:
            bool = False
if bool:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9192
length = int(input())
height = input().split(" ")

most = 0
count = 0

for i in range(length-1):
  if int(height[i]) >= int(height[i+1]):
    count += 1
  else:
    if count > most:
      most = count
      count = 0
    else:
      count = 0
if count > most:
      most = count
print(most)

Measured memory_bytes: 11132
require 'prime'
def prime?(n)
	return false if n == 1
	for i in 2..n-1
		return false if n % i == 0
	end
	true
end

n = gets.strip.to_i
j = 0
for i in 0..n-1
	j += 1 if Prime.prime?(gets.strip.to_i)
end
puts j

Measured memory_bytes: 8896
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    ABs = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(N)]
    ABs = sorted(ABs, key=lambda x: (x[1], x[0]))
    now = 0
    for A, B in ABs:
        now += A
        if B < now:
            print('No')
            return
    print('Yes')


if __name__ == "__main__":
    main()


Measured memory_bytes: 55948
//
// Created by tac on 2016/10/22.
//

#include <cstdlib>
#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>

namespace {

double distance(std::vector<double> x, std::vector<double> y, int p) {
    double d = 0.0;
    auto size = x.size();
    for (int i = 0; i < size; ++i) {
        d += std::pow(std::abs(x[i] - y[i]), p);
    }

    return std::pow(d, 1.0 / p);
}

double distance_inf(std::vector<double> x, std::vector<double> y) {
    double max_value = -1;
    auto size = x.size();
    for (int i = 0; i < size; ++i) {
        max_value = std::max(max_value, std::abs(x[i] - y[i]));
    }
    return max_value;
}


}

int main() {
    int n;
    std::vector<double> x;
    std::vector<double> y;
    int s;

    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> s;
        x.push_back(s);
    }
    for (int i = 0; i < n; ++i) {
        std::cin >> s;
        y.push_back(s);
    }
    std::cout << std::fixed << std::setprecision(6);
    std::cout << distance(x, y, 1) << std::endl;
    std::cout << distance(x, y, 2) << std::endl;
    std::cout << distance(x, y, 3) << std::endl;
    std::cout << distance_inf(x, y) << std::endl;

    return EXIT_SUCCESS;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

vector<vi> G;
vi deg;
int dp[100005];

int main(){
  int n,m; cin>>n>>m;
  G.assign(n, vi());
  deg.assign(n, 0);
  rep(i,m){
    int x,y; cin>>x>>y;
    x--; y--;
    G[x].push_back(y);
    deg[y]++;
  }
  queue<int> que;
  rep(i,n){
    if(deg[i]==0) que.push(i);
  }
  
  while(!que.empty()){
    auto v=que.front(); que.pop();
    for(auto nv: G[v]){
      deg[nv]--;
      if(deg[nv]==0){
        que.push(nv);
        chmax(dp[nv], dp[v]+1);
      }
    }
  }
  int ans=0;
  rep(i,n) chmax(ans,dp[i]);
  cout<<ans<<endl;
}
 

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <utility>
#define INF 10000000
using namespace std;



int main(){
  int n;
  cin >> n;
  vector<vector<int>> graph(n, vector<int>(n, INF));
  for (int i=0;i<n;i++)
    graph[i][i] = 0;
  for (int i=0;i<n;++i){
    int id,k;
    cin >> id >> k;
    for(int j=0;j<k;++j){
      int to, c;
      cin >> to >> c;
      graph[id][to] = c;
    }
  }
  for (int i=0;i<n; ++i){
    for (int j=0;j<n;j++){
      for (int k=0;k<n;k++){
        graph[j][k] = min(graph[j][k], graph[j][i] + graph[i][k]);
      }
    }
  }

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

  return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  int sum;
  int sub;
  int mul;
  sum = A+B;
  sub = A-B;
  mul = A*B;
  int ret[3];
  ret[0] = sum;
  ret[1] = sub;
  ret[2] = mul;
  sort(ret, ret+3, greater<int>());
  cout << ret[0] <<endl;

}



Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

set<ll> div(ll N) {
    set<ll> ans;
    for(ll x = 1; x * x <= N; x++) {
        if (N % x == 0) {
            ans.insert(x);
            ans.insert(N / x);
        }
    }
    return ans;
}

vint div_num(ll N) {
    vint d(N + 1, 1);
    vector<bool> is_prime(N + 1, true);
    d[0] = 0;
    is_prime[0] = false;
    is_prime[1] = false;
    REP(i, 2, N + 1) d[i]++;
    //is_prime[2] = true;
    for (ll x = 2; x * x <= N; x++) {
        if (is_prime[x] == false) continue;
      
        for (ll y = 2; x * y <= N; y++) {

            is_prime[x * y] = false;
        }
    }

    for (ll x = 2; x <= N; x++) {
        if (is_prime[x] == false) continue;

        for (ll y = 2; x * y <= N; y++) {
            d[x * y] += d[y] - 1;
        }
    }
    
    return d;
}
//
//void sieve(size_t max) {
//   
//    if (max + 1 > IsPrime.size()) {     // resizeで要素数が減らないように
//        IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
//    }
//    IsPrime[0] = false; // 0は素数ではない
//    IsPrime[1] = false; // 1は素数ではない
//
//    for (size_t i = 2; i * i <= max; ++i) // 0からsqrt(max)まで調べる
//        if (IsPrime[i]) // iが素数ならば
//            for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
//                IsPrime[i * j] = false;      // 素数ではない
//}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N;
    cin >> N;

    ll ans = 0;
    auto d = div_num(N);
    REP(k, 1, N + 1) {
        //auto d2 = div(k);
        //cout << k << ":" << d2.size() << " " << d[k] << endl;
        ans += ll(k) * d[k];
    }
    cout << ans << endl;
    return 0;
}

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

int n,p,l[100000];

void heap_sort(int n, int v[]){
  int now,nxt;
  for(int i=1;i<n;i++){
    now = i;
    while(now){
      nxt = (now-1)>>1;
      if(v[nxt] < v[now])swap(v[nxt],v[now]);
      else break;
      now = nxt;
    }
  }
  
  for(int i=n-1;i>0;i--){
    swap(v[i],v[0]);
    now = 0; nxt = (now+1)<<1;
    while(nxt-1 < i){
      if(v[now] < v[nxt-1]){
	if(nxt<i && v[nxt-1] < v[nxt]){
	  swap(v[now],v[nxt]);
	  now = nxt;
	}else{
	  swap(v[now],v[nxt-1]);
	  now = nxt-1;
	}
      }else if(nxt<i && v[now] < v[nxt]){
	swap(v[now],v[nxt]);
	now = nxt;
      }else break;
      nxt = (now+1)<<1;
    }
  }
}

int main(){
  while(scanf("%d",&n),n){
    long long num = n,len = 0;
    for(int i=0;i<n;i++){ scanf("%d",&p); len += p;}

    for(int i=0;i<n-1;i++)scanf("%d",&l[i]);
    heap_sort(n-1,l);
    
    for(int i=n-2;i>=0;i--){
      if( (num-1)*(len+l[i]) < num*len )break;
      num--; len += l[i];
    }
    printf("%lld\n",num*len);
  }
}
   

Measured memory_bytes: 1284
n = int(input())

a = list(map(int, input().split()))
ans = 0
flag = False
for index, i in enumerate(a, start = 1):
  target = i
  if flag:
    target = a[i-2]

  if index == target:
    ans += 1
    flag = True
  else:
    flag = False
print(ans)

Measured memory_bytes: 20512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX = 2e5 + 10;
int cnt[MAX][4];
ll modExp(ll b, ll p) {
	ll res = 1;
	while(p > 0) {
		if(p & 1) res = (res * b) % MOD;
		b = (b * b) % MOD, p >>= 1;
	}
	return res;
}
void add(ll &a, ll b) {
	b %= MOD;
	a = (a + b) % MOD;
}
void mul(ll &a, ll b) {
	b %= MOD;
	a = (a * b) % MOD;
}
void sub(ll &a, ll b) {
	b %= MOD;
	a = (a - b) % MOD;
	a = (a + MOD) % MOD;
}
int get(int l, int r, int i) {
	return cnt[r][i] - cnt[l - 1][i];
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	string s; cin >> s;
	int n = s.size();
	s = "X" + s;
	ll ans = 0;
	for(int i = 1; i <= n; i ++) {
		if(s[i] == '?') cnt[i][3] ++;
		else cnt[i][s[i] - 'A'] ++;
		for(int j = 0; j < 4; j ++) cnt[i][j] += cnt[i - 1][j];
	}
 	for(int i = 1; i <= n; i ++) {
 		if(s[i] == 'A' || s[i] == 'C') continue;
		ll lft = get(1, i - 1, 0);
		ll rht = get(i + 1, n, 2);
		ll cur1 = (lft * rht) % MOD;
		mul(cur1, modExp(3, get(1, n, 3) - (s[i] == '?')));
		ll lq = get(1, i - 1, 3), rq = get(i + 1, n, 3);
		ll cur2 = 0;
		ll tmp = (lq * rht) % MOD;
		mul(tmp, modExp(3, lq + rq - 1));
		add(cur2, tmp);
		tmp = (lft * rq) % MOD;
		mul(tmp, modExp(3, lq + rq - 1));
		add(cur2, tmp);
		tmp = (lq * rq) % MOD;
		mul(tmp, modExp(3, lq + rq - 2));
		add(cur2, tmp);
		ll cur = cur1;
		add(cur, cur2);
		add(ans, cur);
 	}
 	cout << ans;
	
	return 0;
}

Measured memory_bytes: 5320
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
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 _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
  int n;cin>>n;int k;cin>>k;
  int h[n];rep(i,n)cin>>h[i];
  vector<int> dp(n,1e9+7);
  dp[0]=0;
  rep(i,1,n){
    rep(j,1,k+1){
      if(i-j<0)continue;
      chmin(dp[i],abs(h[i]-h[i-j])+dp[i-j]);
    }
  }
  cout<<dp[n-1]<<endl;
}


    



  


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    long long int ans=0;
    
    int arr[n];
    
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        ans = ans^arr[i];
    }
    
    for(int i=0;i<n;i++)
    {
        cout<<(ans^arr[i])<<" ";
    }
    
    cout<<"\n";
    
    return 0;
}


Measured memory_bytes: 4360
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    x,k,d = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    x=abs(x)
    if x-k*d>=0:
        print(x-k*d)
        return 
    ans=float("inf")
    if (x//d)%2==k%2:
        ans=min(ans,x%d)
    else:
        ans=min(ans,abs(x%d-d))
    print(ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 72724
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;



int main(){
    ll h,w,n; cin >> h >> w >> n;
    ll sr,sc; cin >> sr >> sc;

    string t,a; cin >> t >> a;

    bool ok = false;
    ll pos,end;
    pos = sc;end = 0;
    rep(i,n){
        if(t[i] == 'L')pos--;
        if(pos == end){ok = true; break;}
        if(a[i] == 'R' && pos < w)pos++;
        // debug(pos);
    }
    debug(ok);
    pos = sc;end = w+1;
    rep(i,n){
        // ll pos = sc, end = w+1;
        if(t[i] == 'R')pos++;
        if(pos == end){ok = true; break;}
        if(a[i] == 'L' && 1 < pos)pos--;
    }
    debug(ok);
    pos = sr;end = 0;
    rep(i,n){
        // ll pos = sr, end = 0;
        if(t[i] == 'U')pos--;
        if(pos == end){ok = true; break;}
        if(a[i] == 'D' && pos < h)pos++;
    }
    pos = sr;end = h+1;
    debug(ok);
    rep(i,n){
        // ll pos = sr, end = h+1;
        if(t[i] == 'D')pos++;
        if(pos == end){ok = true; break;}
        if(a[i] == 'U' && 1 < pos)pos--;
    }
    debug(ok);

    cout << (ok ? "NO" : "YES") << endl;
}

Measured memory_bytes: 776
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

const int MAX=INT_MAX/10;
int main(){
	int n;
	while(cin>>n,n){
		vi p(n),t(n);
		REP(i,n){
			cin>>p[i]>>t[i];
		}
		vvi dp(n+1,vi(4,MAX));
		if(p[0]<=t[0]){
			dp[0][1]=p[0];
		}else{
			dp[0][1]=MAX;
		}
		REP(i,n-1){
			REP(j,3){
				if(t[i+1]-t[i]>=abs(p[i+1]-p[i])*(j+1)){
					dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+abs(p[i+1]-p[i]));
				}
			}
			REP(j,4){
				if(t[i+1]-t[i]>=p[i]*(j+1)+p[i+1]){
					dp[i+1][1]=min(dp[i+1][1],dp[i][j]+p[i]+p[i+1]);
				}
			}
		}
		int ans=MAX;
		REP(i,4){
			ans=min(ans,dp[n-1][i]+p[n-1]);
		}
		if(ans==MAX){
			int last=-1;
			for(int i=n-1;i>=0;i--){
				REP(j,4){
					if(dp[i][j]!=MAX){
						last=max(last,i);
					}
				}
			}
			cout<<"NG "<<last+2<<endl;
		}else{
			cout<<"OK "<<ans<<endl;
		}
	}
}

Measured memory_bytes: 1220
/*input
7 7
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b; cin >> a >> b;
    string ans1 = "";
    string ans2 = "";
    for(int i = 0; i < b; i++) ans1 += to_string(a);
    for(int i = 0; i < a; i++) ans2 += to_string(b);
    if(ans1 <= ans2) cout << ans1;
	else cout << ans2;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()	{
  int x, y;
  cin >> x >> y;
  if ((x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) && (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12))	{
    cout << "Yes" << endl;
    return 0;
  }
  else if ((x == 4 || x == 6 || x == 9 || x == 11) && (y == 4 || y == 6 || y == 9 || y == 11))	{
    cout << "Yes" << endl;
    return 0;
  }
  else if (x == 2 && y == 2)	{
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64
#define n_max 100000
int n;


void BFS(vector<pair<llong,llong>> tree[],llong saitan[],int tmp,bool visited[]){
    for(auto itr = tree[tmp].begin(); itr != tree[tmp].end();itr++){
        if(not visited[(*itr).first]){
            saitan[(*itr).first] = saitan[tmp] + (*itr).second;
            visited[(*itr).first]=true;
            BFS(tree, saitan,(*itr).first, visited);
        }
    }
}


int main(){
    cin >> n;
    vector<pair<llong,llong>> tree[n_max+5];
    llong a,b,c;
    REP(i,n-1){
        scanf("%ld%ld%ld",&a,&b,&c);
        tree[a].push_back(make_pair(b,c));
        tree[b].push_back(make_pair(a,c));
    }
    int Q,K;
    cin >> Q >> K;

    llong saitan[n_max+5]={};
    bool visited[n_max+5];
    saitan[K]=0;
    visited[K]=true;
    BFS(tree,saitan,K,visited);


    int x,y; 
    REP(i,Q){
        scanf("%d%d",&x,&y);
        printf("%ld\n",saitan[x] + saitan[y]);
    }
}

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

int main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	vector<int>rooms(n+1,-1);
	unordered_map<int,vector<int>>conn;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		conn[x].push_back(y);
		conn[y].push_back(x);
	}
	queue<int>q;
	unordered_set<int>s;
	q.push(1);
	s.insert(1);
	int count=n-1;
	while(!q.empty()){
		int sizes=q.size();
		for(int i=0;i<sizes;i++){
			int val=q.front();
			q.pop();
			for(int j=0;j<(int)conn[val].size();j++){
				int curr=conn[val][j];
				if(s.find(curr)==s.end()){
					count--;
					q.push(curr);
					rooms[curr]=val;
					s.insert(curr);
				}
			}
		}
	}
	if(count!=0){
		cout<<"No";
		return 0;
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++){
		cout<<rooms[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 17616
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main (String[] args) {
    Scanner in = new Scanner(System.in);

    while (in.hasNext()) {
      String S = in.next();
      String T = in.next();
      
      
      if (canTransform(S, T) && canTransform(T, S)) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
  
  private static boolean canTransform (String S, String T) {
    char[] mapping = new char[26];
    Arrays.fill(mapping, ' ');

    boolean canTransform = true;
    for (int i = 0 ; i < T.length(); ++i) {
      if (mapping[T.charAt(i) - 'a'] == ' ') {
        mapping[T.charAt(i) - 'a'] = S.charAt(i);
      } else {
        if (mapping[T.charAt(i) - 'a'] != S.charAt(i)) {
          return false;
        }
      }
    }
    
     return true;
  }
}

Measured memory_bytes: 28820
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
   int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  bool ok=true;
  rep(i,n){
    if(a[i]%2==1) continue;
    if(a[i]%5!=0&&a[i]%3!=0) ok=false;
  }
    if(ok){
      cout<<"APPROVED"<<endl;
    }
    else{
      cout<<"DENIED"<<endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a_dic = {}
for i in range(n):
    if not a[i] in a_dic:
        a_dic[a[i]] = 1
    else:
        a_dic[a[i]] += 1
sigma = 0
for key, item in a_dic.items():
    sigma += item*(item-1)//2
for i in range(n):
    print(sigma-a_dic[a[i]]+1)

Measured memory_bytes: 86348
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;

  int x; cin>>x;
  int ans;
  if (x <= 599) ans=8;
  else if (x <= 799) ans=7;
  else if (x <= 999) ans=6;
  else if (x <= 1199) ans=5;
  else if (x <= 1399) ans=4;
  else if (x <= 1599) ans=3;
  else if (x <= 1799) ans=2;
  else ans=1;
  COUT(ans);
  return 0;
}


Measured memory_bytes: 3648
import numpy as np
n, a = int(input()), np.array(list(map(int,input().split())))
odd, div2, div4 = len(np.where(a%2==1)[0]), len(np.where((a%2==0) & (a%4!=0))[0]), len(np.where(a%4==0)[0])
ans = "Yes" if (n%2==0 and odd <= div4) or (n%2==1 and ((odd-1==div4 and odd+div4==n) or div4 >= odd)) else "No"
print(ans)

Measured memory_bytes: 23128