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

using namespace std;

typedef long long LL;
#define N 300000

LL n,m,a[N],f[N],fa[N],cnt,bel[N],ans,c[N][2];
struct node{
	LL x,y,z;
	bool operator < (const node &p) const{
		return z<p.z;
	}
}b[N];

LL gfa(LL x){return x==fa[x]?x:fa[x]=gfa(fa[x]);}

void merge(LL x,LL y,LL z){
	x=gfa(x); y=gfa(y);
	if (x!=y){
		fa[x]=fa[y]=++cnt;
		fa[cnt]=cnt; a[cnt]=z;
		f[cnt]=f[x]+f[y];
		c[cnt][0]=x; c[cnt][1]=y;
	}
}

void dfs(LL u,LL fl){
	if (u<=n){bel[u]=fl; return;}
	if (fl||f[u]>=a[u]){
		dfs(c[u][0],fl?fl:u);
		dfs(c[u][1],fl?fl:u);
		return;
	}
	dfs(c[u][0],0);
	dfs(c[u][1],0);
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=n;++i){scanf("%lld",a+i); f[i]=a[i];}
	for (LL i=1;i<=m;++i) scanf("%lld%lld%lld",&b[i].x,&b[i].y,&b[i].z);
	sort(b+1,b+m+1);
	cnt=n;
	for (int i=1;i<=n;++i) fa[i]=i;
	for (LL i=1;i<=m;++i) merge(b[i].x,b[i].y,b[i].z);
	dfs(cnt,0);
	for (LL i=1;i<=m;++i) ans+=(bel[b[i].x]!=bel[b[i].y])|(b[i].z>f[bel[b[i].x]]);
	printf("%lld\n",ans);
	
	return 0;
}
			

Measured memory_bytes: 18944
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N, K;
  cin >> N >> K;
  int C[N] = {0};
  rep(i, N){
    int a; 
    cin >> a; a--;
    C[a]++;
  }
  int cnt = 0;
  ll ans = 0;
  rep(i, N){
    if(C[i]) cnt++;
  }
  if(cnt <= K) cout << 0 << endl;
  else{
    sort(C, C+N);
    rep(i, N-K){
      ans += (ll) C[i];
    }
    cout << ans << endl;
  }
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int g[4][4]{};
  REP(i, 3){
    int a, b; cin >> a >> b;
    a--; b--;
    g[a][b] = g[b][a] = 1;
  }

  int p[] = {0, 1, 2, 3};
  do{
    bool reach = true;
    REP(i, 3){
      if(!g[p[i]][p[i+1]]) reach = false;
    }
    if(reach){
      cout << "YES" << endl;
      return 0;
    }
  }while(next_permutation(p, p+4));

  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
//const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}


int main() {
	ll A, B;

	cin >> A >> B;

	ll C = gcd(A, B);

	vector<ll> cands, cands2;
	for (ll i = 1; (i * i) <= C; i++) {

		if (C % i == 0) {
			cands.push_back(i);
			if(i != C / i)
			cands.push_back(C / i);
		}


	}

	bool flag = true;
	sort(cands.begin(), cands.end());
	ll num = 1;
	for (int i = 1; i < cands.size(); i++) {
		for (ll j = 2; j * j <= cands[i]; j++) {
			if (cands[i] % j == 0)
				flag = false;

		}

		if (flag == true)
			num += 1;

		flag = true;
	}


	cout << num << endl;


	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
int main() {
	//得点の高い問題から貪欲的に解くイメージ
	int D, G, p[11], c[11];
	cin >> D >> G;
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}
	int ans = 1e9;
	for (int mask = 0; mask<(1 << D); mask++) {
		int s = 0, num = 0, rest_max = -1;//numはいままでといた数　
		for (int i = 0; i < D; i++) {//完全に100i問題をとくかどうか
			if (mask >> i & 1) {
				s += 100 * (i + 1)*p[i] + c[i];
				num += p[i];
			}
			else {
				rest_max = i;//問の点数は昇順だから、完全に説いてない問題のうち、最大の得点のもの
			}
		}
		if (s < G) {
			int s1 = 100 * (rest_max + 1);
			int need = (G - s + s1 - 1) / s1;
			if (need >= p[rest_max]) {
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}
	cout << ans << endl;
}




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

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    int N;
    long long P;
    cin >> N >> P;
    const auto &pf = prime_factorize(P);
    long long res = 1;
    for (auto p : pf) {
        for (int j = 0; j < p.second/N; ++j) res *= p.first;
    }
    cout << res << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> v, c;
  for (int i = 0; i < n; i++){
    int a;
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < n; i++){
    int a;
    cin >> a;
    c.push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < n; i++){
    if (v[i] - c[i] > 0) ans += v[i] - c[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec));
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	string s;
	cin>>s;
	int n=s.size();
	int a[26];
	rep(i,26) a[i]=0;
	rep(i,n) {
		a[s[i]-'a']++;
	}
	rep(i,26) {
		if(a[i]%2==1) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <utility>
#include <set>
#include <random>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <functional>
#include <bitset>
#define LL long long

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (a-b>=0)
    {
        cout << "delicious" << endl;
    }
    else if (b - a <= x)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "dangerous" << endl;
    }



}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int N, M;
vector< vector< int > > adj;
vector< bool > vis;

void dfs(int v, int& cnt) {
	if (vis[v]) return;
	vis[v] = true;
	++cnt;
	for (int u : adj[v]) dfs(u, cnt);
}

int main() {
	cin >> N >> M;
	
	adj.assign(N, vector< int >());
	
	for_(i,0,M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	int A = 0, B = 0;
	vis.assign(N, false);
	
	for_(v,0,N) {
		if (vis[v]) continue;
		int cnt = 0;
		dfs(v, cnt);
		if (cnt == 1) ++A;
		else ++B;
	}
	
	cout << abs(B - A) << endl;
}

Measured memory_bytes: 3184
object Main extends App {
  @scala.annotation.tailrec
  def loop(acc: BigInt, list: List[BigInt]): BigInt =
    list match {
      case _ if 1000000000000000000L < acc => -1
      case Seq() => acc
      case x :: xs => loop(acc * x, xs)
    }

  val sc = new java.util.Scanner(System.in)
  val list@x :: xs = List.fill(sc.nextInt())(BigInt(sc.nextBigInteger()))
  println(if (list.contains(0)) 0 else loop(x, xs))
}


Measured memory_bytes: 70812
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;

char rgb_c(char a, char b){
  string s = "RGB";
  vi rgb(3);
  rep(i, 3){
    if (s[i] == a or s[i] == b) rgb[i]++;
  }
  char c = 'R';
  rep(i, 3){
    if (rgb[i]==0) c = s[i];
  }
  return c;
}

int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int cnt = 0;

  vi cr(n);
  cnt = 0;
  for (int i=n-1;i>=0;i--){
    if (s[i] == 'R') cnt++;
    cr[i] = cnt;
  }

  vi cg(n);
  cnt = 0;
  for (int i=n-1;i>=0;i--){
    if (s[i] == 'G') cnt++;
    cg[i] = cnt;
  }

  vi cb(n);
  cnt = 0;
  for (int i=n-1;i>=0;i--){
    if (s[i] == 'B') cnt++;
    cb[i] = cnt;
  }


  ll ans = 0;
  rep(i, n){
    for(int j=i+1;j<n;j++){
      if (s[j] == s[i]) continue;
      char kc = rgb_c(s[i], s[j]);
      if (kc == 'R') ans += cr[j];
      if (kc == 'G') ans += cg[j];
      if (kc == 'B') ans += cb[j];
      int k = j+(j-i);
      if (k < n && s[k] == kc) ans--;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){

    while(1){
        int N;
        cin >> N;
        if(N == 0){
            break;
        }

        vector<vector<bool>> stone(21, vector<bool>(21, false));
        int x, y;
        for(int i = 0; i < N; i++){
            cin >> x >> y;
            stone[x][y] = true;
        }

        int tempX = 10;
        int tempY = 10;

        int M;
        cin >> M;
        string dir;
        int move;
        for(int i = 0; i < M; i++){
            cin >> dir >> move;

            while(move > 0){
                if(dir == "N"){
                    tempY += 1;
                }
                else if(dir == "E"){
                    tempX += 1;
                }
                else if(dir == "S"){
                    tempY -= 1;
                }
                else if(dir == "W"){
                    tempX -= 1;
                }

                move--;

                stone[tempX][tempY] = false;
            }
        }

        bool isOk = true;
        for(int i = 0; i <= 20; i++){
            for(int j = 0; j <= 20; j++){
                if(stone[i][j]){
                    isOk = false;
                    break;
                }
            }
        }

        if(isOk){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
        
    }

    return 0;
}


Measured memory_bytes: 3140
with Ada.Text_IO;
use Ada.Text_IO;
with Ada.Integer_Text_IO;
use Ada.Integer_Text_IO;

procedure Main is
	x:Integer;
begin
	get(x);
    x:=x mod 10;
    if x=2 or x=4 or x=5 or x=7 or x=9 then
    put_line("hon");
    elsif x=0 or x=1 or x=6 or x=8 then
    put_line("pon");
    else
    put_line("bon");
    end if;
end Main;

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 5001
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

int a[6] = {500, 100, 50, 10, 5, 1};
int solve(int n){
	int ans = 0;
	while(1){
		for(int i = 0;i < 6;i++){
			if(n >= a[i]){
				n -= a[i];
				ans++;
				break;
			}
		}
		if(n == 0)break;
	}
	return ans;
}

int main(){
	int n;
	while(cin >> n, n){
		cout << solve(1000-n) << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
#define int LL
const int mo=1e9+7;
typedef pair<int,int> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
int n,m,vis[300005];
signed main(){
	read(n);read(m);int l=1,r=n;
	while(m){
		//printf("%d %d %d\n",l,r,n-r+2);
		if(!vis[r]&&!vis[n-r+2]&&r!=n-r+2)
			printf("%lld %lld\n",l,l+r-1),vis[r]=vis[n-r+2]=1,m--,l++,r--;
		r--;
	}
	return 0;
}

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, A[int(1e5 + 5)];
int cnt[3];
ll ans = 1;

int main(){
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> A[i];

  for (int i = 1; i <= N; i++){
    ll now = 0;
    bool flag = false;
    for (int j = 0; j < 3; j++){
      if (cnt[j] == A[i]){
        now++;
        if (!flag){
          flag = true;
          cnt[j]++;
        }
      }
    }
    ans *= now; ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4020
import sys
sys.setrecursionlimit(10**6)

def main():
	n = int(input())
	lst = []
	for _ in range(n):
		lst += [int(input())]
	lst.sort()
	ylst = lst[::-1]
	ans = 0
	if n % 2 == 1:
		pib = int((n-1)/2)
		for i in range(n):
			ans += 2 * abs(lst[i]-lst[pib])
		print(ans - min(abs(lst[pib-1]-lst[pib]), abs(lst[pib]-lst[pib+1])))
	elif n == 2:
		print(lst[1]-lst[0])
	else:
		pib = int(n/2) - 1
		for i in range(pib):
			ans += abs(lst[i] - lst[pib]) * 2
			ans += abs(ylst[i] - ylst[pib]) * 2
		ans += abs(lst[pib] - ylst[pib]) * (n-1)
		print(ans)
	return

main()

Measured memory_bytes: 7892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<60;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,K;cin>>N>>K;
    
    ll left=-1,right=INF;
    
    while(right-left>1){
        ll mid=(left+right)/2;
        
        ll rem=mid+1;
        for(int i=0;i<N-1;i++){
            rem--;
            rem-=(rem/K);
        }
        
        if(rem>=1) right=mid;
        else left=mid;
    }
    
    cout<<right<<endl;
    
    
}




Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin>>s;
  int n=s.size();
  string t="",u="";
  
  for(int i=0;i<(n-1)/2;i++){
  	t=t+s[i];
  }
  for(int i=(n+3)/2-1;i<n;i++){
  	u=u+s[i];
  }
  
  bool ans=1;
  for(int i=0;i<n;i++){
  	if(s[i]!=s[n-1-i]) ans=0;
  }
  for(int i=0;i<t.size();i++){
  	if(t[i]!=t[t.size()-1-i]) ans=0;
  }
 for(int i=0;i<u.size();i++){
  	if(u[i]!=u[u.size()-1-i]) ans=0;
  }
  
  
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
d = dict()
prev = ''
for i, s in enumerate(S):
    if i > 0 and s[0] != prev:
        print('No')
        break
    if d.get(s, 0) > 0:
        print('No')
        break
    d[s] = 1
    prev = s[-1]
else:
    print('Yes')

Measured memory_bytes: 9140
#include <stdio.h>
typedef long long ll;

int main(){
    int l,r;
    scanf("%d %d",&l,&r);
    ll answer=2019;
    // r=r-l<2019?r:l+2019;
    if(r-l>2019*2) r=l+2019*2;
    for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
            ll a=(i*j)%2019;
            // answer=a<answer?a:answer;
            if(a<answer) answer=a; 
        }
    }
    printf("%d\n",answer);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long n,a[1<<17],m=-1,i;
int main(){
  cin>>n;
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  for(i=0;i<n-1;i++){a[i+1]+=a[i];if(a[i]*3<a[i+1])m=i;}
  cout<<n-m-1<<endl;
}


Measured memory_bytes: 1024
def main18():
    num = int(input())
    data = input().split()
    weight = []
    for i in range(num):
        weight.append(int(data[i]))
    s = []
    result = 10000000000
    for i in range(2):
        s.append(0)
    for i in range(num):
        s[0] = s[0] + weight[i]
    for i in range(num):
        s[0] = s[0] - weight[i]
        s[1] = s[1] + weight[i]
        ab = abs(s[0]-s[1])
        if result < ab:
            break
        else:
            result = ab
    print(result)

if __name__ == "__main__":
    main18()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int x,y;
cin>>x>>y;
set<int>a{1,3,5,7,8,10,12},b{4,6,9,11},c{2};
if((a.count(x)&&a.count(y))||
    (b.count(x)&&b.count(y))||
    (c.count(x)&&c.count(y))){
        cout<<"Yes"<<endl;
    }
else{
    cout<<"No"<<endl;
}
//system("pause");
return 0;
}

Measured memory_bytes: 256
n, k = map(int, raw_input().split())
A = [int(raw_input())-k for i in xrange(n)]
su = 0
v = [(0, 0)]
for i in xrange(n):
    su += A[i]
    v.append((su, i+1))
v.sort()

data = [0]*(n+5)
def sum(i):
    s = 0
    while i > 0:
        s += data[i]
        i -= i & -i
    return s
def add(i, x):
    while i <= n+2:
        data[i] += x
        i += i & -i
ans = 0
for e, i in v:
    ans += sum(i+1)
    add(i+1, 1)
print ans


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

int main(){  
	int H;
	int W;
	cin >> H >> W;
	string C[H];
	for(int i = 0; i < H; i++){
		cin >> C[i];
	}	
	for(int i = 0; i < H; i++){
		cout << C[i] << endl;
		cout << C[i] << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int d;
  scanf("%d", &d);
  long c[26];
  for (int i = 0; i < 26; i++) {
    scanf("%ld", &c[i]);
  }
  long s[d][26];
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%ld", &s[i][j]);
    }
  }
  int t[d];
  long score,max;
  int max_contest;
  long last[26];
  for (int i = 0; i < 26; i++) {
    last[i] = -1;
  }
  for (int i = 0; i < d; i++) {
    for (int contest = 0; contest < 26; contest++) {
      score = s[i][contest];
      for (int j = 0; j < 26; j++) {
        if (j == contest) {
          continue;
        }
        score -= c[j]*(i-last[j]);
      }
      if (contest == 0 || score > max) {
        max = score;
        max_contest = contest;
      }
    }
    last[max_contest] = i;
    printf("%d\n", max_contest+1);
  }

  return 0;
}

Measured memory_bytes: 1808
#include <iostream>
#include <string>

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '+') { ans++; }
        else { ans--; }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>

using namespace std;
typedef long long ll;
const int N = 1e5+5;
ll n,m;

int main(){
	priority_queue<ll>q;
	cin>>n>>m;
	for(ll i=0;i<n;i++){
		ll x;
		cin>>x;
		q.push(x);
	}
	for(ll i=0;i<m;i++){
		ll num=q.top();
		q.pop();
		num=num/2;
		q.push(num);
	}
	ll ans=0;
	while(q.size()){
		ans+=q.top();
		q.pop();
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1400
N = int(input())
T,A = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

ans=0
cnt=10000
TEMP=0.006

for i in range(N):
    n = abs(A - (T-H[i]*TEMP))
    if n < cnt:
        ans=i+1
        cnt = n
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M; cin >> N >> M;
  int ac = 0,wa = 0;
  vector<int> wrong(N + 1,0);
  vector<bool> clear(N + 1,true);
  for(int i = 0; i < M; i++){
    int p;
    string S; cin >> p >> S;
    
    if(S == "AC"){
      if(clear.at(p)){
        clear.at(p) = false;
        ac++;
        wa += wrong.at(p);
      }
    }
    else{
      if(clear.at(p)) wrong.at(p)++;
    }
  }
  
  cout << ac << " " << wa << endl;      
}
      

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1 << 16;
int n, m;
int bit1[MAXN]; // 二?制数中有多少个 1
int dp[20][10][MAXN];
vector<int> G[20];
int dfs(int u, int h, int bits) {
    if(bit1[bits] == 1) return 1;
    if((1 << h) < bit1[bits]) return 0;
    if(dp[u][h][bits] != -1) return dp[u][h][bits];
    else dp[u][h][bits] = 0;
    int& res = dp[u][h][bits];
    for(int i = bits & (bits - 1); i; i = bits & (i - 1)) {
        if((i >> u) & 1) {
            int j = bits ^ i;
            for(int k = 0; k < G[u].size(); k++) {
                int v = G[u][k];
                if((j >> v) & 1) {
                    res += dfs(u, h - 1, i) * dfs(v, h - 1, j);
                }
            }
        }
    }
    return res;
}
int main() {
    for(int i = 0; i < MAXN; i++) {
        bit1[i] = bit1[i >> 1] + (i & 1);
    }
    while(cin >> n >> m && (n + m)) {
        memset(dp, -1, sizeof dp);
        for(int i = 0; i < n; i++) G[i].clear();
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                int x;
                cin >> x;
                if(x) G[i].push_back(j);
            }
        }
        int h = ceil(log(n) / log(2));
        cout << dfs(m - 1, h, (1 << n) - 1) << endl;
    }
    return 0;

}

Measured memory_bytes: 54852
<?php
$a = fgets(STDIN);
$is_a = false;
$is_b = false;
for($i = 0; $i < strlen($a); $i++) {
  if($a[$i] === 'A') {
    $is_a = true;
  }
  if($a[$i] === 'B') {
    $is_b = true;
  }
}

if($is_a && $is_b) {
  echo 'Yes';
} else {
  echo 'No';
}
?>

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;

const int maxN = 2e5 + 10;
const int inf = 1e18;

typedef pair<int, int> ii;

int n, m, sum, st[maxN * 4], lazy[maxN * 4];

vector <ii> a[maxN];

void push(int id){
    st[id * 2] += lazy[id];
    lazy[id * 2] += lazy[id];
    st[id * 2 + 1] += lazy[id];
    lazy[id * 2 + 1] += lazy[id];
    lazy[id] = 0;
}

void update(int x, int y, int d, int id = 1, int l = 0, int r = n){
    if(x > r || l > y)
        return;

    if(l >= x && r <= y){
        st[id] += d;
        lazy[id] += d;
        return;
    }

    int mid = (l + r) / 2;
    push(id);
    update(x, y, d, id * 2, l, mid);
    update(x, y, d, id * 2 + 1, mid + 1, r);
    st[id] = max(st[id * 2],st[id * 2 + 1]);
}

int get(int x, int y, int id = 1, int l = 0, int r = n){
    if(x > r || l > y)
        return -inf;

    if(l >= x && r <= y)
        return st[id];

    int mid = (l + r) / 2;
    push(id);
    return max(get(x, y, id * 2, l, mid), get(x, y, id * 2 + 1, mid + 1, r));
}

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(); cout.tie();
    cin >> n >> m;

    for(int i = 0; i < m; ++i){
        int l,r,x;
        cin >> l >> r >> x;
        a[r].push_back({l,x});
        sum += x;
    }

    update(0, n,sum);
    for(int i = 1; i <= n; ++i){
        update(i, i, get(0, i - 1) - sum);
        for(auto j : a[i])
            update(0, j.fi - 1, -j.se);
    }

    cout << st[1] << endl;
}


Measured memory_bytes: 22696
import java.util.*;

public class Main{
	
	public static double find(double arr[],double dp[][],int tail,int i,int n)
	{
		if(i>=n)
			return 1;
		
		if(dp[tail][i]==-1)
		{
			double op1=(arr[i])*find(arr,dp,tail,i+1,n);
			double op2=0;
			if(tail<n/2)
				op2=(1-arr[i])*find(arr,dp,tail+1,i+1,n);
			
				dp[tail][i]=op2+op1;
				
		}
		
			return dp[tail][i];
	}
    public static void main(String[] args) 
    {
       Scanner s=new Scanner(System.in);
       int n=s.nextInt();
       double arr[]=new double[n];
       for(int i=0;i<n;i++)
    	   arr[i]=s.nextDouble();
       
       double dp[][]=new double[n/2+1][n];
       for(int i=0;i<=n/2;i++)
       {
    	   for(int j=0;j<n;j++)
    		   dp[i][j]=-1;
       }
       System.out.print(find(arr,dp,0,0,n));
    }
}

Measured memory_bytes: 69576
class complete_btree:
    def __init__(self, vals):
        self.vals=vals
        self.index_max = len(self.vals)

    def check(self, i):
        assert(i >= 1)
        assert(i <= self.index_max)

    def val_at(self, i):
        self.check(i)
        return self.vals[i-1]

    def left_idx(self, i):
        self.check(i)
        t = 2*i
        if t <= self.index_max:
            return t
        else:
            return None

    def right_idx(self, i):
        self.check(i)
        t = 2*i + 1
        if t <= self.index_max:
            return t
        else:
            return None

    def parent_idx(self, i):
        self.check(i)
        t = i//2
        if t > 0:
            return t
        else:
            return None


if __name__ == "__main__":
    H = int(input())   # <= 250
    vals_str = input()   # |val|<=2,000,000,000 = 2e9
    vals = vals_str.split(' ')

    cbt = complete_btree(vals)
    for i in range(1, H+1):
        print('node {i}: key = {k}, '.format(i=i, k=cbt.val_at(i)), end='')
        p_idx = cbt.parent_idx(i)
        l_idx = cbt.left_idx(i)
        r_idx = cbt.right_idx(i)
        if p_idx is not None:
            print('parent key = {k}, '.format(k=cbt.val_at(p_idx)), end='')
        if l_idx is not None:
            print('left key = {k}, '.format(k=cbt.val_at(l_idx)), end='')
        if r_idx is not None:
            print('right key = {k}, '.format(k=cbt.val_at(r_idx)), end='')
        print('')

Measured memory_bytes: 7800
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	H := readInt()
	var count int
	num := 1
	for {
		count += num

		if H == 1 {
			break
		}

		H /= 2
		num *= 2
	}
	fmt.Println(count)
}


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

int main()
{
    /* ------- 宣言と入力 ------- */

    int A, B, C;

    cin >> A >> B >> C;

    /* ------- 計算 ------- */

    string ans = "No";

    if (A == B && A != C)
    {
        ans = "Yes";
    }
    if (B == C && C != A)
    {
        ans = "Yes";
    }
    if (C == A && A != B)
    {
        ans = "Yes";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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 ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
template<typename T>
T argument(const pair<T, T> &a, const pair<T, T> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/

int const MAX = 2000000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

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

    int n, k; std::cin >> n >> k;
    ll ans = 1;
    rep(i, n) { ans *= k; chmod(ans); }
    std::cout << ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 3212
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define nl '\n'
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;

int main () {
	SpeedForce;
	setIO();
	cin >> n;
	For (i, 1, n) if (i * i <= n) {
	    For (j, 1, n) if (i * i + j * j <= n) {
	        For (k, 1, n) if(i * i + j * j + k * k + i * j + j * k + i * k <= n) {
	           a[i * i + j * j + k * k + i * j + j * k + i * k]++;
	           
	        }
	        
	    } else break;
	} else break;
    For (i, 1, n) cout << a[i] << nl;
    
	return Accepted;
}

// B...a

Measured memory_bytes: 17648
#include <bits/stdc++.h>
/**
 *    author:  dattrinh
 *    created:    Codeforces Round #635
**/
#define pb push_back
#define fi first
#define ss second
#define tp(x) fixed<<setprecision(x)
using namespace std;
using ll = int64_t;
const int N = 1000003;
ll t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    while(n){
        if(n%10==7){cout<<"Yes"; return 0;}
        n/=10;
    }
    cout<<"No";
    return 0;
}






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

int main(){
  int64_t W,H,x,y;
  cin >> W >> H >> x >> y;
  double area=(W*H)/2.0;
  bool flag;
  if((x==W/2.0)&&(y==H/2.0)){
    flag=true;
  }else{
    flag=false;
  }
  cout << fixed << setprecision(6);
  cout << area << " " << flag << endl;
  return 0;
}


Measured memory_bytes: 256
/*
 * Author: Anmol Choudhary
 */
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nextl cout<<"\n"
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<"["<<#x<<"="<<x<<"] , ["<<#y<<"="<<y<<"]"<<"\n"
const ll mod = 1000000007;
const ll maxn = 20005;
const double mm = 1e+30;
ll power(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res;
}
void solve()
{
    ll dp[maxn];
    ll h,n;
    cin>>h>>n;
    rep0(i,maxn) dp[i]=mod;
    dp[0]=0;
    rep0(i,n){
        ll x,y;
        cin>>x>>y;
        repp(j,x,maxn){
            dp[j]=min(dp[j],dp[j-x]+y);
        }
    }
    ll mi=mod;
    repp(i,h,maxn) mi=min(mi,dp[i]);
    pr(mi);
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nextl;
    }
    return 0;
}


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

signed main(){
  int n,k; cin>>n>>k;
  if(k==1){
    cout<<0<<endl;
    return 0;
  }
  if(n<=k-n){
    cout<<n<<endl;
    return 0;
  }
  n-=(n/k)*k;
  if(n<=k-n)
    cout<<n<<endl;
  else
    cout<<k-n<<endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int A, B, K; cin >> A >> B >> K;

    set<int> st;
    for (int i = A; i < A+K; i++) {
        if (i <= B) st.insert(i);
    }
    for (int i = B; i > B-K; i--) {
        if (i >= A) st.insert(i);
    }

    for (int t : st) {
        cout << t << "\n";
    }

    return 0;
}


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

using namespace std;

int main()
{
    int c=0,k=0;
    string s;
    cin>>s;
    int sizer=s.size();
    for(int i=0 ; i<sizer;i++)
    {
         k+=(bool)(islower(s[i]));

    }
      for(int i=2 ; i<sizer-1;i++)
    {
         c+=(s[i]=='C');

    }
    if(s[0]=='A'&& c==1&&k==sizer-2){cout<<"AC";}
        else  cout<<"WA";
    return 0;
}


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

const int MOD = 1000000007;

long long N;
vector<long long> G[200001];
long long num_children[200001];
bool val[200001];

long long extGCD(long long a, long long b, long long *px, long long *py){
    if(b == 0){
        *px = 1;
        *py = 0;
        return a;
    }
    long long d = extGCD(b, a%b, py, px);
    *py -= a/b * (*px);
    return d;
}

long long modinv(long long a, long long mod){
    long long x, y;
    extGCD(a, mod, &x, &y);
    x %= mod;
    if(x < 0) x += mod;
    return x;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long visit(long long v){
    val[v] = 1;
    num_children[v]=1;
    for(long long i=0; i<G[v].size(); ++i){
        if(val[G[v][i]]==0){
            num_children[v] += visit(G[v][i]);
        }
    }
    return num_children[v];
}

int main() {
    //input
    long long N;
    cin >> N;
    long long A,B;
    for(long long i=1; i<=N-1; i++){
        cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    //calc
    fill(val,val+(N+1),0);
    visit(1);
    long long exper = ((modpow(2,N-1,MOD)*(2-N) -1))%MOD;
    while(exper<0){
        exper += MOD;
    }
    for(long long i=2; i<=N; i++){
        exper = (exper + ((modpow(2,num_children[i],MOD)-1)*(modpow(2,N-num_children[i],MOD)-1))%MOD)%MOD;
    }
    exper = (exper*modinv(modpow(2,N,MOD),MOD))%MOD;

    //answer
    cout << exper << endl;
    system("pause");
    return 0;
}

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

int main()
{
    string S;
    ll K;
    cin >> S >> K;

    ll answer = 0;
    ll answer1 = 0;
    string S1 = S;
    rep (i, S1.size() - 1) {
        if (S1[i] == S1[i + 1]){
            answer1++;
            S1[i + 1] = ' ';
        }
    }

    if (K == 1) {
        rep (i, S.size() - 1) {
            if (S[i] == S[i + 1]){
                answer++;
                S[i + 1] = ' ';
            }
        }
    } else {
        string S2 = S + S;

        ll answer2 = 0;
        rep (i, S2.size() - 1) {
            if (S2[i] == S2[i + 1]){
                answer2++;
                S2[i + 1] = ' ';
            }
        }

        if (K % 2 == 0) {
            ll answerAdd = 0;
            if (S2[0] == S2[S2.size() - 1]) {
                answerAdd = (K / 2) - 1;
            }
            answer = answer2 * K / 2 + answerAdd;
        } else {
            ll answer3 = 0;
            S2 = S + S + S;

            rep (i, S2.size() - 1) {
                if (S2[i] == S2[i + 1]){
                    answer3++;
                    S2[i + 1] = ' ';
                }
            }

            ll answerAdd = 0;
            if (S2[0] == S2[S2.size() - 1] && answer3 - answer2 != answer1) {
                answerAdd = (K - 3) / 2;
            }
            answer = (answer2 * (K - 3) / 2) + answer3 + answerAdd;
        }
    }

    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<cctype>
#include<cmath> 
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
 
int main(){
  int N,M,ans;
  cin >> N >> M;
  ans=(N-1)*(M-1);
 
  cout << ans << endl;
 
 
  return 0;
}
 

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

#define int             long long
#define ipi(x)          int x; cin>>x;
#define ips(s)			string s;cin>>s;
#define w(x)            int x; cin>>x; while(x--)
#define mk(arr,n,type)  type *arr=new type[n];
#define mod             pow(10,9)+7
#define inf             1e18
#define endl			"\n"
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >

void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main() {
	c_p_c();
	ipi(n);
	ips(s);
	string output = "";
	if (s.length() <= n)
		cout << s << endl;
	else {
		for (int i = 0; i < n; i++) {
			output = output + s[i];
		}
		output = output + "...";
		cout << output << endl;
	}
	return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

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

    vector<bool> l(1000, false);
    for(int i = 1; i < 35; i++){
        for(int j = 2; j < 11; j++){
            if(pow(i,j) > 1000) continue;
            l[(int)pow(i,j)] = true;
        }
    }
    for(int i = x; i > 0; i--){
        if(l[i]){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=m/n;i>=1;i--)
	{
		if(m%i==0)
		{
			int t=m/i;
			if(t>=n)
			{
				cout<<i<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    lli a,b,c;
    cin>>a>>b>>c;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
    return 0;
}

Measured memory_bytes: 256
import math
n = input()
n = int(n)
x = list(map(int,input().split()))
y = list(map(int,input().split()))

def myfunc(a,n):
    c = 0
    while a!=[]:
        c += (a[0]-1)*math.factorial(n-1)
        for i in range(len(a)):
            if a[i]>a[0]:
                a[i] -= 1
        del a[0]
        n -= 1
    return c

print(abs(myfunc(x,n)-myfunc(y,n)))

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

int main()
{
  int n,u,v;cin>>n>>u>>v;
  vector<int> a(n-1);
  vector<int> b(n-1);
  int i;
  for(i=0;i<n-1;i++)cin>>a.at(i)>>b.at(i);
  vector<vector<int>> got(n+1,vector<int>(0));
  for(i=0;i<n-1;i++)
  {
    got.at(a.at(i)).push_back(b.at(i));
    got.at(b.at(i)).push_back(a.at(i));
  }
  vector<bool> visit(n+1,false);
  visit.at(0)=true;
  queue<int> q;
  queue<int> subq;
  vector<int> numT(n+1,1000000);
  q.push(u);
  visit.at(u)=true;
  numT.at(u)=0;
  int num=1;
  while(!q.empty())
  {
    while(!q.empty())
    {
      int top = q.front();
      for(i=0;i<got.at(top).size();i++)
      {
        if(!visit.at(got.at(top).at(i)))
        {
          subq.push(got.at(top).at(i));
          visit.at(got.at(top).at(i))=true;
          numT.at(got.at(top).at(i))=num;
        }
      }
      q.pop();
    }
    while(!subq.empty())
    {
      q.push(subq.front());
      subq.pop();
    }
    num++;
  }
  for(i=0;i<=n;i++)visit.at(i)=false;
  visit.at(0)=true;
  while(!q.empty())q.pop();
  while(!subq.empty())subq.pop();
  vector<int> numA(n+1,0);
  q.push(v);
  visit.at(v)=true;
  numA.at(v)=0;
  num=1;
  while(!q.empty())
  {
    while(!q.empty())
    {
      int top = q.front();
      for(i=0;i<got.at(top).size();i++)
      {
        if(!visit.at(got.at(top).at(i)))
        {
          subq.push(got.at(top).at(i));
          visit.at(got.at(top).at(i))=true;
          numA.at(got.at(top).at(i))=num;
        }
      }
      q.pop();
    }
    while(!subq.empty())
    {
      q.push(subq.front());
      subq.pop();
    }
    num++;
  }
  int maxa=0;
  if(got.at(u).size()==1&&got.at(u).at(0)==v)cout<<0<<endl;
  else
  {
    for(i=1;i<=n;i++)
    {
      if(numA.at(i)>numT.at(i))
      {
        if(numA.at(i)>maxa)maxa=numA.at(i);
      }
    }
    cout<<maxa-1<<endl;
  }
}

Measured memory_bytes: 7424
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N = iin()
A = iln()

right = 0
total = 0
xor_total = 0
ans = 0
for left in range(N):
    while right < N and total + A[right] == xor_total ^ A[right]:
        total += A[right]
        xor_total ^= A[right]
        right += 1
    ans += right - left
    if left == right: right += 1
    else:
        total -= A[left]
        xor_total -= A[left]
print(ans)

Measured memory_bytes: 25620