akhauriyash/Code-Regression huggingface dataset:
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline

    N, Q = map(int, input().split())

    Graph = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        a, b = (int(x) - 1 for x in input().split())
        Graph[a].add(b)
        Graph[b].add(a)

    ctr = [0] * N
    for _ in range(Q):
        p, x = map(int, input().split())
        p -= 1
        ctr[p] += x

    root = 0
    visited = [False] * N
    visited[root] = True

    dq = deque()
    dq.append(root)

    while dq:
        v = dq.pop()
        x = ctr[v]
        for u in Graph[v]:
            if visited[u]:
                continue
            visited[u] = True
            ctr[u] += x
            dq.append(u)

    print(*ctr)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81440
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: u32 = read();
    let b: u32 = read();
    let c: u32 = read();
    let x: u32 = read();
    let mut res = 0;
    for n1 in 0..(c + 1) {
        let mut y: u32 = 0;
        let y1 = n1 * 50;
        for n2 in 0..(b + 1) {
            let y2 = n2 * 100;
            for n3 in 0..(a + 1) {
                let y3 = n3 * 500;
                y = y1 + y2 + y3;
                if y == x {
                    res += 1;
                }
                if y >= x {
                    break
                }
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 4352
object Main {
  def main(args: Array[String]) = {
      val list = io.Source.stdin.getLines().map{_.toInt}.toList
      val N = list(0)
      val K = list(1)
      val X = list(2)
      val Y = list(3)
 
      val answer = if(N > K) K * X + (N-K) * Y else N * X
 
      println(answer)
  }
}

Measured memory_bytes: 21576
//last updated : 11.04.2020
#include <bits/stdc++.h>
using namespace std;

#define ll              long long
#define ld              long double
#define pll             pair <ll, ll>
#define plll            pair <ll, pll>

#define fa(i, n, N)     for (ll i = n; i <= N; ++i)
#define fac(i, n, b, N) for (ll i = n; i <= N && b; ++i)
#define fd(i, n, N)     for (ll i = n; i >= N; --i)

#define mp              make_pair
#define pb              push_back
#define pob             pop_back
#define pf              push_front
#define pof             pop_front
#define fi              first
#define se              second

#define ms(arr,t)       memset (arr, t, sizeof(arr));
#define all(x)          x.begin(), x.end()
#define len             length()
#define endl            '\n'

#define isss(x, s)      istringstream x (s)
#define db(x)           cout << ">>>>>> " << #x << " -> " << x << endl
#define AAAA            cout << "\t------" << endl;

//urgent cases only!
#define get_rt		cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms.\n"

const ll inf = INT_MAX;
const ll inf2 = 1e18;
const ll MAX = 1e5+5;
const ll MOD = 1e9+7;
const double pi = acos(-1.0);
const double EPS = 1e-9;

void init(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

inline void iofile (){
	freopen ("input.txt", "r", stdin);
	// freopen ("output.txt", "w", stdout);
}


ll n;

int main() {
    init(10);
    //iofile();
	
	cin >> n;
	n <<= 1;
	
	cout << (double)(n) * pi << endl;

	return 0;
}


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

#define LL long long
#define LD long double
#define INF 1000000000
#define PR pair<int,int>
#define Min(a,b) a=min(a,b)
#define Max(a,b) a=max(a,b)
#define pb push_back
#define mp make_pair

LL N, W, V;
LL w[105];
LL v[105];
LL dp[105][1000005];


int main() {
	//cin >> N >> W;
	scanf("%d %d", &N, &W);
    for (int i = 1; i <= N; i++) {
		//cin >> w[i] >> v[i];
		scanf("%d %d", &w[i], &v[i]);
        V += v[i];
	}

	dp[0][0] = 0;
	for (int i = 1; i <= V; i++) {
		dp[0][i] = INF;
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= V; j++) {
			dp[i][j] = dp[i-1][j];
			if (j >= v[i])
				dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
		}
	}

	for (int i = V; i >= 0; i--) {
		if (dp[N][i] <= W) {
			cout << i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 285184
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstdio>
#include<vector>
#define ll long long
using namespace std;

const int N=100005;

struct E{
	int x,y,w;
	E(){}
	E(int x,int y,int w):x(x),y(y),w(w){}
}mem[N];
int n,x,y,w;
int sz[N],f[N];
ll tag[N],ans[N];
vector<int> lev[N];

bool cmp(E a,E b){
	return a.w>b.w;
}

int find(int k){
	if (f[k]!=k) f[k]=find(f[k]);
	return f[k];
}

void merge(int x,int y,int w){
	int k;
	if (sz[x]>sz[y]) swap(x,y);
	tag[y]+=1ll*sz[x]*w;
	for (int j=0;j<lev[x].size();j++){
		k=lev[x][j];
		ans[k]+=1ll*sz[y]*w+tag[x];
		ans[k]-=tag[y];
		lev[y].push_back(k);
	}
	sz[y]+=sz[x]; f[x]=y;
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<n;i++){
		scanf("%d%d%d",&x,&y,&w);
		mem[i]=E(x,y,w);
	}
	sort(mem+1,mem+n,cmp);
	for (i=1;i<=n;i++){
		sz[i]=1; f[i]=i;
		lev[i].push_back(i);
	}
	for (i=1;i<n;i++){
		x=find(mem[i].x); y=find(mem[i].y);
		w=mem[i].w;
		merge(x,y,w);
	}
	ans[0]=tag[find(1)];
	for (i=1;i<=n;i++) printf("%lld\n",ans[i]+ans[0]);
	return 0;
}

Measured memory_bytes: 13944
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a;
    cin>>a;
    string s;
    cin>>s;
    long long b=(s[0]-'0')*100+(s[2]-'0')*10+s[3]-'0';
    long long x=a*b;
    cout<<x/100<<endl;
    return 0;
}

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

int main(){
    string N;
    cin >> N;
    int sum = 0;
    for(int i = 0; i < N.size(); i++){
        sum += (N.at(i)-'0');
    }
    if(sum % 9 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

constexpr int inf = 1e9;

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> sum(n + 1), rsum(n + 1);
    for(int i = 0; i < n; ++i) {
        sum[i + 1] = sum[i] + (s[i] == 'W');
    }
    for(int i = n - 1; i >= 1; --i) {
        rsum[i - 1] += rsum[i] + (s[i] == 'E');
    }

    int ans = inf;
    for(int i = 0; i < n; ++i) {
        ans = min(ans, sum[i] + rsum[i]);
    }
    cout << ans << endl;
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;
 
int main(void){
	
	int N;
	string S;
	
	cin >> N >> S;
	
	rep(i, S.length()){
		if(S[i] + N > 'Z')
			cout << char(S[i] + N - 26);
		else
			cout << char(S[i] + N);
	}
	
	return 0;
}

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

int main(){
    char S[200001],T[200001];
    cin >> S;
    cin >> T;
    int ans=0,i=0;
    do{
        if(S[i]!=T[i]) ans++;
    }while(S[i++]!=0);
    cout << ans;
    return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const string yes = "YES";
const string no = "NO";

int main()
{
  ll N;
  scanf("%lld",&N);
  vector<ll> p(N);
  for(int i=0; i<N; i++){
    scanf("%lld",&p[i]);
  }
  ll t=0;
  for (int i=0; i<N; i++) {
    if (p[i]!=i+1) t++;
  }
  if (t<=2) cout << yes << endl;
  else cout << no << endl;

  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int n;
  while(cin>>n && n){
    int ans = 0;
    REP(x, 55)REP(y, 96){
      int l = x * x * x + y * (y + 1) * (y + 2) / 6;
      if(l <= n) ans = max(ans, l);
    }
    cout<<ans<<endl;
  }

  return 0;
}

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

int main(){
    int N;
    cin >> N;
    int sm = 0;
    int mx = 1;
    for(int i=1; i<=N; i++){
        sm += i;
        if(sm >= N){
            mx = i;
            break;
        }
    }
    int rem = sm - N;
    for(int i=1; i<=mx; i++)
        if(i != rem) cout << i << endl;

    return 0;
}

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

using namespace std;

#define gc getchar_unlocked
#define foi(i,n) for(int i=0;i<n;i++)
#define Foi(i,k,n) for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define fol(i,n) for(ll i=0;i<n;i++)
#define Fol(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pl;
typedef vector<int>     vi;
typedef vector<ll>      vl;
typedef vector<pii>     vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

int mpow(int base, int exp) {
    base %= mod;
    int result = 1;
    while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m){
    int i, u, v;
    while(m--){
        cin>>u>>v;
        g[u-1].pb(v-1);
        g[v-1].pb(u-1);
    }
}

void dfs(int u, int par){
    for(int v:g[u]){
        if (v == par) continue;
        dfs(v, u);
    }
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll quo=x/d;
    if(quo<k)
    {
        k-=quo;
        x%=d;
    }
    else
    {
        x -= k*d;
        k=0;
    }
    if(k%2&&k>0)
        x=min(x+d,abs(x-d));
    cout<<abs(x);   
    return 0;
}

Measured memory_bytes: 10684
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

const int mod = 1000000007;
int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	ll cnt(0);
	rep(i, n) {
		cnt += a[i];
	}
	ll ans(0);
	rep(i, n) {
		cnt -= a[i];
		ll k = cnt % mod;
		ans += a[i] * k;
		ans %= mod;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4836
def CHECK_NUM(i):
    x = i
    if x % 3 == 0:
        print(' ', x, sep='', end='')
    else:
        INCLUDE3(x)


def INCLUDE3(i):
    x = i
    while x:
        if x % 10 == 3:
            print(' ', i, sep='', end='')
            return ()
        x //= 10


n = int(input())
for i in range(1, n + 1):
    CHECK_NUM(i)
print()



Measured memory_bytes: 6240
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
vector<int> de;
int c[252521],w[252521];
vector<int> v[252521];
vector<int> mi,ka;
lint mo=1000000007;
int omi(int a){
	if(a==mi[0]) return mi[1];
	return mi[0];
}
vector<lint> zyo,rz;
lint co(int a,int b){
	return ((zyo[a+b]*rz[a])%mo*rz[b])%mo;
}
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
int main()
{
	zyo.pb(1);
	rep(i,252521) zyo.pb((zyo[i]*(i+1))%mo);
	rep(i,252521) rz.pb(invMod(zyo[i],mo));
	
	int n,x,y,inf=1001001001;
	cin>>n>>x>>y;
	rep(i,n){
		cin>>c[i]>>w[i];
		de.pb(c[i]);
	}
	sort(All(de));de.erase(unique(All(de)),de.end());
	rep(i,n){
		c[i]=lower_bound(All(de),c[i])-de.begin();
		v[c[i]].pb(w[i]);
	}
	int m=de.size();
	if(m<2){
		cout<<1<<endl;return 0;
	}
	rep(i,m){
		v[i].pb(inf);
		sort(All(v[i]));
	}
	rep(i,m) mi.pb(v[i][0]);
	sort(All(mi));
	rep(i,m){
		int om=omi(v[i][0]);
		int a=upper_bound(All(v[i]),x-v[i][0])-v[i].begin(),b=upper_bound(All(v[i]),y-om)-v[i].begin();
		if(b<1) continue;
		ka.pb(max(a,b));
	}
	int sum=0;lint out=1;
	rep(i,ka.size()){
		out*=co(sum,ka[i]);
		out%=mo;
		sum+=ka[i];
	}
	cout<<out<<endl;
}


Measured memory_bytes: 18544
from collections import defaultdict
def main():
    N = int(input())
    d = defaultdict(int)
    ans = 0
    for a in tuple(map(int,input().split())):
        d[a] += 1
    for v in d.items():
        if v[0] > v[1]:
            ans += v[1]
        else:
            ans += v[1]-v[0]
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 18672
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}


void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
//////////////////////////

ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}

#define N 1000005
ll dp[N];

ll s1[N],s2[N];

vector<ll>v[N];
int main(){fastio
    rep(i,1,N-1){
        dp[i]+=bunbo(i);
        for(ll j=i*2;j<=N-1;j+=i){
            dp[j]-=dp[i];
        }
    }
    
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    
    bool use[N];memset(use,false,sizeof(use));
    rep(i,0,n-1)use[a[i]]=true;
    rep(i,1,N-1){
        for(ll j=i;j<=N-1;j+=i){
            if(use[j])v[j].pb(i);
        }
    }
    
    
    rep(i,0,n-1){
        for(auto x:v[a[i]]){
            s1[x]+=a[i];
            s2[x]+=a[i]*a[i];
        }
    }
    rep(i,0,N-1){
        s1[i]=mod(s1[i]);
        s2[i]=mod(s2[i]);
    }
    
    ll ans=0;
    rep(x,1,N-1){
        ll ad=mod(po(s1[x],2)-s2[x])*bunbo(2);
        ad=mod(ad);
        
        ll AD=mod(ad*dp[x]);
        Add(ans,AD);
    }
    cout<<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 89344
#include<bits/stdc++.h>
using namespace std;
char s1[101],s2[101];
int main()
{
    gets(s1);
    gets(s2);
    int n=strlen(s1);
    int m=strlen(s2); 
    sort(s1,s1+n);
    sort(s2,s2+m);
    for(int i=0;i<fmax(n,m);i++)
    {
        if(s1[i]<s2[m-i-1])
        {
            printf("Yes\n");
            return 0;
        }
        if(s1[i]>s2[m-i-1])
            break;
    }
    printf("No\n");
    return 0;
} 

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

using namespace std;

int main(){
	int t;
	cin>>t;
	//cout<<t;
	int ans=0;
	int a[20],b[20],c[20];
	for(int i=0;i<t;i++){
		cin>>a[i];
	}
	for(int i=0;i<t;i++){
		cin>>b[i];
	}
	for(int i=0;i<t-1;i++){
		cin>>c[i];
	}
	for(int i=0;i<t;i++){
		ans+=b[a[i]-1];
		if(i<t-1 && a[i+1]-a[i]==1){
			ans+=c[a[i]-1];
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i=0;i<N;++i) par[i] = i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx!=ry) par[rx] = ry;
    }
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx==ry;
    }
}UF;

int main(void){
    int n, m, p[100010];
    cin >> n >> m;
    UF tree(n);
    for(int i=0;i<n;++i) cin >> p[i];
    for(int i=0;i<m;++i){
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }
    int ans = 0;
    for(int i=0;i<n;++i){
        if(tree.same(i,p[i]-1)) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


from bisect import bisect_left

def calc_LIS(A):
    dp = [float('inf')] * len(A)
    for a in A:
        i = bisect_left(dp, a)
        dp[i] = a
    return bisect_left(dp, float('inf'))


def main(args):
    n = int(input())
    A = [int(input()) for _ in range(n)]
    result = calc_LIS(A)
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

//bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

struct Edge {
    ll to, cost;
};


class Dijkstra {
    ll vector_count;

    vector<ll> distances;
    vector<vector<Edge>> edges;

public:
    Dijkstra(ll n) {
        vector_count = n;
        distances.resize(n, INF);
        edges.resize(n);
    }

    void insertTowWay(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
        edges[to].push_back({from, cost});
    }

    void insert(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
    }

    void dijkstra(ll k) {
        distances[k] = 0;  // 始点sへの最短距離は0

        priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
        que.push(P(0, k));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
            if (distances[v] < p.first) {
                continue;
            }
            for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
                if (distances[e.to] > distances[v] + e.cost) {
                    distances[e.to] = distances[v] + e.cost;
                    que.push(P(distances[e.to], e.to));
                }
            }
        }
    }

    ll distance(ll to) {
        return distances[to];
    }

};

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

    Dijkstra dijkstra(n);

    int m;
    cin >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        dijkstra.insertTowWay(a, b, 1);
    }
    dijkstra.dijkstra(0);
    if (dijkstra.distance(n - 1) == 2) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}



Measured memory_bytes: 17632
n, m = map(int,input().split())
s_list = []
p_list = []

for i in range(m):
    tmp = []
    tmp = list(map(int,input().split()))
    s_list.append(tmp)

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

ans = 0

for i in range((2**n)):
    bin_i = [int(x) for x in bin(i)[2:]]
    while len(bin_i) != n:
        bin_i.insert(0,0)
    flag = 0
    for j in range(m):
        tmp = 0
        for k in range(1,s_list[j][0]+1):
            tmp += bin_i[s_list[j][k]-1]
        if tmp%2 != p_list[j]:
            flag = 1
            break
    if flag == 0:
        ans += 1

print(ans)


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

ll N, K;


ll score(ll x, vector<ll> &P, vector<ll> &C, vector<ll> &sum, vector<ll> &cycle) {
    ll res = -100000000000000000;
    ll point = 0;
    ll location = x;

    for (int i = 1; i <= min(K, cycle[x]); ++i) {
        location = P[location];
        point += C[location];
        if (sum[x] < 0) res = max(res, point);
        else res = max(res, point + ((K - i) / cycle[x]) * sum[x]);
    }
    return res;
}

int main() {
    cin >> N >> K;
    vector<ll> P(N);
    rep(i, N) {
        cin >> P[i];
        --P[i];
    }
    vector<ll> C(N);
    rep(i, N) cin >> C[i];

    vector<bool> seen(N, false);

    vector<ll> sum(N);
    vector<ll> cycle(N);

    rep(i, N) {
        ll tmp_sum = 0;
        int tmp_cycle = 0;
        int tmp_location = i;

        if (seen[i] == true) continue;

        while (true) {
            tmp_location = P[tmp_location];
            tmp_sum += C[tmp_location];
            ++tmp_cycle;
            if (tmp_location == i) break;
        }
        rep(j, tmp_cycle) {
            tmp_location = P[tmp_location];
            cycle[tmp_location] = tmp_cycle;
            sum[tmp_location] = tmp_sum;
            seen[tmp_location] = true;
        }

    }

    ll ans = -100000000000000000;
    rep(i, N) ans = max(ans, score(i, P, C, sum, cycle));
    cout << ans << endl;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;

int main() {
	optimizar_io
	int n; 
	ll d, x[200010], y[200010];
	
	cin >> n >> d;
	d = d*d;
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		ll dist = x[i]*x[i] + y[i]*y[i];
		if (dist <= d)
			cnt++;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 6740
#include <iostream>
#include <vector>
#include <cstdlib>
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; }

const long long INF = 1LL << 60;

// 入力
int N;
long long h[100010];

// DP テーブル
long long dp[100010];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) cin >> h[i];

    // 初期化 (最小化問題なので INF に初期化)
    for (int i = 0; i < 100010; ++i) dp[i] = INF;

    // 初期条件
    dp[0] = 0;

    // ループ
    for (int i = 1; i < N; ++i) {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    // 答え
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

int main() {
	int n;
	cin >> n;
	
	vector<int> vi(n);
	ll ans = 0;

	for (int i = 0; i < n; i++) {
		cin >> vi[i];
	}

	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			ans += vi[i] * vi[j];
		}
	}

	cout << ans << endl;
}


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

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

int main()
{
    int N, K, keta;
    cin >> N >> K;
    keta = 0;
    while(N > 0){
        N /= K;
        keta++;
    }
    cout << keta << endl;
    
    return 0;
    
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string firstS, secondS, thirdS;
    cin >> firstS;
    cin >> secondS;
    cin >> thirdS;
    cout << firstS.substr(0,1) + secondS.substr(0,1) + thirdS.substr(0,1)<< endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const long long INF = 1LL << 60;
const ll C = 1000000000+7;

int main() {
    string s;
    ll k, i=0;
    cin >> s >> k;

    while(true) {
        if(s[i] == '1') i++;
        else break;
    }
    if(i < k) cout << s[i] << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int ac = 0,wa=0,tle=0,re=0;
        while(n-->0){
            String cases = in.next();
            if(cases.equals("AC"))
                ac++;
            else if(cases.equals("WA"))
                wa++;
            else if(cases.equals("TLE"))
                tle++;
            else if(cases.equals("RE"))
                re++;
        }

        System.out.println("AC x "+ac);
        System.out.println("WA x "+wa);
        System.out.println("TLE x "+tle);
        System.out.println("RE x "+re);
        in.close();
    }
}

Measured memory_bytes: 58916
#include<stdio.h>

int main(void){
    int n,x,minj;
    int count=0;
    scanf("%d",&n);
    int A[n];
    for(int i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    for(int i=0;i<n;i++){
        minj=i;
        for(int j=i+1;j<n;j++){
            if(A[j]<A[minj]){
                minj=j;
            }
        }
        if(!(A[minj]==A[i])){
            count++;
            x=A[minj];
            A[minj]=A[i];
            A[i]=x;
        }
    }
    for(int i=0;i<n;i++){
        printf("%d",A[i]);
        if(i<n-1){
            printf(" ");
        }
    }
    printf("\n%d\n",count);
    
    
    return 0;
}


Measured memory_bytes: 2052
import sys
input = sys.stdin.readline

n = int(input())
A = tuple(map(int, input().split()))
B = tuple(map(int, input().split()))
C = [0]*(3*n)
for i in range(n):
  C[i] = B[i]^B[(i+1)%n]
  C[i+n] = A[i]^A[(i+1)%n]
  C[i+n+n] = C[i+n]

def z_algo(S):
    N = len(S)
    A = [0]*N
    A[0] = N
    i, j = 1, 0
    while i < N:
        while i+j < N and S[j] == S[i+j]:
            j += 1
        A[i] = j
        if not j:
            i += 1
            continue
        k = 1
        while i+k < N and k+A[k] < j:
            A[i+k] = A[k]
            k += 1
        i += k
        j -= k
    return A  

P = z_algo(C)
for i, p in enumerate(P[n:n+n]):
  if p >= n:
    x = A[i]^B[0]
    print(i, x)

Measured memory_bytes: 55468
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    string S;
    int w;
    cin>>S>>w;
    string ans="";
    for(int i=0;i<S.size();i+=w)
        ans+=S[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string n;
  cin>>n;
  long long int count=0;
  for(long long int i=0; i<n.size(); i++){
    count+=n[i]-'0';
  }
  if(count%9==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3752
N, M = map(int, input().split(' '))
dp = [0 for _ in range(N + 1)]
for _ in range(M):
    i = int(input())
    dp[i] = -float('inf')

mod = 10**9 + 7
dp[0] = 1
for i in range(N+1):
    if dp[i] ==  -float('inf'):
        continue

    if 0 <= i-1 < N and dp[i-1] != -float('inf'):
        dp[i] += dp[i-1]

    if 0 <= i-2 < N and dp[i-2] != -float('inf'):
        dp[i] += dp[i-2]

    dp[i] = dp[i] % mod

print(dp[N] )

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

int main() {
    long long N, M; cin >> N >> M;
    if(M > N) swap(N, M);

    int rst = 0;
    if(M == 1) {
       if(N == 1) {
          rst = 1;
       } else {
          rst = N - 2;
       }
       cout << rst << endl;
    } else {
       cout << (N - 2) * (M - 2) << endl;
    }
}


Measured memory_bytes: 256
from math import ceil
N,K=map(int,input().split())
A=sorted(list(map(int,input().split())))
if K==0:print(max(A));exit()

left,right=0,10**9+1
while right>left+1:
    cnt=K
    mid=(left+right)//2
    for i in range(N):
        cnt -=ceil(A[i]/mid)-1
    if cnt>=0:right=mid
    elif cnt<0:left=mid

print(right)

Measured memory_bytes: 104276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)
#define dec(i, l, r) for (int i = l; i >= r; i--)
#define pii pair<ll, ll>
#define fi first
#define se second
#define pb push_back
const int maxn = 1e6 + 5;

int t;
ll n, a, b, c, d;

int main() {
    cin >> t;
    while (t--) {
        map<ll, ll> dp;
        cin >> n >> a >> b >> c >> d;
        ll inf = 1e13;
        dp[0] = inf;
        priority_queue<pii, vector<pii>, greater<pii> > que;
        que.push(pii(0, n));
        while (que.size()) {
            pii t = que.top();
            que.pop();
            if (t.se != n && t.fi > dp[t.se]) continue;
            if (dp[0] >= t.fi && (dp[0] - t.fi) / d >= t.se) {
                dp[0] = t.fi + t.se * d;
            }
          //  if (t.se > inf) continue;
            if (t.se & 1) {
                if (!dp[t.se / 2] || dp[t.se / 2] > t.fi + a + d) {
                    dp[t.se / 2] = t.fi + a + d;
                    que.push(pii(dp[t.se / 2], t.se / 2));
                }
                if (!dp[t.se / 2 + 1] || dp[t.se / 2 + 1] > t.fi + a + d) {
                    dp[t.se / 2 + 1] = t.fi + a + d;
                    que.push(pii(dp[t.se / 2 + 1], t.se / 2 + 1));
                }
            } else {
                if (!dp[t.se / 2] || dp[t.se / 2] > t.fi + a) {
                    dp[t.se / 2] = t.fi + a;
                    que.push(pii(dp[t.se / 2], t.se / 2));
                }
            }
            if (t.se % 3 <= 1) {
                if (!dp[t.se / 3] || dp[t.se / 3] > t.fi + b + t.se % 3 * d) {
                    dp[t.se / 3] = t.fi + b + t.se % 3 * d;
                    que.push(pii(dp[t.se / 3], t.se / 3));
                }
            } else {
                if (!dp[t.se / 3 + 1] ||
                    dp[t.se / 3 + 1] > t.fi + b + (3 - t.se % 3) * d) {
                    dp[t.se / 3 + 1] = t.fi + b + (3 - t.se % 3) * d;
                    que.push(pii(dp[t.se / 3 + 1], t.se / 3 + 1));
                }
            }
            if (t.se % 5 <= 2) {
                if (!dp[t.se / 5] || dp[t.se / 5] > t.fi + c + t.se % 5 * d) {
                    dp[t.se / 5] = t.fi + c + t.se % 5 * d;
                    que.push(pii(dp[t.se / 5], t.se / 5));
                }
            } else {
                if (!dp[t.se / 5 + 1] ||
                    dp[t.se / 5 + 1] > t.fi + c + (5 - t.se % 5) * d) {
                    dp[t.se / 5 + 1] = t.fi + c + (5 - t.se % 5) * d;
                    que.push(pii(dp[t.se / 5 + 1], t.se / 5 + 1));
                }
            }
        }
        cout << dp[0] << "\n";
    }
}

Measured memory_bytes: 4428
#include <iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

int main() {
	int k, s;
	cin >> k >> s;

	int count = 0;
	int z;
	for (int x = 0; x <= k; x++) {
		for (int y = 0; y <= k; y++) {
			z = s - x - y;
			if (z > k) {
				continue;
			}
			else if (z >= 0) {
				count += 1;
			}
			else {
				continue;
			}
		}
	}
	
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3188
def main():
    N, M = map(int, input().split())
    *a, = map(int, input().split())

    ans = N - sum(a)
    if ans >= 0:
        print(ans)
    else:
        print(-1)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()


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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(i,n) for(int i=0;i<(n);++i)
//#define repA(i,a,n) for(int i=a;i<=(n);++i)
//#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007 //998244353
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xffffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll binpow(ll a,ll b){	if(a==0) return 0; if(b==0) return 1;ll ans=1;while(b>0){if(b&1) ans=ans*a; a=a*a; b=b>>1;}	return ans;}
template <typename T> 
T Min(T a,T b){ return a<b?a:b; }
template <typename T>
T Max(T a,T b){ return a>b?a:b; }

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	string s;
	cin>>s;
	if(s.back()=='s') s+="es"; else s+='s';
	db(s);
	
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



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

int n,dp[1001][1001],maxi;
char mas[1001][1001];

int dynamic_p(){
  for(int x=0;x<n;x++){
    if(mas[x][0]!='*') dp[x][0] = 1;
  }
  for(int x=0;x<n;x++){
    if(mas[0][x]!='*') dp[0][x] = 1;
  }
  for(int i=1;i<n;i++){
    for(int j=1;j<n;j++){
      if(mas[i][j]!='*') dp[i][j] = 1 + min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1]);
      maxi = max(maxi,dp[i][j]);
    }
  }
  return maxi;
}

int main(){
  while(cin >> n,n){
    maxi = 0;
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++) cin >> mas[i][j];
    }
    cout << dynamic_p() << endl;
  }
}

Measured memory_bytes: 6060
#include<bits/stdc++.h>
using namespace std;
int func(int n,int m,int A[][3],int dp[][3])
{
    if(n<0)
        return 0;
    if(n==0)
        return 0;
    if(dp[n][m]!=-1)
        return dp[n][m];
    int maxi=0;
    for(int i=0;i<=2;i++)
    {
        if(i!=m)
        {
            int x = A[n-1][i]+func(n-1,i,A,dp);
            if(x>maxi)
                maxi = x;
        }
    }
    return dp[n][m] = maxi;
}
int main()
{
    int n;
    cin>>n;
    int A[n][3];
    for(int i=0;i<n;i++)
        cin>>A[i][0]>>A[i][1]>>A[i][2];
    int dp[n+1][3];
    for(int i=0;i<=n;i++)
        for(int j=0;j<3;j++)
            dp[i][j] = -1;
    dp[n][0] = max(A[n-1][1]+func(n-1,1,A,dp),A[n-1][2]+func(n-1,2,A,dp));
    dp[n][1] = max(A[n-1][0]+func(n-1,0,A,dp),A[n-1][2]+func(n-1,2,A,dp));
    dp[n][2] = max(A[n-1][0]+func(n-1,0,A,dp),A[n-1][1]+func(n-1,1,A,dp));
    cout<<max({dp[n][0],dp[n][1],dp[n][2]})<<endl;
    
}

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

int main () {
  int N ;
  cin >> N ;
  vector<int> line(N) ;
  
  for(int i = 0 ; i < N ; i++ ) {
    cin >> line[i] ;
  }
  
  int ookii = 0 ;
  
  for(int i = 0 ; i < N ; i++ ) {
    ookii = max(ookii,line[i]) ;
  }
  
  int pre = 0 ;
  
  for(int i = 0 ; i < N ; i++ ) pre += line[i] ;
  
  if( pre - ookii <= ookii) cout << "No" << endl ;
  else cout << "Yes" << endl ;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

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

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

int main(){
    string s,t;cin>>s>>t;
    int n = s.size()-t.size()+1;
    for(int i=n;i>=0;i--){
        bool f = true;
        for(int j=0;j<t.size();j++){
            if(s[i+j]!='?' && s[i+j]!=t[j])f = false;
        }
        if(f){
            s.replace(i,t.size(),t);
            rep(k,s.size())if(s[k]=='?')s[k] = 'a';
            cout<<s<<endl;
            return 0;
        }
    }
    cout<<"UNRESTORABLE"<<endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,m;
	cin>>n;
	int d[n];
	rep(i,n)cin>>d[i];
	cin>>m;
	int t[m];
	rep(i,m)cin>>t[i];
	sort(d,d+n);
	sort(t,t+m);
	bool check=false;
	if(n<m)cout<<"NO"<<endl;
	else{
		int a,b;
		a=b=0;
		while(a<m){
			if(t[a]==d[b]){a++;b++;}
			else{
				if(t[a]<d[b]){check=true;break;}
				else b++;
			}
		}
		cout<<((check)?"NO":"YES")<<endl;
	}
	return 0;
}

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

int main() {
 int N;
 cin >> N;
 if(N % 10 == 2 || N % 10 == 4 || N % 10 == 5 || N % 10 == 7 || N % 10 == 9) {
   cout << "hon";
 }else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8) {
   cout << "pon";
 }
 else {
   cout << "bon";
 }
 return 0;
}



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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }



int main(){
  ll N, A, B;
  cin >> N >> A >> B;
  if(A % 2 == B % 2) print((B - A) / 2);
  else print(min(A, N - B + 1) + (B - A) / 2);
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i, a, n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i, a, n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i, a, n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i, a, n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i, a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
//constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;

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

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

inline void init() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

template<class T>
inline istream &operator>>(istream &input, vector<T> &v) {
    for (auto &elemnt : v)input >> elemnt;
    return input;
}

int main() {
    init();
    int a,b;
    cin >> a >> b;
    cout << (a+b)/2 << "\n";
    return 0;
}



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

int main(){
  int N;
  cin >> N;
  int cnt=0;
  if(N<10){cout << N << endl;}
  else if(N<100){cout << 9 << endl;}
  else if(N<1000){cout << N-90 << endl;}
  else if(N<10000){cout << 909 << endl;}
  else if(N<100000){cout << N-9090 << endl;}
  else{cout << N-9090-1 << endl;}
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

    int N, Q;

    cin >> N >> Q;

    vector< pair<int, int> > ab(N - 1);
    vector<int> a(N + 1);

    vector<int> q(N + 1);

    for(int i = 0; i < N - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        ab[i] = make_pair(x, y);
    }

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

    for(int i = 0; i < Q; i++)
    {
        int x, value;
        cin >> x >> value;
        a[x] += value;
    }

    for(int i = 0; i < N - 1; i++)
    {
        a[ab[i].second] += a[ab[i].first];
    }

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

Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,k;
  cin >> n >> k;
  ll res = 0;
  res = k;
  for(int i = 1;i < n;i++)res *= k - 1;
  cout << res << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = []
c = []
for _ in range(q):
    d, e = map(int, input().split())
    b.append(d)
    c.append(e)
f = {}
for i in range(n):
    try:
        f[a[i]] += 1
    except KeyError:
        f[a[i]] = 1
ans = 0
for i in f.keys():
    ans += i * f[i]
for i in range(q):
    try:
        ss = f[b[i]]
        ans += (c[i] - b[i]) * ss
        if(not(c[i] in f)):
            f[c[i]] = 0
        f[c[i]] += f[b[i]]
        f[b[i]] = 0
        print(ans)
    except KeyError:
        print(ans)

Measured memory_bytes: 26196
N,M = map(int,input().split())

LMAX = 0
RMIN = N
for i in range(M):
    l,r = map(int,input().split())
    if l>LMAX:LMAX=l
    if r<RMIN:RMIN=r
        
ans = RMIN-LMAX+1
print(ans if ans>=0 else 0)

Measured memory_bytes: 3060
#include <cstdio>

using namespace std;

int main()
{
    int m, f, r;
    while (scanf("%d%d%d", &m, &f, &r) == 3)
    {
        if (m == -1 && f == -1 && r == -1)
            break;
        if (m == -1 || f == -1)
        {
            printf("F\n");
        }
        else
        {
            if (m + f >= 80)
            {
                printf("A\n");
            }
            else if (m + f >= 65 && m + f < 80)
            {
                printf("B\n");
            }
            else if (m + f >= 50 && m + f < 65)
            {
                printf("C\n");
            }
            else if (m + f < 30)
            {
                printf("F\n");
            }
            else if (m + f >= 30 && m + f < 50)
            {
                {
                    if (r >= 50)
                    {
                        printf("C\n");
                    }
                    else
                    {
                        printf("D\n");
                    }
                }
            }
        }
    }
    return 0;
}



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

int main() {
  int A, B;
  cin >> A >> B;
  if (A-A/2*2==0 || B-B/2*2==0){
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <vector>
#include <cstdlib>

using namespace std;

int main()
{
  vector<string> vec;
  string str;

  do {
    cin >> str;
    vec.push_back(str);
  } while(str != "=");

  int result = atoi(vec[0].c_str());
  int value;
  for(int i = 1; i < vec.size() - 1; i += 2) {
    value = atoi(vec[i+1].c_str());
    
    if(vec[i] == "+") {
      result += value;
    } else if(vec[i] == "-") {
      result -= value;
    } else if(vec[i] == "*") {
      result *= value;
    } else {
      result /= value;
    }
  }

  cout << result << endl;

  return 0;
}

Measured memory_bytes: 1212