akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define all(A) A.begin(),A.end()
typedef long long ll;

int main(){
  string s;
  cin >> s;
  int n = s.size();
  if(n == 1){
    cout << "YES" << endl;
    return 0;
  }
  map<char,int> mp;
  rep(i,n){
    mp[s[i]] ++;
  }
  if(mp.size() == 1){
    cout << "NO" << endl;
    return 0;
  }
  if(mp.size() == 2){
    if(n == 2) cout << "YES" << endl;
    if(n > 2) cout << "NO" << endl;
    return 0;
  }
  vector<int> v;
  for(auto p : mp) v.push_back(p.second);
  int _min = *min_element(all(v));
  int _max = *max_element(all(v));
  if(_max-_min <= 1) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lli long long int
#define f(i,a,b) for(i=a;i<b;i++)
#define ff first
#define sc second
#define pb push_back
#define full(v) v.begin(),v.end()
#define ms(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define mod2 998244353
#define msb(b) memset(b,true,sizeof(b))
#define msf(b) memset(b,false,sizeof(b))
#define MAXN 100005
// bool prime[1000000]; // 10**6
// lli pri[100000],x=0;
/*void sieve()
{
  msb(prime);
  prime[0]=prime[1]=false;
  for(int p=2;p*p<=1000000;p++)
  {
    if(prime[p])
    {
      for(int i=p*2;i<=1000000;i+=p)
        prime[i]=false;
      // a[x++]=p;
    }
  }
} */

int main()
{
    fio;
    int t,n,i,j;
    cin >> n;
    int a[n];
    map<int,int> m;
    f(i,0,n)
    {
        cin >> a[i];
        m[a[i]]++;
    }
    int ans = 0;
    f(i,0,n)
    {
        bool flag = true;
        for(int j = 1; j * j <= a[i]; j++)
        {
            if(a[i] % j == 0)
            {
                if((j != a[i] && m[j] >= 1) || (j == a[i] && m[j] > 1))
                    flag = false;
                else if(j != a[i]/j  && ((a[i]/ j != a[i] && m[a[i]/j] >= 1) || (a[i]/j == a[i] && m[a[i]/j] > 1)))
                    flag = false;
            }
            if(!flag)
                break;
        }
        if(flag)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 33156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<double> last(1,1.0);
    rep(i,1,n+1) {
        vector<double> dp(i+1);
        double p;
        cin >> p;
        rep(j,0,i+1) {
            if(j>0) dp[j]=p*last[j-1];
            if(j<i) dp[j]+=(1-p)*last[j];
        }
        swap(dp,last);
    }
    double ans=0;
    rep(i,(n+1)/2,n+1) {
        ans+=last[i];
    }
    cout<<setprecision(12);
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n=ii()
    cnt=0
    for i in range(n+1):
        if i%3!=0 and i%5!=0:cnt+=i
    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9060
int dice24[24][6]=
{
	{2,1,5,0,4,3},{2,0,1,4,5,3},{2,4,0,5,1,3},{2,5,4,1,0,3},{4,2,5,0,3,1},
	{5,2,1,4,3,0},{1,2,0,5,3,4},{0,2,4,1,3,5},{0,1,2,3,4,5},{4,0,2,3,5,1},
	{5,4,2,3,1,0},{1,5,2,3,0,4},{5,1,3,2,4,0},{1,0,3,2,5,4},{0,4,3,2,1,5},
	{4,5,3,2,0,1},{1,3,5,0,2,4},{0,3,1,4,2,5},{4,3,0,5,2,1},{5,3,4,1,2,0},
	{3,4,5,0,1,2},{3,5,1,4,0,2},{3,1,0,5,4,2},{3,0,4,1,5,2},
};
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

const int maxn=4;
int n,dice[maxn][6],ans;

vector<string> names;
int  ID(const char* name)
{
	string s(name);
	int n=names.size();
	for (int i=0;i<n;i++)
	if (names[i]==s) return i;
	names.push_back(s);
	return n;
}

int r[maxn],color[maxn][6];

void check()
{
	for (int i=0;i<n;i++)
		for (int j=0;j<6;j++)
		color[i][dice24[r[i]][j]]=dice[i][j];
	int tot=0;
	for (int j=0;j<6;j++)
	{
		int cnt[maxn*6];
		memset(cnt,0,sizeof(cnt));
		int maxface=0;
		for (int i=0;i<n;i++)
			maxface=max(maxface,++cnt[color[i][j]]);
		tot+=n-maxface;
	}
	ans=min(ans,tot);
}

void dfs(int d)
{
	if (d==n) check();
	else for(int i=0;i<24;i++)
	{
		r[d]=i;
		dfs(d+1);
	}
}
int main()
{
	while (scanf("%d",&n)==1&&n)
	{
		names.clear();
		for (int i=0;i<n;i++)
			for (int j=0;j<6;j++)
			{
				char name[30];
				scanf("%s",name);
				dice[i][j]=ID(name);
			}
		ans=n*6;
		r[0]=0;
		dfs(1);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2732
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();
  //aa もしくは abaがあればアンバランス
  for(int i=0;i<N-1;i++){
    if(s[i] == s[i+1]){
      cout << i+1 << " " << i+2 << endl;
      return 0;
    }
  }

  for(int i=0;i<N-2;i++){
    if(s[i] == s[i+2]){
      cout << i+1 << " " << i+3 << endl;
      return 0;
    }
  }

  cout << -1 << " " << -1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef pair<int, int> P;

int n;
vector<P> ax, ay;
vector<pair<int,P> > es;

struct UnionFindTree{
    int par[100000], rank[100000];

    void init(int k){
        for(int i=0;i<k;i++){
            par[i]=i;
            rank[i]=1;
        }
    }
    int find(int a){
        if(par[a] == a)return a;
        else{
            par[a] = find(par[a]);
            return par[a];
        }
    }
    bool same(int a, int b){
        return find(a) == find(b);
    }
    void unite(int a, int b){
        a = find(a);
        b = find(b);
        if(a == b)return;
        if(rank[a]<rank[b]){
            par[a] = b;
        }
        else{
            par[b] = a;
            rank[a]++;
        }
    }
};

int kruskal(){
    UnionFindTree g;
    g.init(n);
    int res = 0;
    for(int i=0;i<es.size();i++){
        int cost = es[i].first, u = es[i].second.first, v = es[i].second.second;
        if(g.same(u,v))continue;
        res += cost;
        g.unite(u,v);
    }
    return res;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        ax.push_back({x,i});
        ay.push_back({y,i}); 
    }
    sort(ax.begin(),ax.end());
    sort(ay.begin(),ay.end());
    for(int i=0;i<n-1;i++){
        es.push_back({abs(ax[i+1].first-ax[i].first), {ax[i].second,ax[i+1].second}});
        es.push_back({abs(ay[i+1].first-ay[i].first), {ay[i].second,ay[i+1].second}});
    }
    sort(es.begin(),es.end());

    cout << kruskal() << endl;

    return 0;
}

Measured memory_bytes: 7144
N = int(input())
H = [int(_) for _ in input().split()]
dp = [0, 0]
dp[0] = abs(H[1] - H[0])
if N == 2:
    print(dp[0])
else:
    dp[1] = abs(H[2] - H[0])
    for i in range(3, N):
        dp = [dp[1]] + [
            min(dp[0] + abs(H[i] - H[i - 2]), dp[1] + abs(H[i] - H[i - 1]))
        ]
    print(dp[-1])


Measured memory_bytes: 13928
# -*- coding: utf-8 -*-


def main():
    n, q = map(int, input().split())
    s = input()
    m = len(s)
    ac = [0 for _ in range(m)]

    for k in range(m - 1):
        if s[k] == 'A' and s[k + 1] == 'C':
            ac[k + 1] = ac[k] + 1
        else:
            ac[k + 1] = ac[k]

    for i in range(q):
        li, ri = map(int, input().split())
        print(ac[ri - 1] - ac[li - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 6180
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, w;
    cin >> n >> w;
    vector<int> values(n);
    vector<int> weights(n);
    vector<vector<int>> cache(w+1, vector<int>(n+1, 0));
    for(int i=0; i<n; ++i){
        cin >> values[i] >> weights[i];
    }

    for(int ni=1; ni<=n; ++ni){
        for(int wi=1; wi<=w; ++wi){
            if(weights[ni-1]>wi){
                cache[wi][ni]=cache[wi][ni-1];
            } else{
                cache[wi][ni]=max(cache[wi][ni-1], cache[wi-weights[ni-1]][ni-1]+values[ni-1]);
            }
        }
    }
    cout << cache[w][n] << "\n";
}


Measured memory_bytes: 7076
#include <stdio.h>
int main(){
    long long int a,b,c,x,result;
    scanf("%lld %lld %lld",&a,&b,&x);
    if (a%x==0){
        c=a/x-1;
    }
    else{
        c=a/x;
    }
    result=b/x-c;
    printf("%lld",result);
    return 0;
}

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

using namespace std;
int ans;
int main(){
	int n;
	cin >> n;
	int a[n];
	int b[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		b[i] = a[i];
	}
	for(int i = 0; i < n - 1; i++){
		for(int j = i + 1; j < n; j++){
			ans += a[i] * b[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
H=[0]+list(map(int,input().split()))
S=[0]*(n+1)
r=0
while H!=S:
    for i in range(n):
        if H[i]==0 and H[i+1]!=0:
            r+=1
    for i in range(n):
        if H[i+1]!=0:
            H[i+1]-=1
print(r)

Measured memory_bytes: 3060
#include<stdio.h>
int G[101][101];
int d[101];
int n;
int Que[1000];
int head=0, tail=0;
void enqueue(int q){
  Que[head]=q;
  head++;
}  
int dequeue(){
  tail++;
  return Que[tail-1];
} 
int size(){
  return head-tail;
}

void bfs(int i){
  int j;
  for(j=0;j<n;j++){
    if(G[i][j]==1 && d[j]==-1){
      d[j]=d[i]+1;
      enqueue(j);
    }
  }
}  
int main(){ 
  int i,j,v,k,u;
  scanf("%d",&n);
  for(i=0;i<101;i++) d[i]=-1;
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      G[u-1][v-1]=1;
    } 
  }
  d[0]=0;
  bfs(0);
  while(size()!=0) bfs(dequeue());
   
  for(i=0;i<n;i++) printf("%d %d\n",i+1,d[i]);
   
  return 0;
}

Measured memory_bytes: 636
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m = map(int,ipt().split())
    d = dict()
    mod = 10**9+7
    p = primes(m)
    for i in p:
        t = 0
        while True:
            if m%i == 0:
                m //= i
                t += 1
            else:
                break
        if t > 0:
            d[i] = t
        if i > m:
            break
    if m > 1:
        d[m] = 1
    ans = 1

    #nCrをmodで割った余りを求める。Nに最大値を入れて使用。
    N = 10**5+1000
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    def cmb(n,r,mod):
        if r<0 or r>n :
            return 0
        r = min(r,n-r)
        return g1[n]*g2[r]*g2[n-r]%mod
    for i in range(2,N+1):
        g1.append((g1[-1]*i)%mod)
        inverse.append((-inverse[mod % i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)

    for i in d.values():
        ans = (ans*cmb(n-1+i,i,mod))%mod

    print(ans)

    return

#√nまでの素数の配列を返す関数
def primes(n):
    if n < 4:
        return []
    else:
        pri = [2]
        k = 3
        while k*k <= n:
            for i in pri:
                if k%i == 0:
                    break
                elif i == pri[-1]:
                    pri.append(k)
            k += 2
        return pri

if __name__ == '__main__':
    main()


Measured memory_bytes: 16728
#include <cstdio>
#include <algorithm>
using std::min;
 
#define MAXN 100003

int abs(int z)
{
    if (z<0)
        return -z;
    else
        return z;
}
 
int main(void)
{
    int N,i,j;
    int h[MAXN], p[MAXN];
    scanf("%d",&N);
    for (i=0;i<N;i++)
    {
        scanf("%d",h+i);
    }
    p[N-1]=0;
    p[N-2]=abs(h[N-2]-h[N-1]);
    for(i=N-3;i>=0;i--)
    {
        p[i]=min(p[i+1]+abs(h[i]-h[i+1]),p[i+2]+abs(h[i]-h[i+2]));
    }
    printf("%d\n",p[0]);
 
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int ctoi(char c) {return c-'0';}/*char to int*/
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}/*MAX*/
int lcm(ll a,ll b){return a*b/gcd(a,b);}/*MIN*/
bool primecheck(ll n){/*sosuu*/if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int  main(){
int n;
cin >> n;
vector<pair<string,int>>a(n);
for(int i=0;i<n;i++){
    string s;
    int z;
    cin >> s >> z;
    a.at(i)=make_pair(s,z);
}
string che;
cin >> che;
int ans = 0;
bool now = false;
for(int i=0;i<n;i++){
    if(now)ans+=a.at(i).second;
 if(che==a.at(i).first){
     now = true;
 }
}
cout << ans << endl;
}





Measured memory_bytes: 764
import math
A, B = map(int, input().split())

def gcd(a, b):
	if b == 0: return(a)
	else : return gcd(b, a % b)
		
G = gcd(A, B)
ctr = 1
for i in range(2, int(math.sqrt(G)) + 1):
    if G == 1: 
        break
    if G % i == 0: 
        ctr += 1
    while G % i == 0:
        G /= i
        
if G == 1:        
    print(ctr)
else:
    print(ctr + 1)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << b / c - a / c + (a % c == 0 ? 1 : 0) << endl;
    return 0;
}

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

int main(){
    while(true){
        int n;
        long ans = 100000000000;
        cin >> n;
        if(n == 0)return 0;
        vector<int > a(n);
        rep(i,n)cin >> a[i];

        rep(i,n){
            for(int j = i+1;j<n;j++){
                int temp = abs(a[i]-a[j]);
                if(ans > temp)ans = temp;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3096
#include<stdio.h>
#define sentinel 2000000000
#define MAX 500000
int n,cnt;
int L[MAX/2+2],R[MAX/2+2];
void merge(int A[],int left,int mid,int right){
    int n1,n2,i,j,k;
    n1=mid-left;
    n2=right-mid;
    for(i=0;i<n1;i++) L[i]=A[left+i];
    for(i=0;i<n2;i++) R[i]=A[mid+i];

    i=j=0;
    L[n1]=R[n2]=sentinel;
    for(k=left;k<right;k++){
	cnt++;
	if(L[i]<=R[j]) A[k]=L[i++];
	else A[k]=R[j++];
    }
}

void mergeSort(int A[],int left,int right){
    int mid;
    if(left+1<right){
	mid=(left+right)/2;
	mergeSort(A,left,mid);
	mergeSort(A,mid,right);
	merge(A,left,mid,right);
    }
}

int main(void){
    int i;
    int A[MAX];

    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);

    mergeSort(A,0,n);
    
    for(i=0;i<n;i++){
	if(i) printf(" ");
	printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",cnt);

    return 0;
}



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
const int INF = 1001001001;

int main(){
  int n;
  string s;
  cin >> n;
  cin >> s;
  int ans = 0;
  for(int i=0;i<1000;i++){
    string num = to_string(i);
    while(num.size()<3){
      num.insert(0,"0");
    }
    bool ok1 = 0,ok2 = 0,ok3 = 0;
    for(int j=0;j<n;j++){
      if(ok1 ==0 && s.at(j) == num.at(0)){
        ok1 = 1;
      }else if(ok1 == 1  && ok2==0 && s.at(j) == num.at(1)){
        ok2 = 1;
      }else if(ok1 == 1 && ok2 ==1 && ok3==0 && s.at(j) == num.at(2)){
        ok3 = 1;
      }
    }
    if(ok3 == 1) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

long gcd(long a, long b){
    if(a < b){
        long temp = b;
        b = a;
        a = temp;
    }
    long c = a%b;
    if(c==0){
        return b;
    }
    else{
        return gcd(c,b);
    }
}

int main(){
    long A, B;
    cin >> A >> B;
    long g = gcd(A, B);
    long temp = g;
    long ans = 0;
    for(long i = 2; i < 10000000; i++){
        if(g % i == 0 ){
            while(g % i == 0){
                g /= i;
            }
            ans++;
        }
    }
    if(g > 10000000 ) cout << ans + 2 << endl;
    else cout << ans+1 <<endl;
    return 0;
}

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

int main(){
  string S;
  cin>>S;
  int len=S.length();
  int ans=0;
  int cnt=0;
  for(int i=0;i<len;i++){
    if(S.at(i)=='A'||S.at(i)=='C'||S.at(i)=='G'||S.at(i)=='T'){
      cnt++;
    }
    else {
      cnt=0;
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}


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

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

//   if (k > q){
//       rep(i,n){
//           cout << "Yes" << endl;
//           return 0;
//       }      
//   }

  vector<int> p(n);
  rep(i,q){
      int ai;
      cin >> ai;
      ai--;
      p[ai] = p[ai] + 1;
  }

  rep(i,n){
      int point = k - q + p[i];
      if (point > 0) cout << "Yes" << endl;
      else cout << "No" << endl;
  }

  return 0;

}

Measured memory_bytes: 1024
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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

int main() {
  IN(ll, a);
  IN(ll, b);
  IN(ll, c);
  IN(ll, d);
  ll ac = a * c;
  ll ad = a * d;
  ll bc = b * c;
  ll bd = b * d;
  ll max = ac;
  chmax(max, ad);
  chmax(max, bc);
  chmax(max, bd);
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] a = new int[n+1];
        int[] b = new int[n+1];

        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            a[i+1] = b[n-i] = 20000*i+1;
        }

        for (int i = 0; i < n; i++) {
            a[p[i]] += i;
            b[p[i]] += i;
        }

        for (int i = 1; i <= n; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();

        for (int i = 1; i <= n; i++) {
            System.out.print(b[i] + " ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 30996
import java.io.*;
  
public class Main {
    public static void main(String... args) throws IOException {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final StringBuilder sb = new StringBuilder();
        while (true) {
            final String line = br.readLine();
            final int index = line.indexOf(" ");
            final int x = Integer.parseInt(line.substring(0, index));
            final int y = Integer.parseInt(line.substring(index+1));
            if (x == 0 && y == 0) break;
            sb.append(x < y ? x + " " + y : y + " " + x).append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 22780
/*-- ILSH  --*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back 
#define pop pop_back
#define mp make_pair
#define vii vector < int >
#define vll vector < ll > 
#define dt cout<<"HERE\n";
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpi vector < pll >
#define vpl vector < pll >
#define fi first
#define se second 
#define sz size 
#define len length 

const ll inf=1e18+1e17;
//const ll mod =1e9+7;
const ll mod = 998244353;

ll modInverse(ll a,ll m){ll m0=m;ll y=0,x=1;if(m == 1)return 0;while(a> 1){ll q=a/m;ll t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}  
ll powm(ll a,ll b){a=a%mod;ll res=1;while(b){if(b&1)res=(res*a)%mod;a=(a*a)%mod;b>>=1;}return (res%mod);}


const ll N = 2e5+5;

void solve(){
	int n;
	cin>>n;
	ll arr[n];
	for ( int i=0;i<n;i++){
		cin>>arr[i];
		if ( arr[i]==0){
			cout<<0<<'\n';
			return;
		}
	}
	ll ans=1;
	ll lim=1e18;
	for ( int i=0;i<n;i++){
		if ( lim/arr[i]<ans){
			cout<<-1<<'\n';
			return;
		}
		else
			ans=ans*arr[i];
	}
	if ( ans>1e18){
		cout<<-1<<'\n';
		return;
	}
	cout<<ans<<'\n';


}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie( NULL);
	cout.tie(NULL);
//	#ifndef ONLINE_JUDGE
//		freopen ("INPUT.txt" , "r" , stdin);
//		freopen ("OUTPUT.txt", "w" , stdout);
//	#endif

	int t=1;

	//cin>>t;

	for ( int i=1;i<=t;i++){
   // 	cout<<"Case #"<<i<<": ";
    	solve();
 	}
}

Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll isPrime[1000010]={0};
vector<ll> Prime;

void sieve(){
	ll i,j;
	isPrime[0] = isPrime[1] = 1;
	for( i=2; i<1000010; i++)if(isPrime[i]==0)for(j=2*i; j<1000010; j+=i)isPrime[j]=1;
	for( i=1; i<1000010; i++)if(isPrime[i]==0)Prime.push_back(i);
}
ll modMul(ll a,ll b,ll mod){
	ll res=0;
	if(mod<=MOD){
        return ((a%mod)*(b%mod))%mod;
	}
	while(b){
		if(b&1)res = (res+a)%mod;
		a = (2*a)%mod;
		b = b/2;
	}
	return res;
}
ll modPow(ll x,ll n,ll mod){
	ll r = 1;
	while(n){
		if(n&1)r = modMul(r,x,mod);
		x = modMul(x,x,mod);
		n = (n>>1);
	}
	return r;
}
vector<int>v;
void printDivisors(int n) 
{ 
    // Vector to store half of the divisors 3343434 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i==0) 
        { 
            if (n/i == i) // check if divisors are equal 
                if (i%2!=0){
                	v.push_back(i);
				} 
            else
            { 
                if (i%2!=0){
                	v.push_back(i);
				}  
  
                // push the second divisor in the vector 
                if ((n/i)%2!=0){
                	v.push_back(n/i);
				} 
            } 
        } 
    } 
  
    // The vector will be printed in reverse 
} 
int sum=0;
long long int knapsack(int a[],int w[],int n,int W){
	long long int dp[n+1][sum+1];
	for (int i=1;i<=sum;i++){
		dp[0][i]=INT_MAX;
	}
	for (int i=0;i<=n;i++){
		dp[i][0]=0;
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=sum;j++){
			if (a[i-1]>j){
				dp[i][j]=dp[i-1][j];
			}
			else{
				dp[i][j]=min(dp[i-1][j],w[i-1]+dp[i-1][j-a[i-1]]);
			}
		}
	}

	int m=-1;
	for (int i=sum;i>=0;i--){
		if (dp[n][i]<=W){
			m=i;
			break;
		}
	}
	return m;
	
}
void solve (){
	int n,W;
	cin>>n>>W;
	int a[n],w[n];
	for(int i=0;i<n;i++){
		cin>>w[i];
		cin>>a[i];
		sum+=a[i];
	}
	cout<<knapsack(a,w,n,W)<<endl;
	
}
	
	

int main(){
	int t;

	t=1;
	while(t--){
		solve();
		}
		
	}


Measured memory_bytes: 82408
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var aa = ToIntArray(input.ReadLine(), n);

        Func<long, long> f = (x) => {
            return aa.Sum(a => Math.Abs(a - x));
        };

        for (int i=0; i<n; i++) {
            aa[i] -= (i + 1);
        }

        Array.Sort(aa);
        var ce = aa.Length / 2;

        long min = long.MaxValue;
        min = Math.Min(min, f(aa[ce]));
        //min = Math.Min(min, f(aa[ce +1]));

        return min;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 29244
#include<stdio.h>
int main(void){
  int N,A[100],i,j,count=0,key=0;
  
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }

  for(i = 0 ; i < N ; i++){
    for(j = N-1 ; j > i ; j--){
      if(A[j] < A[j-1]){
	key = A[j];
	A[j] = A[j-1];
	A[j-1] = key;
	count++;
      }
    }
  }
  for(j = 0 ; j < N ; j++){
    printf("%d",A[j]);
    if(j < N-1){
      printf(" ");
    }  
  }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max(a,b) (a>b?a:b)
typedef struct b{int C,G;}b;
int N,K,i,j,k,dp[12][2014]={0},JB[14][2014]={0},s[14]={0};
b B[2014];
int c(const void *p,const void *q)
{
	b x=*(b*)p,y=*(b*)q;
	return x.G==y.G?y.C-x.C:x.G-y.G;
}

int main()
{
	scanf("%d%d",&N,&K);
	for(i=0;i<N;i++)scanf("%d%d",&B[i].C,&B[i].G);
	qsort(B,N,sizeof(b),c);
	for(i=0;i<N;i++)
	{
		JB[B[i].G][s[B[i].G]+1]=JB[B[i].G][s[B[i].G]]+B[i].C+s[B[i].G]*2;
		s[B[i].G]++;
	}
	for(i=10;i>=0;i--)
		for(j=0;j<=K;j++)
			for(k=0;k<=s[i];k++)
			{
				if(k>j)
					dp[i][j]=max(dp[i][j],dp[i+1][j]);
				else
					dp[i][j]=max(dp[i][j],max(dp[i+1][j],dp[i+1][j-k]+JB[i][k]));
			}

	printf("%d\n",dp[0][K]);
	return 0;
}

Measured memory_bytes: 800
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n, a, b;
  cin >> n >> a >> b;
  if ((b - a) & 1) {
    cout << (min(a - 1, n - b) + ((b - a + 1) / 2));
  } else
    cout << (b - a) / 2;

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int calc(int i) {
    if (i == 0) return i;
    return i % 10 + calc(i / 10);
}

int main() {

    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);

    int ar[N + 1];
    ar[0] = 0;
    for (int i = 1; i <= N; ++i) {
        ar[i] = calc(i);
    }

    int c = 0;
    for (int i = 1; i <= N; ++i) {
        if (A <= ar[i] && ar[i] <= B) {
            // printf("%d\n", i);
            c += i;
        }
    }

    printf("%d\n", c);

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramC
    {
        static List<int>[] _list;
        static int _n;
        static int _m;

        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            _n = int.Parse(inputs[0]);
            _m = int.Parse(inputs[1]);

            _list = new List<int>[_n];
            for (var i = 0; i < _n; i++)
            {
                _list[i] = new List<int>();
            }

            for (var i = 0; i < _m; i++)
            {
                var inputs1 = Console.ReadLine().Split(" ");
                var a = int.Parse(inputs1[0]) - 1;
                var b = int.Parse(inputs1[1]) - 1;
                _list[a].Add(b);
            }

            var result = dfs(0, 0) ? "POSSIBLE" : "IMPOSSIBLE";
            Console.WriteLine(result);
        }

        static bool dfs(int v, int count)
        {
            if (count == 2)
            {
                return v == _n - 1;
            }

            foreach (var l in _list[v])
            {
                var b = dfs(l, count + 1);
                if (b)
                    return true;
            }

            return false;
        }
    }
}


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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  for (int i = 0; i < 3; ++i)
    for (int j = 0; j < 3; ++j)
      cin >> a[i][j];

  int n;
  cin >> n;
  for (int k = 0; k < n; ++k) {
    int b;
    cin >> b;
    for (int i = 0; i < 3; ++i)
      for (int j = 0; j < 3; ++j)
        if (a[i][j] == b)
          a[i][j] = 0;
  }

  bool yes = false;
  for (int i = 0; i < 3; ++i)
    if (a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0)
      yes = true;
  for (int j = 0; j < 3; ++j)
    if (a[0][j] == 0 && a[1][j] == 0 && a[2][j] == 0)
      yes = true;
  yes = yes || (a[0][0] == 0 && a[1][1] == 0 && a[2][2] == 0) ||
        (a[0][2] == 0 && a[1][1] == 0 && a[2][0] == 0);

  if (yes)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    int ans = 0;
    vector<int> v;
    SORT(a);
    REP(i, N) {
        if (binary_search(ALL(v), a[i]) == false) {
            int cnt = upper_bound(ALL(a), a[i]) - lower_bound(ALL(a), a[i]);
            v.push_back(a[i]);
            if (cnt < a[i])
                ans += cnt;
            else if (a[i] < cnt)
                ans += cnt - a[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  string s; cin >>s; bool shit=1;
  for(int i=0; i<3; i++) if(s[i]==s[i+1]) shit=0;
  if(shit) cout <<"Good";
  else cout <<"Bad";
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3596
#include<iostream>
#include<limits>
#define INFINITY 0x7FFFFFFF
void mergeSort(int* A, int left, int right);
using namespace std;
int ct = 0;
int main() {
	int* S;
	int n;
	cin >> n;
	S = new int[n];
	for (int i = 0; i < n; ++i) {
		cin >> S[i];
	}
	/*for (int i = 0; i < n; ++i) {
	cout << S[i];
	cout << " ";
	}
	cout << endl;
	*/
	mergeSort(S, 0, n);

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

	return 0;

}

void merge(int* A, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int* L;
	int* R;
	L = new int[n1 + 1];
	R = new int[n2 + 1];
	for (int i = 0; i < n1; ++i) {
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; ++i) {
		R[i] = A[mid + i];
	}
	L[n1] = (int)INFINITY;
	R[n2] = (int)INFINITY;
	int i = 0;
	int j = 0;

	for (int k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i = i + 1;
			ct++;
		}
		else {
			A[k] = R[j];
			j = j + 1;
			ct++;
		}
	}
	delete[]L;
	delete[]R;
}

void mergeSort(int* A, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}


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

int main()
{
    string s;
    cin >> s;
    int f1 = 0,f2 = 0,f3 = 0,sm = 0;
    if(s[0] == 'A'){
        f1 = 1;
    }
    for(int i = 2; i < s.size()-1; i++){
        if(s[i] == 'C'){
            f2 = 1;
        }
    }
    for(int i = 0; i < s.size(); i++){
        if(s[i] >= 'a' && s[i] <= 'z'){
            sm++;
        }
    }
    if(sm == s.size()-2){
        f3 = 1;
    }
    if(f1 == 1 && f2 == 1 && f3 == 1){
        cout << "AC";
    }else{
        cout << "WA";
    }
}

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

int main() {
	ll a, b;
	cin >> a >> b;
	
	vector<ll> aa;
	ll n = a;
	for (ll i = 2; i * i <= a; i++) {
		if (n % i == 0) {
			aa.push_back(i);
			while (n % i == 0) {
				n /= i;
			}
		}
	}
	if(n!=1) aa.push_back(n);
	ll ans = 1;
	rep(i, aa.size()) {
		//cout << aa[i] << endl;
		if (b % aa[i] == 0) ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct node
{
	int a[4];int err;
	friend node operator +(node x,node y)
	{
		x.a[0]+=y.a[0];x.a[1]+=y.a[1];x.a[2]+=y.a[2];x.a[3]+=y.a[3];
		if (y.err==1) x.err=1;
		else if ((y.err==0)&&(x.err==2)) x.err=0;
		return x;
	}
};
int col[1000100];
vector <int> des[1000100];
node dfs(int s)
{
	node ans;ans.a[0]=ans.a[1]=ans.a[2]=ans.a[3]=0;ans.err=2;ans.a[col[s]]++;
	bool p=false,q=false;
	for (int k=0;k<des[s].size();k++)
	{
		if (des[s][k]>0) p=true;else q=true;
		ans.a[0]++;
		if (col[abs(des[s][k])])
		{
			if ((des[s][k]>0)&&((col[des[s][k]]-col[s]+3)%3==1)) {}
			else if ((des[s][k]<0)&&((col[-des[s][k]]-col[s]+3)%3==2)) {}
			else ans.err=1;
		}
		else if (des[s][k]>0)
		{
			col[des[s][k]]=col[s]%3+1;
			ans=ans+dfs(des[s][k]);
		}
		else
		{
			col[-des[s][k]]=(col[s]+1)%3+1;
			ans=ans+dfs(-des[s][k]);
		}
	}
	if ((p&&q)&&(ans.err==2)) ans.err=0;
	return ans;
}
	
int main()
{
	int n,m;scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		des[u].push_back(v);des[v].push_back(-u);
	}
	long long ans=0;
	for (int i=1;i<=n;i++) if (!col[i])
	{
		col[i]=1;
		node p=dfs(i);
		if (p.err==1)
		{
			p.a[2]+=p.a[1]+p.a[3];
			ans+=(long long)p.a[2]*p.a[2];
		}
		else if (p.err==2)
		{
			ans+=p.a[0]/2;
		}
		else ans+=(long long)p.a[1]*p.a[2]+(long long)p.a[2]*p.a[3]+(long long)p.a[3]*p.a[1];
		//cerr<<i<<' '<<ans<<endl;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 41984
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // 'S' := "BC"

    string s_original; cin >> s_original;
    string s; s.reserve(s_original.size());
    REP(i, s_original.size()) {
        s.push_back(s_original[i]);
        if (s.size() >= 2) {
            if (*(s.end()-1) == 'C' && *(s.end()-2) == 'B') {
                s.pop_back();
                s.pop_back();
                s.push_back('S');
            }
        }
    }

    ll ans = 0;
    ll snum = 0;
    ll base = 0;
    REP(i, s.size()) {
        if (s[i] == 'S') {
            ans += i - (base + snum);
            snum++;
        } else if (s[i] != 'A') {
            base = i+1;
            snum = 0;
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << x << endl;

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> H(N, 0);
  rep(i, N)
  {
    cin >> H[i];
  }
  sort(H.rbegin(), H.rend());

  long long ans = 0;
  rep(i, N)
  {
    if (i < K)
    {
      continue;
    }
    ans += H[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int

void func(ll a, ll b, ll c, ll k, string& res){
	if(res=="Yes") return;
	if(k==0){
		if(c>b && b>a) res="Yes";
		return;
	}
	func(a*2, b, c, k-1, res);
	func(a, b*2, c, k-1, res);
	func(a,b,c*2, k-1, res);
}
int main() {
	int a, b, c, k;
	cin>>a>>b>>c>>k;
	string res="No";
	func(a, b, c, k, res);
	cout<<res<<endl;
	// while(true){
	// 	if(c>b && b>a) {res="Yes"; break;}
	// 	if(k<=0) break;
	// 	while(b<=a && k>0){
	// 		b=b*2;
	// 		k--;
	// 	}
	// 	while(c<=b && k>0){
	// 		c=c*2;
	// 		k--;
	// 	}
	// }
	// cout<<res<<endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main()
{
    int n, k;
    cin >> n >> k;
    ll h[n], m = INF;
    REP(i, n) cin >> h[i];
    SORT(h, n);
    REP(i, n - k + 1){
        int l = i, r = i + k - 1;
        m = min(m, h[r] - h[l]);
    }
    cout << m << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using namespace std;

int main() {
    int n, w[110];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> w[i];

    int ans = 10000000;
    for (int i = 0; i < n + 1; i++) {
        int sum1 = 0;
        int sum2 = 0;
        for (int j = 0; j <= i; j++) {
            sum1 += w[j];
        }
        for (int j = i + 1; j < n; j++) {
            sum2 += w[j];
        }
        ans = min(ans, abs(sum1 - sum2));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

const int mod = 998244353;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

struct combination {
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; i--) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

mint dp[3005][3005];

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    dp[a][b] = 1;
    for (int i = a; i <= c; i++) {
        for (int j = b; j <= d; j++) {
            if (i == a && j == b) continue;
            dp[i][j] += dp[i-1][j]*j+dp[i][j-1]*i;
            dp[i][j] -= dp[i-1][j-1]*(i-1)*(j-1);
        }
    }
    cout << dp[c][d] << endl;
}

Measured memory_bytes: 74156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.1415926535
#define MOD 1000000007
 
int main(){
  
  ll N,K;
  cin >> N >> K;
  ll d[K];
  ll A[K][N];
  for(int i = 0;i < K;i++){
    cin >> d[i];
    for(int j = 0;j < d[i];j++){
      cin >> A[i][j];
    }
  }
  
  ll have[N];
  for(int i = 0;i < N;i++)  have[i] = 0;
  for(int i = 0;i < K;i++){
    for(int j = 0;j < d[i];j++){
      have[A[i][j] - 1]++;
    }
  }
  
//  for(int i = 0;i < N;i++)  cout << have[i] << endl;
  ll cnt = 0;
  for(int i = 0;i < N;i++){
    if(have[i] == 0)  cnt++;
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3732
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
#define eps 1e-6
#define eq(x,y) (fabs((x)-(y)) < eps)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
const int mod = 998244353;
long double PI = acosl(-1);
const ll infl = 1e18+100;
const int inf = 2e9+100;
const int nmax = 600+5;
const int MAXLG = log2(nmax)+1;
//mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
//typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ost;

const int N = 2e5+5;
int sq[N];

int vis[2][nmax][nmax];
int n;

vector<pii>dydx;

inline bool thikase(int i, int j, int idx){
    if(i<0 or j<0 or i>=2*n or j>=2*n) return false;
    if(vis[idx][i][j]!=-1) return false;
    return true;
}

int delx[4] = {-1,1,-1,1};
int dely[4] = {-1,1,1,-1};


void dfs(int i, int j, int idx, int pi=-1, int pj=-1){
    if(pi==-1) vis[idx][i][j] = 0;
    else vis[idx][i][j] = vis[idx][pi][pj]^1;

    for(pii z : dydx){
        for(int k=0; k<4; k++){
            if(thikase(i+z.first*delx[k], j+z.second*dely[k], idx) ){
                dfs(i+z.first*delx[k], j+z.second*dely[k], idx, i, j);
            }
        }
    }
}

void alu(int idx, int D){
    dydx.clear();
    for(int i=0; i<=D; i++){
        if(sq[i]!=-1 and sq[D-i]!=-1){
            dydx.push_back({sq[i], sq[D-i]});
        }
    }

    for(int i=0; i<2*n; i++){
        for(int j=0; j<2*n; j++){
            if(vis[idx][i][j]==-1)
                dfs(i,j,idx);
        }
    }
}


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

    memset(vis, -1, sizeof vis);
    memset(sq, -1, sizeof sq);

    for(int i=0; i*i<N; i++) sq[i*i] = i;

    int D1,D2;
    cin>>n>>D1>>D2;

    alu(0, D1);
    alu(1, D2);

    vector<vector<pii> >types(4);
    for(int i=0; i<2*n; i++){
        for(int j=0; j<2*n; j++){
            int num = vis[0][i][j] + 2*vis[1][i][j];
            types[num].push_back({i,j});
        }
    }
    for(int i=0; i<4; i++){
        if(types[i].size()>=n*n){
            while(types[i].size()>n*n) types[i].pop_back();
            for(pii z : types[i])
                cout<<z.first<<" "<<z.second<<"\n";
            break;
        }
    }
}
/*

*/


Measured memory_bytes: 41304
N = int(input())
grid = []
A = list(map(int, input().strip().split()))
Ai = [n-1 for n in A]
B = list(map(int, input().strip().split()))
C = list(map(int, input().strip().split()))
ans = 0
for i in range(N):
  ans += B[Ai[i]]
  if((i > 0) and (Ai[i] == Ai[i-1]+1)):
  	ans += C[Ai[i-1]]
print(ans)

Measured memory_bytes: 3192
using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long m = 0;
            long a = 0;
            long r = 0;
            long c = 0;
            long h = 0;
            string s;
            for (int i = 0; i < N; i++)
            {
                s = Console.ReadLine();
                if (s[0] == 'M') m++;
                else if (s[0] == 'A') a++;
                else if (s[0] == 'R') r++;
                else if (s[0] == 'C') c++;
                else if (s[0] == 'H') h++;
            }
            //the posibilities are "mar mac mah mrc mrh mch arc arh ach rch" just aggregate wont do it.
            //m *a posibilitiesof m *r posibilities of ma

            long aggregation = (m * a * r) + (m * a * c) + (m * a * h) + (m * r * c) + (m * r * h) + (m * c * h) + (a * r * c) + (a * r * h) + (a * c * h) + (r * c * h);          
         
            Console.WriteLine(aggregation);
        }
    }
}


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

#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000

using namespace std;

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

	ll n, m;
	ll ac = 0, wa = 0;
	cin >> n >> m;
	vll vet(n);
	for(int i = 0; i < m; ++i){
		ll p;
		string s;
		cin >> p >> s; 
		if(s == "WA"){
			if(vet[p-1].ff == 0){
				vet[p-1].ss++;
			}
		} else{
			if(vet[p-1].ff == 0){
				vet[p-1].ff = 1;
				ac++;
				wa += vet[p-1].ss;
			}
		}
	}
	cout << ac << " " << wa << endl;



	return 0;
}


Measured memory_bytes: 1792