akhauriyash/Code-Regression huggingface dataset:
def solve():
    # N = int(raw_input())
    # D = [int(raw_input()) for i in range(N)]
    N = int(input())
    D = [int(input()) for i in range(N)]
    if sum(D) % 2 > 0:
        print ('-1')
        return
    Di = sorted([(di, i) for i, di in enumerate(D)], key = lambda x : x[0], reverse = True)
    d_to_i = {dd:i for dd, i in Di}
    # child = [[] for i in range(N)]
    ans = []
    n_child = [1] * N
    d_child = [0] * N
    for valD, node in Di:
        valD_par = valD - N + 2 * n_child[node]
        if valD_par in d_to_i.keys():
            node_par = d_to_i[valD_par]
            # child[node].append(node_par) ##
            # child[node_par].append(node)
            ans.append((node_par + 1, node + 1))
            n_child[node_par] += n_child[node]
            d_child[node_par] += n_child[node] + d_child[node]
            if n_child[node_par] == N:
                break
        else:
            print ('-1')
            return
    # check if Di satisfied or not
    d_min, i_min = Di[-1]
    if d_child[i_min] != d_min:
        print ('-1')
        return
    # for i in range(N):
    #     for j in child[i]:
    #         print str(i + 1) + ' ' + str(j + 1)
    for i,j in ans:
        print (str(i) + ' ' + str(j))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 46240
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int N = Integer.parseInt(sc.next());
	static String A = sc.next();
	static String B = sc.next();
	static String C = sc.next();
	public static void main(String[] args) {
//		System.out.println(N);
//		System.out.println(A);
//		System.out.println(B);
//		System.out.println(C);
		int ans = 2*N;
		for (int i = 0; i < N; i++) {
			if (A.charAt(i) == B.charAt(i) &&
					A.charAt(i) == C.charAt(i)) {
				ans -= 2;
			} else if (A.charAt(i) == B.charAt(i) ||
					A.charAt(i) == C.charAt(i) ||
				B.charAt(i) == C.charAt(i)) {
				ans -= 1;
			}
//			System.out.println(ans);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

int main(){
    
    ll N;
    array<ll, 100000> A;
    
    cin >> N;
    for(ll i = 0; i < N; ++i){
        cin >> A[i];
    }
    
    ll ans = 1;
    int direc = 0;
    for(int i = 1; i < N; ++i){
        if(A[i] > A[i - 1]){
            if(direc < 0){
                ans += 1;
                direc = 0;
            }else{
                direc = 1;
            }
        }else if(A[i] < A[i - 1]){
            if(direc > 0){
                ans += 1;
                direc = 0;
            }else{
                direc = -1;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double
# define ull unsigned long long

# define pb push_back
# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vld vector < ld >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < long , long >
# define pDD pair < D , D >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b));
# define mod 1000000007

# define pp(n) printf("%.10f",n);
# define line cout<<"\n";

const D pie = acos(-1);
const D hpie = asin(1);
const D qpie = atan2(1,1);
const D tpie = 2*pie;

string vow = "aeiou";

void solve( int test_case )
{
    int n;
    cin >> n;

    vll q ( n+1 );
    for ( int i=1 ; i<=n ; i++ ) cin >> q[i];

    ll odd = 0;
    ll even = 0;

    for ( int i=2 ; i<=n ; i+=2 ) even += q[i];
    for ( int i=1 ; i<=n ; i+=2 ) odd  += q[i];

    //cout << odd << " " << even ; line

    vll a ( n+1 );
    a[1] = odd - even;

    for ( int i=2 ; i<=n ; i++ )
        a[i] = (q[i-1] - (a[i-1]/2))*2;

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

int main()
{
    fast
    int t = 1;
    //cin>>t;

    for ( int i=0 ; i<t ; i++ ) solve(i);
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll ans = 1;
  ll N,K; cin >> N >> K;
  rep(i,N){
    if(i==0) ans *= K;
    else ans*= (K-1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int X = input.nextInt();
        int Y = input.nextInt();
        int Z = input.nextInt();
        if(X%(Y+Z) >= Z){
            System.out.println(X/(Y+Z));
        }
        else{
            System.out.println(X/(Y+Z)-1);
        }
    }
}

Measured memory_bytes: 23124
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007


ll add(ll a, ll b)  { return ((a % mod + b % mod) % mod); }
ll sub(ll a, ll b)  { return ((a % mod - b % mod) % mod); }
ll mult(ll a, ll b) { return (((a % mod) * (b % mod)) % mod); }

const ll mxn = 1e6 + 1;
ll p[mxn] , f[mxn] , g[mxn];

void pre()
{
    p[0] = 1;
    for (ll i = 1 ; i < mxn ; ++i) {
        p[i] = (p[i - 1] % mod * 10);
        p[i] %= mod;
    }

    f[0] = 1;
    for (ll i = 1 ; i < mxn ; ++i) {
        f[i] = (f[i - 1] % mod * 9);
        f[i] %= mod;
    }

    g[0] = 1;
    for (ll i = 1 ; i < mxn ; ++i) {
        g[i] = (g[i - 1] % mod * 8);
        g[i] %= mod;
    }
}


void solve()
{
    ll n;
    cin >> n;

    if (n < 2) {
        cout << 0;
        return;
    }


    ll ans = (2 * f[n] - g[n] + mod) % mod;
    ans = (p[n] - ans + mod) % mod;

    cout << ans % mod;

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    pre();
    //TEST
    solve();
}



Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N + 1);
    vector<ll> B(N + 1);
    REP(i, N + 1)
    cin >> A.at(i);
    REP(j, N)
    cin >> B.at(j);
    ll ans = 0;
    REP(k, N)
    {
        ans += min(A[k], B[k]);
        ll tmp = B[k] - A[k];
        if (tmp > 0)
        {
            ans += min(A[k + 1], tmp);
            A[k + 1] -= tmp;
            if (A[k + 1] < 0)
                A[k + 1] = 0;
        }
        else
            continue;
    }

    ans += min(A[N], B[N]);
    cout << ans << endl;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
using namespace atcoder;
// cout << fixed << setprecision(10）<<  << endl;

int main(){
    int n, m; cin >> n >> m;
    dsu data(n);
    rep(i,m){
        int a, b; cin >> a >> b;
        a--; b--;
        data.merge(a,b);
    }
    auto save = data.groups();
    cout << (int)save.size() - 1 << endl;
    return 0;
}

Measured memory_bytes: 9008
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    print(3*N**2)





if __name__ == "__main__":
    main()

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

using namespace std;


template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s)
{
    return '"' + s + '"';
}

string to_string(const char* s)
{
    return to_string((string) s);
}

string to_string(bool b)
{
    return (b ? "true" : "false");
}

string to_string(vector<bool> v)
{
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v)
{
    string res = "";
    for (size_t i = 0; i < N; i++)
    {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v)
{
    bool first = true;
    string res = "{";
    for (const auto &x : v)
    {
        if (!first)
        {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p)
{
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p)
{
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out()
{
    cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif



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

    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << '\n';
    return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll kai(ll num){
  ll div=pow(10,9)+7;
  if(num==1){
    return 1;
  }else{
    return (num%div)*kai(num-1)%div;
  }
}

int main()
{
  ll n,m;
  cin>>n>>m;
  ll div=pow(10,9)+7;

  if(abs(n-m)>1){
    cout<<0<<endl;
    return 0;
  }

  if(n==m){
    // cout<<kai(n)<<endl;
    cout<<kai(n)*kai(m)*2%div<<endl;
  }else{
    cout<<kai(n)*kai(m)%div<<endl;
  }
  return 0;
}


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



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

    if(abs(x-a)>abs(x-b)) cout << 'B' <<endl;
    else cout <<'A'<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int a[1010];
int b[1010];
int main(){
	int n,m;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	scanf("%d",&m);
	for(int i=0;i<m;i++)scanf("%d",b+i);
	a[n]=-1,b[m]=-1;
	for(int i=0;;i++){
		if(a[i]==b[i]){
			if(a[i]==-1){
				puts("0");
				return 0;
			}
		}else{
			puts(a[i]<b[i]?"1":"0");
			return 0;
		}
	}
}


Measured memory_bytes: 2112
import sys
sys.setrecursionlimit(10**7)
def main(n,ki,uv):
  # n: 頂点数
  # ki: 木
  # Euler Tour の構築
  S=[] # Euler Tour
  F=[0]*n # F[v]:vにはじめて訪れるステップ
  depth=[0]*n # 0を根としたときの深さ
  def dfs(v,pare,d):
    F[v]=len(S)
    depth[v]=d
    S.append(v)
    for i,w in ki[v]:
      if w==pare:continue
      dfs(w,v,d+1)
      S.append(v)
  dfs(0,-1,0)
  # Sをセグメント木に乗せる
  # u,vのLCAを求める:S[F[u]:F[v]+1]のなかでdepthが最小の頂点を探せば良い
  # F[u]:uに初めてたどるつくステップ
  # S[F[u]:F[v]+1]:はじめてuにたどり着いてつぎにvにたどるつくまでに訪れる頂点
  # 存在しない範囲は深さが他よりも大きくなるようにする
  INF = (n, None)
  # LCAを計算するクエリの前計算
  M = 2*n
  M0 = 2**(M-1).bit_length() # M以上で最小の2のべき乗
  data = [INF]*(2*M0)
  for i, v in enumerate(S):
    data[M0-1+i] = (depth[v], i)
  for i in range(M0-2, -1, -1):
    data[i] = min(data[2*i+1], data[2*i+2])
  # LCAの計算 (generatorで最小値を求める)
  def _query(a, b):
    yield INF
    a += M0; b += M0
    while a < b:
      if b & 1:
        b -= 1
        yield data[b-1]
      if a & 1:
        yield data[a-1]
        a += 1
      a >>= 1; b >>= 1
  # LCAの計算 (外から呼び出す関数)
  def query(u, v):
    fu = F[u]; fv = F[v]
    if fu > fv:
      fu, fv = fv, fu
    return S[min(_query(fu, fv+1))[1]]
  
  todo=[[0,[]]]
  path=[[]]*n
  mi=[1]*n
  while todo:
    v,ary=todo.pop()
    path[v]=ary
    mi[v]=0
    for i,nv in ki[v]:
      if mi[nv]==1:
        todo.append([nv,ary+[i]])
        mi[nv]=1

  for i in range(n):
    path[i]=set(path[i])
  memo={}
  ans=0
  for i in range(2**m):
    chk=set(())
    for j in range(m):
      if (i>>j)&1:
        chk.add(j)
    must_w=set(())
    for c in chk:
      if c in memo:
        tmp=memo[c]
      else:
        u,v=uv[c]
        dd=query(u,v)
        tmp=path[u]|path[v]
        tmp-=path[dd]
        memo[c]=tmp
      must_w|=tmp
    t=n-1-len(must_w)
    if len(chk)%2==1:
      ans-=pow(2,t)
    else:
      ans+=pow(2,t)
  print(ans)
if __name__=='__main__':
  n=int(input())
  ki=[[] for _ in range(n)]
  for i in range(n-1):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    ki[u].append([i,v])
    ki[v].append([i,u])
  m=int(input())
  uv=[]
  for _ in range(m):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    uv.append([u,v])
  main(n,ki,uv)


Measured memory_bytes: 74644
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin);i>(end);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" <<; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define f first
#define s second
#define pb push_back
#define INF 1000000000000000000

using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;


int main()
{
	// 入力
	ll N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	vec l(Q), r(Q);
	REP(i, Q) {
		cin >> l[i] >> r[i];
		l[i]--;
		r[i]--;
	}

	vec numac(N, 0);

	REP(i, N - 1) {
		if (i > 0) {
			if (S[i] == 'A' && S[i + 1] == 'C') {
				numac[i] = numac[i - 1] + 1;
			}
			else numac[i] = numac[i - 1];
		}
		else if (i == 0) {
			numac[0] = 0;
			if (S[i] == 'A' && S[i + 1] == 'C') {
				numac[0]++;;
			}
		}
	// debug(numac[i]);
	}
	numac[N - 1] = numac[N - 2];

	REP(i, Q) {
		if (l[i] > 0) cout << numac[r[i] - 1] - numac[l[i] - 1] << endl;
		else cout << numac[r[i] - 1] << endl;
	}


	return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
int main()
{
    int a,b,n,count;
    while(scanf("%d%d",&a,&b)!=EOF){
   if(a>=0&&b>=0){
    n=a+b;
    count=0;
    while(n!=0){
        n=n/10;
        count++;
    }
    printf("%d\n",count);
   }
   }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

	int n, d, p = 1;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d;

		p *= d%2 == 0 ? 2 : 1;
	}

	int c = pow(3, n) - p;

	cout << c << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if(a==b && a!=c){
        cout << "Yes" << endl;
    }
    else if(c==b && a!=c){
        cout << "Yes" << endl;
    }
    else if(a==c && b!=c){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main(){
  int n,m; cin>>n; m=n/2;
  vector<int> e(m), o(m);
  for(int i=0; i<m; ++i)cin>>e[i]>>o[i];

  sort(e.begin(), e.end());
  sort(o.begin(), o.end());

  vector<pair<int,int>> ee, oo;
  ee.push_back(make_pair(0,0)); oo.push_back(make_pair(0,0));
  int num=1, l=e[0];
  for(int i=1; i<m; ++i){
    if(e[i]==l)++num;
    else{ee.push_back(make_pair(num,l)); l=e[i]; num=1;}
  }
  ee.push_back(make_pair(num,l));

  l=o[0]; num=1;
  for(int i=1; i<m; ++i){
    if(o[i]==l)++num;
    else{oo.push_back(make_pair(num,l)); l=o[i]; num=1;}
  }
  oo.push_back(make_pair(num,l));

  sort(ee.begin(),ee.end());
  sort(oo.begin(),oo.end());

  int es=ee.size(), os=oo.size();
  if(ee[es-1].second!=oo[os-1].second)cout<<2*m-ee[es-1].first-oo[os-1].first<<endl;
  else{
    if(2*m-ee[es-1].first-oo[os-2].first>=2*m-ee[es-2].first-oo[os-1].first)cout<<2*m-ee[es-2].first-oo[os-1].first<<endl;
    else cout<<2*m-ee[es-1].first-oo[os-2].first<<endl;
  }
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
vector<int>dp(100007,INT_MAX);
vector<int>vect(100007);
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    dp[0]=0;
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    for(int i=0;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i+j<n)
                dp[i+j]=min(dp[i+j],dp[i]+abs(vect[i]-vect[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
s = [input() for _ in range(N)]

end_A = 0
start_B = 0
AB_count = 0
both = 0

for i in range(N):
    if 'AB' in s[i]:
        AB_count += s[i].count('AB')
    if s[i][0] == 'B':
        start_B += 1
    if s[i][len(s[i])-1] == 'A':
        end_A += 1
    if s[i][0] == 'B' and s[i][len(s[i])-1] == 'A':
        both += 1
start_B -= both
end_A -= both

if both == 0:
    print(AB_count + min(start_B, end_A))
elif end_A + start_B > 0:
    print(AB_count + both + min(start_B, end_A))
else:
    print(AB_count + both - 1)

Measured memory_bytes: 3700
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;


int cnt[200020];
void solve() {
	int N; cin >> N;
	vector<int>A(N);
	REP(i, N) {
		cin >> A[i];
		cnt[A[i]]++;
	}
	ll sum = 0;
	REP(i, N + 1) {
		sum += cnt[i] * (cnt[i] - 1) / 2;
	}
	REP(i, N) {
		int num = A[i];
		int tmp = sum;
		tmp -= cnt[num] * (cnt[num] - 1) / 2;
		tmp += (cnt[num] - 1)*(cnt[num]-2) / 2;
		print(tmp);
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 4736
#include<stdio.h>

int main(){
  int n,m,i,j,s,z;
  int ans[1000][1000]={{0}};
  int matrix[100][100]={{0}};
  int vector[1000][1]={{0}};
  /*Input*/
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&matrix[i][j]);
    }
  }
  for(i=0;i<m;i++){
    scanf("%d",&vector[i][0]);
  }
  /*Output*/
  for(z=0;z<n;z++){
    for(s=0;s<m;s++){
      ans[z][0] += (matrix[z][s]*vector[s][0]);
    }
  }
  for(i=0;i<n;i++){
    printf("%d\n",ans[i][0]);
  }

  return 0;
  
}



Measured memory_bytes: 5776
import java.util.*;
import java.io.*;
import java.lang.*;


public class Main{
	public static void main(String[] args) throws IOException{
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;++i)
			arr[i] = sc.nextInt();
		int[] dp = new int[n];
		dp[0] = 0;
		dp[1] = Math.abs(arr[1] - arr[0]);
		for(int i=2;i<n;++i){
			dp[i] = Math.min(Math.abs(arr[i]-arr[i-1])+dp[i-1],Math.abs(arr[i]-arr[i-2])+dp[i-2]);
		}
		System.out.println(dp[n-1]);
	}
}

class sc{
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tokenizer = new StringTokenizer("");
    static String next() throws IOException{
        while (!tokenizer.hasMoreTokens())
            tokenizer = new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }
    static int nextInt() throws IOException{
        return Integer.parseInt(next());
    }
    static double nextDouble() throws IOException{
        return Double.parseDouble(next());
    }
    static long nextLong() throws IOException{
        return Long.parseLong(next());
    }
    static float nextFloat() throws IOException{
    	return Float.parseFloat(next());
    }
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;



int main(){
    int N; cin >> N;
    vi A(N);
    for(auto &x : A)cin >> x;

    vector<vector<ll>> dp(N+1, vector<ll>(2, 0));
    dp[0][1]=-INF;
    for(int i=0; i<N; i++){
        dp[i+1][0]=max(dp[i][0]+A[i], dp[i][1]-A[i]);
        dp[i+1][1]=max(dp[i][0]-A[i], dp[i][1]+A[i]);
    }
    cout << dp[N][0] << endl;
    return 0;
}

Measured memory_bytes: 9072
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N, M;
int main() {
    while (cin >> N >> M) {
        vector<int> deg(N, 0);
        for (int i = 0; i < M; ++i) {
            int a, b;
            cin >> a >> b;
            --a, --b;
            deg[a]++; deg[b]++;
        }
        bool ok = true;
        for (int i = 0; i < N; ++i) {
            if (deg[i] & 1) ok = false;
        }
        if (ok) puts("YES");
        else puts("NO");
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_a_genius = 0; ngtkana_is_a_genius < int(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (int i = int(begin); (i) < int(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) 0;
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::string s; std::cin >> s;
  for (char & c : s) {
    int k = c - 'A';
    k += n;
    k %= 26;
    c = 'A' + k;
  }
  std::cout << s << std::endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

n = int(input())
s = list(str(input()))

num_list = []
r, g, b = 0, 0, 0
for i in range(n-1, -1, -1):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    elif s[i] == "B":
        b += 1
    num_list.append([r, g, b])

num_list.reverse()

ans = 0
for i in range(n-2):
    if s[i] == "R":
        ans += num_list[i+1][1] * num_list[i+1][2]  # G , B
        for j in range(0, (n-i-1)//2):
            a, b, c = i, j+i+1, j+j+i+2
            # print(a, b, c)
            if {s[b], s[c]} == {"G", "B"}:
                ans -= 1
    if s[i] == "G":
        ans += num_list[i+1][0] * num_list[i+1][2]  # R, B
        for j in range(0, (n-i-1)//2):
            a, b, c = i, j+i+1, j+j+i+2
            # print(a, b, c)
            if {s[b], s[c]} == {"R", "B"}:
                ans -= 1
    if s[i] == "B":
        ans += num_list[i+1][0] * num_list[i+1][1]  # R, G
        for j in range(0, (n-i-1)//2):
            a, b, c = i, j+i+1, j+j+i+2
            # print(a, b, c)
            if {s[b], s[c]} == {"R", "G"}:
                ans -= 1
# print(num_list)
print(ans)


Measured memory_bytes: 9620
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>a(N);
	rep(i, N) in >> a[i];

	std::vector<LL>a_imos(N + 1);
	rep(i, N) a_imos[i + 1] = a_imos[i] + a[i];

	LL ans = 1145148101919;
	for (LL i = 1; i < N; ++i)
	{
		LL x = a_imos[i], y = a_imos[N] - a_imos[i];
		ans = std::min(ans, std::abs(x - y));
	}

	out << ans << std::endl;
}


Measured memory_bytes: 3328
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const int MAXN = 111;
int N;
VI G[MAXN];
int par[MAXN];
int depth[MAXN];
VI ord;

int bfs(int s) {
    memset(par, ~0, sizeof par);
    par[s] = s;
    depth[s] = 0;
    ord.clear();
    ord.push_back(s);
    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) if (par[*e] == -1) {
	    par[*e] = v;
	    depth[*e] = depth[v]+1;
	    ord.push_back(*e);
	}
    }
    
    return max_element(depth, depth+N) - depth;
}

VI center;
VI B[MAXN];
LL bfs2() {
    REP (i, N) B[i].clear();
    memset(par, ~0, sizeof par);
    ord.clear();

    EACH (s, center) {
	par[*s] = *s;
	depth[*s] = 0;
	ord.push_back(*s);
    }
    if (center.size() == 2u) {
	par[center[0]] = center[1];
	par[center[1]] = center[0];
    }

    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    depth[*e] = depth[v]+1;
	    ord.push_back(*e);
	}
    }

    REP (i_, N) {
	int v = ord[i_];
	B[depth[v]].push_back(v);
    }
    int max_depth = *max_element(depth, depth+N);

    LL leaves = 1;
    for (int d=max_depth-1; d>=0; d--) {
	int max_degree = 0;
	int sub = 1;
	if (d == 0 && center.size() == 1u) {
	    sub = 0;
	}

	EACH (e, B[d]) {
	    amax(max_degree, (int)G[*e].size() - sub);
	}

	leaves *= max_degree;
    }

    if (center.size() == 2u) leaves *= 2;

    return leaves;
}


void MAIN() {
    scanf("%d", &N);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }


    int x = bfs(0);
    int y = bfs(x);
    int max_depth = depth[y];

    int core = -1;
    int cur = y;
    while (1) {
	if ((max_depth+1) / 2 == depth[cur]) {
	    core = cur;
	}
	cur = par[cur];
	if (cur == x) break;
    }

    LL ans = 1LL<<60;

    if (max_depth % 2 == 1) {
	center.push_back(core);
	center.push_back(par[core]);
	LL tmp = bfs2();
	amin(ans, tmp);
    } else {
	center.push_back(core);
	LL tmp = bfs2();
	amin(ans, tmp);
	center.push_back(-1);
	EACH (e, G[core]) {
	    center.back() = *e;
	    tmp = bfs2();
	    amin(ans, tmp);
	}
    }

    printf("%d %lld\n", (max_depth+2)/2, ans);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define out(a) cout << a << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)

int main() {
    string s; cin >> s;
    string t;
    rep(i, SZ(s)) {
        if (s[i] == '0') t += '0';
        else if (s[i] == '1') t += '1';
        else t = t.substr(0, SZ(t) - 1);
    }
    out(t);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define con continue
#define bk break
#define LL long long
#define db double
#define pt cout<<'\n'
#define ms(a, b) memset((a), (b), sizeof(a))
#define mp make_pair
#define endl '\n'
int inf=2147483647;const long long ll =9223372036854775807,ninf=1000000000;const double eps = 1e-6; const long long nll =223372036854775807;
#define sz size()
#define len(X) strlen(X)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ULL unsigned long long
#define de cout<<"test"<<endl;
#define st system("pause");
#define M_PI 3.1415926
LL A[100005]={};
int main()
{
   LL a,b,c;
   while(cin>>a>>b>>c){
    for(int i=0;i<a;i++)
        cin>>A[i];
    LL ans=0;
    for(int i=0;i<a-1;i++){
        ans+=min(b*(A[i+1]-A[i]),c);
    }
    cout<<ans<<endl;






   }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

struct edge
{
    int to;
    int cost;
    edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector< vector < edge > > Graph;

int N, M;
Graph G;
vector<int> x;

void dfs(int now, int pre){
    REP(i, G[now].size()){
        int next = G[now][i].to;
        if(next == pre) continue;
        if(x[next] != INF) continue;
        x[next] = x[now] + G[now][i].cost;
        dfs(next, now);
    }
}

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

    cin >> N >> M;
    G = Graph(N);
    x = vector<int>(N, INF);
    REP(i, M){
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        G[l].pb(edge(r, d));
        G[r].pb(edge(l, -d));
    }
    REP(i, N){
        if(x[i] == INF){
            x[i] = 0;
            dfs(i, -1);
        }
    }
    REP(l, N){
        // cout << x[l] << "\n";
        for(auto e : G[l]){
            if(x[e.to] - x[l] != e.cost){
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");

    return 0;
}

Measured memory_bytes: 12032
from fractions import gcd

N, P = map(int, input().split())
S = input().strip()

if gcd(10, P) > 1:
    ans = 0
    for i in range(len(S)):
        s = int(S[i])
        if s % P == 0:
            ans += (i+1)
    print(ans)
else:
    p = [0]*P
    ans = 0
    s = 0
    for i in range(len(S)-1, -1, -1):
        s = (s + int(S[i])*pow(10, N-1-i, P)) % P
        m = s % P
        if m == 0:
            p[m] += 1
            ans += p[m]
        else:
            ans += p[m]
            p[m] += 1

    print(ans)


Measured memory_bytes: 67160
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    bool ans = false;
    for(int c = 1; c <= 3; c++) {
        ans |= a * b * c % 2;
    }
    cout << (ans ? "Yes" : "No") << endl;
    return 0;
}


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

int main() {
    string S;
    int N;
    cin >>N>>S;
    for(int i=0;i<S.size();i++){
        if((char)(S[i]+N)<='Z')cout<<(char)(S[i]+N);
        else cout<<(char)(S[i]+N-26);
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 1e5 + 100;
const long long MNN = 2e3 + 10;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, X, b[MNN][MNN], ans = INF;

int main(){
	ios;
	cin >> n >> X;
	llong sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> b[i][0];
		sum += b[i][0];
	}ans = sum;
	for(int k = 1; k < n; k++){
		llong sum = 0;
		for(int i = 1; i <= n; i++){
			int j = i - k;
			if(j <= 0) j += n;
			b[i][k] = min(b[i][k - 1], b[j][0]);
			sum += b[i][k];
		}ans = min(ans, sum + k * X);
	}cout << ans;
	return 0;
}


Measured memory_bytes: 31616
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

// 入力
int N;
long long W, weight[110], value[110]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];
    
    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= W; ++j) {
            
            // i 番目の品物を選ぶ場合
            if (j + weight[i] <= W) {
                chmax(dp[i+1][j + weight[i]], dp[i][j] + value[i]);
            }
            
            // i 番目の品物を選ばない場合
            chmax(dp[i+1][j], dp[i][j]);
        }
    }
    
    // 最適値の出力
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		int[][] s = new int[H][W];
		for(int i = 0; i < H; i++) {
			String S = sc.next();
			for(int j = 0; j < W; j++)
				s[i][j] = Character.getNumericValue(S.charAt(j));
		}
		int ans = 100000;
		LOOP:for(int i = 0; i < 1 << H; i++) {
			int temp = 0;
			int[][] x = new int[H][W];
			for(int j = 0; j < H; j++) {
				for(int k = 0; k < W; k++)
					x[temp][k] += s[j][k];
				if((1 & i >> j) == 1)
					temp++;
			}
			int[] sum = new int[H];
			for(int j = 0; j < W; j++) {
				for(int k = 0; k < H; k++) {
					if(x[k][j] > K)
						continue LOOP;
					sum[k] += x[k][j];
					if(sum[k] > K) {
						temp++;
						for(int l = 0; l < H; l++)
							sum[l] = x[l][j];
						break;
					}
				}
			}
			ans = Math.min(ans, temp);
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 45956
#include<stdio.h>
int ans=11111;
int dfs(int depth,int use[],int d,int g,int p[],int c[]){
	int i,j;
	int count=0;
	int plus=0;
	int all=0;
	if(depth==d){
		for(i=0;i<d;i++){
			if(use[i]==1){
				count+=p[i];
				plus+=(100*(i+1)*p[i])+c[i];
			}
		}
		if(g>plus){
			for(i=d-1;i>=0;i--){
				if(use[i]==0){
					for(j=0;j<p[i];j++){
						if(g>plus){
						plus+=100*(i+1);
						count++;
						all++;
						}
					}
					if(all==p[i])count=22222;
					break;
				}
			}
		}
		if(count<ans)ans=count;
		return 0;
	}	
	
	use[depth]=1;
	dfs(depth+1,use,d,g,p,c);
	use[depth]=0;
	dfs(depth+1,use,d,g,p,c);
}

int main(){
	int i,d,g,p[11],c[11];
	int use[11]={};
	
	scanf("%d %d",&d,&g);
	
	for(i=0;i<d;i++){
		scanf("%d %d",&p[i],&c[i]);
	}
	dfs(0, use, d, g, p, c);
	
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <queue>
 
using namespace std;
 
#define N 3
#define N2 9
 
struct Puzzle{
    int f[N2];
    int space;
    string path;
     
    bool operator < (const Puzzle &p) const{
        for(int i=0;i<N2;i++){
            if(f[i]==p.f[i]) continue;
            return f[i]>p.f[i];
        }
        return false;
    }
};
 
static const int dx[4]={-1,0,1,0};
 
static const int dy[4]={0,-1,0,1};
 
static const char dir[4]={'u','a','d','r'};
 
bool isTarget(Puzzle p){
    for(int i=0;i<N2;i++){
        if(p.f[i]!=(i+1)) return false;
    }
    return true;
}
 
 
string bfs(Puzzle s){
    queue<Puzzle> Q;
    map<Puzzle,bool> V;
    Puzzle u,v;
    s.path="";
    Q.push(s);
    V[s]=true;
     
    while(!Q.empty()){
        u=Q.front();Q.pop();
        if(isTarget(u)) return u.path;
        int sx=u.space/N;
        int sy=u.space%N;
        for(int r=0;r<4;r++){
            int tx=sx+dx[r];
            int ty=sy+dy[r];
            if(tx<0||ty<0||tx>=N||ty>=N) continue;
            v=u;
            swap(v.f[u.space],v.f[tx*N+ty]);
            v.space=tx*N+ty;
            if(!V[v]){
                V[v]=true;
                v.path+=dir[r];
                Q.push(v);
            }
        }
    }
     
    return "unsolvable";
}
 
 
int main(){
    Puzzle in;
     
    for(int i=0;i<N2;i++){
        cin>>in.f[i];
        if(in.f[i]==0){
            in.f[i]=N2;
            in.space=i;
        }
    }
     
    string ans = bfs(in);
     
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 30656
inp = list(map(int,input().split()))
row=inp[0]
col=inp[1]
k=inp[2]
arr=[]
for i in range(row):
    s=input()
    arr.append(s)
ans=0
for i in range((1<<row)-1,-1,-1):
    for j in range((1<<col)-1,-1,-1):
        black=0
        for a in range(row):
            for b in range(col):
                if ((i>>a)&1 ==0 and (j>>b)&1 ==0):
                    if arr[a][b]=='#':
                        black+=1
        if black==k:
            ans+=1
print (ans)

Measured memory_bytes: 9168
n = int(input())
s = input()
bf = []
af = []
st = ['*']

for c in s:
    pre = st[-1]
    st.append(c)    

    if c ==  ')':
        if (pre == '(') :
            st.pop()
            st.pop()
            af.pop()
            continue
        bf.append('(')
    else:
        af.append(')')
ans = ''.join(bf) + s + ''.join(af)
print(ans)



Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    string S;
    cin >> S;

    vector<ll> cnt(26);
    rep(i, SZ(S)) { cnt[S[i] - 'a']++; }

    rep(i, 26) {
        if (cnt[i] == 0) {
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }

    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 3672
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int H = scan.nextInt();
    int A = scan.nextInt();
    int count = 1;
    while(H - A > 0){
      count += 1;
      H = H - A;
    }  
    System.out.println(count);
  }
}



Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(){
    priority_queue<pair<int, int> > PQ;
    int color[MAX];
    int d[MAX];
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }
    
    d[0] = 0;
    PQ.push(make_pair(0, 0));
    color[0] = GRAY;
    
    while(!PQ.empty() ){
        pair<int, int> f = PQ.top();
        PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first * (-1)) continue;
        
        for(int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second){
                d[v] = d[u] + adj[u][j].second;
                PQ.push(make_pair(d[v]* (-1), v));
                color[v] = GRAY;
            }
        }
    }
    
    for(int i = 0; i < n; i++){
        cout << i << " " << (d[i] == INFTY ? -1: d[i]) << endl;
    }
}

int main(){
    int k, u, v, c;
    
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }
    
    dijkstra();
    
    return 0;
}



Measured memory_bytes: 8076