akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
	int i,n,pm,pe,pj;
	while(scanf("%d",&n)){
		if(n==0)break;
		for(i=0;i<n;i++){scanf("%d %d %d",&pm,&pe,&pj);
			if(pm==100||pe==100||pj==100){puts("A");}
			else if((pm+pe)/2>=90){puts("A");}
			else if((pm+pe+pj)/3>=80){puts("A");}
			else if((pm+pe+pj)/3>=70){puts("B");}
			else if((pm+pe+pj)/3>=50&&(pm>=80||pe>=80)){puts("B");}
			else{puts("C");}
		}
	}
return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9)+7;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  int n;
  string s;
  cin>>n>>s;
  int tot = 1;
  for(int i=1;i<n;i++){
  	if(s[i]!=s[i-1]){
  		tot++;
  	}
  }
  cout<<tot<<endl;
} 







Measured memory_bytes: 512
ans=[]
n=int(input())
A1=list(map(int,input().split()))
A2=list(map(int, input().split()))

for i in range(n):
 ans.append(sum(A1[0:i+1])+sum(A2[i:n]))

print(max(ans))

#d,eには同じ入力が入っている
#sum2row=sum(e)
#uc=it.accumulate(u)
#ucは1行目の累計和のリスト
#print(uc)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
using namespace std;
 
typedef long long ll;
ll k, c1, c2;
string s;
int main()
{
	ll i;
	cin >> s >> k;
	if (k % 2) {
		for (i = 1; i < s.size(); i++) {
			if (s[i] == s[i - 1]) c1++, i++;
		}
		if (i == s.size() && s[s.size() - 1] == s[0]) c1++, i = 2;
		else i = 1;
	} else {
		i = 1;
	}
	s += s;
	for (; i < s.size(); i++) {
		if (s[i] == s[i - 1]) c2++, i++;
	}
	c2 *= k / 2;
	if (i == s.size() && s[s.size() - 1] == s[0]) c2 += k / 2 - 1;
	cout << c1 + c2 << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import itertools

A,B,C,D = [int(i) for i in input()]
for ops in range(8):
    ops2 = []
    val = 0
    if ops%2 == 0:
        val = A+B
        ops2.append('+')
    else:
        val = A-B
        ops2.append('-')

    if (ops//2)%2 == 0:
        val += C
        ops2.append('+')
    else:
        val -= C
        ops2.append('-')

    if (ops//4)%2 == 0:
        val += D
        ops2.append('+')
    else:
        val -= D
        ops2.append('-')
    if val == 7:
        print(str(A)+ops2[0]+str(B)+ops2[1]+str(C)+ops2[2]+str(D)+'='+str(7))
        break
        


Measured memory_bytes: 3064
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
bool ok = true;
int dfs(vvi &v, vi &dp, vi &x, int i, int p) {
	if (dp[i] != -1)return dp[i];

	vector<pii> tmp;
	REP(j, v[i].size()) {
		if (v[i][j] == p)continue;
		tmp.push_back(pii{ dfs(v,dp,x,v[i][j],i),x[v[i][j]] });
	}
	vvi nap(tmp.size(), vi(x[i] + 1, INF));
	if (tmp.size() != 0) {
		if (tmp[0].first <= x[i])nap[0][tmp[0].first] = tmp[0].second;
		if (tmp[0].second <= x[i])nap[0][tmp[0].second] = tmp[0].first;

		FOR(j, 1, tmp.size()) {
			REP(k, x[i] + 1) {
				if (nap[j - 1][k] < INF) {
					if (tmp[j].first == 0) 	nap[j][k] = nap[j - 1][k] + tmp[j].second;
					else if (k + tmp[j].first <= x[i])nap[j][k + tmp[j].first] = min(nap[j - 1][k + tmp[j].first], nap[j - 1][k] + tmp[j].second);
					if (tmp[j].second == 0)nap[j][k] = nap[j - 1][k] + tmp[j].first;
					else if (k + tmp[j].second <= x[i])nap[j][k + tmp[j].second] = min(nap[j - 1][k + tmp[j].second], nap[j - 1][k] + tmp[j].first);
				}
			}
		}
		int ans = INF;
		REP(j, x[i] + 1) {
			ans = min(ans, nap[tmp.size() - 1][j]);
		}
		if (ans == INF)ok = false;
		return dp[i] = ans;
	}
	else {
		return dp[i] = 0;
	}

}


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vvi v(n);
	REP(i, n - 1) {
		int p;
		cin >> p;
		v[p - 1].push_back(i + 1);
		v[i + 1].push_back(p - 1);
	}
	vi x(n);
	REP(i, n)cin >> x[i];
	vi dp(n, -1);
	dfs(v, dp, x, 0, -1);
	if (ok)cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1304
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


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;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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


int main() {
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	
	int s[4];
	s[0] = max(x, y) * 2 * c;
	s[1] = 2 * x * c + max(0, y - x) * b;
	s[2] = 2 * y * c + max(0, x - y) * a;
	s[3] = x * a + y * b;
	int sum = INF;
	rep(i, 4) sum = min(sum, s[i]);
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

static const int MAX_MEMBERS = 20;

int Members;

vector<int> power;
int seek = 0;

int FightingPower[MAX_MEMBERS], n, res;
const int INF = 1000001;

void dfs(int i, int a_sum, int b_sum) {
	if (i == n) {
		res = min(abs(a_sum - b_sum), res);
	}
	else {
		dfs(i + 1, a_sum + FightingPower[i], b_sum);
		dfs(i + 1, a_sum, b_sum + FightingPower[i]);
	}
}

int main() {
	while (cin >> n && n!=0) {
		for (int i = 0; i<n; i++) {
			cin >> FightingPower[i];
		}
		res = INF;
		dfs(0, 0, 0);
		cout << res << endl;
	}
}

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

using ll = long long; 
/*

2
1 4


*/
int calc_cost(vector<int> arr, int choice) {
    int ans = 0;
    for (int num : arr) {
        ans += (num - choice) * (num - choice);
    }
    return ans;
}

int main() {
    int N;
    
    scanf("%d", &N);
    
    vector<int> arr(N);
    
    int total = 0;
    
    for (int i = 0; i < N; i++) {
        scanf("%d", &arr[i]);
        total += arr[i];
    }
    
    int avg = total / N;
    
    /*
    sort(arr.begin(), arr.end());
    
    int med = arr[N/2];
    
    cout << med << endl;
    
    int ans = 0;
    
    for (int n : arr) {
        ans += (n - med) * (n - med);
    }
    */
    
    int ans = min({calc_cost(arr, avg-1), calc_cost(arr, avg), calc_cost(arr, avg+1)});
    
    
    printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>

int map[11][11];

int main(void)
{
    while(true) {
        int n;

        scanf("%d", &n);
        if(!n) break;

        memset(map, 0, sizeof(map));

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

        for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            map[i][n] += map[i][j];
        for(int j=0; j<=n; j++)
        for(int i=0; i<n; i++)
            map[n][j] += map[i][j];

        for(int i=0; i<=n; i++)
        {
            for(int j=0; j<=n; j++)
                printf("%5d", map[i][j]);
            printf("\n");
        }

    }
    return 0;
}

Measured memory_bytes: 1044
#include <cstdio>
int imap[10000][10000];

int main() {

    int n, t, sum;
    for(; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        for (int i = 0; i < n; i++) {
            sum = 0;
            for (int j = 0; j < n; j++) {
                scanf("%d", &t);
                sum+=t;
                imap[i][j] = t;
            }
            imap[i][n] = sum;
        }
        for (int i = 0; i <= n; i++) {
            sum = 0;
            for (int j = 0; j < n; j++) {
                sum+= imap[j][i];
            }
            imap[n][i] = sum;
        }

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



Measured memory_bytes: 2676
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
	int n, i, j, h = 0, cnt = 0, m, p, k = 3, l[10], S, L, s[10], a[10];
	for (i = 1; i <= 9; i++) {
		for (j = 1; j <= 9; j++) {
			int seki = i*j;
			printf("%dx%d=%d\n", i, j, seki);
		}
	}

}

Measured memory_bytes: 3112
def main():
    N, M = map(int, input().split())
    commit = [list() for i in range(N)]

    for i in range(M):
        no, sta = input().split()
        commit[int(no)-1].append(sta)

    AC_total = 0
    WA_total = 0

    for i in range(len(commit)):
        AC = 0
        WA = 0
        for j in range(len(commit[i])):
            if len(commit[i]) == 0:
                continue
            else:
                if commit[i][j] == "WA":
                    WA += 1
                elif commit[i][j] == "AC":
                    AC += 1
                    AC_total += AC
                    WA_total += WA
                    break
    print(AC_total, WA_total)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20272
#include "bits/stdc++.h"
using namespace std ;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll ;
typedef long double ldb ;

#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl '\n'

#define all( x ) x.begin(),x.end() 
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )

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

const int MAX = 20 + 10 ;
const ll INF = 1e18 ;
const int MOD = 1e9 + 7 ;

ll mat[MAX][MAX], tmp[MAX], n, m, x, ans = MOD ;

void sol( ll ind, ll mask ){
  if( ind == n ){
    for( ll i = 0 ; i < MAX; i++ )
      tmp[i] = 0 ;
    ll cost = 0 ;
    for( ll i = 0 ; i < 13 ; i++ ){
      if( mask&(1<<i) ){
        for( ll j = 1 ; j <= m ; j++ )
          tmp[j] += mat[i][j] ;
        cost += mat[i][0] ;
      }
    }
    bool f = 1 ;
    for( ll i = 1 ; i <= m ; i++ ){
      f &= (tmp[i] >= x ) ;
    }
    if( f )
      ans = min( ans, cost ) ;
  }
  else{
    sol( ind+1, mask ) ;
    sol( ind+1, mask|(1<<ind));
  }
}

void sol( ){
  cin >> n >> m >> x ;
  for( ll i = 0 ; i < n ; i++ )
    for( ll j = 0 ; j < m+1 ; j++ )
      cin >> mat[i][j] ;
  sol( 0, 0 ) ;
  if( ans >= MOD )
    ans = -1 ;
  cout << ans << nl ;
}

signed main( ){
  timesaver ;
//  ll t = 1 ; cin >> t ; while(t--)
  {
    sol( );
  }
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
long long mod=1e9+7;

long long modpow(long long a,long long p){
    if(p==0)return 1;
    if(p%2==0){
      long long halfP=p/2;
      long long half=modpow(a,halfP);
      return half*half%mod;
    }else{
      return a*modpow(a,p-1)%mod;
    }
}

long long comb(long long a,long long b){
  if(b>a-b)return comb(a,a-b);
  long long ansMul=1;
  long long ansDiv=1;
  for(int i=0;i<b;i++){
    ansMul*=(a-i);
    ansDiv*=(i+1);
    ansMul%=mod;
    ansDiv%=mod;
  }
  long long ans=ansMul*modpow(ansDiv,mod-2)%mod;
  return ans;
}


int main(){
  long long h,w,a,b;
  cin>>h>>w>>a>>b;
  vector<long long> tx(h+w+2);
  vector<long long> fx(h+w+2);
  tx[0]=1;
  fx[0]=1;
  long long tmp=1;
  for(int i=1;i<h+w+2;i++){
    tx[i]=(i*tx[i-1])%mod;
    fx[i]=modpow(tx[i],mod-2);
  }
  long long ans=0;
  for(int i=0;i+b<w;i++){
    long long x=(h-a-1)+(b+i);
    long long y=(h-a-1);
    long long l=(a-1)+(w-b-1-i);
    long long r=(w-b-1-i);
    ans+=((((tx[x]*fx[y])%mod)*fx[x-y])%mod)*((((tx[l]*fx[r])%mod)*fx[l-r])%mod)%mod;
    ans%=mod;
  }
  ans%=mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 3328
n = int(input())
b = n
a = []

while n % 2 == 0:
    a.append(2)
    n //= 2
f = 3
while f * f <= n:
    if n % f == 0:
        a.append(f)
        n //= f
    else:
        f += 2
if n != 1:
    a.append(n)
    
print(f'{b}:',*a)


Measured memory_bytes: 5608
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4 5 1
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2

output:
INF
0
-5
-3

OR
input:
4 6 0
0 1 2
0 2 3
1 2 -5
1 3 1
2 3 2
3 1 0

output:
NEGATIVE CYCLE
"""

import sys
from math import isinf


def generate_adj_table(_v_info):
    for each in _v_info:
        source, target, cost = map(int, each)
        init_adj_table[source][target] = cost
    return init_adj_table


def bellman_ford():
    distance[root] = 0

    for j in range(vertices - 1):
        for current, current_info in enumerate(adj_table):
            for adj, cost in current_info.items():
                if distance[current] + cost < distance[adj]:
                    distance[adj] = distance[current] + cost

    for current, current_info in enumerate(adj_table):
        for adj, cost in current_info.items():
            if distance[current] + cost < distance[adj]:
                print('NEGATIVE CYCLE')
                return list()

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges, root = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])

    distance = [float('inf')] * vertices
    init_adj_table = tuple(dict() for _ in range(vertices))

    adj_table = generate_adj_table(v_info)

    res = bellman_ford()
    for ele in res:
        if isinf(ele):
            print('INF')
        else:
            print(ele)

Measured memory_bytes: 8480
/************************************************
*Author        :  lrj124
*Created Time  :  2018.12.02.20:14
*Mail          :  1584634848@qq.com
*Problem       :  c
************************************************/
#include <bits/stdc++.h>
using namespace std;
int n,ans;
inline void dfs(long long now) {
	if (now <= n) {
		int tmp = now,f1=0,f2=0,f3=0;
		while(tmp) { int x = tmp%10;tmp/=10;if(x==3)f1=1;if(x==5)f2=1;if(x==7)f3=1;}
	if (f1&&f2&&f3)ans++;
	}
	else return;
	dfs(now*10+3),dfs(now*10+7),dfs(now*10+5);
}
int main() {
	scanf("%d",&n);
	dfs(0);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
def main():
    n,m=map(int,input().split(' '))
    a = []
    b = []
    ans = True
    for i in range(n):
        a.append(list(input()))
    for i in range(m):
        b.append(list(input()))
    for i in range(n-m+1):
        for j in range(n-m+1):
            if a[i][j:j+m] == b[0]:
                for k in range(m):
                    if a[i+k][j:j+m] != b[k]:
                        ans = False
                if ans == True:
                    print('Yes')
                    exit()
                ans = True

    print('No')

if __name__ == '__main__':
    main()

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

int main()
{
  int n;
  cin >> n;
  set<int> st;
  bool ans = false;
  for (int i = 0; i < n; i++)
  {
    ll a;
    cin >> a;
    auto res = st.insert(a);
    ans = res.second;
    if (!ans)
    {
      break;
    }
  }
  if (ans)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 12972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e11
int main(){
    ll n,m;
    cin>>n>>m;
    vector<vector<int>>island(n+1);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        island[a].push_back(b);
    }
    bool ans=false;
    for(auto x:island[1]){
        for(auto y:island[x]){
            if(y==n){
                ans=true;
            }
            if(ans)break;
        }
        if(ans)break;
    }
    if(ans)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 8576
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)1e6 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;


int a[N];

void solve() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int u, v;
        scanf("%d %d", &u, &v);
        --u;
        --v;
        if (u > v) {
            swap(u, v);
        }
        ++a[u];
        ++a[v];
    }
    for (int i = 0; i < n; ++i) {
        if (a[i] % 2) {
            printf("NO\n");
            return;
        }
    }
    printf("YES\n");
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

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

char a[5][5];

int main()
{
	for(int i = 1; i <= 3; i++)
		for(int j = 1; j <= 3; j++){
			cin >> a[i][j];
		}
		cout << a[1][1] << a[2][2] << a[3][3] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <iterator>
#include <stack>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pub(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define forit0(i,n) for(ll i =0;i<n;i++)
#define forit(i,l,r) for(ll i =l;i<=r;i++) // run in inclusive range [l to r]
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} // array output macro 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];} //array input macro
#define getl(s) getline(cin,s);

ll dp[102][100002];
ll knpsck(vector<ll>&wt,vector<ll>&val,ll w,ll n){
    if(w==0 || n==0){
        return 0;
    }
    if(dp[n][w]!=-1){
        return dp[n][w];
    }
    if(wt[n-1]<=w){
        return dp[n][w] = max((val[n-1]+knpsck(wt,val,w-wt[n-1],n-1)),(knpsck(wt,val,w,n-1)));
    }
    return dp[n][w] = knpsck(wt,val,w,n-1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w;
    cin>>n>>w;
    vector<ll>wt;
    vector<ll>val;
    memset(dp,-1,sizeof(dp));
    for(ll i =0;i<n;i++){
        ll w,v;
        cin>>w>>v;
        wt.pub(w);
        val.pub(v);
    }
    knpsck(wt,val,w,n);
    cout<<dp[n][w];
    return 0;
}


Measured memory_bytes: 83244
import sys
import numpy as np
from heapq import heappop, heappush

# A* algorithm (Dijikstraの発展形) を使う
# Dijikstraでは始点からの距離が短い頂点から探索していくが、A*は終点からの距離が近い頂点から順に探索していくので計算量は少なくなる傾向にある。
# ただしA* algorithm では予め終点までの推定距離が分かっている必要がある。
def main():
    H, W = map(int, sys.stdin.readline().split())

    grid = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)], dtype='U')
    grid = np.pad(grid, 1, mode='constant')
    # atcoderではnp.pad() のargにconstant_valuesを指定できないみたい

    
    i = j = 1 # start
    c = 0     # real cost
    h = (H - 1) + (W - 1) # goalまでの推定cost 
    s = c + h # score
    q = [] # open list
    heappush(q, (s, c, i, j))
    visited = set() # closed list
    
    # 今回は最短距離を求めれば良いので必要ないが、最短経路を求める場合には親nodeの記録が必要
    # parent = [[None] * (W + 1) for _ in range(H+1)]

    can_go = False
    while q:
        s, c, i, j = heappop(q)
        visited.add((i, j))
        if c == s: 
            can_go = True
            break
        for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
            y = i + dy
            x = j + dx
            if grid[y][x] == '.' and not (y, x) in visited:
                visited.add((y, x))
                # parent[y][x] = (i, j)
                h = (H - y) + (W - x)
                s = h + c + 1
                heappush(q, (s, c+1, y, x))
 
    if can_go:
        ans = np.sum(grid == '.') - (c + 1)
    else:
        ans = -1
    print(ans)

    
    # 経路も求める場合はこんな感じ
    # i, j = H, W
    # res = [(H, W)]
    # while parent[i][j]:
    #     i, j = parent[i][j]
    #     res.append((i, j))
    # res = list(reversed(res))
    # print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 12548
#include <stdio.h>
int main (){
  int numi,num,x,y,w,h,n,i,j,catx[100],caty[100];
  scanf("%d",&num);
  for(numi=0;numi<num;numi++){
    scanf("%d %d %d %d",&x,&y,&w,&h);
    scanf("%d",&n);
    
    for (i=0;i<n;i++){
      scanf("%d %d",&catx[i],&caty[i]);
    }

    j=0;
    for(i=0;i<n;i++){
      if (catx[i]>=x && caty[i]>=y && catx[i]<=x+w && caty[i]<=y+h)j++;
    }

    printf("%d\n",j);
    
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

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

    auto calculate_count = [&] (int sign){
        ll count = 0;
        ll sum = 0;
        rep(i,n){
            int now  = a[i];
            
            if (sign*(sum + now) <= 0) now = sign*(abs(sum)+1);
            sum += now;
            count += abs(now-a[i]);

            sign *= -1;
        }
        return count;
    };

    ll ans = min(calculate_count(1), calculate_count(-1));
    cout << ans << endl;
}

Measured memory_bytes: 3960
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int N;
    cin >>N;
    int vec[N+1];
  	vec[0]=0;
    REP(i,N){
        cin>>vec[i+1];
    }
    vector<vector<int>>dp(N+1,vector<int>(2,0));
    dp[1][1]=vec[1];
    dp[2][1]=max(vec[1],vec[2]);
    for(int i=3;i<=N;i++){
        if(i%2==1){
            dp[i][0]=max(dp[i-2][0]+vec[i],dp[i-1][1]);
            dp[i][1]=dp[i-2][1]+vec[i];
        }
        else{
            dp[i][0]=max(dp[i-2][0]+vec[i],dp[i-1][0]);
            dp[i][1]=max(dp[i-2][1]+vec[i],dp[i-1][1]);
        }
    }
	cout<<dp[N][(N+1)%2]<<endl;
}


Measured memory_bytes: 15668
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define F first
#define S second
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
using namespace std;
int main()
{
   	fast
    ll n;
    cin >> n;
    cout << n*n <<"\n";
    return 0;
}


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

#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to));
#define sort(a) sort(a.begin(), a.end())

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

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

  cout << a * b - 1 * (a + b) + 1 << endl;
}

Measured memory_bytes: 256
// AOJ 2618: Trip to Kyoto
// 2018.1.25 bal4u@uu

#include <stdio.h>

#define ABS(a)    ((a)>=0?(a):-(a))
#define MIN(a,b)  ((a)<=(b)?(a):(b))

int x1[10002], y1[10002], x2[10002], y2[10002];
char *msg[2] = { "%d.0\n", "%d.5\n" };

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int calc(int x1, int y1, int x2, int y2)
{
	x1 += 200000000, y1 += 200000000;
	x2 += 200000000, y2 += 200000000;
	if (x1%20 == 0 && x2%20 == 0) {
		if      (x1 == x2) return ABS(y1-y2);
		else if (y1/20 == y2/20) return ABS(x1-x2) + MIN(y1%20+y2%20, 40-y1%20-y2%20);
	} else if (y1%20 == 0 && y2%20 == 0) {
		if      (y1 == y2) return ABS(x1-x2);
		else if (x1/20 == x2/20) return ABS(y1-y2) + MIN(x1%20+x2%20, 40-x1%20-x2%20);
	}
	return ABS(x1-x2) + ABS(y1-y2);
}

int main()
{
	int n, x, y, i, j, k, s, t, ans;
	int xmin, xmax, ymin, ymax;
	int x0, y0;

	n = in();
	x = in() << 1, y = in() << 1;
	x1[0] = x, y1[0] = y, xmin = xmax = x2[0] = x+y, ymin = ymax = y2[0] = x-y;
	for (i = 1; i < n; i++) {
		x = in() << 1, y = in() << 1;
		x1[i] = x,   y1[i] = y;
		x2[i] = x+y, y2[i] = x-y;
		if      (x2[i] < xmin) xmin = x2[i];
		else if (x2[i] > xmax) xmax = x2[i];
		if      (y2[i] < ymin) ymin = y2[i];
		else if (y2[i] > ymax) ymax = y2[i];
	}
 
	x = (xmin + xmax) >> 1, y = (ymin + ymax) >> 1;
	x0 = (x + y) >> 1, y0 = (x - y) >> 1;

	ans = 0x7fffffff;
	for (i = x0-30; i <= x0+30; i++) {
		for (j = y0-30; j <= y0+30; j++) {
			if (i%20 && j%20) continue;
			t = 0; for (k = 0; k < n; k++) if (t < (s = calc(i, j, x1[k], y1[k]))) t = s;
			if (ans > t) ans = t;
		}
	}
	printf(msg[ans & 1], ans >> 1);
	return 0;
}


Measured memory_bytes: 2080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    if(n==1 && m==1){
        cout << 1 << endl;
    }
    else if(n==1 || m==1){
        cout << max(n,m)-2 << endl;
    }
    else cout << (n-2)*(m-2) << endl;



    return 0;
}

Measured memory_bytes: 256
hs = Array.new(2) { Hash.new(0) }
hs[0][0] = 0
hs[1][0] = 0
# => [{0=>0}, {0=>0}]
# この初期化によりハッシュ数（2）を保証する

N = gets.strip.to_i
gets.strip.split.map(&:to_i).each_with_index do |n, i|
  hs[i%2][n] += 1
end

e = hs[0].sort_by { |_, v| -v }
o = hs[1].sort_by { |_, v| -v }

if e[0][0] != o[0][0]
  n = e[0][1] + o[0][1]
else
  n = [e[0][1] + o[1][1], e[1][1] + o[0][1]].max
end
puts N - n


Measured memory_bytes: 20704
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, p, l2, l1, r1, r2, res = 0;
    cin>>n;
    int index[111111];
    rep(i, n) {
        cin>>p;
        index[p] = i;
    }
    multiset<int> s;
    s.insert(-1);
    s.insert(-1);
    s.insert(n);
    s.insert(n);
    rev(i, n + 1, 1) {
        auto now = s.lower_bound(index[i]);
        r1 = *now;
        r2 = *++now;
        l1 = *----now;
        l2 = *--now;
        res += ((l1 - l2) * (r1 - index[i]) + (r2 - r1) * (index[i] - l1)) * i;
        s.insert(index[i]);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 5760
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)
using namespace std;

#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

int main(void) {
	int N;
	vector<string> S;
	vector<vector<int>> counts;
	cin >> N;
	S.resize(N);
	counts.resize(N);
	REP(i, N) counts[i].resize(26);
	REP(i, N) {
		cin >> S[i];
	}
	REP(i, N) {
		sort(S[i].begin(), S[i].end());
	}
	REP(i, N) {
		char ch = '-';
		int count = 0;
		REP(j, S[i].size()) {
			if (S[i][j] == ch) count++;
			else {
				if (ch != '-') counts[i][ch - 'a'] = count;
				ch = S[i][j]; count = 1;
			}
		}
		counts[i][ch - 'a'] = count;
	}
	for (char c = 'a'; c <= 'z'; c++) {
		int min_count = 100;
		REP(i, N) min_count = min(min_count, counts[i][c - 'a']);
		REP(i, min_count) cout << c;
	}
	cout << endl;
	return 0;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  for (int i=0 ; ; i++){
    c -= b;
    if (c <= 0){
      cout << "Yes" << endl;
      break;
    }
    a -= d;
    if (a <= 0){
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
  string S;
  cin >> S;
  int scale;
  scale = S.size();
  rep(i,0,scale){
      cout << 'x' ;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int compare(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}

int maxsiumai(int n, int a[n]){
    qsort(a,n,sizeof(a[n]),compare);
    return a[n-1];
}


int main(void){
    int n,i,j;
    scanf("%d",&n);
    int a[n],b[n],c[n],h[n][3],smax[3],maxh;

    /*h[k-1][x] k日目にxを選んだ時にのmax累計幸福度 */

    for(i=0;i<n;i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
    }
    for(i=0;i<n;i++){
        for(j=0;j<3;j++){
            h[i][j]=0;
        }
    }


    for(i=0;i<n;i++){

        if(i==0){
            h[i][0]=a[i];
            h[i][1]=b[i];
            h[i][2]=c[i];
            continue;
        }
        
        smax[2] = 0;

        smax[0] = h[i-1][1];
        smax[1] = h[i-1][2];
        h[i][0] = a[i] + maxsiumai(2,smax);

        smax[0] = h[i-1][0];
        smax[1] = h[i-1][2];
        h[i][1] = b[i] + maxsiumai(2,smax);

        smax[0] = h[i-1][0];
        smax[1] = h[i-1][1];
        h[i][2] = c[i] + maxsiumai(2,smax);      
    }

    smax[0] = h[n-1][0];
    smax[1] = h[n-1][1];
    smax[2] = h[n-1][2];

    maxh = maxsiumai(3,smax);

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

    return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <string>
#include <list>
using namespace std;

    
int main(){
    int A,B;
    cin>>A>>B;
    int b=B*10,e=(B+1)*10;
    int i;
    for (i=b; i<e; i++) {
        if ((int)(i*0.08)==A&&(int)(i*0.1)==B) {
            break;
        }
    }
    if (i==e) {
        cout<<-1<<endl;
    }else{
        cout<<i<<endl;
    }
    return 0;
}


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

const int N = 55;

int sa[N], ta[N];

int main () {
  string s, t; cin >> s >> t;
  if (t.size() > s.size()) {
    cout << "UNRESTORABLE\n";
  } else {
    bool ans = false;
    for (int i = s.size()-t.size(); i >= 0 ; i--) {
      bool ok = true;
      string temp = s;
      for (int j = 0; j < t.size(); j++) {
        ok &= (s[i+j] == t[j] or s[i+j] == '?' ? 1 : 0);
        temp[i+j] = t[j];
      }
      if (ok) {
        for (int j = 0; j < s.size(); j++) {
          cout << (temp[j] == '?' ? 'a' : temp[j]);
        }
        cout << endl;
        ans = true;
        break;
      }
    }
    if (not ans) cout << "UNRESTORABLE\n";
  }
  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

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

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

ll fac(int n) {
  ll ret = 1ll;
  for (int i = 1; i <= n; i++) { ret = ret * i % 1000000007ll; }
  return ret;
}

void solve() {
  int N;
  cin >> N;
  vector<int> a(N);
  cin >> a;
  auto dp = vect(N + 1, vect(10, -INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 10; j++) {
      if (dp[i][j] == -INF) continue;
      chmax(dp[i + 1][j], dp[i][j]);
      chmax(dp[i + 1][(j + a[i]) % 10], dp[i][j] + a[i]);
    }
  }
  cout << max(0, *max_element(dp[N].begin() + 1, dp[N].end())) << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdlib>

using namespace std;

int main()
{
   int a,b,x;
   cin>>a>>b>>x;
   if(a==x)
    cout<<"YES"<<endl;
    else if(a>x)
        cout<<"NO"<<endl;
   else if(a+b>=x)
    cout<<"YES"<<endl;
   else if(a+b<x)
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n,x,r=1<<29;
    for(scanf("%d",&n);n--;){
        int r0=0;
        scanf("%d",&x);
        for(;x%2<1;x/=2)r0++;
        if(r>r0)r=r0;
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main() {
    long long x, y;
    cin >> x >> y;
    long long num = x;
    long long count = 1;
    while (true) {
        if (num * 2 <= y) {
            num *= 2;
            count++;
        }
        else goto next;
    }
    next:
    cout << count << endl;
}

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

class Program
{
  /// <summary>
  ///   The main entry point for the application
  /// </summary>
  [STAThread]
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    int[] l = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    Array.Sort(l);
    int sum = l.Where((a, i) => i % 2 == 0).Sum();
    Console.WriteLine(sum);
  }
}


Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <set>

using namespace std;

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

	set<string> ss;

	for (int i = 0; i < (int)s.size(); i++) {
		for (int j = 1; j <= k; j++) {
			if (i + j > (int)s.size()) break;
			ss.insert(s.substr(i, j));
		}
	}
	cout << *next(ss.begin(), k - 1) << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
typedef long long ll;
typedef long double ld;
 
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()

#define N 500001

typedef struct Query
{
	int l, r, idx;
}query;
int block;

bool cmp(query a, query b)
{
	if(a.l/block != b.l/block) return a.l/block < b.l/block;
	return a.r < b.r;
}

int ans[N], c[N], cnt[N];
query q[N];
int main()
{
	fastIO;
	int n, m; cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> c[i];
	block = (int)sqrt(n);
	for(int i = 0; i < m; i++) cin >> q[i].l >> q[i].r, q[i].idx = i;
	sort(q,q + m,cmp);

	int l = 0, r = -1, temp = 0;
	for(int i = 0; i < m; i++)
	{
		int ql = q[i].l - 1, qr = q[i].r - 1;
		while(r < qr) temp += !cnt[c[++r]]++;
		while(r > qr) temp -= !--cnt[c[r--]];
		while(l < ql) temp -= !--cnt[c[l++]];
		while(l > ql) temp += !cnt[c[--l]]++;
		ans[q[i].idx] = temp;
	}
	for(int i = 0; i < m; i++) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 15440
#pragma GCC optimize ("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
 
const int maxN = 1 << 21;
 
 
void solve()
{
	int a, b, c, d;
	char in[5];
	scanf ("%s", in);
	
	printf("%s\n", (in[0] == '7' or in[1] == '7' or in[2] == '7' ? "Yes" : "No"));
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 3764
#include <iostream>

using namespace std;

int main() {
    long long X;
    cin >> X;

    long long totalAmount = 100;
    int year = 0;
    // do
    do {
        totalAmount = totalAmount + totalAmount / 100;
        ++year;
    } while (totalAmount < X);

    cout << year << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define N 1000001
using namespace std;
char S[N];
int sum[N];
int n;
long long ans;
int main(){
	scanf(" %s",S+1);
	n=strlen(S+1);
	ans=(long long)n*(n+1)/2+1-n;
	for (int i=1;i<=n;i++)sum[S[i]-'a']++;
	for (int i=0;i<26;i++)ans-=((long long)sum[i]*sum[i]-sum[i])/2;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C;long long K;
  scanf("%d%d%d%lld",&A,&B,&C,&K);
  if(K&1) printf("%d",B-A);
  else printf("%d",A-B);
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args)throws IOException {
		
		int i=0,j=0;
		int[] mount = new int[10];
		int[] h_mount = {0,0,0};
		String str;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
				
		while(i<10){
			str=new String(in.readLine());
			mount[i]=Integer.parseInt(str);
			
			if(mount[i]<0 || mount[i]>10000){
				i--;
			}
			
			i++;
		}
		
		sortMethod(mount,10);
		for(i=0;i<3;i++){
			h_mount[i]=mount[i];
			System.out.println(h_mount[i]);
		}


	}
	
	public static void sortMethod(int[] array,int num){
		int tmp;
		int x,y;
		for(x=0;x<num-1;x++){
			for(y=x+1;y<num;y++){
				if(array[x]<array[y]){
					tmp = array[x];
					array[x]=array[y];
					array[y]=tmp;
				}
			}
		}
	}

}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int n;
  string s;
  cin >> n >> s;

  re(i, n) {
    re(j, s.size()) {
      if(s[j] == 'Z') s[j] = 'A';
      else s[j]++;
    }
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> a;
  for(int i = 0; i < n; i++) {
    int tmp_a;
    cin >> tmp_a;
    auto itr = find(a.begin(), a.end(), tmp_a);
    if(itr == a.end()) {
      a.push_back(tmp_a);
    } else {
      a.erase(itr);
    }
  }

  cout << a.size() << endl;
  return 0;
}


Measured memory_bytes: 3736
using System;
class Program
{
    static void Main(string[] args)
    {
        string q01 = Console.ReadLine();
        string[] ary = q01.Split(' ');
        int i01 = Convert.ToInt32(ary[0]);
        int i02 = Convert.ToInt32(ary[1]);
        int i03 = Convert.ToInt32(ary[2]);

        int a01 = i02 > i03 ? i03 : i02;
        int a02 = i02 + i03 < i01 ? 0 : (i02 + i03) - i01;

        Console.WriteLine(a01 + " " + a02);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct BIT {
    BIT(int n) : s(n + 1), n(n) {}
    int sum(int k) {
        int r = 0;
        for (; k > 0; k -= k & -k) r += s[k];
        return r;
    }
    void add(int i, int v) {
        for (int k = i + 1; k <= n; k += k & -k) s[k] += v;
    }
    vector<int> s;
    int n;
};

struct Line {
    bool operator<(const Line& l) {
        return t < l.t;
    }
    double t;
    int16_t a, b, c;
    uint16_t j;
};

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

    int n;
    cin >> n;

    vector<Line> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i].a >> l[i].b >> l[i].c;
    }

    BIT b(n);
    int m = (n - 1) * n / 2;
    int h = (m + 1) / 2;

    for (int u = 0; u < 2; u++) {
        for (int i = 0; i < n; i++) {
            l[i].t = (double)l[i].a / l[i].b;
        }
        sort(l.begin(), l.end());

        for (int i = 0; i < n; i++) {
            l[i].j = i;
        }

        double x, x1 = 1e+9, x0 = -x1;
        while (1) {
            x = (x0 + x1) * 0.5;
            if (x1 - x0 < 1e-9 * max(abs(x), 1.0)) break;

            for (int i = 0; i < n; i++) {
                l[i].t = (l[i].c - l[i].a * x) / l[i].b;
            }
            sort(l.begin(), l.end());

            fill(b.s.begin(), b.s.end(), 0);

            int k = m;
            for (int i = 0; i < n; i++) {
                int j = l[i].j;
                k -= b.sum(j);
                b.add(j, 1);
            }
            if (k < h) x0 = x; else x1 = x;
        }

        cout << fixed << setprecision(12) << x << " \n"[u];

        if (u == 1) break;

        for (int i = 0; i < n; i++) {
            swap(l[i].a, l[i].b);
        }
    }

    return 0;
}


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

int main(){
  int a, b; cin >> a >> b;
  if((a >= 9) or (b >= 9)){
    printf("%s", ":(");
    return 0;
  }else{
    printf("%s", "Yay!");
    return 0;
  }
}

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

bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}

int main() {
    long long X;
    cin >> X;
    long long res = X;
    while (!is_prime(res)) ++res;
    cout << res << endl;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        int N = sc.nextInt();
        int A[] = new int[N];
        int B[] = new int[N];

        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            B[i] = sc.nextInt();
        }

        if(N ==1) {
            os.println("No");
            return;
        }

        int secondP = 1;

        for (int i = 0; i < N; i++) {
            if(0 < i && A[i] != A[i-1])
                secondP = 0;
            if(A[i] == B[i]){
                while(secondP < N) {
                    if(A[i] != B[secondP] && A[secondP] != B[i]) {
                        int tmp = B[i];
                        B[i] = B[secondP];
                        B[secondP] = tmp;
                        break;
                    }
                    secondP++;

                }
                if(A[i] == B[i]) {
                    os.println("No");
                    return;
                }
            }
        }
        os.println("Yes");
        for (int i = 0; i < N; i++) {
            os.print(B[i]);
            if(i < N-1)
                os.print(" ");
        }
        os.println();
    }

}

Measured memory_bytes: 60784
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}
 
using namespace std;                                                                                  
using namespace __gnu_pbds; 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;                                            
typedef pair < long long  , long long > pll ;

typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int N = 3e5 + 123;

int n, k, l;

int a[N];

main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	(pr[i] - pr[j])/(i - j) >= K
//	pr[i] - pr[j] >= K * i - K * j
//	pr[i] - K * i >= pr[j] - K * j
	ordered_set st;
	st.insert({0,0});
	cin >> n >> k;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		a[i] += a[i - 1];
		st.insert({a[i] - k * i,i});

		ans += st.order_of_key({a[i] - k * i,i});
	}	
	ret(ans);
	
	
}
 


Measured memory_bytes: 14336
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val k = sc.nextInt()

    println(abc156b(n, k))
}

private fun abc156b(n: Int, k: Int): Int {
    var count = 1
    while (true) {
        var temp = Math.pow(k.toDouble(), count.toDouble()).toInt()
        if (n < temp) return count

        count++
    }

}


Measured memory_bytes: 29604