akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <deque>
#include <algorithm>

using namespace std;

template<typename T>
class RangeAddQuery {
public:
    explicit RangeAddQuery(int n) : N(calcN_(n)) {
        mVal.assign(2*N+1, 0);
    }
    void update(int l, int r, T value){
        updateImpl_(l, r, value, 0, 0, N);
    }
    T get(int idx){
        int i = N + idx - 1;
        auto res = mVal[i];
        while(i > 0){
            i = (i-1)/2;
            res += mVal[i];
        }
        return res;
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void updateImpl_(int l, int r, T value, int idx, int rangeL, int rangeR){
        if(r <= rangeL || rangeR <= l) return;
        if(l <= rangeL && rangeR <= r){
            mVal[idx] += value;
        } else {
            int rangeM = (rangeL+rangeR)/2;
            updateImpl_(l, r, value, 2*idx+1, rangeL, rangeM);
            updateImpl_(l, r, value, 2*idx+2, rangeM, rangeR);
        }
    }
    const int N;
    vector<T> mVal;
};

long long solve(const string& S){
    const int n = S.size();
    RangeAddQuery<int> raq(n);
    vector<deque<int>> pos(26);
    for(int i=0;i<n;i++) pos[S[i]-'a'].push_back(i);
    if(count_if(pos.begin(), pos.end(), [](auto& v){ return v.size()%2 == 1; }) != n%2) return -1;
    long long res = 0;
    for(int i=0;i<n/2;i++){
        int minIdx = 0;
        int minCost = 1000000007;
        for(int j=0;j<pos.size();j++){
            if(pos[j].size() < 2) continue;
            int a = pos[j].front();
            int b = pos[j].back();
            int cost = abs(a + raq.get(a) - i) + abs(b + raq.get(b) - (n-i-1));
            if(cost < minCost){
                minCost = cost;
                minIdx = j;
            }
        }
        res += minCost;
        raq.update(0, pos[minIdx].front(), 1);
        raq.update(pos[minIdx].back(), n, -1);
        pos[minIdx].pop_front();
        pos[minIdx].pop_back();
    }
    for(auto& v : pos){
        if(!v.empty()) res += abs(v.front() + raq.get(v.front()) - n/2);
    }
    return res;
}

int main(){
    string S; cin >> S;
    cout << solve(S) << endl;
}


Measured memory_bytes: 3332
s = [int(input())]

while True:
    prev_el = s[-1]
    next_el = 0

    if prev_el % 2 == 0:
        next_el = prev_el // 2
    else:
        next_el = 3 * prev_el + 1

    s.append(next_el)

    if s.count(next_el) == 2:
        break

print(len(s))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> s(n);
  for(Int i=0;i<n;i++) cin>>s[i];

  Int ans=0;
  vector<Int> used(n,0);
  for(Int d=1;d<=n;d++){
    Int res=0;
    for(Int k=1;k*d<=n;k++){
      Int a=(n-1)-k*d;
      Int b=a-d;
      if(b<=0||a<=0||a>=n-1||b>=a) continue;
      assert(0<b&&b<a&&a<n-1);      
      assert(a*(k+1)-b*k==n-1);

      if(used[k*d]==d) break;      
      res+=s[k*d];
      used[k*d]=d;
      
      if(used[(n-1)-k*d]==d) break;
      res+=s[(n-1)-k*d];
      used[(n-1)-k*d]=d;
      
      chmax(ans,res);
    }
  }    
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

void solve(){
	int a , b ;
	cin >> a >> b ;
	if(a == b) cout << "Yes\n" ;
	else cout << "No\n" ;

}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
vector<int> v;
int main()
{
	int n,k;
	string s;
	ll ans=0;
	cin>>n>>k;
	cin>>s;
	if(s[0]=='R' && s[1]=='R')
		ans++;
	if(s[n-1]=='L' && s[n-2]=='L')
		ans++;
	char st=s[0];
	for(int i=1;i<n-1;i++)
	{
		if(s[i]=='L')
		{
			if(s[i-1]=='L')
				ans++;
		}else{
			if(s[i+1]=='R')
				ans++;
		}
	}
	int ind=0;
	while(ind<n)
	{
		char tmp=s[ind];
		int cnt=1;
		while(ind<n && s[ind]==tmp)
		{
			ind++;
			cnt++;
		}
		v.push_back(cnt);
	}
	if(v.size()==1)
	{
		cout<<ans<<endl;
		return 0;
	}
	//後ろからL
	ll zou=0;
	int ko=v.size()/2;
	if(v.size()&1 && st=='R')
	{
		ko++;
		zou=(ll)min(k,ko-2)*2LL;
		if(k>=ko-1)
			zou+=(ll)min(k-ko,2)*1LL;
	}else if(v.size()&1 && st=='L'){
		zou=(ll)min(k,ko)*2LL;
	}else{
		zou=(ll)min(k,ko-1)*2LL;
		if(k>=ko)
			zou++;
	}
	//前からR
	ko=v.size()/2;
	ll zou2=0;
	if(v.size()&1 && st=='L')
	{
		ko++;
		zou2=(ll)min(k,ko-2)*2LL;
		if(k>=ko-1)
			zou2+=(ll)min(k-ko,2)*1LL;
	}else if(v.size()&1 && st=='R'){
		zou2=(ll)min(k,ko)*2LL;
	}else{
		zou2=(ll)min(k,ko-1)*2LL;
		if(k>=ko)
			zou2++;
	}
	cout<<ans+max(zou,zou2)<<endl;
	return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#define NIL (-1)
#define MAX 10000
using namespace std;

struct Node{int parent, left, right;};

struct Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int id, int p){
    D[id] = p;
    if(T[id].left != NIL) setDepth(T[id].left, p+1);
    if(T[id].right  != NIL) setDepth(T[id].right, p+1);
}

int setHeight(int id){
    int h1 = 0, h2 = 0;
    if(T[id].left != NIL) h1 = setHeight(T[id].left) + 1;
    if(T[id].right != NIL)h2 = setHeight(T[id].right) + 1;
    return H[id] = max(h1, h2);
}

void print(int id){
    int degree = 0, sibling, tmp;
    if(T[id].parent == NIL)sibling = NIL;
    else{
        tmp = T[id].parent;
        if(T[tmp].left == id) sibling = T[tmp].right;
        else sibling = T[tmp].left;
    }
    if(T[id].left != NIL) degree++;
    if(T[id].right != NIL) degree++;
    cout << "node " << id;
    cout << ": parent = " << T[id].parent;
    cout << ", sibling = " << sibling;
    cout << ", degree = " <<  degree;
    cout << ", depth = " << D[id];
    cout << ", height = " << H[id];
    cout << ", ";
    if(T[id].parent == NIL) cout << "root";
    else if(T[id].right == NIL && T[id].left == NIL) cout << "leaf";
    else cout << "internal node";
    cout << endl;
}

int main(){
    int i, id, r;
    cin >> n;
    for(i = 0; i < n; i++){
        T[i].parent = NIL;
    }
    for(i = 0; i < n; i++){
        cin >> id;
        cin >> T[id].left >> T[id].right;
        T[T[id].left].parent = id;
        T[T[id].right].parent = id;
    }
    for(i = 0; i < n; i++){
        if(T[i].parent == NIL) r = i;
    }
    setDepth(r, 0);
    setHeight(r);
    for(i = 0; i < n; i++){
        print(i);
    }
    return 0;
}


Measured memory_bytes: 3084
from collections import Counter
n = int(input())
s = []
for i in range(n):
  si = input()
  s.append(si)
  
C = Counter(s)
s_num = C.values()
m = max(s_num)
s_max = []
for k, v in C.items():
  if v == m:
    s_max.append(k)
s_max = sorted(s_max)
for sj in s_max:
  print(sj)


Measured memory_bytes: 35572
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	
	int n = s.size();
	
	if (s[n - 1] == 's') {
		cout << s << "es" << endl;
	}
	else {
		cout << s << "s" << endl;
	}
	
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int A,B; cin>>A>>B;
	int k= ceil((double)(B-1)/(A-1));
	cout<<k<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N,M;
    scanf("%d%d",&N,&M);
    int A[M],i,sum=0,b=0;
    for(i=0;i<M;i++)
    {
        scanf("%d",&A[i]);
        sum=sum+A[i];

    }
    b=N-sum;
   if(b>=0)
   {
       printf("%d",b);
   }
   else if(b<0)
   {
       printf("-1");
   }
   return 0;
}


Measured memory_bytes: 2188
#include <iostream>
#include <stdio.h>

using namespace std;
int n,m,b[210000],x,y;
long long h[210000];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        scanf ("%lld",&h[i]);
    }
    for(int i=1;i<=m;i++)
    {
        scanf ("%d%d",&x,&y);
        if(h[x]>h[y])
            b[y]=1;
        if(h[x]<h[y])
            b[x]=1;
        if(h[x]==h[y])
        {
            b[x]=1;
            b[y]=1;
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i])
            sum++;
    }
    printf ("%d\n",sum);
    return 0;
}


Measured memory_bytes: 4428
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){

  long n;
  cin >> n;
  vector<long> v;

  for(long i = 1; i< long(sqrt((double)n) + 1); i++ ){
    if(n%i==0){
      v.push_back(i);
      v.push_back(n/i);
    }
  }
  if(v.size()<3) {
    cout << n-1 << endl;
    return 0;
  };

  long a;
  a = v.size();
  long temp1 = v[a-2];
  long temp2 = v[a-1];

  long res;
  res = temp1 -1 + temp2 -1;

  cout << res << endl;

  return 0;
};


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int32_t main(){
	boost;
	int a,b;
	cin>>a>>b;
	cout<<max(0LL,a-2*b);	
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
long a,b,x;
long f(long n){
  if(n==-1) return 0;
  else return n/x+1;
}

int main()
{
  cin >> a >> b >> x;
  long ans;
  
  ans = f(b)-f(a-1);
  cout << ans << endl;
}

Measured memory_bytes: 256
def get_primes(n):
    sieve = [True]*(n+1)
    primes = []
    reslut = 1
    for i in range(2, n+1):
        if sieve[i]:
            primes.append(i)
            for j in range(i, n+1, i):
                sieve[j] = False
    return primes

def solve(n):
    mod = 10**9 + 7
    primes = get_primes(n)
    result = 1
    for prime in primes:
        count = 0
        i = prime 
        while i <= n:
            count += n//i
            i *= prime
        result = result*(count + 1)%mod
    return result
    

n = int(input())
print(solve(n))
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string s;
	cin>>s;
	bool flag = false;
	int a=0,b=0,c=0,d=0;
	for(char i:s){
		if(i=='N')a++;
		else if (i=='W')b++;
		else if (i=='E')c++;
		else d++;
	}
	if(((a>0&&d>0)||(a==0&&d==0))&&((b>0&&c>0)||(b==0&&c==0)))flag = true;
	
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

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

    string s;
    cin >> s;

    string ans = "";
    for(int i = 0; i < s.size(); i += 2){
        ans += s[i];
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define fst first
#define sc second
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;

const int N = 40;
const int LOG = 21;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LLMOD = 998244353;
const ll LLINF = 1e18;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    forn(i, n - 1) {
        if (a[i] > a[i + 1] || (a[i] == a[i + 1] && (!i || a[i - 1] < a[i])) ) a[i]--;
        if (a[i] > a[i + 1]) {
            cout << "No\n";
            return 0;
        }
        if (i && a[i - 1] > a[i]) {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 640
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    int a,b;
    cin>>a>>b;
    if(b==1){
        cout<<0<<endl;
        return;
    }
    int res=b/a+(bool)(b%a);
    while(res*a-res+1<b)res++;
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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


def solve(N: int, K: int, h: "List[int]"):
    dp = [float("inf")] * N
    dp[0] = 0
    for i in range(1, N):
        for j in range(max(0, i-K), i):
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]))
    print(dp[-1])


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)


if __name__ == '__main__':
    main()


Measured memory_bytes: 55588
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;


int main() {
  string s, t; cin >> s >> t;
  vector<ll> start(26, -1), goal(26, -1);
  rep(i, 0, s.size()){
    int a = s[i] - 'a';
    int b = t[i] - 'a';
    if(start[b] != -1 || goal[a] != -1){
      if(start[b] != a || goal[a] != b){
        cout << "No" << endl;
        return 0;
      }
    }
    goal[a] = b;
    start[b] = a;
  }
  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h> 
using namespace std;
int main() 
{ 
string s1,s2;
cin>>s1>>s2;
int m=s1.size(),n=s2.size();
int dp[m+1][n+1];
for(int i=0;i<=m;i++){
    for(int j=0;j<=n;j++){
        if(i==0 || j==0){
            dp[i][j]=0;
            }
            else if(s1[i-1]==s2[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
                
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
    }
   
}
int i=m,j=n;
string s="";
while(i>0 && j>0){
 if(s1[i-1]==s2[j-1]){
        s+=s1[i-1];
        i--;j--;
    }
    else if(dp[i-1][j]>dp[i][j-1]){
        i--;
    }
    else{
        j--;
    }
}
reverse(s.begin(),s.end());
cout<<s<<endl;
} 


Measured memory_bytes: 35456
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	s, _ := r.ReadString('\n')
	s = strings.TrimRight(s, " \t\n")
	slice := strings.Split(s, " ")
	a := string(slice[0])
	b := string(slice[1])
	c := string(slice[2])
	A, _ := strconv.Atoi(a)
	B, _ := strconv.Atoi(b)
	C, _ := strconv.Atoi(c)

	ints := []int{A, B, C}
	sort.Ints(ints)
	fmt.Println(ints[2]*10 + ints[1] + ints[0])

}


Measured memory_bytes: 1740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
map<ll,ll>M;
int n;
ll a[200005];
int main(){
	scanf("%d",&n);
	repn(i,n) scanf("%lld",&a[i]);
	M[0]++;
	ll cur = 0;
	repn(i,n) {
		cur += a[i];
		M[cur]++;
	}
	ll ans = 0;
	for(map<ll,ll>::iterator it=M.begin();it!=M.end();it++){
		ll x = it->sc;
		ans += x*(x-1)/2LL;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 14336
N, Q = [int(_) for _ in input().split()]
S = '.' + input() + '.'
TD = [input().split() for _ in range(Q)]


def check(x):
    for t, d in TD:
        if S[x] == t:
            if d == 'L':
                x -= 1
            else:
                x += 1
    if x == 0:
        return -1
    elif x == N + 1:
        return 1
    else:
        return 0


#to_left_end
ok = 0
ng = N + 1

while ng - ok > 1:
    mid = (ok + ng) // 2
    if check(mid) == -1:
        ok = mid
    else:
        ng = mid
l = ok

#to_right_end
ok = N + 1
ng = 0
while ok - ng > 1:
    mid = (ok + ng) // 2
    if check(mid) == 1:
        ok = mid
    else:
        ng = mid
r = ng
print(r - l)

# https://img.atcoder.jp/exawizards2019/editorial.pdf


Measured memory_bytes: 41336
n,m = gets.split.map(&:to_i)
l = m.times.map{gets.split.map(&:to_i)}
ps = gets.split.map(&:to_i)

ans = 0
[0, 1].repeated_permutation(n) do |bits|
  light = 0
  m.times do |i|
    k = l[i][0]
    s = l[i][1..-1]
    cnt = 0
    s.each do |ss|
      if bits[ss-1] == 1
        cnt += 1
      end
    end
    light += 1 if cnt % 2 == ps[i]
  end
  ans += 1 if light == m
end

puts ans

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e9
#define EPS 1e-9
#define PI 3.141592653589793238
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("in3.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    int T=1;
    // cin >> T;
    FOR1(tt, T)
    {
        //cout << "Case #" << tt << ": ";
        int n, d;
        cin >> n >> d;
        int ans = 0;
        FOR1(i, n){
            int x, y;
            cin >> x >> y;
            if(x*x + y*y <= d*d) ans++;
        }
        cout << ans;
        cout << '\n';
    }
    return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 1000000007;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

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

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

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;

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

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


int main() {
    while (true) {
        int n, s;
        cin >> n;
        if (n == 0) break;
        cin >> s;
        int p[2*n];
        REP(i, 2*n) {
            cin >> p[i];
        }
        int dp[2*n][s+1];
        REP(i, 2*n) {
            REP(j, s+1) {
                dp[i][j] = -1;
            }
        }
        FOR(j, 1, s+1) {
            REP(i, 2*n) {
                if (j == 1) dp[i][j] = 0;
                else {
                    FOR(k, 1, p[i]+1) {
                        if (j - k < 1) break;
                        else if (dp[(i+1)%(2*n)][j-k] == 0) dp[i][j] = 1;
                    }
                    if (dp[i][j] == -1) dp[i][j] = 0;
                }
            }
        }
        cout << dp[0][s] << endl;
    }
    return 0;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {int x,y,z,a,b,c,m;
            cin>>x>>y>>z;
            a = abs(x-y);
            b = abs(x-z);
            c = abs(y-z);
            m = min({a+c,b+c,c+b,a+b,c+a,b+a});
            cout<<m<<endl;
           }

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, K, ans=0, tmp=0, dgt[42][2];
vector<ll> A;

signed main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
        int ct=0;
        while(a>=1) {
            ll a1 = a%2;
            dgt[ct][a1]++;
            a /= 2;
            ct++;
        }
    }
    for(int i=41;i>=0;i--) {
        if(K<pow(2,i)) continue;
        if(N-dgt[i][1]>dgt[i][1]) {
            tmp += pow(2,i);
            if(tmp>K) {
                tmp -= pow(2,i);
                //break;
            }
        }
    }
    for(int i=0;i<A.size();i++) {
        ans += A[i]^tmp;
    }
    //cout << tmp << " " << ans << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 10;
vector<vector<ll>> edge(MAX_N, vector<ll>{});

// Return pattern num of white, black under n
pair<ll, ll> dfs(int prev, int n){
    // End of tree
    if(edge[n].size() == 1 && edge[n][0] == prev){return pair<ll, ll>{1, 1};}
    ll w_ret = 1, b_ret = 1;
    for(auto& v:edge[n]){
        if(v == prev){continue;}
        pair<ll, ll> ret = dfs(n, v);
        b_ret *= ret.first;
        w_ret *= (ret.first + ret.second);
        b_ret %= MOD;
        w_ret %= MOD;
    }
    return pair<ll, ll>{w_ret, b_ret};
}

int main(){
    int n; cin >> n;
    int x, y;
    for(int i=0; i<n-1; i++){
        cin >> x >> y; x--; y--;
        edge[x].push_back(y);
        edge[y].push_back(x);
    }
    // Debug
    // for(int i=0; i<n; i++){
    //     for(auto& v:edge[i]){
    //         cout << v << " ";
    //     }
    //     cout << "\n";
    // }
    pair<ll, ll> ans = dfs(-1, 0);
    cout << (ans.first + ans.second) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 12672
n = int(input())
mat = [[0] * n for _ in range(n)]
d, f = [0] * n, [0] * n
for _ in range(n):
    adj = list(map(int, input().split()))
    i = adj[0]
    v = adj[2:]
    for j in v:
        mat[i - 1][j - 1] = 1

time, current = 0, 0
stack = []
while 0 in f:
    if not stack:
        for i, v in enumerate(f):
            if v == 0:
                stack.append(i)
                time += 1
                d[i] = time
                break
    time += 1
    current = stack[-1]
    for i in range(len(mat[current])):
        if mat[current][i] and not d[i]:
            current = i
            d[i] = time
            stack.append(i)
            break
    else:
        f[current] = time
        current = stack.pop()

for l in zip(range(1, n + 1), d, f):
    print(*l)

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

using namespace std;

int const INF = 1<<29;

int main() {
  int N, M, S, g1, g2;
  
  while(cin >> N >> M >> S >> g1 >> g2 && N) {
    int cost[100][100]; fill(cost[0], cost[0]+10000, INF);
    for(int i=0; i<N; i++) cost[i][i] = 0;
    S--, g1--, g2--;
    for(int i=0; i<M; i++) {
      int a, b, c; cin >> a >> b >> c; a--, b--;
      cost[a][b] = c;
    }
    
    for(int k=0; k<N; k++)
      for(int i=0; i<N; i++)
	for(int j=0; j<N; j++)
	  cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
    
    int ans = INF;
    for(int k=0; k<N; k++) {
      ans = min(ans, cost[S][k] + cost[k][g1] + cost[k][g2]);
    }
    
    cout << ans << endl;
  }
  
  return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cop(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;

vector<ll> A, B;
ll n;

bool check(){
    rep(i, n){
        if(A[i] != B[i]) return true;
    }
    return false;
}

int main(){

    int n;
    cin >> n;
    vector<ll> v(n);
    rep(i, n) scanf("%lld", &v[i]);
    sort(v.begin(), v.end());
    double ans = v[0];
    for(int i = 0; i < n-1; ++i){
        ans = (ans+v[i+1])/2.0;
    }
    ppp(ans);

    return 0;
}


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

using namespace std;

bool b[100000];

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

    for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++){
        bool fl = 0;
        b[0] = i;
        b[1] = j;
        for (int it = 1; it < n - 1; it++){
            if ((b[it] && s[it] == 'o') || (!b[it] && s[it] == 'x')){
                b[it + 1] = b[it - 1];
            }
            else{
                b[it + 1] = !b[it - 1];
            }
        }

        if ((b[n - 1] && s[n - 1] == 'o') || (!b[n - 1] && s[n - 1] == 'x')){
            if (b[0] != b[n - 2])
                fl = 1;
        }
        else{
            if (b[0] == b[n - 2])
                fl = 1;
        }

        for (int it = 0; it < n; it++){
            if (b[it] && s[it] == 'o'){
                if (b[(it - 1 + n) % n] != b[(it + 1) % n])
                    fl = 1;
            }
            if (b[it] && s[it] == 'x'){
                if (b[(it - 1 + n) % n] == b[(it + 1) % n])
                    fl = 1;
            }

            if (!b[it] && s[it] == 'o'){
                if (b[(it - 1 + n) % n] == b[(it + 1) % n])
                    fl = 1;
            }
            if (!b[it] && s[it] == 'x'){
                if (b[(it - 1 + n) % n] != b[(it + 1) % n])
                    fl = 1;
            }
        }

        if (!fl){
            for (int it = 0; it < n; it++)
                cout << (b[it] ? 'S' : 'W');
            return 0;
        }
    }

    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#define ll long long int
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define PI 3.141592653589793
using namespace std;

int main()
{    
    int n,k,r,s,p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;

    int sum = 0;
    REP(i,k)
    {
        char prev = 'n';
        for(int j=i;j<n;j+=k)
        {
            char cur = t[j];
            if(cur == prev)
            {
                prev = 'n';
                continue;
            }
            if(cur == 'r') sum += p;
            else if(cur == 's') sum += r;
            else sum += s;
            prev = cur;
        }
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
ll MOD = 1e9+7;
ll MOD2 = 998244353;
int inf = 1e8;
ll INF = 1e16;
string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    map<int, ll> mp;
    rep2(i, 2, N){
        int j = 2, k = i;
        while(j*j <= k){
            while(k%j == 0){
                k /= j;
                if(mp.count(j)) mp[j]++;
                else mp[j] = 1;
            }
            j++;
        }
        if(k != 1){
            if(mp.count(k)) mp[k]++;
            else mp[k] = 1;
        } 
    }
    ll ans = 1;
    for(auto &e: mp){
        ans *= e.second+1, ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int i;
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int sum = 0, max = 0, min = 1000;
			for(i = 0; i < n; i++){
				int s = sc.nextInt();
				if(max < s) max = s;
				if(min > s) min = s;
				sum += s;
			}
			System.out.println((sum - max - min) / (n - 2));
		}
	}
}

Measured memory_bytes: 29536
n = int(input())
S = list(input().split())
q = int(input())
T = list(input().split())
S.append(-1)
Sum = 0 #これで個数をカウント

for i in range(len(T)):
    S[n] = T[i] #番犬のKEY:T[i]をS[n]に代入
    t = 0
    while(S[t] != S[n]):
        t += 1
    if t == n:
        continue
    else:
        Sum += 1
print(Sum)


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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
cnt = Counter(a)
s = sum(a)
q = I()
for _ in range(q):
    b, c = LI()
    s -= b * cnt[b]
    s += c * cnt[b]
    cnt[c] += cnt[b]
    cnt[b] = 0
    print(s)


Measured memory_bytes: 89296
n = int(input())
A = list()
for i in range(1,n+1):
    if i % 3 == 0:
        A.append(i)
    elif "3" in str(i):
        A.append(i)
print(" ", end="")
for i in range(len(A)-1):
    print(A[i], end=" ")
print(A[len(A)-1])



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

N = int(input())
a_arr = [int(i) for i in input().split()]
a_arr2 = sorted(a_arr, reverse=True)
Alice = []
Bob = []

for j in range(len(a_arr2)):
  if j % 2 == 0:
    Alice.append(a_arr2[j])
  else:
    Bob.append(a_arr2[j])

print(sum(Alice) - sum(Bob))

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = int(1e9) + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N, C;
    cin >> N >> C;
    vv<int> program = vvec(1e5 + 5, C, 0);
    rep(i, N) {
        int s, t, c;
        cin >> s >> t >> c;
        for (s--; s < t; ++s) program[s][c - 1] = 1;
    }

    int ans = 0;
    rep(i, 1e5 + 1) {
        int cnt = accumulate(all(program[i]), 0);
        ans = max(ans, cnt);
    }
    write(ans);
}

Measured memory_bytes: 15104
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


N = _i()

s_list = []
for _ in range(N):
    s = list(_s())
    s.sort()
    s_list.append(''.join(s))

s_list.sort()
s_list.append('')

ans = 0
pre = ''
cur = 0
for s in s_list:
    if s == pre:
        cur += 1
    else:
        ans += (cur + 1) * cur // 2
        cur = 0
        pre = s

print(ans)


Measured memory_bytes: 10612
S = input()

if S[0] == S[1] and S[2] == S[3] and S[1] != S[2]:
    print("Yes")
elif S[0] == S[2] and S[1] == S[3] and S[0] != S[1]:
    print("Yes")
elif S[0] == S[3] and S[1] == S[2] and S[0] != S[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#最大増加部分列（Longest Increasing Subsequence）
def LIS(N,a):
  """数列の長さN, 数列a→最大増加部分列の長さ
  計算量はN^2"""
  res=0
  dp=[1]*N#最後がa[i] となるような最長の増加部分列の長さ
  for i in range(N):
    for j in range(i):
      if XY[j][0]<XY[i][0] and XY[j][1]<XY[i][1]:
        dp[i]=max(dp[i],dp[j]+1)
    res=max(res,dp[i])
  return res

import math 
x1,y1,x2,y2=map(int,input().split())
N=int(input())
W=abs(x2-x1)
H=abs(y2-y1)
xsgn=2*(x2>x1)-1
ysgn=2*(y2>y1)-1
XY=[]
for i in range(N):
  x,y=map(int,input().split())
  if (x-x1)*(x-x2)<=0 and (y-y1)*(y-y2)<=0:
    XY+=[[xsgn*(x-x1),ysgn*(y-y1)]]
N=len(XY)
short=20-5*math.pi
long=10*math.pi-20
straight=100*(W+H)
from bisect import bisect
 
# find LIS
XY.sort()
XY = [y for x,y in XY]

dp = [H+1]*len(XY)
 
for i,f in enumerate(XY):
  dp[bisect(dp,f)] = f
fountain = bisect(dp,H)
if fountain<min(W,H)+1:
  print(straight-short*fountain)
else:
  print(straight-short*(fountain-1)+long)

Measured memory_bytes: 38680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  map<int,int>f;
  int n,x;
  cin>>n;
  while(n--)
  {
    cin>>x;
    if(++f[x]>1)
    {
      cout<<"NO"<<endl;
      return 0; 
    }
  }
  cout<<"YES"<<endl;
  return 0;
}

Measured memory_bytes: 9600
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
unsigned int randxor()
{
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t;
    t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}
int d=365;
vector<int> ans(d);
vector<int> ans1(d);
vector<int> c(26);
vector<vector<int> > s(d);
int score=-1000000000;
int keisan(){
  int cost=0,i,j;
  vector<int> x(26,-1);
  for(i=0;i<d;i++){
    cost+=s[i][ans1[i]];
    x[ans1[i]]=i;
    for(j=0;j<26;j++){
      cost=cost-c[j]*(i-x[j]);
    }
  }
  return cost;
}
void solve(){
  int i;
  if(score<keisan()){
    for(i=0;i<d;i++){
      ans[i]=ans1[i];
    }
    score=keisan();
    int v=randxor()%d;
    int w=randxor()%d;
    swap(ans1[v],ans1[w]);
  }
  else{
    for(i=0;i<d;i++){
      ans1[i]=ans[i];
    }
  }
}
int main(){
  int i,j;
  int ti=clock();
  cin >> d;
  for(i=0;i<26;i++){
    scanf("%d",&c[i]);
  }
  for(i=0;i<d;i++){
    for(j=0;j<26;j++){
      int a;
      scanf("%d",&a);
      s[i].push_back(a);
    }
  }
  for(i=0;i<d;i++){
    ans1[i]=i%26;
    ans[i]=ans1[i];
  }
  while(clock()-ti<197.9*CLOCKS_PER_SEC/100){
    solve();
  }
  for(i=0;i<d;i++){
    printf("%d\n",ans[i]+1);
  }
  return 0;
}

Measured memory_bytes: 3876
import java.io.*;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) throws IOException{
		//
		int[] data = new int[10001];
		Scanner input = new Scanner(System.in);
		for(int i=0; i < 10001; i++){
			data[i] = Integer.parseInt(input.nextLine());
			if( data[i] == 0){
				break;
			}
		}
		
		
		
		for(int i=0; i < 10001; i++){
			if( data[i] == 0){
				break;
			}
			System.out.println("Case "+ (i+1) + ": " + data[i]);
		}
		//
	}
}

Measured memory_bytes: 62372
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

ll mpow(ll n, ll t) {
  rep(i,t) n*=n;
  if (t==0) n=1;
  return n;
}

int main() {
  int N,Q,a;
  ll b,c;
  cin >> N;
  map<ll,ll> A;
  rep(i,N) {
    cin >> a;
    A[a]++;
  }
  
  ll ans = 0;
  for (auto itr=A.begin();itr!=A.end();itr++) {
    ans += itr->first * itr->second;
  }
  // cout << ans << endl;
  cin >> Q;
  rep(i,Q) {
    cin >> b >> c;
    ans += c*A[b];
    ans -= b*A[b];

    A[c] += A[b];
    A[b]=0;
    
    cout << ans << endl;
  }
}

Measured memory_bytes: 9460
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def enumerate_bridges(graph):
    """
    橋を列挙する
    http://nupioca.hatenadiary.jp/entry/2013/11/03/200006
    :param list of (list of int) graph:
    """
    N = len(graph)
    ret_bridges = []
    pres = [-1] * N
    lows = [-1] * N
    order = -1
    for v in range(N):
        if pres[v] >= 0:
            continue
        edges = [(None, v, True)]
        while edges:
            v, u, forward = edges.pop()
            if forward:
                if pres[u] >= 0:
                    # もう来たことがある
                    lows[v] = min(lows[v], lows[u])
                    continue
                edges.append((v, u, False))
                parent, v = v, u
                order += 1
                pres[v] = lows[v] = order
                for u in graph[v]:
                    if u == parent:
                        continue
                    edges.append((v, u, True))
            else:
                if v is None:
                    continue
                if lows[u] == pres[u]:
                    ret_bridges.append((v, u))
                lows[v] = min(lows[v], lows[u])
    return ret_bridges


N, M = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]
graph = [[] for _ in range(N + 1)]
for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)
bridges = enumerate_bridges(graph)
print(len(bridges))


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;

int main() {
	int n; cin >> n;
	vi A(n); Loop(i, n) cin >> A[i];
	vi B = A;
	sort(B.begin(), B.end());
	map<int, int> mp;
	Loop(i, n) {
		mp[A[i]] = i;
	}
	int ans = 0;
	Loop(i, n) {
		int s = (mp[B[i]] - i);
		if (s % 2 != 0) ans++;
	}
	cout << ans / 2 << endl;
	return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N;
	unsigned long long c[5] = {0,0,0,0,0};	
	unsigned long long ans=0;

	cin >> N;
	for(int i=0;i<N;i++){
		string tmp;
		cin >> tmp;
		switch(tmp[0]){
			case 'M':
				c[0]++;
				break;
			case 'A':
				c[1]++;
				break;
			case 'R':
				c[2]++;
				break;
			case 'C':
				c[3]++;
				break;
			case 'H':
				c[4]++;
				break;
		}
	}
	
	for(int i=0;i<3;i++){
		if(c[i]==0) continue;
		for(int j=i+1;j<4;j++){
			if(c[j]==0) continue;
			for(int k=j+1;k<5;k++){
				if(c[k]==0) continue;
				ans += c[i]*c[j]*c[k];
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int N, M;
    cin >> N >> M;
    int a[50], b[50], c[50], d[50];
    for(int i=0;i<N;i++)
        cin >> a[i] >> b[i];
    for(int i=0;i<M;i++)
        cin >> c[i] >> d[i];
    
    // N人の学生
    for(int i=0;i<N;i++){
        int ans = INT_MAX, dist, index = 0;
        // M個のチェックポイント
        for(int j=0;j<M;j++){
            dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(dist < ans){
                ans = dist;
                index = j;
            }
        }
        cout << index + 1 << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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; }

std::string S;

int main()
{
  std::cin >> S;

  rep( i, S.size() )
    std::cout << 'x';

  std::cout << std::endl;

  return 0;
}

Measured memory_bytes: 256