akhauriyash/Code-Regression huggingface dataset:
<?php

class Solver
{
    private $number_of_elements;
    private $values = array();

    public function __construct()
    {
        $lines = array();
        while (1) {
            if (!$line = fgets(STDIN)) break;
            $line = trim($line);
            $lines[] = $line;
        }

        $this->number_of_elements = $lines[0];
        $this->values = explode(' ', $lines[1]);
    }

    public function getAnswer()
    {
        $change_frec = 0;
        for ($i = 0; $i < $this->number_of_elements; $i++) {
            $minj = $i;
            for ($j = $i; $j < $this->number_of_elements; $j++) {
                if ($this->values[$j] < $this->values[$minj]) {
                    $minj = $j;
                }
            }
            if ($minj!=$i) {
                list($this->values[$i], $this->values[$minj]) = [$this->values[$minj], $this->values[$i]];
                $change_frec++;    
            }
        }
        echo implode(' ', $this->values) . PHP_EOL;
        echo $change_frec . PHP_EOL;
    }
}

$answer = new Solver;
$answer->getAnswer();


Measured memory_bytes: 9424
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    private static final long MOD=(int)1e9+7;
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,j,N,M;

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        int K=Integer.parseInt(s[1]);

        s=br.readLine().trim().split(" ");
        long a[]=new long[N];
        for(i=0;i<N;i++) a[i]=Integer.parseInt(s[i]);

        ArrayList<Long> p=new ArrayList<>();
        ArrayList<Long> n=new ArrayList<>();

        for(i=0;i<N;i++)
        {
            if(a[i]>=0) p.add(a[i]);
            else n.add(a[i]);
        }

        Collections.sort(p);
        Collections.sort(n,Collections.reverseOrder());

        ArrayDeque<Long> positive = new ArrayDeque<>(p);
        ArrayDeque<Long> negative = new ArrayDeque<>(n);

        ArrayDeque<Long> sol=new ArrayDeque<>();

        if(K%2==1&&!positive.isEmpty())
        {
            sol.add(positive.pollLast());
            K--;
        }

        while (K>0&&positive.size()>=2&&negative.size()>=2)
        {
            long p1=positive.pollLast(),p2=positive.pollLast();
            long n1=negative.pollLast(),n2=negative.pollLast();

            if(p1*p2>n1*n2)
            {
                negative.addLast(n2);
                negative.addLast(n1);

                sol.addLast(p1);
                sol.addLast(p2);
            }
            else
            {
                positive.addLast(p2);
                positive.addLast(p1);

                sol.addLast(n1);
                sol.addLast(n2);
            }
            K-=2;
        }

        while (K>0&&positive.size()>=2)
        {
            sol.addLast(positive.pollLast());
            sol.addLast(positive.pollLast());
            K-=2;
        }

        if(K>0&&!negative.isEmpty())
        {
            if(K%2==0)
            {
                while (K>0&&!negative.isEmpty())
                {
                    sol.addLast(negative.pollLast());
                    K--;
                }
            }
            else
            {
                while (K>0&&!negative.isEmpty())
                {
                    sol.addLast(negative.pollFirst());
                    K--;
                }
            }
        }

        while (K>0&&!positive.isEmpty())
        {
            sol.addLast(positive.pollLast());
            K--;
        }
        while (K>0&&!negative.isEmpty())
        {
            sol.addLast(negative.pollFirst());
            K--;
        }

        long ans=1;
        for(long z:sol) ans=(ans*z)%MOD;
        if(ans<0) ans+=MOD;

        System.out.println(ans);
    }
}


Measured memory_bytes: 70240
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    string S;
    cin >> S;
    ll a=0;
    string S2="";
    while(a<S.size()){
        if(a<S.size()-1&&S[a]=='B'&&S[a+1]=='C'){
            S2+='D';a++;
        }
        else S2+=S[a];
        a++;
    }
    ll ans=0;
    ll acounter=0;
    for(ll i=0;i<S2.size();i++){
        if(S2[i]=='A')acounter++;
        else if(S2[i]=='D')ans+=acounter;
        else acounter=0;
    ;}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

struct SegmentTree {
    int n;
    vector<ll> node;
    ll calc(ll a, ll b) {
        return min(a, b);
    }
    ll e = LINF;
    SegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, e);
        for (int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = calc(node[2 * i + 1], node[2 * i + 2]);
        }
    }
    void update(int x, ll val) {
        x = n + x - 1;
        node[x] = val;
        while (x > 0) {
            x = (x - 1) / 2;
            node[x] = calc(node[2 * x + 1], node[2 * x + 2]);
        }
    }
    ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return e;
        if (a <= l && r <= b) return node[k];
        ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return calc(vl, vr);
    }
    ll at(int x) {
        return node[n + x - 1];
    }
};

int main() {
    int n;
    cin >> n;
    vector<ll> vec(n);
    rep(i, n) cin >> vec[i];
    SegmentTree segt(vec);
    int ans = 0;
    rep(i, n) {
        if (vec[i] <= segt.query(0, i + 1)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7552
import bisect

N,Q = (int(x) for x in input().split())

stop_arr = [tuple(map(int, input().split())) for _ in range(N)]
Q_arr = [int(input()) for _ in range(Q)]

stop_arr.sort(key=lambda x:x[2])

ans_arr = [-1]*Q
skip_arr = [-1]*(Q+1)

for s,t,x in stop_arr:
    q_start = bisect.bisect_left(Q_arr, s-x)
    q_stop = bisect.bisect_left(Q_arr, t-x)
    l = q_start
    while l < q_stop:
        if skip_arr[l] == -1:
            skip_arr[l] = q_stop
            ans_arr[l] = x
            l += 1
        else:
            l = skip_arr[l]

print(*ans_arr, sep="\n")


Measured memory_bytes: 57132
import queue
n, m = map(int,input().split())
g = [[] for _ in range(n+1)]
g_cost = [ float('inf') for _ in range(n+1)]
g_ans = [ 0 for _ in range(n+1)]
for i in range(0,m):
    s,t = map(int,input().split())
    g[s].append(t)
    g[t].append(s)

q = queue.Queue()
q.put(1)
g_cost[1] = 0
while not q.empty():
    room = q.get()
    for c_room in g[room]:
        if g_cost[room]+1 < g_cost[c_room]:
            g_cost[c_room] = g_cost[room]+1
            g_ans[c_room] = room
            q.put(c_room)
# print(g_cost)
# print(g_ans)
print("Yes")
for i in range(2,n+1):
    print(g_ans[i])


Measured memory_bytes: 38044
#include<cstdio>

int main()
{
  char S[10];
  scanf("%s", S);

  int ans = 0;
  for (int i = 0; i < 4; ++i){
    if (S[i] == '+') ++ans;
    else --ans;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
   ll n, k;
   cin >> n >> k;
   ll sum = 0;
   rep(i, n-2)sum+=i+1;
   if(k>sum){
       cout << -1;
       return 0;
   }
   ll m = 2*10;
   vector<pair<int, int>> ans;
   for(int i=1; i<=n; ++i)for(int j=i+1; j<=n; ++j){
       ans.push_back(make_pair(i, j));
   }
   ll cnt[200];
   rep(i, 200)cnt[i]=n-1;
   rep(i, k){
       pair<int, int> tmp = ans.back();
       if(cnt[tmp.first]<=1||cnt[tmp.second]<=1)continue;
       ans.pop_back();
   }
   
   cout << ans.size() << endl;
   rep(i, ans.size())cout << ans[i].first << " " << ans[i].second << endl;

}

Measured memory_bytes: 384
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if((b-a) > 0):
  a = a+v*t
  b = b+w*t
  if(a >= b):
    print("YES")
  else:
    print("NO")
    
elif((b-a) < 0):
  a = a-v*t
  b = b-w*t
  if(a <= b):
    print("YES")
  else:
    print("NO")
    

Measured memory_bytes: 9136
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 , mod = 1e9 + 7 ;
int n , dp[N] , sum[N] , nxt[N][2] , last[3] , tlast[3] ;
string s ;

inline void add (int &a , int b) {
	a += b ;
	if (a >= mod) a -= mod ;
}

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

	cin >> s ;
	n = _sz(s) ;

	for (int i = 0 ; i < n ; i ++) {
		if (i == n - 1) return cout << "1\n" , 0 ;
		if (s[i] == s[i + 1]) break ;
	}

	last[0] = last[1] = last[2] = n + 2 ;
	tlast[0] = n ;

	for (int i = n - 1 ; i >= 0 ; i --) {
		sum[i] = (sum[i + 1] + (s[i] - 'a' + 1)) % 3 ;

		nxt[i][0] = last[(sum[i] + 2) % 3] ;
		nxt[i][1] = last[(sum[i] + 1) % 3] ;

		if (s[i] == 'a') nxt[i][0] = i + 1 ;
		if (s[i] == 'b') nxt[i][1] = i + 1 ;

		if (i && s[i - 1] == s[i]) {
			for (int j = 0 ; j < 3 ; j ++) last[j] = tlast[j] ;
		}
		
		tlast[sum[i]] = i ;
	}

	dp[0] = 1 ;
	for (int i = 0 ; i < n ; i ++) {
		add(dp[nxt[i][0]] , dp[i]) ;
		add(dp[nxt[i][1]] , dp[i]) ;
	}

	int ans = 0 ;
	for (int i = 1 ; i <= n ; i ++) 
		if (sum[i] == 0) add(ans , dp[i]) ;

	cout << ans << '\n' ;
}

Measured memory_bytes: 2000
n=int(input())
a=[int(input()) for i in range(n)]
l,r=0,0
lm=[0]
rm=[0]
for i in range(n):
    l=max(l,a[i])
    r=max(r,a[-1-i])
    lm.append(l)
    rm.append(r)
for i in range(n):
    print(max(lm[i],rm[n-i-1]))

Measured memory_bytes: 87384
#include<bits/stdc++.h>
using namespace std ;
typedef long long int ll;
#define pb push_back
#define endl        '\n'
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0);
    ll n;
    cin>>n;
    ll x=1;
    for(ll i=2;i<=sqrt(n)+1;i++)
    {
        if(n%i==0)
            x=i;
    }
    cout<<x+n/x-2;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};

double dist (double a, double b,  double c, double d){
    
    return sqrt((a-c)*(a-c) + (b-d)*(b-d));
    
}

bool check(int x,int y,vector<string> a,vector<string> b ){
    for(auto i = 0; i<b.size();i++){
        for(auto j =0; j<b.size();j++){
            if(a[x+i][y+j]!= b[i][j]) return false;
        }
    }
    return true;
}

int dist(pii a, pii b){
    return abs(a.first-b.first) + abs(a.second-b.second);
}


int main() {
    string s;cin>>s;
    int alpha[26]={0};
    rep(i,s.size())alpha[s[i]-'a']++;
    rep(i,26){if(alpha[i]==0){ printf("%c\n",i+'a'); return 0;}}
    cout<<"None" << endl;
    return 0;
}







Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    vector<string> s(3);
    rep(i, 0, 3) cin >> s[i];
    rep(i, 0, 3) {
      cout << static_cast<char>(s[i][0]-32);
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

#define N 11000
#define INF 0x3f3f3f3f
#define _for(i, a, b) for (int i = (a); i < (b); ++i)

typedef long long ll;

int main() {
    int n;
    while (scanf("%d", &n) != EOF) {
        int sum = 0, MAX = -INF;
        for (int i = 0; i < n; ++i) {
            int x; scanf("%d", &x);
            MAX = max(MAX, x);
            sum += x;
        }
        sum -= MAX;
        if (MAX < sum) puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 760
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int>A(N),B(N),C(N);
    for(int i = 0;i < N;i++)cin >> A[i];
    for(int i = 0;i < N;i++)cin >> B[i];
    for(int i = 0;i < N;i++)cin >> C[i];
    sort(A.begin(),A.end());
    sort(C.begin(),C.end());
    ll cnt = 0;
    for(int i = 0;i < N;i++){
        auto ita = lower_bound(A.begin(),A.end(),B[i]);
        auto itc = upper_bound(C.begin(),C.end(),B[i]);
        cnt += distance(A.begin(),ita) * distance(itc,C.end());
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<int, PII> PPII;
typedef pair<int, PPII> PPPII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	ll N, M;
	while(cin >> N >> M && N && M){
	ll P[1010];
	ll res = 0;
	vector<int> two;
	REP(i, N){
		cin >> P[i];
	}
	P[N] = 0;
	REP(i, N+1){
		REP(j, N+1){
			if(P[i]+P[j] <= M)
				two.push_back(P[i]+P[j]);
		}
	}
	sort(all(two));
	REP(i, N+1){
		REP(j, N+1){
			ll a = P[i]+P[j];
			if(a > M) continue;
			res = max(res, a+(*(upper_bound(all(two), M-a)-1)));
		}
	}
	cout << res << endl;
	}
}

Measured memory_bytes: 10648
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        int ans = c;
        if(a == c) ans = b;
        if(b == c) ans = a;
        System.out.print(ans);
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     ll n,r;
     cin>>n>>r;
     if(n>=10)
     cout<<r<<endl;
     else{
         cout<<r+100*(10-n)<<endl;
     }
}

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

using namespace std;

int main()
{
    int a[200];
    int n;
    int counter = 0;
    int counterB = 0;

    cin >> n;

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

    while(true)
    {
        for (int i = 0; i < n; ++i)
        {
            if(a[i] % 2 == 0)
            {
                counterB++;
                a[i] = a[i] / 2;
            }
        }

        if(counterB == n)
        {
            counter++;
        }
        else
        {
            break;            
        }

        counterB = 0;
        
    }

    cout << counter;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_d

N = int(input())

alphabet = "abcdefghijklmnopqrstuvwxyz"

curr_str = []

def print_str(curr_str):
    string = ""
    for i in curr_str:
        string += alphabet[i]
    print(string)


def dfs(index, curr_str, curr_char):
    if curr_char > index:
        return None
    if curr_char > max(curr_str) + 1:
        return None

    if index == N-1:
        print_str(curr_str + [curr_char])
        return None

    for i in range(N):
        dfs(index+1, curr_str+[curr_char], i)


if N == 1:
    print("a")
else:    
    for i in range(N):
        dfs(1, [0], i)

Measured memory_bytes: 4412
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,Q;
  string S;
  cin >> N >> Q;
  cin >> S;
  int l[Q],r[Q];
  for(int i=0; i<Q; i++){
    cin >> l[i] >> r[i];
  }
  int AC[N] = {0};
  int count = 0;
  bool checkA = false;
  for(int i=0; i<N; i++){
    if(S[i] == 'A'){
      checkA = true;
    }else if(S[i] == 'C'){
      if(checkA == true){
        count++;
      }
      checkA = false;
    }else{
      checkA = false;
    }
    AC[i] = count;
  }
  
  for(int i=0; i<Q; i++){
    cout << AC[r[i]-1] - AC[l[i]-1] << endl;
  }
  return 0;
}

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

int main()
{
	typedef set<string> set_t;
	int n;
	set_t Dic;
	string cmd,word;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> cmd;
		if (cmd == "insert")
		{
			cin >> word;
			Dic.insert(word);
		}
		if (cmd == "find")
		{
			cin >> word;
			if (Dic.count(word))
			{
				cout << "yes" << endl;
			}
			else
				cout << "no" << endl;
		}
	}
}

Measured memory_bytes: 32568
#include <stdio.h>

int main(void){
    
    long long int sum=0,i,n,T,t[200001]={};
    
    scanf("%lld %lld",&n,&T);
    
    scanf("%lld",&t[0]);
    
    for( i = 1; i < n; i++){
        scanf("%lld",&t[i]);
        
        if( t[i] <= T ){
            sum = t[i];
        }
        if( t[i] > T ){
            if( t[i] - t[i-1] < T ){
                sum = sum + ( t[i] - t[i-1] );
            }
        else sum += T;
        }
    }
    
     printf("%lld\n",sum+T);

       return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> P;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
   template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   int gcd(int a,int b){return b?gcd(b,a%b):a;};

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

ll N;
ll a[100];
ll S = 0;



int main(){
   cin >> N;
   REP(i, N){
      cin >> a[i];
      S += a[i];
   }
   ll th = -1;
   ll diff = INF;
   REP(i, N){
      if (abs(a[i] * N - S) < diff){
         th = i;
         diff = abs(a[i] * N - S);
      }
   }
   cout << th << endl;
   
}

Measured memory_bytes: 256
import collections
import itertools
def solve(n, s_list):

    counter = collections.Counter()
    for s in s_list:
        if s[0] in "MARCH":
            counter[s[0]] += 1

    ans = 0
    for i, j, k in itertools.combinations("MARCH",3):
        ans += counter[i]*counter[j]*counter[k]

    return ans


if __name__ == "__main__":
    n = int(input())
    s_list = [input() for i in range(n)]
    print(solve(n, s_list))



Measured memory_bytes: 10112
#include<map>
#include<string>
#include<vector>
#include<iostream>

using namespace std;

map<string,int> price,cost;
map< string,vector<string> > recipe;

int calcMinCost(string item)
{
	if(cost[item]!=-1)	return cost[item];

	vector<string> rcp=recipe[item];
	if(rcp.size()==0)	return cost[item]=price[item];

	int syncost=0;
	for(int i=0;i<rcp.size();i++)	syncost+=calcMinCost(rcp[i]);
	return cost[item]=min(price[item],syncost);
}

int main()
{
	for(int n;cin>>n,n;){
		for(int i=0;i<n;i++){
			string item;
			int p;	cin>>item>>p;
			price[item]=p;
			cost[item]=-1;
		}

		int m;	cin>>m;
		for(int i=0;i<m;i++){
			string item;
			int k;	cin>>item>>k;
			vector<string> material(k);
			for(int j=0;j<k;j++)	cin>>material[j];
			recipe[item]=material;
		}

		string tar;	cin>>tar;
		cout<<calcMinCost(tar)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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

  if (s[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int c_cnt = 0, c_ind = 0;
  for (int i = 2; i < s.size() - 1; i++) {
    if (s[i] == 'C') {
      c_cnt++;
      c_ind = i;
    }
  }
  if (c_cnt != 1) {
    cout << "WA" << endl;
    return 0;
  }

  for (int i = 0; i < s.size(); i++) {
    if (i == 0 || i == c_ind) continue;
    if (!(s[i] >= 'a' && s[i] <= 'z')) {
      cout << "WA" << endl;
      return 0;
    }
  }

  cout << "AC" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fr(i,n) for(i=0;i<n;i++)
#define pb push_back
#define vi vector<int>
#define mod 1000000007

using namespace std;

int main ()
{
    string s;
    cin>>s;
    if(s.compare("ABC")==0)
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;
}



Measured memory_bytes: 3624
import copy


def insertion_sort(arr, n, g, cnt):
    for i in range(g, n):
        v = arr[i]
        k = i - g
        while k >= 0 and arr[k] > v:
            arr[k + g] = arr[k]
            k = k - g
            cnt += 1
        arr[k + g] = v
    return arr, cnt


def shell_sort(arr, n, G):
    A = copy.deepcopy(arr)
    c = 0
    for i in G:
        A, c = insertion_sort(A, n, i, c)
    return A, c


n = int(input())
A = []
for i in range(n):
    A.append(int(input()))
G = [1]
h = 1
while h * 3 + 1 <= n:
    h = 3 * h + 1
    G.append(h)

a, cnt = shell_sort(A, n, G[::-1])

print(len(G))
print(*G[::-1])
print(cnt)
for i in a:
    print(i)



Measured memory_bytes: 54084
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
using namespace std;
int main(){
  int N, D, X;
  cin >> N >> D >> X;
  int p[D][N];
  for(int i = 0; i < D; ++i)
    for(int j = 0; j < N; ++j)
      cin >> p[i][j];
  int val;
  for(int d = 1; d < D; ++d){
    val = 0;
    int dp[N+1][X+1];
    for(int i = 0; i <= N;++i)
      fill(dp[i],dp[i]+X+1,0);

    for(int i = 1; i <= N; ++i){
      for(int j = 0; j <= X; ++j){
	dp[i][j] = max(dp[i-1][j],dp[i][j]);
	if(j >= p[d-1][i-1]) dp[i][j] = max(dp[i][j],dp[i][j-p[d-1][i-1]]+p[d][i-1]);
      }
    }

    for(int i = 0; i <= X; ++i){
      val = max(val,dp[N][i]+X-i);
    }

    X = val;
  }
  cout << val << endl;
  return 0;
}

Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265358979
#define MOD 998244353
const int MAX = 510000;

int main() {
  ll N,A,B;
  cin>>N>>A>>B;
  unsigned long long ans=0;
  if((B-A)%2ll==0){
    ans=abs((B-A)/2ll);
  }
  else{
  	unsigned long long p=N-(A+B-1ll)/2ll,q=(A+B-1ll)/2ll;
  	ans=min(p,q);
  }
  cout<<ans;
  
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a =[list(map(int,input().split())) for i in range(m)]
ans=[]
for i in range(m):
    for k in range(2):
        ans.append(a[i][k])
# print(ans)
import collections
ans=collections.Counter(ans)
# ans_sorted=sorted(ans.items(), key=lambda x:x[0])
# print(ans_sorted)
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	double a, b;
	cin >> a >> b;
	double mean = 0;
	mean = ((a + b) / 2);
		cout << round(mean);
}

Measured memory_bytes: 3824
#include <iostream>
typedef long long ll;
using namespace std;
int n;
int a[10];
int ans;
void dfs(int index, ll seki){
  if(index == n){
    if(seki%2==0) ans++;
    return ;
  }
  dfs(index+1, seki*(a[index]-1));
  dfs(index+1, seki*(a[index]));
  dfs(index+1, seki*(a[index]+1));
  return ;
}
int main(void){
  ans = 0;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  dfs(1, a[0]-1);
  dfs(1, a[0]);
  dfs(1, a[0]+1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall Educational_DP_C.cpp -o .\out\Educational_DP_C.out
.\out\Educational_DP_C.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

constexpr int INF = 1e9;

int dp[100005][3];
int a[100005][3];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  dp[1][0] = a[0][0];
  dp[1][1] = a[0][1];
  dp[1][2] = a[0][2];
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      dp[i+1][j] = max(dp[i+1][j], dp[i][(j+1)%3]+a[i][j]);
      dp[i+1][j] = max(dp[i+1][j], dp[i][(j+2)%3]+a[i][j]);
    }
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int x;
        cin >> x;
        mp[x]++;
    }
    int q;
    cin >> q;
    int ans = 0;
    rep(i, q) {
        int y;
        cin >> y;
        if (mp.count(y)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7708
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    int ans = 0;
    REP(i,N){
        int a;cin>>a;
        if(~i&1) if(a&1) ans++;
    }
    cout<<ans<<endl;
}


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

int main() {
    int n;
    cin >> n;
    set<string> string_set;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        string_set.insert(s);
    }
    cout << string_set.size() << endl;
    return 0;
}

Measured memory_bytes: 19124
/* ex 7_3
   person_A */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


int main(void){
    //行列と行数、列数、空白の記録用配列の宣言
    char** matrix;
    int height,width,*whiterow,*whitecolumn,i,j;
    //行数、列数の入力
    scanf("%d %d",&height,&width);
    //配列の動的メモリ確保
    matrix=(char**)calloc(height,sizeof(char*));
    whiterow=(int*)calloc(height,sizeof(int));
    whitecolumn=(int*)calloc(width,sizeof(int));
    if(matrix==NULL||whiterow==NULL||whitecolumn==NULL){
        fprintf(stderr,"memory allocation error.\n");
        exit(1);
    }
    for(i=0;i<height;i++){
        matrix[i]=(char*)calloc(width,sizeof(char));
        if(matrix[i]==NULL){
            fprintf(stderr,"memory allocation error.\n");
            exit(1);
        }
    }
    //matrixの要素の入力
    for(i=0;i<height;i++){
        for(j=0;j<width;j++){
            scanf(" %c",&matrix[i][j]);
        }
    }

    //whiterowに空白行の記録
    for(i=0;i<height;i++){
        for(j=0;j<width;j++){
            if(matrix[i][j]!='.'){
                break;
            }
            else if(j==width-1){
                whiterow[i]=1;
            }
        }
    }
    //whitecolumnに空白列の記録
    for(j=0;j<width;j++){
        for(i=0;i<height;i++){
            if(matrix[i][j]!='.'){
                break;
            }
            else if(i==height-1){
                whitecolumn[j]=1;
            }
        }
    }
    //結果の出力
    for(i=0;i<height;i++){
        if(whiterow[i]==1){
            continue;
        }
        for(j=0;j<width;j++){
            if(whitecolumn[j]==0){
                printf("%c",matrix[i][j]);
            }
        }
        printf("\n");
    }
    //配列の解放
    for(i=0;i<height;i++){
        free(matrix[i]);
    }
    free(matrix);
    free(whiterow);
    free(whitecolumn);

    return 0;
}

Measured memory_bytes: 1644
#include <iostream>

using namespace std;

int main(){

  int N, C[500]={} ,S[500]={},F[500]={};

  cin >> N;

  for(int i = 0; i < N-1; i++){
    cin >> C[i] >> S[i] >> F[i];
  }

  for(int i = 0; i < N-1; i++){
    int sum = S[i]+C[i];
    for(int j = i+1; j < N-1;j++){
      if(sum < S[j]){
	sum = S[j];
      }
      else if(sum%F[j]!=0){
	sum += F[j] - sum%F[j];
      }
      sum += C[j];
    }
    cout << sum << "\n";
  }

  cout << 0 << "\n";
  
  return 0;
}

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

int main(){
    int N, cnt = 0;
    int Num[210];
    cin >> N;
    for (int i = 0; i < N; i++) cin >> Num[i];
    
    while (true) {
        bool exist_odd = false;
        for (int i = 0; i < N; i++) {
            if (Num[i] % 2 != 0) exist_odd = true;
        }
        if (exist_odd) break;
        for (int i = 0; i < N; i++) Num[i] /= 2;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

int linear_search(long key, long nums[], int size) {
  int i = 0;
  nums[size] = key;

  while (nums[i] != key) {
    i++;
  }

  if (i == size) {
    return -1;
  } else {
    return key;
  }
}

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

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

  int q;
  cin >> q;

  int count = 0;
  for (int j = 0; j < q; j++) {
    long t;
    cin >> t;

    int result = linear_search(t, S, n);
    if (result == -1) {
      continue;
    }

    count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 3092
from collections import deque
a=[]
for i in range(3):
	S=deque(raw_input())
	a.append(S)

p=a[0].popleft()
ind=0

while len(a[ind])>0:
	if p=="a":p=a[0].popleft()
	elif p=="b":p=a[1].popleft()
	elif p=="c":p=a[2].popleft()

	if p=="a": ind=0
	elif p=="b": ind=1
	elif p=="c": ind=2

print p.upper()

Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  ll a, b, c;
  cin >> a >> b >> c;
  ll sum = a + b;
  if(a +b <c && 4 * a * b < (c-a-b)*(c-a-b)){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    n,q = map(int,ipt().split())
    base = 10**9+1
    hq = []
    for i in range(n):
        s,t,x = map(int,ipt().split())
        if t < x:
            continue
        hpq.heappush(hq,max(0,(s-x))*2*base+x*2+1)
        hpq.heappush(hq,(t-x)*2*base+x*2)

#    print(hq)
    iv = []
    dd = dict()
    for i in range(q):
        f = True
        d = (int(ipt())+1)*2*base
        while hq and hq[0] < d:
            hi = hpq.heappop(hq)
            t = hi//(2*base)
            p = hi%2
            x = (hi//2)%base
            if p:
                dd[x] = True
                hpq.heappush(iv,x)
            else:
                dd[x] = False
        while iv:
            ii = iv[0]
            if dd[ii]:
                print(ii)
                f = False
                break
            else:
                hpq.heappop(iv)
        if f:
            print(-1)

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 143772
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    bool flg = true;
    for(int i=0;i<4;i++){
        if(S[i] == S[i+1]){
            flg = false;
            break;
        }
    }
    if(flg == true){
        cout << "Good";
    }else{
        cout << "Bad";
    }
    return 0;
}

    


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; long long k; cin >> n >> k;
  vector<int> a(n); REP(i, n) cin >> a[i];
  map<int, vector<int> > mp;
  REP(i, n) mp[a[i]].emplace_back(i);
  vector<int> nx(n);
  for (auto p : mp) {
    vector<int> vec = p.second;
    int sz = vec.size();
    REP(i, sz - 1) nx[vec[i]] = vec[i + 1];
    nx[vec[sz - 1]] = vec[0];
  }
  long long loop = 1;
  int pos = 0;
  while (true) {
    int nxt = nx[pos];
    if (nxt <= pos) {
      if (loop == k) break;
      ++loop;
    }
    pos = nxt + 1;
    if (pos == n) {
      pos = -1;
      break;
    }
  }
  if (pos == -1) k %= loop;
  if (k == 0) return 0;
  loop = 1;
  pos = 0;
  while (true) {
    int nxt = nx[pos];
    if (nxt <= pos) {
      if (loop == k) break;
      ++loop;
    }
    pos = nxt + 1;
  }
  vector<int> ans;
  map<int, bool> mp2;
  FOR(i, pos, n) {
    if (!mp2.count(a[i])) {
      mp2[a[i]] = true;
      ans.emplace_back(a[i]);
    } else {
      while (ans.back() != a[i]) {
        mp2.erase(ans.back());
        ans.pop_back();
      }
      ans.pop_back();
      mp2.erase(a[i]);
    }
  }
  int len = ans.size();
  REP(i, len) cout << ans[i] << (i == len - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 35188
A,B,C,X,Y = map(int,input().split())
a = 0

if A + B < C * 2:
    a += (A + B) * min(X, Y)
else:
    a += 2 * C * min(X, Y)

if X > Y:
    a += min(A, C * 2) * (X - Y)
else:
    a += min(B, C * 2) * (Y - X)
        
print(a)

Measured memory_bytes: 3060
def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a
    return gcd(b % a, a)


n = int(input())
a = list(map(int, input().split()))
b = [0] * (n + 1)
c = [0] * (n + 1)

for i in range(n):
    b[i + 1] = gcd(b[i], a[i])
    c[i + 1] = gcd(c[i], a[-i - 1])

ans = 0
for i in range(n):
    ans = max(ans, gcd(b[i], c[n - i - 1]))

print(ans)

Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
int main(){
  ll n;
  cin>>n;
  ll a[n]={};
  ll r;
  ll ca=0;
  ll cb=0;
  ll cc=0;
  for(ll i=0; i<n; i++){
  cin>>r;
  if(r%4==0){
  ca++;}
  else if(r%2==0){
  cb++;}
  else
  cc++;}
  if(cb>=1){
  cc++;}
  if(cb>=1){
  if(cc-1>ca){
  cout<<"No"<<endl;}
  else
  cout<<"Yes"<<endl;}
  else{
  if(cc-1>ca){
  cout<<"No"<<endl;}
  else
  cout<<"Yes"<<endl;}}


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

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    long long ans = 0;
    for (int i = 0; i < n; i++) {
        long long u = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        long long d = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += u * d;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<iostream>
#include<utility>
#include<cstring>
using namespace std;
bool comp[101][101];
int main(){
  int n;
  int num;
  while(cin>>n,n){
    memset(comp,0,sizeof(comp));
    for(int i=0;i<n;i++){
      cin>>num;
      for(int j=0;j<num;j++){
	int tmp; cin>>tmp;
	comp[i][tmp-1]=true;
      }
    }
    
    cin>>num;
    int list[num];
    int ans = -1;
    for(int i=0;i<num;i++){
      cin>>list[i];
      list[i]--;
    }
    for(int i=0;i<n;i++){
      bool match=true;
      for(int j=0;j<num;j++){
	if(comp[i][list[j]]==false){
	  match=false;
	  break;
	}
      }
	if(match==true){
	  if(ans==-1){
	    ans = i+1;
	  }else{
	    ans=-1;
	    break;
	  }
	}
      }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
    char status = 'A';
    int junk, count{0};
    cin >> junk;
    cin.get();
    string strg;
    cin >> strg;
    for (int i = 0; i < strg.length() - 2; i++) {
        if (strg[i] == 'A' && strg[i + 1] == 'B' && strg[i + 2] == 'C') {
            ++count;
        }
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <bitset>
#define ll long long 
#define ri register int 
using std::min;
using std::bitset;
using std::max;
template <class T>inline void read(T &x){
    x=0;int ne=0;char c;
    while(!isdigit(c=getchar()))ne=c=='-';
    x=c-48;
    while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
    x=ne?-x:x;return ;
}
const int maxn=405;
const int inf=0x7fffffff;
bitset <maxn> o[maxn];
bool ok[maxn];
int a[100005],b[100005],m,n;
int main(){
    int x,y;
    bool flag=0;
    read(n),read(m);
    for(ri i=1;i<=m;i++)read(a[i]),read(b[i]);
    for(ri i=1;i<=n;i++){
        o[i][i]=1;flag=0;
        for(ri j=m;j>=1&&!flag;j--){
            x=o[i][a[j]],y=o[i][b[j]];
            if(x&y){
                ok[i]=1;
                flag=1;continue;
            }
            if(x){o[i][b[j]]=1;}
            if(y){o[i][a[j]]=1;}
        }
    }
    ll ans=0;
    for(ri i=1;i<=n;i++){
        if(ok[i])continue;
        for(ri j=i+1;j<=n;j++){
            if(ok[j])continue;
            if(!((o[i]&o[j]).any()))ans++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
import kotlin.math.max

fun main() {
  val (A, B) = readInts()
  val a = A + B
  val b = A * B
  val c = A - B
  println(max(a, max(b, c)))
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 36180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll N,K;cin>>N>>K;
    if(K%2==1){
        ll x=N/K;
        cout<<x*x*x<<endl;
    }
    else{
        ll x=N/(K/2);
        ll y=x/2;
        x-=y;
        cout<<x*x*x+y*y*y<<endl;
    }
}

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

if N==1:
    print(A1[0]+A2[0])
    exit()
else:
    for i in range(N):
        ansA1=0
        ansA2=0
        for j in range(i+1):
            ansA1+=A1[j]
        for k in range(j,N):
            ansA2+=A2[k]
        ans1=ansA1+ansA2
        ans.append(ans1)

print(max(ans))

Measured memory_bytes: 9124
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans=LINF,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,aa,bb;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>a>>b>>c>>x>>y;
    rep(i,ohara){
        aa=i;
        bb=i;
        cnt+=(i*2)*c;
        if(x>aa)cnt+=(x-aa)*a;
        if(y>bb)cnt+=(y-bb)*b;
        ans=min(ans,cnt);
        cnt=0;
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//一括include
using namespace std;
int main()
{
    int n,num;
    int a[100];

    cin >> n;
    for (int i = 0; i < n;i++){
        cin >> a[i];
    }
    sort(a, a + n);
    num=abs(a[0] - a[n - 1]);
    cout << num << endl;

}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      if now<=s:now=s+a
      else:now=(now+d-1)//d*d+a
    print(now)
if __name__=="__main__":
  f()


Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll a, b, c, x, y;

    cin >> a >> b >> c;

    x = c-a-b;
    y = powl(x,2);

    if(x>0 && y>4*a*b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

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

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

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

LL A, V, B, W, T;

void MAIN() {
    scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);

    bool yes = false;
    if (W < V) {
	LL D = abs(A - B);
	if (T * (V - W) >= D) yes = true;
    }
    puts(yes? "YES": "NO");
}

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



Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define takearr(a,n) int a[n];for(int i=0;i<n;i++)cin>>a[i]
#define rep(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(int i=a;i<=b;i++)
#define mods (1000*1000*1000)+7

int main()
{

  int n;cin>>n;
  takearr(a,n);
  int ans[n];memset(ans,0,sizeof(ans));
  ans[1]=abs(a[1]-a[0]);
  f(i,2,n)
    {
      ans[i]=min(ans[i-1]+abs(a[i]-a[i-1]),ans[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<ans[n-1]<<endl;

}

Measured memory_bytes: 1024
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto s1 = RD!string;
	auto s2 = RD!string;
	auto s3 = RD!string;

	string ans = [cast(char)(s1[0]-'a'+'A'), cast(char)(s2[0]-'a'+'A'), cast(char)(s3[0]-'a'+'A')];

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256