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

typedef int in;
#define int long long
int MAX=1e8;

int n;
int a[100005],b[100005],c[100005],dp[100005][2][2][2];

int f(int idx,int sta,int stb,int stc)
{
    if(idx==n)
        return 0;
    int &ret=dp[idx][sta][stb][stc];
    if(ret!=-1)
        return ret;
    if(sta==0)
        ret=f(idx+1,1,0,0)+a[idx];
    if(stb==0)
        ret=max(ret,f(idx+1,0,1,0)+b[idx]);
    if(stc==0)
        ret=max(ret,f(idx+1,0,0,1)+c[idx]);
    return ret;
}

in main()
{
    int tc=1;
//    cin>>tc;
    while(tc--)
    {
        cin>>n;
        for(int i=0; i<n; i++)
        {
            cin>>a[i]>>b[i]>>c[i];
        }
        memset(dp,-1,sizeof dp);
        cout<<f(0,0,0,0)<<endl;
    }
    return 0;
}


Measured memory_bytes: 16832
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto &it : A)
        cin >> it;

    if (A[0] != 0)
    {
        cout << -1 << endl;
        return 0;
    }

    for (int i = 1; i < N; i++)
    {
        if (A[i] > A[i - 1] + 1)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    for (int i = 1; i < N; i++)
    {
        if (A[i] == A[i - 1] + 1 || A[i] == 1)
            ans++;
        else if (A[i] <= A[i - 1])
            ans += A[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int s;
	cin>>s;
	
	int l=s/100,r=s%100;
	
	if(1<=l&&l<=12){
		if(1<=r&&r<=12){
			cout<<"AMBIGUOUS"<<endl;
		}else cout<<"MMYY"<<endl;
	}else{
		if(1<=r&&r<=12){
			cout<<"YYMM"<<endl;
		}else cout<<"NA"<<endl;
	}
}//解説参考.

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);
int main(){ 
  int n, d, a;
  cin >> n >> d >> a;
  vector<pair<ll, ll>> p(n);
  rep(i,n) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  vector<ll> imos(n+1,0LL);
  ll sum = 0;
  ll res = 0;
  for (int i = 0; i < n; i++) {
    sum -= imos[i];
    if (p[i].second > sum) {
      ll cnt = (p[i].second - sum + a - 1) / a; 
      res += cnt;
      sum += cnt * a;
      auto itr = upper_bound(p.begin(), p.end(), make_pair(p[i].first + 2*d, INF)) - p.begin();
      imos[itr] += cnt * a;
    }
  }
  cout << res << endl;
  return 0;
} 

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

double dp[3001][3001];

int main()
{
    int n;
    cin >> n;
    vector<double> p(n + 1);
    for(int i = 1; i <= n; i++)
        cin >> p[i];

    for(int i = 0; i <= n; i++)
        dp[0][i] = 1;

    for(int i = 1; i <= n; i++)
        for(int x = 0; x <= i; x++)
            if(!x) dp[x][i] = (1 - p[i]) * dp[x][i - 1];
            else dp[x][i] = (1 - p[i]) * dp[x][i - 1] + p[i] * dp[x - 1][i - 1];

    double ans = 0;

    for(int x = 1; x <= n; x++) 
        if(x + x > n)
            ans += dp[x][n];

    printf("%.9lf\n", ans);


    return 0;
}

Measured memory_bytes: 70016
package main
import (
	"fmt"
	"os"
	"strconv"
	"bufio"
)

var sc = bufio.NewScanner(os.Stdin)

func main(){
	for sc.Scan(){
		n := nextInt()
		cnt := 0
		for a:=0; a<=9; a++{
			for b:=0; b<=9; b++{
				for c:=0; c<=9; c++{
					for d:=0; d<=9; d++{
						if a+b+c+d==n{
							cnt++
						}
					}
				}
			}
		}
		fmt.Println(cnt)
	}
}

func next()string{
	//sc.Scan()
	return sc.Text()
}

func nextInt()int{
	a, _ := strconv.Atoi(next())
	return a
}


Measured memory_bytes: 1060
#include<iostream>
using namespace std;
const int M=1e9+7;
int n;
long long a[65];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		long long s;
		cin>>s;
		for(int j=0;j<60;j++){
			if((s>>j)&1LL) a[j]++;
		}
	}
	long long ans=0;
	for(int i=0;i<60;i++){
		long long x=a[i],y=n-a[i];
		long long tmp=(1LL<<i)%M*x%M*y%M;
		ans=(ans+tmp)%M;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#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 Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<int, pi> node;
#define oset tree<pi, null_type,greater<pi>, rb_tree_tag,tree_order_statistics_node_update>

lli dp[105][4][4][4], mod = 1e9+7;
int n;

lli call(int in, int i, int j, int k)
{
    if(i==0 && j==2 && k==1) return 0;
    if(i==2 && j==0 && k==1) return 0;
    if(i==0 && j==1 && k==2) return 0;

    if(in == n) return 1;
    lli &ret = dp[in][i][j][k];
    if(ret != -1) return ret;

    ret = 0;
    for(int x=0; x<4; x++){
        if(i==0 && k==2 && x==1);
        else if(i==0 && j==2 && x==1);
        else ret = (ret+call(in+1, j, k, x))%mod;
    }
    return ret;
}

int main()
{
    cin >> n;
    if(n == 1){
        printf("4\n");
        return 0;
    }
    else if(n == 2){
        printf("16\n");
        return 0;
    }
    else if(n == 3){
        printf("61\n");
        return 0;
    }

    memset(dp, -1, sizeof(dp));

    lli ans = 0;
    for(int i=0; i<4; i++){
        for(int j=0; j<4; j++){
            for(int k=0; k<4; k++){
                ans = (ans+call(3, i, j, k))%mod;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3640
cnt = [0 for i in range(26)]
while True:
      try:
            s = input()
      except:
            break
      for i in range(len(s)):
            m = ord(s[i])-ord('A')
            if(m >= 0 and m < 26):
                  cnt[m]+=1
            m = ord(s[i])-ord('a')
            if(m >= 0 and m < 26):
                  cnt[m]+=1
for i in range(26):
      print(chr(i+ord('a')),":",cnt[i])


Measured memory_bytes: 5564
H, W = gets.split.map(&:to_i)
S = []
S[0] = "." * (W + 2)
H.times {
  S << "." + gets.chomp + "."
}
S << "." * (W + 2)

S_split = []
S.each do |s|
  S_split << s.split("")
end

r = []
(H + 2).times {
 r << Array.new(W + 2, 0)
}
  
(1..H).each do |i|
  (1..W).each do |j|
    if S[i][j] == "#"
      r[i-1][j-1] += 1
      r[i-1][j] += 1
      r[i-1][j+1] += 1
      r[i][j-1] += 1
      r[i][j+1] += 1
      r[i+1][j-1] += 1
      r[i+1][j] += 1
      r[i+1][j+1] += 1
    end
  end
end

(1..H).each do |i|
  (1..W).each do |j|
    if S[i][j] == "#"
      r[i][j] = "#"
    end
  end
end

r.delete_at(H + 1)
r.delete_at(0)

r.each do |a|
  ans = ""
  a.each.with_index do |str, i|
    if i == 0 || i == (W + 1)
      next
    end
    ans = ans + str.to_s
  end
  puts ans
end

Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int>a(n);
  int tmp1=0,tmp2=0;
  for(int i=0;i<n;i++){
    cin>>a.at(i);
    tmp2+=abs(tmp1-a.at(i));
    tmp1=a.at(i);
  }
  tmp2+=abs(a.at(n-1));
  for(int i=0;i<n;i++){
    if(i==0){
      cout <<tmp2-abs(a.at(i))-abs(a.at(i)-a.at(i+1))+abs(a.at(i+1))<<endl;
    }
    else if(i==n-1){
      cout <<tmp2-abs(a.at(i)-a.at(i-1))-abs(a.at(i))+abs(a.at(i-1))<<endl;
    }
    else{
    cout <<tmp2-abs(a.at(i)-a.at(i-1))-abs(a.at(i)-a.at(i+1))+abs(a.at(i-1)-a.at(i+1))<<endl;
    }
  }
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
	int c,k;
	cin>>c>>k;
	vector<int> cnt;
	for(int i=0;i<c;i++)
	{
		int a;
		cin>>a;
		cnt.push_back(a);
	}
	sort(cnt.begin(),cnt.end());
	for(int i=cnt.size()-1;i>=0;i--)
	{
		if(k==0)
		{
			break;
		 } 
		cnt[i]=0;
		k--;
	}
	long long sum=0;
	for(int i=0;i<cnt.size();i++)
	{
		sum+=cnt[i];
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm> 
#include<vector>
#include<string>

#define mod 1000000007
using ll = long long;
using namespace std; 


int main(){
    int k,n; cin >> n >> k;
    int ans=0;
    vector<int> A(n);
    for (int i=0;i<n;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    for(int i=0;i<k;i++){
        ans+=A[i];
    }
    cout << ans << "\n";
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

#define endl '\n'

int p[10],a[10];
bool cvis[10];

int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	p[0]=1;
	p[1]=1;
	for(int i=2;i<=8;i++) p[i]=p[i-1]*i;
	int n,sq,v[2];
	cin>>n;
	for(int t=0;t<2;t++){
		v[t]=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			cvis[i]=1;
		}
		for(int i=1;i<=n;i++){
			int k=0;
			for(int j=1;j<=n;j++){
				if(cvis[j])k++;
				if(j==a[i]) {
					cvis[j]=0;
					break;
				}
		}
		k--;
		v[t]+=k*p[n-i];
		}
		v[t]++;
	}
	cout<<abs(v[0]-v[1])<<endl;
	return 0;
}

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

int main()
{
  int N ;
  cin>>N ;
  string S1,S2 ;
  cin>>S1>>S2 ;
  
  string S ;
  for(int i=0;i<N;i++){
    if(S1.at(i)==S2.at(i)) S.push_back('X') ;
    else{
      S.push_back('Y') ;
      i++ ;
    }
  }
  int64_t ans=1 ;
  for(int i=0;i<S.size();i++){
    if(i==0){
      if(S.at(i)=='X') ans*=3 ;
      else ans*=6 ;
    }else{
      if(S.at(i)=='X'){
        if(S.at(i-1)=='X') ans*=2 ;
        else ans*=1 ;
      }else{
        if(S.at(i-1)=='X') ans*=2 ;
        else ans*=3 ;
      }
    }
  }
  int64_t x=1e9+7 ;
  cout<<ans%x<<endl ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;


int main(){
  string s;
  cin>>s;
  rep(i,2){
    if(s[i]=='9'){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        String S = scan.next();
        int K = scan.nextInt() - 1;
        char c = S.charAt(K);
        String str = "";
        char tmp = S.charAt(0);
        for(int i = 0; i < N; i++){
            tmp = S.charAt(i);
            if(c == tmp){
                str += tmp;
            }else{
                str += "*";
            }
        }
        System.out.println(str);
    }
}


Measured memory_bytes: 21200
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll x, y; cin >> x >> y;
    ll res = 10e12;
    if (x <= y) {
        // 1 2
        res = min(res, y-x);
    }
    if (-x <= y) {
        // -3 5
        res = min(res, y+x+1);
    }
    if (x <= -y) {
        // 3 -5
        res = min(res, -y-x+1);
    }
    if (-x <= -y) {
        // -3 -5
        res = min(res, -y+x+2);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int32_t sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	for (int32_t i = 0; i < ty - sy; i++)
		cout << "U";
	for (int32_t i = 0; i < tx - sx; i++)
		cout << "R";
	for (int32_t i = 0; i < ty - sy; i++)
		cout << "D";
	for (int32_t i = 0; i < tx - sx; i++)
		cout << "L";
	cout << "L";
	for (int32_t i = 0; i < ty - sy + 1; i++)
		cout << "U";
	for (int32_t i = 0; i < tx - sx + 1; i++)
		cout << "R";
	cout << "DR";
	for (int32_t i = 0; i < ty - sy + 1; i++)
		cout << "D";
	for (int32_t i = 0; i < tx - sx + 1; i++)
		cout << "L";
	cout << "U" << endl;

	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];

    int sum = 0;
    rep(i,n)
        rep2(j,i+1,n)
            sum += d[i]*d[j];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Arrow ((***))
import Data.List

sortDesc = sortBy (flip compare)

main :: IO ()
main = do
  n <- readLn
  xs <- map read . words <$> getLine
  let (alice, bob) = (map snd *** map snd) $ partition (odd . fst) $ zip [1..n] $ sortDesc xs
  print $ sum alice - sum bob


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

class UnionFind{
private:
  vector<int> node;
public:
  UnionFind(int n){
    node=vector<int>(n);
    iota(all(node),0);
  }
  int root(int x){
    if(node[x]==x) return x;
    return node[x]=root(node[x]);
  }
  void uni(int x, int y){
    x=root(x);
    y=root(y);
    node[y]=x;
  }
};

int main(){
  int n;
  cin >> n;
  vector<int> x(n),y(n);
  map<int,int> xmp,ymp;
  UnionFind uf(n);
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
    if(xmp.find(x[i])!=xmp.end()){
      uf.uni(i, xmp[x[i]]);
    }else{
      xmp[x[i]]=i;
    }
    if(ymp.find(y[i])!=ymp.end()){
      uf.uni(i, ymp[y[i]]);
    }else{
      ymp[y[i]]=i;
    }
  }
  vector<set<int>> xst(n),yst(n);
  for(int i=0;i<n;i++){
    int r = uf.root(i);
    xst[r].insert(x[i]);
    yst[r].insert(y[i]);
  }
  LL ans=0;
  for(int i=0;i<n;i++){
    ans+=(LL)xst[i].size()*yst[i].size();
  }
  cout << ans-n << endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    bool ok = true;

    rep(i, S.size()) {
        if (i % 2 == 0 && S[i] == 'L') ok = false;
        if (i % 2 != 0 && S[i] == 'R') ok = false;
    }

    cout << (ok ? "Yes" : "No") << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 256
taro_spend = []
spend_num = 0

for i in range(5):
    taro_spend.append(int(input()))
    if taro_spend[i] == 0:
        taro_spend.pop()
        break
    spend_num += 1

changes = [1000 - taro_spend[i] for i in range(spend_num)]

for change in changes:
    change_coin = 0

    if change >= 500:
        change -= 500
        change_coin += 1

    if change >= 100:
        while change >= 100:
            change -= 100
            change_coin += 1
            
    if change >= 50:
        change -= 50
        change_coin += 1
        
    if change >= 10:
        while change >= 10:
            change -= 10
            change_coin += 1

    if change >= 5:
        change -= 5
        change_coin += 1

    if change >= 1:
        while change >= 1:
            change -= 1
            change_coin += 1

    print(change_coin)

Measured memory_bytes: 7800
#include<bits/stdc++.h>
using namespace std;
long long a,b,c[200005],n,d,ans,x[200005],y[200005],l,k;
struct node{
	long long x,y;
}w[200005];
inline bool cmp(node x,node y){
	return x.x<y.x;
}
int main(){
scanf("%lld%lld%lld",&n,&d,&a);
d*=2;
for(int i=1;i<=n;++i){
	scanf("%lld%lld",&w[i].x,&w[i].y);
	w[i].y=(w[i].y+a-1)/a;
}
sort(w+1,w+n+1,cmp);
l=1;
for(int i=1;i<=n;++i){
	while(l<i&&w[i].x-w[l].x>d)k-=c[l++];

	c[i]=w[i].y-k;
	if(c[i]<0)c[i]=0;
	ans+=c[i];
	k+=c[i];
}
printf("%lld",ans);
}

Measured memory_bytes: 5888
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include <functional>

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

const ll MOD=1000000007;
ll dp[100005][13]={0};
int main()
{
	string S;
	cin>>S;
	dp[0][0]=1;
	for(int i=0;i<S.length();i++)
	{	int k=S[i]-'0';

		if(S[i]=='?')
		{
			for(int j=0;j<=9;j++)
			{
				for(int bp=0;bp<13;bp++)
				{

					dp[i+1][((10*bp)+j)%13]=(dp[i+1][((10*bp)+j)%13]+dp[i][bp])%MOD;
				}
			}
		}
		else
		{
			for(int bp=0;bp<13;bp++)
			{
				dp[i+1][((10*bp)+k)%13]=(dp[i+1][((10*bp)+k)%13]+dp[i][bp])%MOD;
			}
		}
	}
	cout<<dp[S.length()][5]<<endl;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
//const ll mod=1000000007;
int GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
V<ll> dp,a;
V<ll> g[200005];
int n;
V<int> ans;
void dfs(int cur,int par){
   int ind=lower_bound(all(dp),a[cur])-dp.begin();
   ll memo=dp[ind];
   dp[ind]=a[cur];
   ll cnt=lower_bound(all(dp),inf)-dp.begin();
   ans[cur]=cnt;
    for(int v:g[cur]){
        if(v==par)continue;
        dfs(v,cur);
    }
    dp[ind]=memo;
}
int main(){
    cin>>n;
    a.resize(n);
    for(int i=0;i<n;i++)cin>>a[i];
    ans.resize(n);
    dp.assign(n,inf);
    for(int i=0;i<n-1;i++){
        int s,t;
        cin>>s>>t;
        g[--s].emplace_back(--t);
        g[t].emplace_back(s);
    }
    dfs(0,-1);
    for(int i=0;i<n;i++)cout<<ans[i]<<"\n";
}

Measured memory_bytes: 29480
#include<stdio.h>
int main(){
  int a,b,h,i,j,k;
  char op;  
 while(1){   
    scanf("%d %c %d",&a,&op,&b);
    h=a+b;
    i=a-b;
    j=a*b;
    k=a/b;
    if(op == '?'){
      break;
    }
    else if(op == '+'){
      printf("%d\n",h);
    }
    else if(op == '-'){
      printf("%d\n",i);
    } 
    else if(op == '*'){
      printf("%d\n",j);
    }
    else if(op == '/'){
      printf("%d\n",k);
    }
  }

  return 0;
}

Measured memory_bytes: 600
import math
n=int(input())
if n <= 5:
  for i in range(n):
    print(0)
else:
  ans=[0]*n
  m=int(math.sqrt(n))-1
  for i in range(1,m+1):
    for j in range(i,m+1):
      for k in range(j,m+1):
        a=(i+j+k)**2-i*j-j*k-k*i
        if a<=n:
          if i==j and j==k:
            ans[a-1]+=1
          elif i!=j and j!=k and k!=i:
            ans[a-1]+=6
          else:
            ans[a-1]+=3
  for i in ans:
    print(i)

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

int N, H[100010];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> H[i];
  int min_h = 2e+9; bool p = true;
  for (int i = N-1; i >= 0; i--) {
    int dif = max(0, H[i] - min_h);
    if (dif > 1) { p = false; break; }
    min_h = H[i] - dif;
  }
  cout << (p ? "Yes" : "No") << endl;
}

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

int main(){
  int v[2001] = {};
  for(int i = 0 ; i <= 1000 ; i++){
    for(int j = 0 ; j <= 1000 ; j++){
      v[i+j]++;
    }
  }
  int n;
  while(cin >> n){
    int ans = 0;
    for(int i = 0 ; i <= 1000 ; i++){
      for(int j = 0 ; j <= 1000 ; j++){
	if(0 <= n-(i+j) && n-(i+j) <= 2000) ans += v[n-(i+j)];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
constexpr int kN = int(1E2 + 10), kK = int(1E5 + 10), kMod = int(1E9 + 7);
int a[kN];
ll dp[kN][kK], s[kN][kK];
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	dp[0][k] = 1;
	s[0][k] = 1;
	//for (int i = 1; i <= n; i++)
	for (int i = 1; i <= n; i++) {
		dp[i][0] = s[i - 1][a[i]];
		for (int j = 1; j <= k; j++) {
			dp[i][j] = (s[i - 1][min(j + a[i], k)] - s[i - 1][j - 1] + kMod) % kMod;
		}
		s[i][0] = dp[i][0];
		for (int j = 1; j <= k; j++) s[i][j] = (s[i][j - 1] + dp[i][j]) % kMod;
	}
	printf("%lld\n", dp[n][0]);
}


Measured memory_bytes: 157936
#include <stdio.h>
#include <stdlib.h>
 
int kaijo(int x) {
    int ans=1;
    for(int i=1;i<=x;i++){
        ans*=i;
    }
    return ans;
}
 
int main() {
    int N;
    scanf("%d", &N);
    int *P = (int*)malloc(N * sizeof(int));
    int *Q = (int*)malloc(N * sizeof(int));
    for(int i=0; i<N; i++) {
        scanf("%d", &P[i]);
    }
    for(int i=0; i<N; i++) {
        scanf("%d", &Q[i]);
    }
    int a = 0, b = 0;
    for(int i=0; i<N-1; i++) {
        a += (P[i] - 1) * kaijo(N-i-1);
        b += (Q[i] - 1) * kaijo(N-i-1);
        for(int j=i+1; j<N; j++) {
            if(P[i] < P[j]){
            	P[j]--;
            }
          	if(Q[i] < Q[j]){
            	Q[j]--;
            }
        }
    }
    printf("%d\n", abs(a-b));
 
    free(P);
    free(Q);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;

namespace AIsing20200711
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(" ");
            int L = int.Parse(input[0]);
            int R = int.Parse(input[1]);
            int d = int.Parse(input[2]);

            int cnt = 0;

            for(var i = L; i<= R; i++)
            {
                if(i % d == 0)
                {
                    cnt++;
                }
            }

            Console.WriteLine(cnt);

        }
    }
}


Measured memory_bytes: 27476
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

const ll MOD = 1e9 + 7;

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

ll calc_pow(ll x, ll pow) {
    if (pow == 0) return 1;
    ll a = calc_pow(x, pow / 2);
    a = a * a % MOD;
    if (pow % 2 == 1) a *= x;
    return a % MOD;
}

ll calc_div(ll a, ll b) {
    return a * calc_pow(b, MOD - 2) % MOD;
}

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

    vector<int> a(n);
    map<int, int> lcm;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        auto now = prime_factor(a[i]);
        for (auto x:now) {
            if (lcm.find(x.first) == lcm.end())lcm[x.first] = 0;
            lcm[x.first] = max(lcm[x.first], x.second);
        }
    }
    ll lcmNum = 1;
    for (auto x:lcm)lcmNum *= calc_pow(x.first, x.second), lcmNum %= MOD;

    ll ret = 0;
    for (int i = 0; i < n; i++) ret += calc_div(lcmNum, a[i]), ret %= MOD;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 152;
const int MAX_K = 22;

int a[MAX_N];
int dp[MAX_N][MAX_K][(MAX_N+1)/2];
int n,m,K;
vector<int> S[MAX_N];
vector<int> T[MAX_N];

int main()
{
	while(1){
	scanf("%d%d",&n,&m);
	if(n==0&&m==0){
		break;
	}
	rep(i,n+1){
		S[i].clear();
		T[i].clear();
	}
	rep(i,n){
		scanf("%d",&K);
		rep(j,K){
			int x,y;
			scanf("%d%d",&x,&y);
			S[i].push_back(x-1);
			T[i].push_back(y);
		}
	}
	rep(i,S[n-2].size()){
		S[n].push_back(S[n-2][i]);
		T[n].push_back(0);
	}
	rep(i,S[n-1].size()){
		S[n].push_back(S[n-1][i]);
		T[n].push_back(0);
	}
	fill(dp[0][0],dp[n+1][0],INF);
	rep(j,S[0].size()){
		dp[0][j][0] = 0;
	}
	rep(j,S[1].size()){
		rep(l,S[0].size()){
			dp[1][j][0] = min(dp[1][j][0],(T[0][l]+T[1][j])*abs(S[1][j]-S[0][l]));
		}
		if(m>=1){
			dp[1][j][1] = 0;
		}
	}
	for(int i=1;i<n;i++){
		rep(j,S[i+1].size()){
			rep(k,m+1){
				rep(l,S[i].size()){
					dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][l][k]+(T[i][l]+T[i+1][j])*abs(S[i+1][j]-S[i][l]));
				}
				if(k>=1){
					rep(l,S[i-1].size()){
						dp[i+1][j][k] = min(dp[i+1][j][k],dp[i-1][l][k-1]+(T[i-1][l]+T[i+1][j])*abs(S[i+1][j]-S[i-1][l]));
					}
				}
			}
		}
	}
	int ans = INF;
	rep(j,S[n].size()){
		rep(k,m+1){
			ans = min(ans,dp[n][j][k]);
		}
	}
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4276
import java.io.*;
import java.util.StringTokenizer;
   
class Main{
   
static final PrintWriter out=new PrintWriter(System.out);

static class binarySearchTree{

static class Node{
int id;
Node p;
Node l;
Node r;
int deg;
Node(int id){
this.id=id; this.p=null; this.l=null; this.r=null; this.deg=0;
}
}

private static Node root;

binarySearchTree(){
root=null;
}

private static void insert(int v){
if(root==null) root=new Node(v);
else __insert(new Node(v));
}

private static void __insert(Node z){
Node x=root;
Node y=null;
while(x!=null){
y=x;
if(z.id<x.id) x=x.l;
else x=x.r;
}
z.p=y;
if(z.id<y.id) y.l=z;
else y.r=z;
y.deg++;
}

static void print(){
inorder(root);
out.println();
preorder(root);
out.println();
}

static void preorder(Node now){
if(now==null) return;
out.print(" "+now.id);
preorder(now.l);
preorder(now.r);
}
 
static void inorder(Node now){
if(now==null) return;
inorder(now.l);
out.print(" "+now.id);
inorder(now.r);
}
 
static void postorder(Node now){
if(now==null) return;
postorder(now.l);
postorder(now.r);
out.print(" "+now.id);
}
}

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
binarySearchTree tree=new binarySearchTree();
int num=Integer.parseInt(br.readLine());
for(int i=0;i<num;i++){
st=new StringTokenizer(br.readLine());
String command=st.nextToken();
if("insert".equals(command)){
int n=Integer.parseInt(st.nextToken());
tree.insert(n);
}
else tree.print();
}
out.flush();
}
}

Measured memory_bytes: 182444
#include <iostream>
#include <string>
int main()
{
    std::string s;
    std::cin >> s;
    
    if(s=="ABC"){
        std::cout << "ARC" << std::endl;
        return 0;
    }
    else{
        std::cout << "ABC" << std::endl;
        return 0;
    }
}   

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define All(v) v.begin(), v.end()
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;

const int MAX_N = (int)1e5 + 5;
multiset<int> S;

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        auto itr = S.lower_bound(a);
        if(itr==S.begin()){
            S.emplace(a);
        } else {
            itr--;
            S.erase(itr);
            S.emplace(a);
        }
    }
    cout<<S.size()<<endl;
    return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc141/tasks/abc141_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            string result = "2018";

            result += s.Substring(4);

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 11092
//Date:06-01-17
 
#include<stdio.h>
#include<string.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 100005
#define NIL -1
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
main(void){
 const int inf = 1e8;
 int n,m ,i ,j ,k;
 scanf("%d%d" ,&n ,&m);
 int a[1000],b[1000],c[1000],dist[100][100];
 for(i = 0; i < m; ++i){
	scanf("%d%d%d" ,a+i ,b+i ,c+i);
	a[i]--,b[i]--;
 }
 for(i = 0; i < n; ++i){
 for(j = 0; j < n; ++j){
 if(i==j)
 dist[i][j]=0;
 else
 dist[i][j]=inf;
 }
 }
 for(i = 0; i < m; ++i){
 dist[a[i]][b[i]]=min(dist[a[i]][b[i]],c[i]);
 dist[b[i]][a[i]]=min(dist[b[i]][a[i]],c[i]);
 }
 for(k = 0; k < n; ++k){
 for(i = 0; i < n; ++i){
 for( j = 0; j < n; ++j){
 dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
 }
 }
 }
 int ans=m;
 for( i = 0; i < m; ++i){
 bool shortest=false;
 for( j = 0; j < n; ++j) if(dist[j][a[i]]+c[i]==dist[j][b[i]]) shortest=true;
 if(shortest==true){
 ans=ans-1;
 }
 }
 printf("%d" ,ans);
return 0;
 }

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
bool dp[101][10001];//dp[i + 1][j] : i番目まで見たときjが作れるか否か
int main() {
    int N; cin >> N;
    int a[N]; rep(i, N) cin >> a[i];
    ll frontSum[N]; frontSum[0] = a[0];
    rep(i, N - 1)
        frontSum[i + 1] = frontSum[i] + a[i + 1];
    ll backSum[N]; backSum[N - 1] = a[N - 1];
    rep(i, N - 1)
        backSum[N - i - 2] = backSum[N - i - 1] + a[N - i - 2];
    ll minv = LLINF;
    rep(i, N - 1) {
        ll x = frontSum[i], y = backSum[i + 1];
        minv = min(minv, abs(x - y));
    }
    cout << minv << endl;
}


Measured memory_bytes: 4096
/*
AOJ - ITP1_6_d
Date: 20180927
Author: Mikoron
 */

#include<stdio.h>

#define MATRIX 100

int main(void) {
        int  n, m, i, j;
        int a[MATRIX][MATRIX], b[MATRIX], c[MATRIX];

        //initialize
        for(i = 0; i < MATRIX; i++) {
                for(j = 0; j < MATRIX; j++) {
                        a[i][j] = 0;
                }
                c[i] = b[i] = 0;
        }

        //input
        scanf("%d %d\n", &n, &m);
        //printf("%d %d\n", n, m);
        for(i = 0; i < n; i++) {
                for(j = 0; j < m; j++) {
                        scanf("%d", &a[i][j]);
                }
        }

        for(i = 0; i < m; i++) {
                scanf("%d\n", &b[i]);
        }

        //process
        for(i = 0; i < n; i++) {
                for(j = 0; j < m; j++) {
                        c[i] += a[i][j] * b[j];
                }
                printf("%d\n", c[i]);
        }

        return 0;
}



Measured memory_bytes: 2140
#include <stdio.h>
#include <string.h>

int main(void)
{
  int len,i,ml,mr,kl,kr,unl;
  char str[101],res[101];

  for(;;){
    gets(str);
    if(!strcmp(str,".")) break;

    unl=0;
    len=strlen(str);
    for(i=0;i<len;i++){
      if(str[i]=='('||str[i]=='['){
	res[unl++]=str[i];
      } else if(str[i]==')'||str[i]==']'){
	if(unl!=0&&(res[unl-1]==str[i]-1||res[unl-1]==str[i]-2)) unl--;
	else break;
      }
    }
    if(unl!=0||i!=len) puts("no");
    else puts("yes");
  }

  return 0;
}


Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
bool check(int n){
    while(n > 0){
        int r = n % 10;
        if(r == 7) return true;
        n = n / 10;
    }
    return false;
}
int main(){
    int n; cin >> n;
    if(check(n)){
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3600
fun main(args: Array<String>) {
    val (H, N) = readLine()!!.split(" ").map(String::toInt)
    val attacks = Array(N) { readLine()!!.split(" ").map(String::toInt).let { it[0] to it[1] } }

    val maxMp = attacks.maxBy { it.second }!!.second

    val dp = arrayOfNulls<Long>(H + 1 + maxMp)
    dp[0] = 0
    for (i in 1..H + maxMp) {
        for ((attack, mp) in attacks) {
            if (i - attack >= 0 && dp[i - attack] != null) {
                dp[i] = Math.min(dp[i] ?: Long.MAX_VALUE, mp + dp[i - attack]!!)
            }
        }
    }

//    dp.forEach(::println)
    dp.sliceArray(H..H + maxMp).filterNotNull().min().let(::println)

}



Measured memory_bytes: 116544
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; ++i) {
        int a, b;
        scanf("%d %d", &a, &b);
        v[i] = {a+b, a-b};
    }
    ll ans = 0, val = -INF<ll>;
    sort(v.begin(),v.end());
    for (int i = 0; i < n; ++i) {
        if(val <= v[i].second){
            ans++;
            val = v[i].first;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char
import           Data.Bits

main = do
  n      <- (read :: String -> Int) <$> getLine
  coords <- listArray (0, n - 1) <$> forM
    [1 .. n]
    (\i -> (\[a, b] -> (a, b)) . map (read :: String -> Int) . words <$> getLine
    )
  let allOrders    = countPermutation [] 0 n
      allDistances = map (calcDistance coords) allOrders
      meanDistance =
        sum allDistances / (fromIntegral (length allDistances) :: Double)
  print meanDistance

countPermutation :: [Int] -> Int -> Int -> [[Int]]
countPermutation order used n
  | used /= shift 1 n - 1 = do
    next <- extractUnused used n
    countPermutation (next : order) (used .|. shift 1 next) n
  | otherwise = return order

extractUnused :: Int -> Int -> [Int]
extractUnused a b = filter (\x -> (shift a (-x) .&. 1) == 0) [0 .. (b - 1)]

calcDistance :: Array Int (Int, Int) -> [Int] -> Double
calcDistance arr (a : b : rest) =
  let (x1, y1) = arr ! a
      (x2, y2) = arr ! b
      xDiff    = (x1 - x2) ^ 2
      yDiff    = (y1 - y2) ^ 2
  in  sqrt (fromIntegral (xDiff + yDiff) :: Double)
        + calcDistance arr (b : rest)
calcDistance arr [a] = 0.0


Measured memory_bytes: 5372
#include<stdio.h>
#include<stdlib.h>

int *A, H;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

void maxHeapify(int i){
  int l = left(i);
  int r = right(i);
  int largest, temp;

  if(l<=H && A[l]>A[i]){
    largest = l;
  }
  else {
    largest = i;
  }

  if(r<=H && A[r]>A[largest]){
    largest = r;
  }

  if(largest != i){
    temp = A[i];
    A[i] = A[largest];
    A[largest] = temp;
    maxHeapify(largest);
  }
}

int main(){
  int i;

  scanf("%d ",&H);
  A = (int *)malloc(sizeof(int) * (H+1));
  for(i=1; i<=H; i++){
    scanf("%d ",&A[i]);
  }

  // buildMaxHeap
  for(i=H/2; i>=1; i--){
    maxHeapify(i);
  }

  for(i=1; i<=H; i++){
    printf(" %d",A[i]);
  }
  puts("");

  return 0;
}



Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	int N, L, x, w;
	queue<int>ans;
	int sum = 0;
	cin >> L >> N;
	for (int i = 0; i < N; i++) {
		cin >> x >> w;
		sum += x*w;
	}
	//cout << sum << endl;
	//return 0;
	if (sum < 0) {
		for (int i = L; i > 0; i--) {
			int calc = abs(sum) / i;
			//cout << i  << " " << calc << " ";
			if (calc != 0) {
				ans.push(i); ans.push(calc);
				sum += calc*i;
			}
			//cout << sum << endl;
		}
	}else if (sum > 0) {
		for (int i = L; i > 0; i--) {
			int calc = sum / i;
			if (calc > 0) {
				ans.push(-i); ans.push(calc);
				sum -= calc*i;
			}
		}
	}
	cout << ans.size() / 2 << endl;
	while(ans.size()) {
		cout << ans.front() << " ";
		ans.pop();
		cout << ans.front() << endl;
		ans.pop();
	}
	return 0;
}

Measured memory_bytes: 3100
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC135
{
    class MainClass
    {

        static int[] s;
        static int[] n;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            n = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);

            var sortn = n.ToList();
            sortn.Sort();

            int diff = 0;

            for(int i = 0;i<s[0];i++){
                if(n[i]!=sortn[i]){
                    diff++;
                }

            }

            if(diff==0||diff==2){
                WriteLine("YES");
            }else{
                WriteLine("NO");
            }



        }
    }
}


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


int main()
{
	string s;
	int n, m;
	while (true)
	{
		cin >> s;
		if (s == "-")
			break;
		cin >> n;
		int p = 0;
		while (n > 0)
		{
			cin >> m;
			s += s.substr(p, m);
			p += m;
			n--;
		}
		cout << s.substr(p) << endl;
	}
	return 0;
}



Measured memory_bytes: 3156
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	
	int Length[3];
	int Triangle[4] = {0};
	bool flag = 0;
	
	while( cin >> Length[0] >> Length[1] >> Length[2]) {
	
	sort(Length, Length+3);
	
	if( Length[0] + Length[1] <= Length[2] ) flag = 1;
	if(flag == 1) continue;
	
	if( Length[0] * Length[0] + Length[1] * Length[1] 
	== Length[2] * Length[2] )
	Triangle[1]++;
	
	else if(Length[0] * Length[0] + Length[1] * Length[1] 
	> Length[2] * Length[2] )
	Triangle[2]++;
	
	else
	Triangle[3]++;
	
	Triangle[0]++;
	}

	cout << Triangle[0] << " " << Triangle[1] << " "
		 << Triangle[2] << " " << Triangle[3] << "\n";
	return 0;
}



Measured memory_bytes: 3136
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    println!("{}",a*a-b);
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		if (S>W) {
			System.out.println("safe");
		} else {
			System.out.println("unsafe");
		}
	}
}


Measured memory_bytes: 35712
// 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    ll N;
    cin >> N;
    ll ans = 0;
    for (ll A = 1; A <= N - 1; ++A)
    {
        // A * B < N を満たすBは各A(=1,...,N - 1)に対して (N - 1) / A 個ある
        // A * B < N を満たす(A, B)に対しA * B + C = N となる正整数Cはちょうど一つに定まるので、
        // A のループごとに (N - 1) / A を足していけば答えが求まる
        ans += (N - 1) / A;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
long long x,k,d;
int main(){
	cin>>x>>k>>d;
	long long QAQ=fabs(x)/d;
	QAQ=min(QAQ,k);
	if(x<0)
		x+=QAQ*d;
	else
		x-=QAQ*d;
	k-=QAQ;k%=2;
	long long ans=min(fabs(x-k*d),fabs(x+k*d));
	cout<<ans;
}

Measured memory_bytes: 3640
n,a,b,c=map(int,input().split())
L=[int(input()) for _ in range(n)]

ans=float('inf')
for i in range(4**n):
  G=[[] for _ in range(4)]
  for j in range(n):
    G[(i//(4**j))%4].append(L[j])
  if len(G[0])==0 or len(G[1])==0 or len(G[2])==0: continue # 一つも割り当てられていない場合条件達成は無理
  tmp=0
  for i,g in enumerate(G):
    if i==3: continue
    wood=sum(g) # 竹の合体
    tmp+=(len(g)-1)*10
    if i==0: tmp+=abs(wood-a)
    if i==1: tmp+=abs(wood-b)
    if i==2: tmp+=abs(wood-c)
  ans=min(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}


int main(){
    LL x,a,b;
    cin>>x>>a>>b;

    if(a-b>=0)cout<<"delicious"<<endl;
    else if(-a+b<=x)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
}

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

int solve(vector<string> &s,int n,int &y,int x){
    if(isdigit(s[y][x])) return s[y++][x] - '0';
    char op = s[y][x];
    ++y,++x;
    vector<int> term;
    while(y < n && (int)s[y].size() > x){
        term.push_back(solve(s,n,y,x));
    }
    if(op == '+') return accumulate(all(term),0);
    else return accumulate(all(term),1,multiplies<int>());
}

int main(void){
    int n;
    while(cin>>n,n){
        vector<string> s(n);
        rep(i,n) cin>>s[i];
        int y = 0;
        cout<<solve(s,n,y,0)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

//https://spherical-harmonics.hatenablog.com/entry/2019/01/09/171824

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    string a;cin>>a;
    bool azot=true;//all zero or two
    for(int i=0; i<n; i++)if(a[i]=='2'){azot=false;break;}
    /*if(azot){
        int ans = 0;

    }else{
        int ans = 0;
        for(int i=0; i<n; i++){
            ans = (ans+(n==(n|(n-i))))%2;
        }
        cout<<ans<<endl;
    }*/
    int ans = 0;
    for(int i=0; i<n; i++){
        int A = a[i]-'1';
        if(!azot)A%=2;
        if(n-1==(i|(n-1-i)))ans ^= A;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define pi acos(-1)
#define eps 0.000001
#define inf (1e9 + 7)
using namespace std;

int n, nn, pos[100005];
long long num[100005], ans[100005], num2[100005], num3[100005];

int getpos(long long a)
{
    int l = 1, r = nn;
    while(l <= r)
    {
        int mid = (l + r) / 2;
        if(num2[mid] > a)
            r = mid - 1;
        else if(num2[mid] < a)
            l = mid + 1;
        else
            return mid;
    }
}

int main()
{
    mem(ans, 0);
    mem(num3, 0);
    scanf("%d", &n);
    for(int i = 1;i <= n;i++)
        scanf("%lld", &num[i]), num2[i] = num[i], pos[i] = inf;
    sort(num2 + 1, num2 + 1 + n);
    nn = unique(num2 + 1, num2 + 1 + n) - num2 - 1;
    for(int i = 1;i <= n;i++)
    {
        int pp = getpos(num[i]);
        num3[pp]++;
        pos[pp] = min(pos[pp], i);
    }
    for(int i = nn;i >= 2;i--)
    {
        long long res = num2[i] - num2[i - 1];
        ans[pos[i]] += res * num3[i];
        num3[i - 1] += num3[i];
        pos[i - 1] = min(pos[i - 1], pos[i]);
    }
    ans[pos[1]] += num2[1] * num3[1];
    for(int i = 1;i <= n;i++)
        printf("%lld\n", ans[i]);
    return 0;
}
/*

    if(!flag)
    {
        printf("%s\n", ch2 + 1);
        return 0;
    }
    */


Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <string>
#include<vector>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;

int main()
{
    ll n,k;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    ll m= 999999999;
    ll dp[n];
    dp[0]=0;
    for(ll i=1;i<n;i++)
        dp[i]=m;
    for(ll i=0;i<n;i++){
        for(ll j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j]= min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    cout<<dp[n-1];
}




Measured memory_bytes: 1792
N = int(input())
r = [0]*N; c = [0]*N
for i in range(N):
    r[i], c[i] = map(int, input().split())

DP = [[0]*N for _ in range(N)]
for l in range(2, N+1): # l は行列の数
    for i in range(0, N):
        j = i + l-1
        if j >= N:
            break
        
        DP_ji = 10**9
        for k in range(i, j):
            DP_ji = min(DP_ji
                        ,DP[k][i] + DP[j][k+1] + r[i]*c[k]*c[j])
        DP[j][i] = DP_ji
print(DP[N-1][0])


Measured memory_bytes: 5660
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a,b;
		a = sc.nextInt();
		b = sc.nextInt();

		if (a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
			System.out.println("Possible");
		} else {
			System.out.println("Impossible");
		}

	}

}


Measured memory_bytes: 21972
import java.util.Scanner;

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

    public static void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = Math.max(a + b, a - b);
        System.out.println(Math.max(ans, a * b));
    }
}

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

void call(int n){
  int i = 1;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0){
      cout << " " << i;
      continue;
    }
    for (int x = i; x > 0; x /= 10) {
      if ( x % 10 == 3 ){
        cout << " " << i;
        break;
      }
    }
  }

  cout << endl;
}

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

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

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0;i<n;i++) cin >>  d[i];
    int ans = 0;
    for(int i=0;i<n;i++) {
        for(int j=i+1;j<n;j++) { // iterates over possibilites without counting same pair twice
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S == "AKIHBR" || S == "AKIHABR" || S == "AKIHABAR" || S == "AKIHABARA" || S == "AKIHABRA" || S == "AKIHBAR" || S == "AKIHBARA" || S == "AKIHBRA"){
    cout << "YES" << endl;
  }
  else if(S == "KIHBR" || S == "KIHABR" || S == "KIHABAR" || S == "AKIHABARA" || S == "KIHABRA" || S == "KIHBAR" || S == "KIHBARA" || S == "KIHBRA"){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256