akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int b_s(long key, vector<long> &V){
    int ok=0, ng=V.size();
    while(ok+1<ng){
        int mid=(ok+ng)/2;
        if(V[mid]<key) ok=mid;
        else ng=mid;
    }
    return ng;
}

int main() {
	int N, Q;
	long A[100010];
	cin >> N >> Q;
	for(int i=0; i<N; ++i) cin >> A[i];
	sort(A, A+N);
	long cnt=0;
	for(int i=N/2; i<N; ++i) cnt += A[i];
	int le=1-N%2, ri=N/2;
	vector<long> v(1, 0), ans(1, cnt);
	while(le<ri){
	    v.push_back((A[le]+A[ri])/2);
	    ans.push_back(cnt);
	    cnt -= A[ri]-A[le];
	    le += 2;
	    ++ri;
	}
	v.push_back(1e10);
	ans.push_back(cnt);
	for(int i=0; i<Q; ++i){
	    long X; cin >> X;
	    cout << ans[b_s(X, v)] << endl;
	}
	// for(int i=0; i<v.size(); ++i) cout << v[i] << ' ' << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 3444
def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 998244353
    ans = 0
    dp = [0]*S

    for i, a in enumerate(A):
        if a > S:
            continue
        dp[0] = i+1
        ans += dp[S-a]*(N-i)

        for j, x in enumerate(dp[:S-a]):
            dp[j+a] += x
    print(ans % mod)


main()


Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    cout << (n - 2) * 180 << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
alpha = "abcdefghij"
ans = []
N = int(input())

def get_right(S):
    alpha_idx = 0
    for i in range(len(S)):
        flag = S.find(alpha[i])
        if flag > 0:
            alpha_idx = i
    return alpha_idx + 2


def dfs(S, num):
    if len(S) == N:
        ans.append(S)
    else:
        right = num + 2
        seq = alpha[:right]
        for i, c in enumerate(seq):
            dfs(S+c, max(i, num))

dfs("a", 0)
ans = sorted(ans)
for a in ans:
    print(a)

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

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  vector<long long> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  vector<long long> forward(N);
  for (int i = 0; i < N; ++i) {
    if (i == 0)
      forward[i] = a[i];
    else
      forward[i] = a[i] + forward[i - 1];
  }

  vector<long long> backward(N);
  for (int i = N - 1; i >= 0; --i) {
    if (i == N - 1)
      backward[i] = a[i];
    else
      backward[i] = a[i] + backward[i + 1];
  }

  long long ret = 10000000000;
  for (int i = 0; i < N - 1; ++i) {
    ret = min(ret, abs(forward[i] - backward[i + 1]));
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int p,a,b,i,n;
	cin>>n;
	a=0;
	b=0;
	for(i=0;i<n;i++){
		cin>>p;
		a=a+p;
		if(b<p) b=p;
	}
	a=a-b/2;
	cout<<a<<endl;
	return 0;
}

	

Measured memory_bytes: 256
from functools import reduce

N, X = map(int, input().split())
delta_x = [abs(int(i)-X) for i in input().split()]


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
def gcd_list(numbers):
    return reduce(gcd, numbers)

print(gcd_list(delta_x))

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

int main(){
	string S;
	cin >> S;
	if(S=="Sunny"){
		cout << "Cloudy" << endl;
	} else if(S=="Cloudy"){
		cout << "Rainy" << endl;
	} else {
		cout << "Sunny" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
#include <bitset>
using namespace std;
int main(){
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if(u == t) cout << a << " " << b -1 << endl;
    else if(u == s) cout << a-1 << " " << b << endl;
    else cout << a << " "<< b << endl;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int h,w;
  cin>>h>>w;
  int ch,cw,dh,dw;
  cin>>ch>>cw>>dh>>dw;
  ch--;cw--;dh--;dw--;
  char s[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>s[i][j];
    }
  }
  queue<int> memo1,memo2;
  memo1.push(ch);memo1.push(cw);
  int ans[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      ans[i][j]=-1;
    }
  }
  ans[ch][cw]=0;
  int dy[4]={1,0,-1,0},dx[4]={0,1,0,-1};
  int now=0;
  while(!memo1.empty()){
    int y=memo1.front();memo1.pop();
    int x=memo1.front();memo1.pop();
    memo2.push(y);memo2.push(x);
    for(int i=0;i<4;i++){
      int ny=y+dy[i],nx=x+dx[i];
      if(ny<0 or ny>=h or nx<0 or nx>=w) continue;
      if(s[ny][nx]=='#') continue;
      if(ans[ny][nx]<0){
        ans[ny][nx]=now;
        memo1.push(ny);memo1.push(nx);
      }
    }
    if(memo1.empty()){
      now++;
      while(!memo2.empty()){
        int by=memo2.front();memo2.pop();
        int bx=memo2.front();memo2.pop();
        for(int i=-2;i<=2;i++){
          for(int j=-2;j<=2;j++){
            int cy=by+i,cx=bx+j;
            if(cy<0 or cy>=h or cx<0 or cx>=w) continue;
            if(s[cy][cx]=='#') continue;
            if(ans[cy][cx]<0){
              ans[cy][cx]=now;
              memo1.push(cy);memo1.push(cx);
            }
          }
        }
      }
    }
  }
  cout<<ans[dh][dw]<<endl;
  return 0;
}


Measured memory_bytes: 8504
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
count = 0

if x < a[0]:
    print(0)
    exit()

for i in range(N):
    if x >= a[i]:
        x = x - a[i]
        count += 1
    else:
        print(count)
        exit()
if x > 0:
    print(count - 1)
else:
    print(count)

Measured memory_bytes: 9144
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jignesh1604
 */

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

class CGoToSchool {
public:
	void solve(std::istream& in, std::ostream& out) {
	    long long int n , i;
	    in >> n;
	    long long int a[n+1] , ans[n+1];
	    for(i = 1 ; i <= n ; i++) {
	        in >> a[i];
	        ans[a[i]] = i;
	    }
        for(i = 1 ; i <= n ; i++) {
            out << ans[i] << " ";
        }
	}
};


int main() {
	CGoToSchool solver;
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007

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

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

void f()
{
  int a,b;
  cin>>a>>b;
  cout<<max(a+b,max(2*a-1,2*b-1))<<nl;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3656
using System;

namespace I___Coins
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var probs = Array.ConvertAll(Console.ReadLine().Split(' '), decimal.Parse);
            var DP = new decimal[N + 1, 2 * N + 1];
            DP[1, N + 1] = probs[0];
            DP[1, N - 1] = 1 - probs[0];

            for (int i = 1; i < N; i++)
            {
                for (int j = N - i; j <= N + i; j++)
                {
                    DP[i + 1, j + 1] += DP[i, j] * probs[i];
                    DP[i + 1, j - 1] += DP[i, j] * (1 - probs[i]);
                }
            }
            decimal result = 0;
            for (int i = N; i <= 2 * N ; i++) result += DP[N, i];

            Console.WriteLine(result);
        }
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int max = A > B ? A : B;
  if(max*2 <= 16) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
A,B=map(int,input().split())
S=[2,3,4,5,6,7,8,9,10,11,12,13,1]
if S.index(A)==S.index(B):
  print("Draw")
elif S.index(A)>S.index(B):
  print("Alice")
else:
  print("Bob")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>=(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;


int main(void){
	short N,Ma,Mb;
	cin >> N >> Ma >> Mb;
	VI a(N),b(N),c(N);

	REP(i,N){
		cin >> a[i] >> b[i] >> c[i];
	}


	long h = MAX(a)*N;
	long w = MAX(b)*N;

	VVI dp(h+1,VI(w+1,loINF));
	dp[0][0] = 0;

	REP(i,N){
		RFOR(j,h,a[i]){
			RFOR(k,w,b[i]){
				if (dp[j-a[i]][k-b[i]] != loINF){
					dp[j][k] = min(dp[j-a[i]][k-b[i]]+c[i],dp[j][k]);
				}
			}
		}
	}

	//dump2d_arr(dp);

	long ans =  loINF;

	for (long i = 1; i * Ma < h && i * Mb < w;i++){
		if (dp[i*Ma][i*Mb] != loINF) ans = min(ans,dp[i*Ma][i*Mb]);
	}

	if (ans == loINF) cout << (-1) << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <stdlib.h>
#include <string>
#define N 1000
using namespace std;

int main()
{
  int sum=0;
  string s;
  while(1)
    {
      cin >> s;
      if(s=="0") break;
      for(int i=0;i<s.size();i++)
        {
          sum+=s[i]-'0';   //??¢????????????????????§?????????????????????                     
        }
      cout << sum << endl;
      sum=0;
    }
  return 0;
}

Measured memory_bytes: 3220
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n, d, x;
	scanf("%d %d %d", &n, &d, &x);
	rep(i, 0, n){
		int a;
		scanf("%d", &a);
		x += 1 + (d-1)/a;
	}
	printf("%d\n", x);
	return 0;
}


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

public class Main {
    char[] cs;
    long allSum = 0;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        cs = sc.next().toCharArray();
        solve();
    }

    void solve() {
        dfs(0, 0, 0);
        System.out.println(allSum);
    }

    void dfs(int pointer, long sum, long rem) {
        if (pointer == cs.length - 1) {
            allSum += sum + Character.getNumericValue(cs[pointer]) + rem * 10;
            return;
        }
        int num = Character.getNumericValue(cs[pointer]);
        dfs(pointer + 1, sum + rem * 10 + num, 0);
        dfs(pointer + 1, sum, rem * 10 + num);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21332
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1e9
using namespace std;

const int maxn = 110;
const int maxp = 1100;
const int maxm = 110000;

int n,m;
struct edge{int y,c,nex;}a[maxm]; int len,fir[maxp],fi[maxp];
inline void ins(const int x,const int y,const int c){a[++len]=(edge){y,c,fir[x]};fir[x]=len;}

int st,ed;
int h[maxp];
queue<int>q;
bool bfs()
{
	for(int i=1;i<=ed;i++) h[i]=0;
	h[st]=1; q.push(st);
	while(!q.empty())
	{
		const int x=q.front(); q.pop();
		for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y)
			if(!h[y]&&a[k].c) h[y]=h[x]+1,q.push(y);
	}
	return h[ed]>0;
}
int dfs(const int x,const int flow)
{
	if(x==ed) return flow;
	int delta=0;
	for(int &k=fi[x],y=a[k].y;k&&delta<flow;k=a[k].nex,y=a[k].y) if(h[y]==h[x]+1&&a[k].c)
	{
		int mk=dfs(y,min(a[k].c,flow-delta));
		delta+=mk;
		a[k].c-=mk; a[k^1].c+=mk;
	}
	if(!delta) h[x]=0;
	return delta;
}
int Flow()
{
	int re=0;
	while(bfs()) 
	{
		for(int i=1;i<=ed;i++) fi[i]=fir[i];
		re+=dfs(st,inf);
	}
	return re;
}

int rec[maxn][maxn],sx,sy,ex,ey;
char str[maxn];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",str);
		for(int j=0;j<m;j++)
		{
			if(str[j]=='o') rec[i][j+1]=1;
			else if(str[j]=='S') sx=i,sy=j+1;
			else if(str[j]=='T') ex=i,ey=j+1;
		}
	}
	if(sx==ex||sy==ey) return puts("-1"),0;
	
	len=1;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(rec[i][j])
	{
		ins(i,n+j,1); ins(n+j,i,1);
	}
	st=n+m+1,ed=st+1;
	ins(st,sx,inf); ins(st,n+sy,inf);
	ins(ex,ed,inf); ins(n+ey,ed,inf);
	printf("%d\n",Flow());
	
	return 0;
}


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

// header area

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

    int count = 0;
    rep(i, N-2){
        if(S.substr(i, 3)=="ABC"){
            count++;
        }
    }

    cout << count << endl;


    return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k,r,s,p;
    string t;
    cin >> n >> k;
    cin >> r >> s >> p;
    cin >> t;
    vector<ll> syu[k];
    ll ten[3];
    ten[0]=p;
    ten[1] = r;
    ten[2] = s;
    rep(i,0,t.size()){
        if(t[i]=='r') syu[i%k].push_back(0);//0=p
        if(t[i]=='s')  syu[i%k].push_back(1);//1=r
        if(t[i]=='p')  syu[i%k].push_back(2);//2=s
    }
    ll sum = 0;
    bool ok = true;
    rep(i,0,k){
        sum += ten[syu[i][0]];
        ok = false;
        rep(j,1,syu[i].size()){
            if(syu[i][j-1] == syu[i][j] && !ok){
                ok = true;
                continue;
            }
            sum += ten[syu[i][j]];
            ok = false;
        }
    }
    cout <<sum << endl;

}

Measured memory_bytes: 5200
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    
    ans = 10 ** 9
    for i in range(N):
        cnt = 0
        ai = A[i]
        while 1:
            if ai % 2 == 0:
                ai //= 2
                cnt += 1
            else:
                break
        ans = min(ans, cnt)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <iostream>

int main(){
  int x, y, z;
  std::cin >> x;
  std::cin >> y;
  std::cin >> z;
  
  if(x < y && y < z) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<int> v;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int nr;
        cin >> nr;
        v.push_back(nr);
    }
    if (n < 3) {
        cout << 0;
        return 0;
    }

    sort(v.begin(), v.end());
    v.push_back(0);
    int total = 0, lastj = 0, lasti = 0;
    for (int i = 0; i < v.size() - 3; i++) {
        if (i > 0) {
            if (v[i] == v[i - 1]) {
                total += lasti;
                continue;
            } else {
                lasti = 0;
            }
        }
        for (int j = i + 1; j < v.size() - 2; j++)
            if (v[i] != v[j]) {
                if (v[j] == v[j - 1]) {
                    total += lastj;
                    lasti += lastj;
                    continue;
                }
                int st = j + 1, dr = v.size() - 2;
                while (v[st] == v[st - 1] && st <= dr)
                    st++;
                if (st > dr) {
                    lastj = 0;
                    continue;
                }
                int ini_st = st;

                while (st < dr) {
                    int mij = (st + dr) / 2;
                    if (v[i] + v[j] > v[mij])
                        st = mij + 1;
                    else
                        dr = mij;
                }
                while (v[i] + v[j] <= v[st])
                    st--;

                total += max(0, st - ini_st + 1);
                lastj = max(0, st - ini_st + 1);
                lasti += lastj;
            }
    }

    cout << total;
    return 0;
}


Measured memory_bytes: 3636
import math
def keisan(a):
    return math.floor(a*0.08),math.floor(a*0.10)

A,B = map(int, input().split())
b = B*10
while b<1001:
    tempa,tempb = keisan(b)
    if tempa == A and tempb == B:
        print(b)
        exit()
    b += 1
print(-1)

Measured memory_bytes: 3064
using System;
using static System.Console;

namespace abc175
{
    class Program
    {
        static long[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new long[0];
            }
            var numList = new long[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = long.Parse(line[i]);
            }
            return numList;
        }
        static void Main()
        {
            var n = int.Parse(ReadLine());
            var lList = ReadNumList();
            var count = 0;
            for (var i = 0; i < n - 2; ++i)
            {
                for (var j = i + 1; j < n - 1; ++j)
                {
                    if (lList[i] == lList[j])
                    {
                        continue;
                    }
                    for (var k = j + 1; k < n; ++k)
                    {
                        if (lList[i] == lList[k] || lList[j] == lList[k])
                        {
                            continue;
                        }
                        if ((lList[i] + lList[j]) > lList[k] &&
                            (lList[j] + lList[k]) > lList[i] &&
                            (lList[k] + lList[i]) > lList[j])
                        {
                            ++count;
                        }
                    }
                }
            }
            WriteLine(count);
        }
    }
}


Measured memory_bytes: 27468
//https://atcoder.jp/contests/abc150/tasks/abc150_b
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n , count = 0, pos = 0, index ;
    string s , s1 ="ABC" ;
    cin >> n >> s ;
    while( (index = s.find(s1, pos)) != string::npos)
    {
        count ++;
        pos = index + 1 ;
    }
    cout << count << endl ;
    // for(int x = 0 ; x < s.size() ; x++)
    // {
    //     if(s[x] == 'A' and s[x + 1] == 'B' and s[x + 2] == 'C')
    //     {
    //         count++;
    //     }
    // }
    // cout << count << endl ;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int dp[3005][3005];
main()
{
   char s[3005],t[3005];
   cin>>s;
   cin>>t;
   int i,j,l1,l2;
   l1=strlen(s);l2=strlen(t);
   for(i=1;i<=l1;i++)
   {
       for(j=1;j<=l2;j++)
       {
           if(s[i-1]==t[j-1])
           {
               dp[i][j]=dp[i-1][j-1]+1;
           }
           else
           {
               dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           }
       }
   }
   //cout<<dp[l1][l2];
   /*for(i=0;i<=l1;i++)
   {
       for(j=0;j<=l2;j++)
       {
           cout<<dp[i][j]<<" ";
       }
       cout<<endl;
   }*/
   char ans[3055];int k1=0;
   int a=l1,b=l2;
   while(1)
   {
       if(a==0 || b==0)break;
       if(dp[a][b]==dp[a-1][b-1]+1 && s[a-1]==t[b-1])
       {
           ans[k1]=s[a-1];k1++;a--;b--;
       }
       else
       {
           if(dp[a-1][b]==dp[a][b])
           {
               a--;
           }
           else
           {
               b--;
           }
       }
   }
   //cout<<ans<<endl;
   for(i=k1-1;i>=0;i--)
   {
       printf("%c",ans[i]);
   }
   cout<<endl;
}


Measured memory_bytes: 38740
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Maximize(m, x) m = max(m, x)
#define Minimize(m, x) m = min(m, x)

// constexpr int MOD = 1e9+7;

using P = pair<int, int>;
#include <map>

int main(void){
    Cin(int, n, ma, mb);
    int n1 = min(17, n), n2 = n - n1;
    Cins3(int, n1, a1, b1, c1);
    Cins3(int, n2, a2, b2, c2);
    
    constexpr int Inf = 1e9;
    Vec2(int, 401, 401, p2);
    For(i, 401) For(j, 401) p2[i][j] = Inf;
    For(d, 1 << n2){
        int a = 0, b = 0, c = 0;
        For(i, n2) if(d & (1 << i)) a += a2[i], b += b2[i], c += c2[i];
        Minimize(p2[a][b], c);
    }
    int ans = Inf;
    For(d, 1 << n1){
        int a = 0, b = 0, c = 0;
        For(i, n1) if(d & (1 << i)) a += a1[i], b += b1[i], c += c1[i];
        for(int k = 1; k*ma <= 400 && k*mb <= 400; k ++){
            if(0 <= k*ma - a && k*ma - a <= 400 && 0 <= k*mb - b && k*mb - b <= 400){
                Minimize(ans, c + p2[k*ma-a][k*mb-b]);
            }
        }
    }
    Cout(ans == Inf ? -1 : ans);
}


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

int main(){
  int n,i;
  char s;
  vector<int> cnt(30,1);
  cin >> n;
  for(i=0;i<n;i++){
    cin >> s;
    cnt[s-97]++;
  }
  long long ans=1;
  for(i=0;i<30;i++){
    ans=(ans*cnt[i])%1000000007;
  }
  cout << ans - 1 << endl;
}

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

int main(){
  string S;
  cin >> S;
  int counter = 0;
  if(S[0] == 'o') ++counter;
  if(S[1] == 'o') ++counter;
  if(S[2] == 'o') ++counter;
  int total = 700 + 100*counter;
  cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>


int main(){
  int i,j,N,factN;
  double L_total = 0;
  double x[8];
  double y[8];

  std::cin >> N;

  for(i=0;i<N;i++){
  std::cin >> x[i] >> y[i];
  }

factN = 0;
  for(i=0;i<N;i++){
    for(j=0;j<i;j++){
      L_total += std::sqrt((x[j] - x[i])*(x[j] - x[i]) + (y[j] - y[i])*(y[j] - y[i]));
        factN += 1;
        }
  }

factN = factN*(N-1);
L_total = (N-1)*(N-1)*L_total;

L_total = L_total/(double)factN;


std::cout << std::setprecision(15);
  std::cout << L_total << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
def worstdata():
    a=0
    return a
#solution:
def vacation(N,act):
    lastact =[]
    dp=[0,max(act[0])]*(N+1) #[i]日目のActivity で得られる最大幸福量
    
    return 0

#input


N,T=pin()
timing=list(pin())

ans=0
for i in range(N):
        if i!=(N-1):ans+=min(timing[i+1]-timing[i],T)
        else:ans+=T
print(ans)
#output
#print(solution(H,N))
#print(["No","Yes"][cond])



Measured memory_bytes: 116204
y,x=map(int,input().split())
var = []
for n in range(y):
    var.append(list(map(int,input().split())))
temp = []
for n in range(x):
    temp.append(int(input()))
for n in range(y):
    num = 0
    for m in range(x):
        num+=var[n][m]*temp[m]
    print(num)


Measured memory_bytes: 6012
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int plen, cnum, width, cspace;
char res[128][64], line[1024];

int main(){
  while(scanf("%d", &plen) && plen){
    scanf("%d%d%d", &cnum, &width, &cspace);

    //    fill(res[0][0], res[4098][63], '.');
    rep(i, plen){
      rep(j, cnum * width + cspace * (cnum-1)) res[i][j] = '.';
      res[i][cnum * width + cspace * (cnum-1)] = '\0';
    }

    int p = 0, c = 0;
    fgets(line, sizeof(line), stdin);
    while(1){
      fgets(line, sizeof(line), stdin);
      if(line[0] == '?') break;
      line[strlen(line)-1] = '\0';
      //      printf("%d %d %d\n", (int)strlen(line), p, c);
      if(p == plen){ c++; p = 0;}
      if(c == cnum){
	rep(i, plen) printf("%s\n", res[i]);
	puts("#");
	p = c = 0;
	rep(i, plen) rep(j, cnum * width + cspace * (cnum-1)) res[i][j] = '.';
      }
      rep(i, strlen(line)){
	if(i && i%width == 0) p++;
	if(p == plen){ c++; p = 0;}
	if(c == cnum){
	  rep(i, plen) printf("%s\n", res[i]);
	  puts("#");
	  p = c = 0;
	  rep(i, plen) rep(j, cnum * width + cspace * (cnum-1)) res[i][j] = '.';
	}
	res[p][c*width+c*cspace+i%width] = line[i];
      }
      p++;
    }
    if(res[0][0] != '.'){
      rep(i, plen) printf("%s\n", res[i]);
      puts("#");
    }
    puts("?");
  }
  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int ans = -1;
    for(int i=1;i<=N;i++){
        int n = 108*i/100;
        if(n==N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    dp = [[0] * (len(A) - i) for i in range(len(A))]

    for i in range(1, len(A)):
        s = sum(A[:i])
        for j in range(len(A) - i):
            s += A[i + j]
            dp[i][j] = min(dp[k][j] + dp[i - k - 1][j + k + 1] for k in range(i)) + s
            s -= A[j]
    print(dp[-1][0])


main()


Measured memory_bytes: 43228
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int ans = 0;
    ans = a + b + c;
    if(ans <= 21){
      System.out.println("win"); 
    }else{
      System.out.println("bust");
      }
  }
}

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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

const int p[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int k;

int main() {
  cin >> k;
  cout << p[k - 1] << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);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 all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	int A, B, C; cin >> A >> B >> C;
	ll sum = A;
	bool flag = false;
	for (int i = 0; i < 10000; ++i){
		if(sum % B == C) flag = true;
		sum += A;
		sum %= B;
	}
	if(flag) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
# 3
A,B,C=map(int,input().split())
K=int(input())

def f(a,b,c,k):
    if k==0:
        return a<b<c
    return f(a*2,b,c,k-1) or f(a,b*2,c,k-1) or f(a,b,c*2,k-1)

print('Yes' if f(A,B,C,K) else 'No')



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

int main() {
    string s, t;
    cin >> s >> t;
    int count = 0;
    for(int i=0; i<3; i++){
        if(s[i]==t[i]){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

int get_max_pack_num(int load_max, int* packs, int pack_num, int truck_num)
{
	int cnt = 0;
	for (int i = 0; i < truck_num; i++) {
		int load_w = 0;
		while (load_w < load_max) {
			if (cnt == pack_num) {
				return cnt;
			}
			if (load_w + packs[cnt] <= load_max) {
				load_w += packs[cnt++];
			}
			else {
				break;
			}
		}
	}
	return cnt;
}

int main()
{
	int pack_num, truck_num;
	cin >> pack_num >> truck_num;

	int* weights = new int[pack_num];
	int w_sum = 0;
	for (int i = 0; i < pack_num; i++) {
		scanf("%d", &weights[i]);
		w_sum += weights[i];
	}

	int left = 0, right = w_sum;
	int ans = 0;
	for (;;) {
		int mid = left + (right - left) / 2;
		int mid_value = get_max_pack_num(mid, weights, pack_num, truck_num);

		
		if (mid_value < pack_num) {
			left = mid + 1;
		}
		else if (mid_value >= pack_num) {
			if (mid_value != get_max_pack_num(mid - 1, weights, pack_num, truck_num)) {
				ans = mid;
				break;
			}
			right = mid;
		}
	}
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 3528
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=60;
int n,m,a[N],max1;
long long ans,d[N*N][N];
bool flag[N*N][N];
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		max1+=a[i];
	}
	d[0][0]=1;
	sort(a+1,a+n+1);
	for(int k=1;k<=n;k++){
		memset(flag,true,sizeof flag);
		for(int i=max1;i>=0;i--){
			for(int j=0;j<=n;j++){
				if(d[i][j]==0)continue;
				d[i+a[k]][j+1]+=d[i][j];
//				flag[i+a[k]][j+1]=false;
			}
		}
	}
	
//	for(int i=1;i<=max1;i++){printf("%d :",i);
//		for(int j=1;j<=n;j++)printf("%d ",d[i][j]);
//		printf("\n");
//	}
	for(int i=1;i<=n;i++)ans+=d[i*m][i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10 , P = 1e9 + 7;
int n , m , x[N] , y[N];

int solve(int *x,int n) {
  ll s=0;
  rep(i,0,n) {
    s+=ll(i-(n-1-i))*x[i]%P;
    if(s<0) s+=P;
    if(s>=P) s-=P;
  }
  return s;
}

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,n) scanf("%d",x+i);
  rep(i,0,m) scanf("%d",y+i);
  printf("%lld\n",ll(solve(x,n))*solve(y,m)%P);
  return 0;
}


Measured memory_bytes: 1024
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#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>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,m;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int a,b;
  cin >> a >> b;
  if(a<b){
    for(int i=1;i<=b;i++)cout<<a;
    cout<<endl;
  }
  else {
    for(int i=1;i<=a;i++)cout<<b;
    cout<<endl;
  }


return 0;
}
///....


Measured memory_bytes: 256
// template
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    int ans;
    if(abs(a - b) <= 1) cout << a + b << endl;
    else cout << 2 * max(a, b)- 1 << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
D = int(input())
c = list(map(int,input().split()))
s = np.empty((D,26))
for i in range(D):
    s[i,:] = np.array(list(map(int,input().split())))

for i in range(D):
    print(s[i,:].flatten().argmax()+1)

Measured memory_bytes: 27112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long.parseLong(stdin.readLine());
        }

        if (a[0] != 0) {
            stdout.println(-1);
            return ;
        }

        long ans = 0;
        for (int i = 0; i < n - 1; i++) {
            if (a[i] + 1 == a[i + 1]) {
                ans += 1;
            } else if (a[i] >= a[i + 1]) {
                ans += a[i + 1];
            } else {
                stdout.println(-1);
                return ;
            }
        }

        stdout.println(ans);
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 38604
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int N = 1e5 + 5;
const int mod = 1e9 + 7; 
using namespace std;

int n, m, vis[N], now; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

bool check(int x)
{
	while(x)
	{
		if(vis[x % 10]) return 0;
		x /= 10; 
	}
	return 1; 
}

int main()
{
	n = read <int> (), m = read <int> ();
	for(int x, i = 1; i <= m; i++) x = read <int> (), vis[x] = 1; 
	while(1)
	{
		if(now < n) { now++; continue; }
		if(check(now)) { printf("%d\n", now); return 0; }
		now++; 
	}
	return 0; 
}


Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		String S = scan.next();
		String T = scan.next();

		//WK変数
		String result = "No";

		if (S.length() + 1 == T.length() && T.startsWith(S)) {
			result = "Yes";
		}

		//演算

		//結果出力
		System.out.println(result);
	}
}

Measured memory_bytes: 35724
#include<iostream>

using namespace std;

int main(){

	int a,b;

	cin >> a >> b;

	if(a>b){
		cout << "a > b" << endl;
	}else if(a<b){
		cout << "a < b" << endl;
	}else{
		cout << "a == b" << endl;
	}
	return 0;

}

Measured memory_bytes: 1156
#include <stdio.h>
int main(){
	unsigned long long int n;
	while(~scanf("%lld",&n)){
		int a[10];
		for(int i=0;i<10;i++){
			a[9-i] = n%10;
			n/=10;
		}
		for(int i=9;i>0;i--){
			for(int j=0;j<i;j++) a[j]=(a[j]+a[j+1])%10;
		}
		printf("%d\n",a[0]);
	}
	return 0;
}

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

int main(){
	int a,b,d,r;
	double f;
	
	cin >> a >>b;
	
	d = a/b;
	r = a%b;
	f = (double)a/b;
	
	cout << d << " " << r << " " << fixed << f <<endl;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
bool flg;
vector<ll> adj[N],col(N);
void dfs(ll node,ll clr){
    if(col[node]!=0){
        if(col[node]!=clr)flg=0;
        return;
    }
    col[node]=clr;
    for(auto &v:adj[node])dfs(v,-clr);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll u,v;cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    ll c1=0,c2=0,c3=0;
    for(ll i=1;i<=n;i++){
        if(col[i]!=0)continue;

        if(adj[i].size()==0)c1++;
        else{
            flg=1;
            dfs(i,1);
            if(flg)c2++;
            else c3++;
        }
    }
    ll ans = 2*n*c1 - c1*c1 + c3*c3 + 2*c3*c2 + 2*c2*c2;
    cout<<ans;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<int>());
    
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int M = 100100;

int n, a[M], b[M];

void read() {
  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> a[i];
}

void kill() {
  copy(a, a + n, b);
  sort(b, b + n);
  for (int i = 0; i < n; ++i)
    a[i] = lower_bound(b, b + n, a[i]) - b;

  int ans = 0;
  for (int i = 0; i < n; ++i)
    if (i % 2 != a[i] % 2)
      ++ans;
  
  ans /= 2;

  cout << ans << endl;
}

int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    vector<vector<ll>> in(n,vector<ll>(3));

    for(int i = 0; i < n; i++){
        cin >> in[i][0] >> in[i][1] >> in[i][2];
    }

    vector<vector<ll>> dp(n+1,vector<ll>(3,0));

    for(int i = 0; i < n; i++){
        for(int k = 0; k < 3; k++){
            for(int j = 0; j < 3; j++){
                if(k == j)continue;
                dp[i+1][j] = max(dp[i+1][j],dp[i][k] + in[i][j]);
            }
        }
    }
    
    cout << max(dp[n][0],max(dp[n][1],dp[n][2])) << endl;

    return 0;
}

Measured memory_bytes: 11264
#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 RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	if(abs(a - b) > 1e18){
		cout << "Unfair" << endl;
		return 0;
	} 

	if(k % 2){
		cout << -a + b << endl;
	}else{
		cout << a - b << endl;
	}
}

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

int n,k;
ll ans;
inline ll Pow(ll a) {return a*a*a;}
int main() {
    cin>>n>>k;
    int t=n/k;
    ans=Pow(t);
    if(!(k&1)){
        t=t+(n%k>=k/2 ? 1 : 0);
        ans+=Pow(t);
    }
    cout<<ans<<endl;
    return 0;
}

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

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

    vector<int> v;

    for (int i=0; i<N; i++) {
        int n;
        cin >> n;
        v.push_back(--n);
    }

    int now = 0, c = 0;
    for (;;) {
        if (now == 1) {
            cout << c << endl;
            break;
        }
        if (c >= N) {
            cout << -1 << endl;
            break;
        }
        c++;
        now = v[now];
    }
}

Measured memory_bytes: 892
package main

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

const mod = 1e9 + 7

func main() {
	_sc.Split(bufio.ScanWords)
	var before, after [13]int
	S := readLine()
	l := len(S)
	if S[0] == '?' {
		for j := 0; j < 10; j++ {
			before[j]++
		}
	} else {
		before[S[0]-'0']++
	}
	for i := 1; i < l; i++ {
		if S[i] == '?' {
			for j := 0; j < 10; j++ {
				for k := 0; k < 13; k++ {
					after[(j+k*10)%13] += before[k] % mod
				}
			}
		} else {
			for k := 0; k < 13; k++ {
				after[(int(S[i]-'0')+k*10)%13] += before[k] % mod
			}
		}
		before = after
		after = [13]int{}
	}
	fmt.Printf("%d\n", before[5]%mod)
}

const _bufferSize = 100000

var _sc = bufio.NewScanner(os.Stdin)
var _rd = bufio.NewReaderSize(os.Stdin, _bufferSize)

func nextInt() int {
	_i, _ := strconv.ParseInt(nextLine(), 10, 64)
	return int(_i)
}

func nextLine() string {
	_sc.Scan()
	return _sc.Text()
}

func readLine() string {
	_b, _, _ := _rd.ReadLine()
	return string(_b)
}


Measured memory_bytes: 768