akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

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

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

    int N;
    cin >> N;

    string S;
    cin >> S;

    int Q;
    cin >> Q;

    for (int q = 0; q < Q; q++) {
        int K;
        cin >> K;

        ll d = 0, dm = 0, m = 0, dmc = 0;
        for (int i = 0; i < N; i++) {
            if (i >= K) {
                char r = S[i - K];
                if (r == 'D') { dm -= m; d--; }
                if (r == 'M') { m--; }
            }
            char c = S[i];
            if (c == 'D') d++;
            if (c == 'M') { dm += d; m++; }
            if (c == 'C') dmc += dm;
        }
        cout << dmc << "\n";
    }

    return 0;
}



Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define INF 0x3f3f3f3f
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=1000000007;
const double PI = acos(-1.0);
const double epsilon = PI / 180.0;//角度转弧度 
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const int N = 1e3+10;

vector<ll> num;
int main() {
	ll n;
	cin>>n;
	for(ll i = 2;i <= n / i;i++) {
		ll cnt = 0;
		for(; n % i == 0;n /= i) {
			cnt++;
		}
		if(cnt != 0)
		num.pb(cnt);
	}
	if(n > 1) num.pb(1);
	int m = num.size();
	ll ans = 0;
	rep(i, 0, m) {
		ll x = num[i];
		ll l = 1, r = x;
		while(l < r) {
			ll mid = l + r + 1 >> 1;
			if(mid * (mid + 1) / 2 <= x) l = mid;
			else r = mid - 1;
		}
		//cout<<x<<" "<<l<<"\n";
		ans += l;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    string s;
    cin >> s;

    vector<ll> w(n), e(n);
    rep(i, n)
    {
        if (s[i] == 'E') {
            e[i]++;
        } else {
            w[i]++;
        }
    }
    for (int i = 1; i < n; ++i) {
        w[i] += w[i - 1];
        e[i] += e[i - 1];
    }
    ll val = n;
    rep(i, n)
    {
        if (i == 0) {
            val = min(val, e[n - 1] - e[0]);
        } else if (i == n - 1) {
            val = min(val, w[n - 2]);
        } else {
            val = min(val, w[i - 1] + (e[n - 1] - e[i]));
        }
    }
    cout << val << endl;
    return 0;
}

Measured memory_bytes: 5396
#include <bits/stdc++.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll dp[102][100005];
ll a[105],w[105],n,t;
void solve(ll n,ll t)
{
    if(dp[n][t]!=-1)
    {
        return ;
    }
    if(n==0)
    {
        if(t>=w[0])
        {
            dp[n][t]=a[0];
            return;
        }
        else
        {
            dp[n][t]=0;
            return;
        }
    }
    dp[n][t]=0;
    if(t>=w[n])
    {
        solve(n-1,t-w[n]);
        solve(n-1,t);
        dp[n][t]=max(dp[n-1][t],dp[n-1][t-w[n]]+a[n]);
    }
    else
    {
        solve(n-1,t);
        dp[n][t]=dp[n-1][t];
    }
    return;
}
int main()
{
cin>>n>>t;
for(ll i=0;i<n;i++)
{
    cin>>w[i]>>a[i];
}
memset(dp,-1,sizeof(dp));
solve(n-1,t);
cout<<dp[n-1][t];
}


Measured memory_bytes: 80000
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple< int,int,int > T;
int main(){
  int h,w;
  cin>>h>>w;
  char ma[101][101];
  int dx[]={0,0,-1,1},dy[]={1,-1,0,0};
  bool res=true;
  for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>ma[i][j];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if (ma[i][j]=='.')continue;
      bool f1=false;
      for(int k=0;k<4;k++){
        int nx=i+dx[k],ny=j+dy[k];
        if(0<=nx and nx<h and 0<=ny and ny<w and ma[i][j]=='#'){
          if(ma[nx][ny]=='#')f1=true;
        }
      }
      if(!f1){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter
from collections import deque


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
a = readints()


def minimum(l):
    c = 0
    for i in range(len(l)):
        if l[i] == 'choose':
            c += 1
    if len(l) == c:
        return 1
    while 'choose' in l:
        l.remove('choose')
        # print(l)
    x = list(set(l))
    return len(x)


color = []
for i in range(N):
    if 1 <= a[i] and a[i] <= 399:
        color.append('gray')
    elif 400 <= a[i] and a[i] <= 799:
        color.append('brown')
    elif 800 <= a[i] and a[i] <= 1199:
        color.append('green')
    elif 1200 <= a[i] and a[i] <= 1599:
        color.append('light blue')
    elif 1600 <= a[i] and a[i] <= 1999:
        color.append('blue')
    elif 2000 <= a[i] and a[i] <= 2399:
        color.append('yellow')
    elif 2400 <= a[i] and a[i] <= 2799:
        color.append('orange')
    elif 2800 <= a[i] and a[i] <= 3199:
        color.append('red')
    elif 3200 <= a[i]:
        color.append('choose')
cnt = color.count('choose')
while 'choose' in color:
    color.remove('choose')
print(minimum(color), len(set(color))+cnt)


Measured memory_bytes: 3832
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
#include<random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){
  
  string s, t;
  cin >> s >> t;
  t.pop_back();
  if(s == t) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3564
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    M, *DC = map(int, read().split())

    total = digits = 0
    for d, c in zip(DC[::2], DC[1::2]):
        total += d * c
        digits += c

    ans = digits - 1 + (total - 1) // 9

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 28240
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
  ll n , a;
  cin >> n >> a;
  ll ans = n;
  rep(k,2,50) {
    for(ll x=2;;++x) {
      ll mul = 1;
      rep(i,0,k) {
        mul *= x;
        if(mul >= n)
          break;
      }
      if(mul >= n) {
        ll need = (x - 1) * k;
        mul = 1;
        rep(i,0,k) mul *= (x - 1);
        while(mul < n) {
          mul /= x - 1;
          mul *= x;
          need++;
        }
        ans = min(ans , need + a * (k - 1));
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll> > a(n);  rep(i, 0, n) cin >> a[i].first >> a[i].second;
  sort(all(a));
  
  ll drink = m;
  ll money = 0;
  rep(i, 0, n) {
    if(drink <= a[i].second) {
      money += drink*a[i].first;
      break;
    }
    else {
      money += a[i].first*a[i].second;
      drink -= a[i].second;
    }
  }
  cout << money << "\n";
}

Measured memory_bytes: 1792
/* ex5_3
    riverstone*/

#include<stdio.h>
#include <stdbool.h>

#define LIM 100 //行数、列数の上限

int main(void){
    
    int height, width, i, j;
    //多次元配列の定義
    //rowとcolは各行と各列に1つ以上の黒が存在するかを記録
    char block[LIM][LIM];
    int row[LIM]={}, col[LIM]={};

    //入力の受け取り
    scanf("%d %d", &height, &width);

    //行列のマス(i,j)を読み取る
    //各行と各列に1つ以上の黒が存在するかをrowとcolに記録
    for(i = 0; i < height; i++){
        for(j = 0; j < width; j++){
            scanf(" %c", &block[i][j]);
            if(block[i][j] == '#'){
                //マス(i,j)が黒のとき,row[i],col[j]を1にする
                row[i] = 1;
                col[j] = 1;
            }
        }   
    }
    
    //rowとcolを見て共に1であるようなマスの場合のみ出力
    for(i = 0; i < height; i++){
        if(row[i] == 1){
            for(j = 0; j < width; j++){
                if(col[j] == 1){
                    //row[i] = tureかつcol[j] = 0のときblock[i][j]を表示
                    printf("%c", block[i][j]);
                }
            }
            //1行すべて処理が終わると改行する
            printf("\n");  
        } 
    }
 
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

using namespace std;

int g[300000],h[300000];
int i,n;

int main()
{
    scanf("%d",&n);
    for (i=1;i<=n;i++)
        scanf("%d",&g[i]);
    for (i=1;i<=n;i++)
        h[i]=g[i];
    sort(h+1,h+n+1);
    for (i=1;i<=n;i++)
        if (g[i]<=h[n/2])
        	printf("%d\n",h[n/2+1]);
        else
        	printf("%d\n",h[n/2]);
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() { 
  int k,t;
  cin >> k >>t;
  vi a(t);
  rep(i,t) cin >> a[i];

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

  int ma = a.back();
  int ans = max(0,ma-(k-ma)-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#6問目
N, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(N-1):
    #まず一番前の要素がxより小さくなければならない
    if(i == 0 and a[i] > x):
        count += a[i] - x
        a[i] = x
        
    if(a[i] + a[i+1] > x):
        count += a[i] + a[i+1] - x
        a[i+1] = x - a[i]
print(count)

Measured memory_bytes: 14252
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.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))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1000000007;

ll gcd(ll x, ll y) {
  ll a, b;
  if (y >= x) {
    a = y;
    b = x;
  } else {
    a = x;
    b = y;
  }
  if (b == 0) return a;
  return gcd(a % b, b);
}

ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main() {
  ll n, m;
  cin >> n >> m;

  vll lst(n);
  rep(i, n) {
    cin >> lst[i];
    lst[i] /= 2;
  }

  ll lcmv = 1;
  rep(i, n) {
    lcmv = lcm(lcmv, lst[i]);
    if(lcmv > m){
      puts("0");
      return 0;
    }
  };

  ll ok = true;
  rep(i, n) {
    ll t = lcmv / lst[i];
    if (t % 2 == 0) {
      ok = false;
      break;
    }
  }

  ll ans = ok ? (m / lcmv + 1) / 2 : 0;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
from functools import reduce
def rerooting(N, adj, merge, identity, finalize):
    """
    merge: (T,T) -> T, (T, merge)はモノイド
    identity: 単位元
    finalize: T -> T

    以下の形で書けるdpは対応可能
    dp[u,v] = finalize(merge(dp[v,k] for k in adj[v] if k != u))
    ただし(u,v)は辺
    """

    order = [None]*N
    parent = [None]*N
    parent[0] = -1
    stack = [0]
    for i in range(N):
        v = stack.pop()
        order[i] = v
        for u in adj[v]:
            if parent[u] is None:
                parent[u] = v
                stack.append(u)

    # from leaf to parent
    dp_down = [None]*N
    for v in reversed(order[1:]):
        p = parent[v]
        dp_down[v] = finalize(reduce(merge,
            (dp_down[c] for c in adj[v] if c != p),
            identity))

    # from parent to leaf
    dp_up = [None]*N
    dp_up[0] = identity
    for v in order:
        if len(adj[v]) == 1 and adj[v][0] == parent[v]:
            continue
        p = parent[v]
        left = [dp_up[v]]
        for u in adj[v]:
            if u != p:
                left.append(merge(left[-1],dp_down[u]))

        right = [identity]
        for u in reversed(adj[v]):
            if u != p:
                right.append(merge(dp_down[u],right[-1]))
        i = 0
        for u in adj[v]:
            if u != p:
                dp_up[u] = finalize(merge(left[i],right[-i-2]))
                i += 1

    for v,l in enumerate(adj):
        order[v] = reduce(merge,
                    (dp_down[u] for u in adj[v] if u != parent[v]),
                    identity)
        order[v] = finalize(merge(order[v], dp_up[v]))

    return order

def solve(N,M,E):

    adj = [[] for _ in range(N)]
    for a,b in E:
        adj[a].append(b)
        adj[b].append(a)

    def merge(x,y):
        return (x*y)%M
    def finalize(x):
        return x+1

    res = rerooting(N,adj,merge,1,finalize)
    return [v-1 for v in res]


if __name__ == '__main__':
    N,M = map(int,input().split())
    E = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(N-1)]
    print(*solve(N,M,E),sep='\n')

Measured memory_bytes: 125156
/**

    WARNING
          This Code Sucks
                        Just Like My Life :(

**/
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template<class T> using orderd_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, w, weight[102], v[102];
long long dp[102][N];
int main(){
    scanf("%d%d",&n,&w);
    for(int i = 1 ; i <= n ; i++){
        scanf("%d%d",&weight[i],&v[i]);
    }
    for(int i = 1 ; i <= n + 1; i++){
        for(int j = 1 ; j <= w ; j++){
            dp[i][j] = dp[i-1][j];
            if (weight[i - 1] <= j)
                dp[i][j] = max(dp[i - 1][j -weight[i - 1]] + v[i-1], dp[i-1][j]);
        }
    }
    printf("%lld",dp[n+1][w]);
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    
    vector<int> a(3*n);
    for (int i = 0; i < 3*n; i++) cin >> a[i];
    
    sort(a.rbegin(), a.rend());
    
    int index = 1;
    long long ans = 0;
    for (int i = 0; i < n; i++){
        ans += a[index];
        index += 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#define MAX 100001
using namespace std;
int val[MAX], row[MAX];
int p[MAX];
vector<int> cango[MAX];
int visited[MAX];
 
void dfs(int id, int start) {
	if (visited[start] == 0) {
		visited[start] = 1;
		row[start] = id;
		val[p[start]] = id;
		vector<int>::iterator ite = cango[start].begin();
		while(ite != cango[start].end()) {
			dfs(id, *ite);
			ite++;
		}
	}
}
 
int main(){
	int rowsize, pairsize;
	cin >> rowsize >> pairsize;
	for (int i=1; i <= rowsize; i++) {
		cin >> p[i];
	}
	for (int i = 1; i <= pairsize; i++) {
		int from, to;
		cin >> from >> to;
		cango[from].push_back(to);
		cango[to].push_back(from);
	}
	int nowid = 1;
	for (int i=1; i<=rowsize; i++) {
		if(visited[i] == 0) {
			dfs(nowid, i);
			nowid++;
		}
	}
  int ans = 0;
	for (int i=rowsize; i >= 1; i--) {
		if (row[i] == val[i]) {
			ans++;
		}
	}
  cout << ans << endl;
 
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

// geometry
typedef long double Real;
#define EPS 1e-12
typedef complex<Real> P;
bool P_less(const P &a,const P &b){
  if(a.real()!=b.real())return a.real()<b.real();
  return a.imag()<b.imag();
}
Real dot(const P &a,const P &b){return real(conj(a)*b);}
Real cross(const P &a,const P &b){return imag(conj(a)*b);}
int ccw(const P &a,const P &b,const P &c){
  Real x = cross(b-a,c-a);
  if(abs(x)<EPS)return 0;
  else if(x<0)return -1;
  else return 1;
}

struct ccw_less{
  P x;
  bool operator()(const P &a,const P &b) const{
    int c = ccw(x,a,b);
    if(c==0) return norm(a-x)<norm(b-x);
    return c==1;
  }
};
vector<P> createConvexHull(vector<P> p){
  // Graham's scan
  vector<P> ret(p.size());
  // ?????????????????????
  int id = 0;
  REPR(i,p.size()) if(P_less(p[i],p[id])) id = i;
  swap(p[0],p[id]);
  // ????§??????????
  ccw_less cw;
  cw.x = p[0];
  sort(p.begin()+1,p.end(),cw);
  // ??°?????????????????£???
  int iter = 0;
  ret[iter++] = p[0];
  REPR(i,p.size()){
    while(iter>=2 && ccw(ret[iter-2],ret[iter-1],p[i])<=0)--iter;
    ret[iter++] = p[i];
  }
  ret.resize(iter);
  return ret;
}

int main(){
  // verify : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0068
  while(true){
    int n;
    scanf("%d",&n);
    if(!n)break;
    vector<P> p(n);
    REP(i,n){
      Real x,y;
      scanf("%Lf,%Lf",&x,&y);
      p[i] = P(x,y);
    }
    vector<P> conv = createConvexHull(p);
    cout<< (n-conv.size()) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#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;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int LG = 18;

vector<ll> x;
int nxt[100001];
int st[LG][100001];

int get(int s, int l)
{
	for(int i = LG - 1; i >= 0; i--)
	{
		if(l&(1<<i)) s = st[i][s];
	}
	return s;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; 
	cin >> n; x.resize(n+1);
	for(int i = 0; i < n; i++)
	{
		cin >> x[i];
	}
	ll d, q; cin >> d >> q;
	x[n] = ll(1e18);
	for(int i = 0; i < n; i++)
	{
		int p = upper_bound(x.begin(), x.end(), x[i] + d) - x.begin();
		p--;
		nxt[i] = p;
		st[0][i] = p;
	}
	
	for(int i = 1; i < LG; i++)
	{
		for(int j = 0; j < n; j++)
		{
			st[i][j] = st[i - 1][st[i-1][j]];
		}
	}
	
	while(q--)
	{
		int a, b; cin >> a >> b;
		a--; b--;
		if(a > b) swap(a, b);
		int lo = 1; int hi = 100000;
		int ans = -1;
		while(lo <= hi)
		{
			int mid = (lo + hi)>>1;
			int pos = get(a, mid);
			if(pos >= b)
			{
				ans = mid; hi = mid - 1;
			}
			else
			{
				lo = mid + 1;
			}
		}
		cout << ans << '\n';
	}
}


Measured memory_bytes: 9088
#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    int a[n],count=0;

    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]!=i+1)
        {
            count++;
        }
    }
    if(count<=2)
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;

}


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

using namespace std;

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

	int a[n] = {0};

	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int xx = min(j-i,abs(x-i)+abs(y-j)+1);
			a[xx]++;
          	
		}
	}

	for(int i=1;i<n;i++)
		cout << a[i] << "\n";
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  
  ll x,y;
  cin >> x >> y;
  
  // x, x*2, (x*2)*2
  // 3, 6, 12, 24,
  // 1, 2, 4, 8
  // x*2^n
  
  ll val = x;
  ll count = 0;
  while(val<=y){
    val *= 2;
    count++;
  }
  
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3568
def main():
    N = int(input())
    t_lst = [0] * (N + 1)
    x_lst = [0] * (N + 1)
    y_lst = [0] * (N + 1)

    for i in range(1, N + 1):
        t, x, y = map(int, input().split())
        t_lst[i] = t
        x_lst[i] = x
        y_lst[i] = y

    ans = "Yes"
    for i in range(N):
        dt = t_lst[i + 1] - t_lst[i]
        dist = abs(x_lst[i + 1] - x_lst[i]) + abs(y_lst[i + 1] - y_lst[i])
        if dt < dist:
            ans = "No"
            break
        elif dt % 2 != dist % 2:
            ans = "No"
            break

    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;

int main() {
    int n;
    ll w;

    cin >> n >> w;

    vector<ll> weights(n);
    vector<ll> vals(n);

    for (int i = 0; i < n; i++)
        cin >> weights[i] >> vals[i];

    int MAX_VAL = n * 1000;

    // dp[val] = weight

    const ll INF = LLONG_MAX / 2;
    vector<ll> dp(MAX_VAL + 1, INF);
    dp[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = MAX_VAL; j >= 0; j--) {
            ll new_val = j + vals[i];
            if (new_val > MAX_VAL || dp[j] == INF)
                continue;
            dp[new_val] = min(dp[new_val], dp[j] + weights[i]);
        }
    }

    for (int j = MAX_VAL; j >= 0; j--) {
        if (dp[j] <= w) {
            cout << j << endl;
            // cout << dp[j] << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int dp[61][2][2][2];

int solve(int pos, int carry, bool tightL, bool tightR, int64 n) {
  if (pos < 0) return 1 - carry;
  int& ret = dp[pos][carry][tightL][tightR];
  if (ret >= 0) return ret;
  int x = ((n & (1LL << pos)) ? 1 : 0);
  ret = 0;
  for (int i = 0; i < 2; ++i) {
    if (tightL && i > x) continue;
    bool nxt_tightL = (tightL && i == x);
    for (int j = 0; j < 2; ++j) {
      if (tightR && j > x) continue;
      bool nxt_tightR = (tightR && j == x);
      for (int nxt_carry = 0; nxt_carry < 2; ++nxt_carry) {
        int64 cnt = 0;
        for (int u = 0; u < 2; ++u) {
          int v = i ^ u;
          int sum = u + v + nxt_carry;
          if (sum % 2 == j && sum / 2 == carry) ++cnt;
        }
        if (cnt) {
          // trace(pos, i, j, nxt_carry, cnt);
          ret += solve(pos - 1, nxt_carry, nxt_tightL, nxt_tightR, n);
          ret %= MOD;
        }
      }
    }
  }
  return ret;
}


int main() {
  int64 n;
  cin >> n;
  memset(dp, 255, sizeof(dp));
  int ret = solve(60, 0, true, true, n);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall ABC102C.cpp -o ./out/ABC102C.out
./out/ABC102C.out
*/

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

typedef long long ll;
ll a[200005];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ll lb, ub;
  ll mid1, mid2;
  lb = -10000000000;
  ub = 10000000000;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
//    ub = max(ub, a[i]);
  }
  mid1 = (ub - lb) / 3 + lb;
  mid2 = (ub - lb) / 3 * 2 + lb;
  for (int i = 0; i < 100; ++i) {
    ll temp1 = 0;
    for (int j = 0; j < n; ++j) {
      temp1 += abs(a[j] - (mid1+(j+1)));
    }
    ll temp2 = 0;
    for (int j = 0; j < n; ++j) {
      temp2 += abs(a[j] - (mid2+(j+1)));
    }
    if (temp1 < temp2) {
      ub = mid2;
      mid1 = (ub - lb) / 3 + lb;
      mid2 = (ub - lb) / 3 * 2 + lb;
    } else {
      lb = mid1;
      mid1 = (ub - lb) / 3 + lb;
      mid2 = (ub - lb) / 3 * 2 + lb;
    }
//    cout << lb << " " << ub << "\n";
  }
  ll ans = 100000000000000;
//  cout << lb << " " << ub << "\n";
  for (int k = lb; k <= ub; ++k) {
    ll temp3 = 0;
    for (int j = 0; j < n; ++j) {
      temp3 += abs(a[j] - (k+(j+1)));
    }
//    ans = min(ans, temp3);
    if (temp3 < ans) {
//      cout << k << "\n";
      ans = temp3;
    }
  }
  cout << ans << "\n";
}


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

void change( int& x, int& y, char& s, char& t )
{
    int temp1 = x;
    x = y;
    y = temp1;

    char temp2 = s;
    s = t;
    t = temp2;
}

void BubbleSort( int a, char* m, int* f )
{
    for( int i = 0; i <= a - 1; i++ )
    {
        for( int j = a - 1; j >= i + 1; j-- )
        {
            if( f[j] < f[j-1])
            {
                change( f[j], f[j-1], m[j], m[j-1] );
            }
        }
    }
}

void SelectionSort( int a, char* m, int* f )
{
    for( int i = 0; i <= a - 1; i++ )
    {
        int min = i;
        for( int j = i; j <= a - 1; j++ )
        {
            if( f[j] < f[min] )
                min = j;
        }
         change( f[i], f[min], m[i], m[min]);
    }
}


 int main()
{
    int n;
    bool judge = true;

    cin >> n;

    char mark1[n], mark2[n];
    int num1[n], num2[n];

    for( int i = 0; i < n; i++ )
    {
        cin >> mark1[i] >> num1[i];
        mark2[i] = mark1[i];
        num2[i] = num1[i];
    }

    BubbleSort( n, mark1, num1 );
    SelectionSort( n, mark2, num2 );

    for( int i = 0; i < n - 1; i++ )
    {
        cout << mark1[i] << num1[i] << " ";
    }
    cout << mark1[n-1] << num1[n-1] << endl;
    cout << "Stable" << endl;

    for( int i = 0; i < n - 1; i++ )
    {
        cout << mark2[i] << num2[i] << " ";
    }
    cout << mark2[n-1] << num2[n-1] << endl;

    for( int i = 0; i < n; i++ )
    {
        if( mark1[i] != mark2[i] )
        {
            judge = false;
            break;
        }
    }

    if( judge == true )
        cout << "Stable" << endl;
    else
        cout << "Not stable" << endl;
    return 0;
}


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

int dp[100005];

vector<int>adj[100005];

int dfs(int x){
    if (dp[x] != 0) return dp[x];
    int res = 0;
    for (int i = 0; i < adj[x].size(); i++){
        res = max(dfs(adj[x][i]),res);
    }
    return dp[x] = 1+res;
}

int main(int argc, char const *argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m; cin >> n >> m;
    for (int i = 0; i < m; i++){
        int x,y; cin >> x >> y;
        adj[x].push_back(y);
    }
    int res = 0;
    for (int i = 1; i <= n; i++){
        res = max(res,dfs(i));
    }
    cout << res-1 << endl;
    return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a * b - (a + b - 1) << endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int d, int n) {
    if (d == 0) {
        if (n == 100) return 101;
        return n;
    }

    int x = 100 ^^ d;
    if (d == 1 && n == 100) return x * n + 100;
    if (d == 2 && n == 100) return x * n + 10000;
    return x * n;
}

void main() {
    auto dn = readints;
    int d = dn[0], n = dn[1];

    auto ans = calc(d, n);
    writeln(ans);
}

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

using namespace std;

#define pii pair<ll, ll>
#define ll long long
#define PRIME 1000000007
#define sq(x) ((x)*(x))
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mset(x,v) memset(x,v,sizeof(x))

int main() {

  ios_base::sync_with_stdio(false); cin.tie(0);

  ll n,arr[100005]={0},i,dp[100005]={0};
  cin >> n;
  dp[0]=0;
  for(i=0;i<n;i++){
    cin >> arr[i];
    if(i==1)
      dp[i]=abs(arr[i]-arr[i-1]);
    else if(i)
      dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout << dp[n-1] << endl;
}


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

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

int main() {
    int n;
    cin >> n;
    float s[100];
    float m[100];
    float a = 0;
    float b = 0;

    rep(i,n){
        cin >> s[i];
    }

    rep(i,n){
        m[i] = 1 / s[i];
    }

    rep(i,n){
        a += m[i];
    }

    b = 1 / a;

    cout << b << endl;


}

Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

A,B,C,X,Y = II()

if A+B<2*C:
    print(A*X+B*Y)
else:
    if X<Y:
        if B>2*C:
            print(X*2*C+(Y-X)*2*C)
        else:
            print(X*2*C+(Y-X)*B)
    else:
        if A>2*C:
            print(Y*2*C+(X-Y)*2*C)
        else:
            print(Y*2*C+(X-Y)*A)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b;
    for(int i=0;i<100000;i++){
        cin >> a >> b;
        if(a==0&&b==0){
            break;
        }
        for (int j=0;j<a;j++){
            for(int k=0;k<b;k++){
                if(k%2==1&&j%2==0){
                    cout << ".";
                }
                else if(k%2==0&&j%2==1){
                    cout << ".";
                }
                else {
                    cout << "#";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
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(); }
template<class T> inline T sqr(T x) { return x*x; }
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define rall(a)		(a).rbegin(), (a).rend()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;


int main()
{
	int n;
	cin >> n;
	rep(_, n){

		string s, w;
		cin >> w >> s;
		int l = s.size();

		for (int i = w.size() - 1; i >= 0;i--){

			if (w[i] == 'J')
				s = s[l - 1] + s.substr(0, l - 1);         
			if (w[i] == 'C')
				s = s.substr(1, l - 1) + s[0];
			if (w[i] == 'E'){
				string t = s;
				s = t.substr(l - l / 2, l / 2);
				if(l % 2)s += t[l / 2];
				s += t.substr(0, l / 2);
			}
			if (w[i] == 'A')
				reverse(all(s));
			if (w[i] == 'P')	
				rep(j, l)if (s[j] >= '0' && s[j] <= '9')s[j] = (s[j] == '0' ? '9' : s[j] - 1);
			if (w[i] == 'M')
				rep(j, l)if (s[j] >= '0' && s[j] <= '9')s[j] = (s[j] == '9' ? '0' : s[j] + 1);

		}

		cout << s << endl;
	}

	return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ld> point;
#define F first
#define S second

ll f(ll n)
{
	if (n < 2) return 1;
	return n * f(n-2);
}

int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	ll x = 1000000000000000000LL;
	cin >> x;
	//x = 100;
	//debug(x, f(x));

	if (x&1)
	{
		cout << "0\n";
		return 0;
	}

	x /= 2;

	const int L = 25;
	vector<ll> dp(L+1);
	ll v = 1;
	for (int i = 1; i <= L; ++i)
	{
		v *= 5;
		dp[i] = x / v;
	}

	debug(dp);

	for (int i = L; i >= 1; --i)
		for (int j = i+1; j <= L; ++j)
			dp[i] -= dp[j];

	debug(dp);

	ll ans = 0;
	for (int i = 1; i <= L; ++i)
		ans += i * dp[i];
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b;
	int ap, bp;
	int i;
	int n;
	
	while (scanf("%d", &n), n != 0){
		ap = 0; bp = 0;
		for (i = 0; i < n; i++){
			scanf("%d %d", &a, &b);
			if (a > b) ap += a + b;
			else if (a < b) bp += a + b;
			else {
				ap += a;
				bp += b;
			}
		}
		printf("%d %d\n", ap, bp);
	}
	return (0);
}

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

ll s;

int main()
{
    cin >> s;
    cout << "0 0 1000000000 1 ";
    const ll m = 1e9;
    int x = (m - s % m) % m;
    int y = (s + x) / m;
    cout << x << " " << y;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <list>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <string>
#include <sstream>
#include <bitset>
#include <string.h>
// #include <limits.h>

#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long        ll;
typedef unsigned long long    ull;

#define INTMAX  99999999

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

#define MAX_N (200*1000)
int N;
int a[MAX_N+1];
// int minR[MAX_N][MAX_N];
int pos[MAX_N];
set<int> posSet;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin >> N;
	FORULE(n,1,N) {
		cin >> a[n];
		pos[a[n]] = n;
	}

	// 最小値として含む区間を足し算すればよい
	// ある数が最小値として採用されるrangeの数 * そのある数 の総和
	// ある数が最小値として採用されるrangeの数 = そのある数より小さい数の配置された左側の場所とその数との距離 * そのある数より小さい数の配置された右側場所とその数との距離
	// そのある数より小さい数の配置された左側の場所とその数との距離 = 小さい数からに配置場所indexを set に追加していく。その追加された場所より小さい数は先に set に追加されており、indexの 差分をみれば距離が求まる
	// そのある数より小さい数の配置された右側の場所とその数との距離 = 小さい数からに配置場所indexを set に追加していく。その追加された場所より小さい数は先に set に追加されており、indexの 差分をみれば距離が求まる
	ll sumMin = 0;
	posSet.insert(0);
	posSet.insert(N+1);
	FORULE(n,1,N) {
		pair<set<int>::iterator, bool> it_pair = posSet.insert(pos[n]);
		set<int>::iterator it = it_pair.first;
		set<int>::iterator it_prev = it; it_prev--;
		set<int>::iterator it_next = it; it_next++;

		// DOUT << "---- pos["<<n<<"]="<<pos[n]<<endl;
		int leftAlt = 0;
		// DOUT << "*it_prev="<<(*it_prev)<<", *it="<<(*it)<<endl;
		leftAlt = (*it)-(*(it_prev));

		int rightAlt = 0;
		// DOUT << "*it="<<(*it)<<", *it_next="<<(*it_next) <<endl;
		rightAlt = (*(it_next))-(*it);
		// DOUT << "leftAlt="<<leftAlt<<", rightAlt="<<rightAlt<<endl;

		sumMin += 1LL * n * leftAlt * rightAlt;
	}
	
	cout << sumMin << endl;

	return 0;
}
 


Measured memory_bytes: 11136
heap_size = gets.chomp.to_i

heap_tree = gets.chomp.split(" ")

heap_tree.each.with_index do |k, i|
  i_p = (i - 1) / 2
  i_l = 2 * i + 1
  i_r = 2 * i + 2

  print "node #{i+1}: key = #{k}, "

  print "parent key = #{heap_tree[i_p]}, " if i != 0
  print "left key = #{heap_tree[i_l]}, " if i_l <= heap_size - 1
  print "right key = #{heap_tree[i_r]}, " if i_r <= heap_size - 1
  puts
end

Measured memory_bytes: 6124
var sx,sy,tx,ty,i:Integer;
begin
	read(sx,sy,tx,ty);
	for i:=sy+1 to ty do write('U');
	for i:=sx+1 to tx do write('R');
	for i:=sy+1 to ty do write('D');
	for i:=sx+1 to tx do write('L');
	write('L');
	for i:=sy+1 to ty do write('U');
	write('UR');
	for i:=sx+1 to tx do write('R');
	write('DR');
	for i:=sy+1 to ty do write('D');
	write('DL');
	for i:=sx+1 to tx do write('L');
	write('U');
end.


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define ALL(c) (c).begin(), (c).end()

const int mod = (int)1e9 + 7;
void add (int &a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
}
int mult (int a, int b)
{
    return (ll)a * b % mod;
}

void solve (int n)
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    vi dp(n + 1, 0);
    vi ndp(n + 1);
    dp[0] = 1;

    const int B = n + 1;
    vvi C(B, vi(B));
    for (int i = 0; i < B; i++)
    {
        C[i][0] = C[i][i] = 1;
        for (int j = 1; j < i; j++)
        {
            C[i][j] = C[i - 1][j];
            add(C[i][j], C[i - 1][j - 1]);
        }
    }

    vi inv(B, 1);
    for (int i = 2; i < B; i++)
    {
        inv[i] = mod - mult(mod / i, inv[mod % i]);
        assert(mult(inv[i], i) == 1);
    }

    for (int i = a; i <= b; i++)
    {
        fill(ALL(ndp), 0);
        for (int j = 0; j <= n; j++)
        if (dp[j])
        {
            int coef = 1;
            for (int g = 0; g * i + j <= n; g++)
            {
                if (g != 0)
                {
                    coef = mult(coef, C[g * i + j][(g - 1) * i + j]);
                    coef = mult(coef, inv[g]);
                }
                if (g == 0 || (c <= g && g <= d))
                    add(ndp[g * i + j], mult(coef, dp[j]));
            }
        }

        copy(ALL(ndp), dp.begin());
    }

    cout << dp[n] << endl;
}

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

    int n;
    while (cin >> n)
        solve(n);
}


Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
def judge():
    cnt = 0  # 今何連続でゾロ目が出ているか記録しておきます

    for _ in range(N):
        x, y = map(int, input().split())
        if x == y:
            # ゾロ目ストリークが1増えました
            cnt += 1
        else:
            # ゾロ目ストリークが切れました
            cnt = 0

        if cnt == 3:
            # 3連続になった瞬間、return True していいです
            return True

    # ダメでした
    return False

N = int(input())

if judge():
    # judge() で Trueが返ってくるとこっちに進みます
    print("Yes")
else:
    # Falseだとこっちです
    print("No")

Measured memory_bytes: 9032