akhauriyash/Code-Regression huggingface dataset:
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0): n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
};

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

  ll n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  BIT<ll> s1(2020), s2(2020);
  rep(i, n) s1.add(a[i]);
  ll ans = 0;
  rep(i, n) {
    ans = (ans + k * (k - 1) / 2 % mod * (n - s1.sum(a[i])) % mod) % mod;
    ans = (ans + k * (i - s2.sum(a[i])) % mod) % mod;
    s2.add(a[i]);
  }
  cout << ans << '\n';




  

  
  return 0;
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int a = i;
        ans += n/i;
        ans -= (n % i == 0);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3644
# coding: utf-8
# Your code here!
S = input()
N = 2 ** (len(S) - 1)
ans = 0
for i in range(N):
    l = ""  #空の文字列に挿入していく
    for j in range(len(S) - 1):
        l += S[j]
        if((i >> j) & 1):
            l += "+"
    l += (S[len(S) - 1])
    #print(l)
    li = list(map(int,l.split("+")))
    for num in li:
        ans += num

print(ans)
    

Measured memory_bytes: 40432
def main():
    N, M = map(int, input().split())
    t = [int(i) for i in input().split()]
    t.sort()

    if N >= M:
        return 0

    x = [j-i for i, j in zip(t, t[1:])]
    x.sort(reverse=True)
    return (t[-1] - t[0]) - sum([x[i] for i in range(N - 1)])


print(main())


Measured memory_bytes: 13832
import bisect
inf = 10**15
mod = 10**9+7
n = int(input())
a = list(map(int, input().split()))
dicL = [a[i]+i for i in range(n)]
dicR = [i-a[i] for i in range(n)]
dicL.sort()
dicR.sort()
ans = 0
for x in range(n-1):
    indL = bisect.bisect_left(dicL, x)
    indR = bisect.bisect_left(dicR, x)
    countL = 0
    countR = 0
    while indL != n and dicL[indL] == x:
        countL+=1
        indL+=1
    while indR != n and dicR[indR] == x:
        countR+=1
        indR+=1
    ans+=countL*countR
print(ans)

Measured memory_bytes: 109936
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const double pi=acos(-1);

int main(){
  int u,s,e,w,n,d;
  int U,S,E,W,N,D;
  cin >> u >> s >> e >> w >> n >> d;
  string t;
  cin >> t;
  rep(i,t.size()){
    U=u;
    S=s;
    E=e;
    W=w;
    N=n;
    D=d;
    if(t[i]=='N'){
      u=S;
      s=D;
      e=E;
      w=W;
      n=U;
      d=N;
    }
    if(t[i]=='E'){
      u=W;
      s=S;
      e=U;
      w=D;
      n=N;
      d=E;
    }
    if(t[i]=='S'){
      u=N;
      s=U;
      e=E;
      w=W;
      n=D;
      d=S;
    }
    if(t[i]=='W'){
      u=E;
      s=S;
      e=D;
      w=U;
      n=N;
      d=W;
    }
  }
  cout << u << endl;
  return 0;
}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define ll long long
#define pb push_back
#define F first
#define S second
#define ld long double
#define rep(i,n) for (int i =0;i < (n); ++i)
#define vi vector<ll>
#define all(v) (v).begin(),(v).end()
const int inf = 1e9 + 10;

void solve() {

	ll n, k; cin >> n >> k;
	vector<bool> a(n, false);
	for (int i = 0; i < k; i++) {
		ll d; cin >> d;
		for (int i = 0; i < d; i++) {
			ll t; cin >> t;
			a[t - 1] = true;
		}
	}
	ll ans = 0;
	for (auto c : a) if (c == false) ans++;
	cout << ans;
}
int main() {

	FASTIO;


	cout << fixed << setprecision(25);
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 3644
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  1000000007
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n' 
#define   bitcount(x)  (int)__builtin_popcount(x) 
#define   sz(x)  (int)x.size()
#define   all(a) a.begin(),a.end() 
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int bigmod(int a, int p, int m){ 
    if (p == 0)  return (1 % m) ; 
    if (p & 1){ 
        int p1 = a % m ;
        int p2 = bigmod( a, p-1, m ); 
        return  (p1 * p2) % m; 
    }
    int p1 = bigmod( a, p/2, m ); 
    return  (p1 * p1) % m; 
}


inline void solve(){
    int  n, k ; 
    cin >> n >> k ; 
    k-- ; 
    vi  fact(n+1), a(n+1); 
    for (int i=1;i<=n;i++) cin >> a[i] ; 
    fact[0] = fact[1] = 1 ; 
    for (int i=2;i<=n;i++) {
      fact[i] = fact[i-1]*i ; 
      fact[i] %= mod ; 
    }
    sort(a.begin()+1,a.end()) ; 
    int  mn=0, mx=0 ; 
    for (int i=1,N;i<=n;i++){

      if (i<=n-k) {
        N = n-i;
        int h= (fact[N]*bigmod(fact[N-k]*fact[k],mod-2,mod)) % mod ; 
        mn += h * a[i] ; 
        mn %= mod ; 
      }
      if (i > k) { 
        N = i-1;
        int h= (fact[N]*bigmod(fact[N-k]*fact[k],mod-2,mod)) % mod ; 
        mx += h * a[i] ; 
        mx %= mod; 
      }
    }
    co((mx-mn+mod)%mod) ; 
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
 

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

int main(){
	int n,tmp;
	vector <int>a;
	
	cin >> n;

	for(int i=0; i<n; i++){
		cin >> tmp;
		a.push_back(tmp);
	}

	int now_Light = a[0];
	a[0] = 0;
	int cnt = 1;
	if(now_Light == 2){
		cout << cnt << endl;
		return 0;
	}
	for(int i=0; i<n-1; i++){
		cnt++;
		int tmp = now_Light;
		now_Light = a[now_Light-1];
		if(now_Light == 0){
			cout << -1 << endl;
			break;
		}
		else if(now_Light == 2){
			cout << cnt << endl;
			break;
		}
		a[tmp-1] = 0;
		if(i==n-2){
			cout << -1 << endl;
		}
	}
}




Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int main() {
   int n;
    cin >> n;
  int sum = 0;

  vector<int> s(n);
  
  for (int i = 0;i<n;i++){
    cin >> s.at(i);
    sum = sum + s.at(i);
  }
  
  sort(s.begin(), s.end()); 
if (sum % 10 == 0){
  for (int i =0;i<n;i++){
    if((sum - s.at(i))%10!=0){
      cout << sum - s.at(i) << endl;
      break;
    }else if(i == n - 1){
      cout << 0 << endl;
    }
  }
}else{
  cout << sum << endl;
}
  
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
// clang-format on
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  //  std::random_device rd;std::mt19937 ran(rd());

  int H, W;
  int h, w;
  cin >> H >> W;
  cin >> h >> w;
  cout << (H - h) * (W - w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  int ans=0;
  for(auto c:S)if(c=='0')ans++;
  cout<<min(ans,(int)S.size()-ans)*2<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb;

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


int main() {
    ll N,D;
    cin >> N >> D;
    vector<vector<ll>> X(N,vector<ll>(D));

    rep(i,N){
        rep(j,D){
            cin >> X[i][j];
        }
    }

    ll ans=0;
    rep(i,N)for(ll j=i+1;j<N;j++){
        ll result = 0;
        rep(k,D){
            result += pow((X[i][k]-X[j][k]),2);
        }

        ll resultNum = sqrt(result);
        if(result == (resultNum*resultNum)){
            ans++;
        }
    }
    
    cout << ans << endl;
}



Measured memory_bytes: 3712
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @aa = map { $_ - 0 } split(/\s+/,<STDIN>);

my %cnt_m = ();
my %cnt_p = ();

my @a2 = ();
$#a2 = $n - 1;
for(my $i=0;$i<$n;$i++){
  my $v1 = $aa[$i] - ($i+1);
  
  $cnt_m{$v1} ++;
  
  my $v2 = $aa[$i] + ($i+1);
  
  $cnt_p{$v2} ++;
  
}

my $t = 0;
foreach my $k (keys %cnt_p){
  my $mi_v = - ( $k - 0 );
  if( exists($cnt_m{$mi_v}) ){
    $t += ( $cnt_p{$k} * $cnt_m{$mi_v} );
  }
}

print "$t\n";



Measured memory_bytes: 78484
#include <iostream>
using namespace std;
int main()
{
  int a,b,k;
  cin >> a >> b >> k;
  int cnt = 0;
  for(int i=100;;i--)
  {
   if(a%i == 0 && b%i == 0)
     cnt++;
    if(cnt == k){
      cout << i;
      break;
    }
  }
}

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

bool table[1001];

typedef struct{
  int t, n, m, s;
} Log;

int main()
{
  while(1){
    int N, M;
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    int r;
    cin >> r;
    Log record[r];
    REP(i,r)
      cin >> record[i].t >> record[i].n >> record[i].m >> record[i].s;
    int q;
    cin >> q;
    REP(i,q){
      int ans = 0;
      int ts, te, s;
      cin >> ts >> te >> s;
      fill(table, table + 1001, true);
      FOR(j,ts,te+1)
        table[j] = false;
      REP(j,r){
        if(record[j].m == s && record[j].s == 0){
          for(int k = j - 1; k >= 0; k--){
            if(record[k].n == record[j].n && record[k].m == record[j].m && (record[k].s & 1)){
              FOR(l,record[k].t,record[j].t+1){
                if(!table[l]){
                  table[l] = true;
                }
              }
              break;
            } 
          }
        } 
      }
      int j = ts;
      while(j <= te){
        bool flag = false;
        while(table[j] && j <= te){
          ans++;
          j++;
          flag = true;
        }
        if(flag)
          ans--;
        while(!table[j] && j <= te){
          j++;
        }
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 1172
using System;

class Program
{
  static void Main(string[] args)
  {
    int N = int.Parse(Console.ReadLine());
    int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N - 1];

    InsertArray(A);
    InsertArray(B);
    InsertArray(C);

    int manzoku = 0;
    int prevIndex = -2;

    for (int i = 0; i < N; i++)
    {
      int index = A[i];
      manzoku += B[index - 1];
      if(index == prevIndex + 1)
      {
        manzoku += C[index - 2];
      }
      prevIndex = index;
    }
    Console.WriteLine(manzoku);
  }

  /*配列に入力された数値を入れる*/
  static void InsertArray(int[] target)
  {
    string[] inputs = Console.ReadLine().Split(' ');
    for (int i = 0; i < target.Length; i++)
    {
      target[i] = int.Parse(inputs[i]);
    }
  }
}

Measured memory_bytes: 13140
import java.util.Scanner;

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

		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		
		for(int i = 0; i < n; i++) {
			s.nextLine();
			a[i] = s.nextInt();
			b[i] = s.nextInt();
			c[i] = s.nextInt();
		}
		
		int[] prevDayA = new int[n];
		int[] prevDayB = new int[n];
		int[] prevDayC = new int[n];
		
		prevDayA[0] = a[0];
		prevDayB[0] = b[0];
		prevDayC[0] = c[0];

		for(int i = 1; i < n; i++) {
			prevDayA[i] = Math.max(prevDayB[i - 1], prevDayC[i - 1]) + a[i];
			prevDayB[i] = Math.max(prevDayA[i - 1], prevDayC[i - 1]) + b[i];
			prevDayC[i] = Math.max(prevDayA[i - 1], prevDayB[i - 1]) + c[i];
		}
		
		System.out.println(Math.max(prevDayA[n-1], Math.max(prevDayB[n-1], prevDayC[n-1])));
		
	}
}


Measured memory_bytes: 158492
import math
a,b,C=map(float,input().split())
sinC=math.sin(math.radians(C))
S=a*b*sinC/2
L = (a**2+b**2-2*a*b*math.cos(math.radians(C)))**(1/2)+a+b
h=b*sinC
print(round(S,5))
print(round(L,5))
print(round(h,5))


Measured memory_bytes: 5700
#include <iostream>
#include <cstring>
#include <string>

class Dice
{
public:
	Dice(int* pValue)
	{
		memcpy(m_value, pValue, sizeof(int) * 6);
	}

public:
	void Roll(char direction)
	{
		int prev[6];
		memcpy(prev, m_value, sizeof(int) * 6);

		switch (direction)
		{
		case 'N':
		{
			m_value[0] = prev[1];
			m_value[1] = prev[5];
			m_value[4] = prev[0];
			m_value[5] = prev[4];
		}
		break;
		case 'E':
		{
			m_value[0] = prev[3];
			m_value[2] = prev[0];
			m_value[3] = prev[5];
			m_value[5] = prev[2];
		}
		break;
		case 'W':
		{
			m_value[0] = prev[2];
			m_value[2] = prev[5];
			m_value[3] = prev[0];
			m_value[5] = prev[3];
		}
		break;
		case 'S':
		{
			m_value[0] = prev[4];
			m_value[1] = prev[0];
			m_value[4] = prev[5];
			m_value[5] = prev[1];
		}
		break;
		default:
			break;
		}
	}

	int GetTop() const
	{
		return m_value[0];
	}

private:
	int m_value[6];
};

int main(int argc, char** argv)
{
	int value[6];
	for (int i = 0; i < 6; ++i)
	{
		std::cin >> value[i];
	}

	std::cin.ignore();

	Dice dice = Dice(value);

	std::string dirStr;
	std::getline(std::cin, dirStr);

	for (char dir : dirStr)
	{
		dice.Roll(dir);
	}

	std::cout << dice.GetTop() << std::endl;

	return 0;
}


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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX
#define N 200005

int par[N],ran[N];

int fin(int n)
{
	while(par[n]!=n)
	{
		par[n]=par[par[n]];
		n=par[n];
	}
	return n;
}

void unio(int x,int y)
{
	int n=fin(x);
	int m=fin(y);
	if(n==m)
		return;
	else if(ran[n]>ran[m])
		par[m]=n;
	else if(ran[m]>ran[n])
		par[n]=m;
	else
	{
		par[m]=n;
		ran[n]++;
	}
}

void dsu(int n)
{
	for(int i=1;i<=n;i++)
		par[i]=i,ran[i]=0;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n,m,ans=0;
	cin>>n>>m;
	dsu(n);
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		unio(x,y);
	}
	map<int,int> ma;
	for(int i=1;i<=n;i++)
		ma[fin(i)]++;
	for(auto x:ma)
		ans=max(ans,x.se);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 19136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using VI = vector<int>;
using VB = vector<bool>;
using Graph = vector<vector<int>>;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int n;
  cin >> n;
  int x[n];
  rep(i, n) cin >> x[i];

  int ans = 2147483647;

  rep(p, 100)
  {
    int count = 0;
    rep(j, n)
    {
      count += (x[j] - p) * (x[j] - p);
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

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

struct UnionFind
{
    vector<int> d;
    UnionFind(int n) : d(n, -1) {}
    int root(int x)
    {
        if (d[x] < 0)
            return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (d[x] > d[y])
            swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -d[root(x)]; }
};

void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C, std::vector<long long> D)
{
    int deg[100005];
    vector<int> to[100005];

    UnionFind uf(N);
    for (int i = 0; i < M; i++)
    {
        int a = A[i];
        int b = B[i];
        --a;
        --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a, b);
    }
    for (int i = 0; i < K; i++)
    {
        int a = C[i];
        int b = D[i];
        --a;
        --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    for (int i = 0; i < N; i++)
    {
        int ans = uf.size(i) - 1 - deg[i];
        for (int u : to[i])
        {
            if (uf.same(i, u))
                --ans;
        }
        printf("%d%c", ans, i == N - 1 ? '\n' : ' ');
    }
    return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    long long K;
    scanf("%lld", &K);
    std::vector<long long> A(M);
    std::vector<long long> B(M);

    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    std::vector<long long> C(K);
    std::vector<long long> D(K);
    for (int i = 0; i < K; i++)
    {
        scanf("%lld", &C[i]);
        scanf("%lld", &D[i]);
    }
    solve(N, M, K, std::move(A), std::move(B), std::move(C), std::move(D));
    return 0;
}


Measured memory_bytes: 9856
import sys
from collections import Counter
input = sys.stdin.readline

def main():
    _ = int(input())
    D = list(map(int, input().split()))
    Dnum = Counter(D)
    if D[0] != 0 or Dnum[0] != 1:
        print(0)
        exit()
    ans = 1
    for i in range(1, max(D)+1):
        ans *= Dnum[i] ** Dnum[i+1]
        if ans == 0:
            break
    print(ans%998244353)


if __name__ == '__main__': main()

Measured memory_bytes: 19872
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX 100000
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg
#define newl cout<<"\n"
using namespace std;
typedef long long ll;
int N;
int L[10];
int main(){
  scan(N);
  rep(i,N)scan(L[i]);
  sort(L,L+N);
  int sum=0;
  rep(i,N-1)sum+=L[i];
  if(L[N-1]<sum)prin("Yes\n");
  else prin("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N;
    cin >> N;

    vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(3, vector<ll>(2, -1e18)));
    dp[0][1][0] = 0;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 2; ++k) {
                if (dp[i][j][k] <= -1e18)
                    continue;
                int nxt = j - (i & 1);
                if (nxt >= 0)
                    dp[i + 1][nxt][0] = max(dp[i][j][k], dp[i + 1][nxt][0]);
                nxt++;
                if (k == 0 && nxt < 3)
                    dp[i + 1][nxt][1] = max(dp[i][j][k] + A, dp[i + 1][nxt][1]);
            }
        }
    }

    cout << max(dp[N][1][0], dp[N][1][1]) << endl;

    return 0;
}


Measured memory_bytes: 42264
#include <stdio.h>

int main(void) {
    int n[5];
        for(int i=0;i<5;i++) scanf("%d", &n[i]);

        for(int i=0;i<5;i++){
          if(n[i]==0){
            printf("%d",i+1);
          }
        }
        return 0;
}


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


int main(int argc, char const* argv[])
{
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size()-1) == b[0] and b.at(b.size()-1) == c[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(r<=y && y<=(H-r)){
		if(r<=x && x<=(W-r)){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;

}

Measured memory_bytes: 584
#include<stdio.h>

int main()
{
	long long int n,m,d;

	scanf("%lld %lld %lld",&n,&m,&d);

	if(d>0)printf("%lf\n",(double)2*(n-d)*(m-1)/(n*n));
	else if(d==0)printf("%lf\n",(double)(n-d)*(m-1)/(n*n));

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "Yes\n"
#define N cout << "No\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i, n) for (int i = 0; i < n; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)


long long mo = 1000000007 ;
int p(long long a , long long b , ll mod)
{
     int ans = 1 ;
    while(b)
    {
        if(b%2)
        {
            ans = ( (ans%mod)*(a%mod) ) %mod ;
        }
        a = ((a%mod)*(a%mod))%mod ;
        b /= 2 ;
    }
    return ans ;
}

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll x , k , d , b , a ;
     cin >> x >> k >> d ;
     if(x < 0)
     {
          x *= (-1) ;
     }
     a = x/d ;
     if(a > k)
     {
          a = (x - d*k) ;
     }
     else
     {
          k -= a ;
          a = (x - a*d) ;
          if(k > 0)
          {
               b = d-a ;
               k-- ;
               if(k%2 == 0)
               {
                    a = b ;
               }
          }
     }
     cout << a << endl ;
}


Measured memory_bytes: 3636
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Yen = sc.nextInt();
		e: for(int x = 0; x <= N; x++){
			for(int y = 0; y <= N; y++){
				int z = N - x - y;
				if((z >= 0) &&(1000*z + 5000*y + 10000*x == Yen)){
					System.out.println(x+" "+y+" "+z);
					break e;
				}else if((x == N) && (y == N)){
					System.out.println("-1 -1 -1");
				}
			}
		}
	}
}

Measured memory_bytes: 23124
ipt=[int(input()) for x in [0]*5]
ans=10**10
for i in range(5):
    tmpans=0
    for j in range(5):
        if i==j:
            tmpans+=ipt[j]
        else:
            if ipt[j]%10!=0:
                tmpans+=(ipt[j]//10 +1)*10
            else:
                tmpans+=ipt[j]
    ans=min(ans,tmpans)
print(ans)

Measured memory_bytes: 38256
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, S: str):
    is_hyphen = True if S[A : A + 1] == "-" else False
    before = S[:A]
    after = S[A + 1 :]
    try:
        int(before)
        int(after)
        if is_hyphen:
            print(YES)
        else:
            print(NO)
    except:
        print(NO)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(A, B, S)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
N = int(input())
S = input()
putFirst = 0
putLast = 0
nowCount = 0
for i in range(N):
    if(S[i] == '('):
        nowCount += 1
    else:
        nowCount -= 1
        if nowCount < 0:
            nowCount = 0
            putFirst += 1
putLast = nowCount
print('(' * putFirst + S + ')' * putLast)

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

int main(){
	int h,w;
	cin>>h>>w;

	char tb[1000][1000];
	queue<pair<pii,int>> que;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			cin>>tb[i][j];
			if(tb[i][j]=='#')que.push({{i,j},0});
		}
	}

	int ans=0;
	while(!que.empty()){
		auto p=que.front();
		que.pop();
		auto q=p.first;
		

		chmax(ans,p.second);

		for (int i = 0; i < 4; i++){
			int nh = q.first+dy[i];
			int nw = q.second+dx[i];

			if(nh<0||nw<0||nh>=h||nw>=w)continue;
			if(tb[nh][nw]=='.'){
				tb[nh][nw]='#';
				que.push({{nh,nw},p.second+1});
			}
		}

	}

	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){

    int N, M; cin >> N >> M;
    vector<int> keta (N);
    for(int i=0; i<N; ++i){
        keta[i] = -1;
    }

    int ans = 0;
    for(int i=0; i<M; ++i){
        int s, c; cin >> s >> c;
        s--;
        if(N > 1 && s == 0 && c == 0){
            ans = -1;
            break;
        }

        if(keta[s] == -1){
            keta[s] = c;
        }else{
            if(keta[s] == c){
                continue;
            }else{
                ans = -1;
                break;
            }
        }
    }

    for(int i=0; i<N; ++i){
        if(keta[i] == -1){
            if(i == 0 && N > 1){
                keta[i] = 1;
            }else{
                keta[i] = 0;
            }
        }
    }

    if(ans != -1){
        for(int i=0; i<N; ++i){
            cout << keta[i];
        }
        cout << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
signed main()
{
	fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll N;
		cin>>N;
		ll ans=0;
		for(ll i=2;i*i<=N;i++)
		{
			ll c=0;
			while(N%i==0)
			{
				N/=i;
				c++;
			}
			ll low=0;
			ll high=1e9;
			ll temp=0;
			while(low<=high)
			{
				ll mid=(low+high)/2;
				if((mid*mid+mid)/2<=c)
				{
					temp=mid;
					low=mid+1;
				}
				else
					high=mid-1;
			}
			ans+=temp;
		}
		if(N>1)
			ans++;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3640
package main

import(
	"fmt"
)

func Solve(t, p string) []int {
	result := make([]int, 0)
	for i,_ := range t {
		if len(t) < i + len(p) {
			break
		}
		s := t[i : i+len(p)]
		if s == p {
			result = append(result, i)
		}
	}
	return result
}

func main() {
	var t, p string
	fmt.Scanf("%s", &t)
	fmt.Scanf("%s", &p)
	result := Solve(t, p)
	for _, v := range result {
		fmt.Println(v)
	}
}


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

int main() {
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  while(a>0&&c>0){
    c-=b;
    if(c<=0){
      cout<<"Yes"<<endl;
      return 0;
    }
    a-=d;
    if(a<=0){
      cout<<"No"<<endl;
    }
  }
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ll a, b, n;
  cin >> a >> b >> n;

  ll ans = (a*n)/b - a*(n/b);
  ll t = n/b;
  ll x = b*t-1;
  ckmax(ans, (a*x)/b - a*(x/b));
  cout << ans << '\n';
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n;
int x[3003],y[3003];
char aru[5555][5555];

int main(){
	cin.sync_with_stdio(false);
  while(1){
    memset(aru,0,sizeof(aru));
    cin>>n;
    if(n==0)break;
    rep(i,n){
      cin>>x[i]>>y[i];
      aru[x[i]][y[i]]=true;
    }
    int res=0;
    rep(i,n)rep(j,i){
      int x3=x[i]+y[i]-y[j];
      int y3=y[i]+x[j]-x[i];
      int x4=x[j]+y[i]-y[j];
      int y4=y[j]+x[j]-x[i];
      int dx=x[i]-x[j],dy=y[i]-y[j];
      if(x3>=0&&y3>=0&&x4>=0&&y4>=0&&x3<=5000&&y3<=5000&&x4<=5000&&y4<=5000&&aru[x3][y3]&&aru[x4][y4]){
        maxch(res,dx*dx+dy*dy);
      }
    }
    cout<<res<<endl;
  }
  return 0;
}

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


class Program{
    public static void Main(){
        int ans = 0;
        int N = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(' ');
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = int.Parse(s[i]);
        }

        for(int j = 0; j < N; j++){
            ans += a[j] - 1;
        }
        WriteLine(ans);
    } 
}

Measured memory_bytes: 11164
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, K = map(int, raw_input().split())
D = set(raw_input().split())
for i in xrange(100000):
    for x in str(N):
        if x in D:
            break
    else:
        print N
        break
    N += 1



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

typedef long long ll;

string s1;
string s2;
ll n1;
ll n2;
ll memo[3001][3001];
char mm[3001][3001];
int mm1[3001][3001];

ll func(ll i,ll j)
{
	if(i == n1-1 || j==n2-1)
	{
		if(s1[i] == s2[j])
			{
				mm[i][j]=s1[i];
				mm1[i][j]=0;
				return 1;
			}
		else if(i == n1-1 && j == n2-1)
			return 0;
		else if(i == n1-1)
			return func(i,j+1);
		else
			return func(i+1,j);
	}

	if(memo[i][j]!=-1)
		return memo[i][j];
	
	if(s1[i] == s2[j])
	{
		memo[i][j]=1+func(i+1,j+1);
		mm[i][j]=s1[i];
		mm1[i][j]=0;
		return memo[i][j];
	}
	else
	{
		ll tt=func(i+1,j);
		ll t1=func(i,j+1);
		memo[i][j]=max(tt,t1);
		if(tt>t1)
			mm1[i][j]=1;
		else
			mm1[i][j]=2;
		return memo[i][j];
	}
 }


int main() 
{
 	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef DEBUG
     		//freopen("input.txt", "rt", stdin);
 	#endif
	cin >> s1;
	cin >> s2;
	s1+='a';
	s2+='z';
	n1=s1.length();
	n2=s2.length();

	for(int i=0;i<3001;i++)
	{
		for(int j=0;j<3001;j++)
		{
			memo[i][j]=-1;
			mm[i][j]='1';
			mm1[i][j]=-1;
		}
	}
	
	ll vv = func(0,0);
	int i=0;
	int j=0;
	int count=0;
	while(mm1[i][j]!=-1)
	{
		if(mm1[i][j]==0)
		cout<<mm[i][j];
		if(mm1[i][j]==0)
		{
			i++;
			j++;
		}
		else if(mm1[i][j]==1)
		{
			i++;
		}
		else
		{
			j++;
		}
	}
	cout<<"\n";
 	return 0;	
}


Measured memory_bytes: 114816
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define loop(i,a,b) for(int i=a; i<b; i++)
#define inf 10000000000099ll
#define mod 1000000007
#define prDouble(x) cout<<fixed<<setprecision(10)<<x

ll dp[3001][3001];
ll sum[3001][3001];

ll solve(vector<int>& v, int i, int j)
{
	if (i == j) return 0;
	if (dp[i][j] != -1) return dp[i][j];

	ll minCost = inf;
	for (int k = i; k < j; k++) {
		minCost = min(minCost, sum[i][j] + solve(v, i, k) + solve(v, k + 1, j));
	}
	return dp[i][j] = minCost;
}

void preProcessing(vector<int>& v, int n) {
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {
			sum[i][j] = v[j] + ((j == i) ? 0 : sum[i][j - 1]);
		}
	}
}

int main()
{
	FASTIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin >> n;
	memset(dp, -1, sizeof dp);
	vector<int> v(n + 1);
	loop(i, 1, n + 1) cin >> v[i];
	preProcessing(v, n);
	cout << solve(v, 1, n);
	return 0;
}



Measured memory_bytes: 76236
from functools import reduce
INF = 10 ** 7
N, M = map(int, input().split())
L = 1 << N
table = [[INF] * L for _ in range(M + 1)]
table[0][0] = 0
for m in range(M):
    cost, _ = map(int, input().split())
    match = reduce(lambda a, b: a | b, (1 << shamt for shamt in map(lambda n: int(n) - 1, input().split())))
    for l in range(L):
        now = table[m][l]
        if l and not now:
            continue
        table[m + 1][l] = min(now, table[m + 1][l])
        table[m + 1][l | match] = min(now + cost, table[m + 1][l | match])
print(table[M][L - 1] if table[M][L - 1] != INF else -1)

Measured memory_bytes: 81112
import re,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
A,B = LI()
S = S()
print('Yes' if re.fullmatch(pattern=r'\d{{{}}}-\d{{{}}}'.format(A,B),string=S) else 'No')


Measured memory_bytes: 3188
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

class ModOperator:
    def __init__(self, MOD: int = 10 ** 9 + 7):
        self.MOD = MOD

    def mod_pow(self, x: int, n: int):
        bi = str(format(n, "b"))
        res = 1
        a = x
        for i in range(len(bi)):
            if n >> i & 1:
                res = (res * a) % self.MOD
            a = (a * a) % self.MOD
        return res
    
    def mod_fact(self, x: int):
        res = 1
        for i in range(1, x + 1):
            res = res * i % self.MOD
        return res % self.MOD
    
    def mod_partial_fact(self, x: int, y: int):
        res = 1
        for i in range(x - y + 1, x + 1):
            res = res * i % self.MOD
        return res % self.MOD

    def mod_inv(self, x: int):
        return self.mod_pow(x, self.MOD - 2)
    
    def mod_comb(self, n: int, k: int):
        numerator = self.mod_partial_fact(n, k)
        denomintator = self.mod_fact(k)
        return numerator * self.mod_inv(denomintator) % self.MOD

def main():
    n, a, b = map(int, input().split())
    op = ModOperator()
    print((op.mod_pow(2, n) - op.mod_comb(n, a) - op.mod_comb(n, b) - 1) % MOD)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;


class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		int k = stdIn.nextInt();
		Integer[] h = new Integer[n];
		for (int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		int diff = 0;
		int diffmin = 0;
		
		Arrays.sort(h, Collections.reverseOrder());
		
		/*
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				if (h[i] < h[j]) {
					h[i] = h[i] + h[j];
					h[j] = h[i] - h[j];
					h[i] = h[i] - h[j];
				}
			}
		}
		*/
		
		diffmin = h[0] - h[0 + k - 1];
			
		for (int i = 0; i < n - k + 1; i++) {
		
			diff = h[i] - h[i + k - 1];
			
			if (diffmin > diff) {
				diffmin = diff;
			}
		}
		
		System.out.println(diffmin);
	
	}
	
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

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

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

int main() {
  int A,B,C;
cin>>A>>B>>C;
  int n=0;
  if(A==B){
   if(A!=C){
    n++; 
   }
  }
  else if(A==C){
     if(A!=B){
    n++; 
   }
  }
   else if(B==C){
     if(A!=B){
    n++; 
   }
  }
  if(n!=0){
   cout<<"Yes"<<endl; 
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M, K) = readLine()!!.split(" ").map { it.toInt() }

    for (i in 0..N) {
        for (j in 0..M) {
            if (K == i * M + j * N - 2 * i * j) {
                println("Yes")
                return
            }
        }
    }
    println("No")
}

Measured memory_bytes: 37812
program test 
implicit none

integer(8) :: i,j,k,l,m,n,r,q
integer(8) :: ll(200000),rr(200000),pp(100000),qq(100000),nn(501,501)=0,nn2(0:501,0:501)=0

read(*,*) n,m,q
do i= 1,m
read(*,*) ll(i),rr(i)
enddo

do i=1,q
read(*,*) pp(i),qq(i)
enddo

do i=1,m
do j=1,ll(i)

nn(j,rr(i)) = nn(j,rr(i)) + 1

enddo
enddo

do i=1,n
do j=1,n
nn2(i,j) = nn2(i,j-1) + nn(i,j)
enddo
enddo

!do i=1,n+1
!write(*,*) nn2(i,1:n+1)
!enddo

do i=1,q
write(*,*) nn2(pp(i),qq(i))
enddo

end program

Measured memory_bytes: 11008
N = int(input())

towns = []
for i in range(N):
    x, y = map(int, input().split())
    towns.append((i, x, y))

# x, y座標の値でソートして、隣接する街の間の道を、隣接リストadjに追加する
adj = [[] for i in range(N)]
for xy in [1, 2]:
    towns.sort(key=lambda t: t[xy])
    for i in range(N - 1):
        t1 = towns[i][0]
        t2 = towns[i + 1][0]
        cost = towns[i + 1][xy] - towns[i][xy]
        adj[t1].append((t2, cost))
        adj[t2].append((t1, cost))

# 最小全域木を求める（プリム法）
import heapq
pq = []
heapq.heappush(pq, (0, 0))

done = set()
ans = 0
while pq:
    cost, v_now = heapq.heappop(pq)

    if v_now in done:
        continue

    ans += cost
    done.add(v_now)

    if len(done) == N:
        break

    for v, c in adj[v_now]:
        if v not in done:
            heapq.heappush(pq, (c, v))

print(ans)


Measured memory_bytes: 77376
#include <bits/stdc++.h>
using namespace std;
/*
string multiply(string x,string y){
    string ans="";
    for(int i=0;i<x.size();i++){
        for(int j=0;j<y.size();j++){

        }
    }
}
*/
int main()
{
    int n;
    cin>>n;
    int x[n],y[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[x[i]-1]=i+1;
    }
    cout<<y[0];
    for(int i=1;i<n;i++){
        cout<<" "<<y[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1536
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    let n : usize = read();
    let m : usize = read();
    let mut a = Vec::new();
    let mut sum = 0;
    for i in 0..n {
        let t : usize = read();
        a.push(t);
        sum += t;
    }
    let mut j = 0;
    for i in 0..n {
        if a[i] * 4 * m < sum {
            continue;
        }
        j += 1;
    }
    if j >= m {
        println!("Yes");
    }
    else {
        println!("No");
    }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MAXN = 301;
 
int main(){
    ll H, W; cin >> H >> W;
    if(H == 1 || W == 1) {
        cout << 1 << endl;
        return 0;
    }
    
    ll R;
    if(W%2 == 1) R = W/2+1;
    else R = W/2;
    ll ans = 0;
    if(H % 2 == 1) ans += (R + (W-R))*(H/2) + R;
    else if (H % 2 == 0) ans += (R + (W-R)) * (H/2);
    cout << ans << endl;
 
 
/*
    if((H*W)%2 == 1) cout << (H*W)/2+1 << endl;
    else {
        if(H%2 == 0)cout << H/2*W << endl;
        else if(W%2 == 0) cout << W/2*H << endl;
    }*/
    
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
long long int p=1e9 +7;
struct matrix{
    vector<vector<ll>> mat;
    matrix(int n, int m){
        mat.resize(n,vector<ll>(m));
    }
    matrix operator*(matrix a){
        matrix ans(this->mat.size(),a.mat[0].size());
        for(int i=0;i<this->mat.size();i++){
            for(int j=0;j<a.mat[0].size();j++){
                for(int k=0;k<a.mat.size();k++){
                    ans.mat[i][j]+=this->mat[i][k]*a.mat[k][j];
                    ans.mat[i][j]%=p;
                }
            }
        }
        return ans;
    }
};
matrix matpower(matrix base,ll power){
    matrix ans(base.mat.size(),base.mat.size());
    ans=base;
    power--;
    while(power){
        if(power & 1){
            ans=ans*base;
        }
        base=base*base;
        power>>=1;
    }
    return ans;
}
ll matsum(matrix m){
    ll ans=0;
    for(int i=0;i<m.mat.size();i++){
        for(int j=0;j<m.mat[0].size();j++){
            ans+=m.mat[i][j];
            ans%=p;
        }
    }
    return ans;
}
ll solve(){
   int n;
   ll k;
   cin>>n>>k;
   matrix edges(n,n);
   for(int i=0;i<n;i++){
       for(int j=0;j<n;j++){
           cin>>edges.mat[i][j];
       }
   }
   return matsum(matpower(edges,k));
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<solve();
}

Measured memory_bytes: 384
//Name: Operation of Frequency of Appearance
//Level: 2
//Category: シミュレーション
//Note:

/**
 * 問題文のとおりにシミュレーションする。
 * 出現頻度操作は、各数の出現回数を数えるパスと、全体を変換するパスの2パスに分けると良い。
 *
 * オーダーは不明。
 */
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

bool solve() {
    int N;
    cin >> N;
    if(!N) return false;

    vector<int> v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
    }
    int ans = 0;
    while(true) {
        vector<int> next(N);
        unordered_map<int,int> freq;
        for(int i : v) {
            freq[i]++;
        }
        for(int i = 0; i < N; ++i) {
            next[i] = freq[v[i]];
        }
        if(next == v) break;
        ++ans;
        next.swap(v);
    }
    cout << ans << endl;
    for(int i = 0; i < N; ++i) {
        if(i > 0) cout << ' ';
        cout << v[i];
    }
    cout << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {

  int n;
  int p[15];
  int max = 0;
  int sum = 0;
  int flag;

  cin >> n;

  for ( int i = 0; i < n; ++i ) {
    cin >> p[i];
    if ( max < p[i] ) {
      max = p[i];
      flag = i;
    }
  }
  
  for ( int i = 0; i < n; ++i ) {
    if ( i != flag ) sum += p[i];
  }
  sum += max/2;
  
  cout << sum << endl;
  
  return 0;
  
}



// HABC-B - Christmas Eve Eve
// source129.cpp


Measured memory_bytes: 256