akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using static System.Math;
using System.Linq;
using static System.Array;

namespace ConsoleApp2
{
    class Program
    {
    

        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            //var c = Console.ReadLine();
            var A = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            var ans = A[0];
            for (int i = 1; i < N; i++)
            {
                ans = Gcd(ans, A[i]);
            }

            Console.WriteLine(ans);
        }

        public static long Gcd(long a, long b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }

    }

}


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

int main(){
  long long n,cost1=0,cost2=0;
  long long sum1=0,sum2=0;
  cin >> n;
  vector<long long> data(n);
  for(long long i=0; i<n; i++) cin >> data[i];
  
  //+-+-+-...
  for(long long i=0; i<n; i++){
    if(i%2==1){
      sum1 += data[i];
      if(sum1 >= 0){
        cost1 += 1+sum1;
        sum1 = -1;
      }
    }else{
      sum1 += data[i];
      if(sum1 <= 0){
        cost1 += 1-sum1;
        sum1 = 1;
      }
    }
  }
  
  //-+-+-+
  for(long long i=0; i<n; i++){
    if(i%2==1){
      sum2 += data[i];
      if(sum2 <= 0){
        cost2 += 1-sum2;
        sum2 = 1;
      }
    }else{
      sum2 += data[i];
      if(sum2 >= 0){
        cost2 += 1+sum2;
        sum2 = -1;
      }
    }
  }
  
  cout << min(cost1,cost2) << endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, k;
    cin >> n >> k;
    int tmp;
    rep(i,n) cin >> tmp;
    int s = k;
    int ans = 1;
    while(s < n){
        s += k-1;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> A(N);
	for (ll i = 0; i < N; ++i) cin >> A[i];

	vector<ll> sum_l(N+1, 0), sum_r(N+1, 0);

	for (ll i = 0; i < N; ++i) sum_l[i+1] = sum_l[i] + A[i];
	ll X = accumulate(A.begin(), A.end(), 0ll);

	ll res{INF};
	for (ll i = 1; i < N; ++i)
	{
		res = min(res, abs(2*sum_l[i] - X));
	}
	std::cout << res << std::endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>

using namespace std;

vector<int> shuffle(const vector<int>& a,int c)
{
	int n=a.size();
	deque<int> da(a.begin()+n/2,a.end());
	deque<int> db(a.begin(),a.begin()+n/2);
	
	vector<int> dc;
	while(dc.size()<n){
		for(int i=0;i<c && da.size();i++){
			dc.push_back(da[0]);
			da.pop_front();
		}
		for(int i=0;i<c && db.size();i++){
			dc.push_back(db[0]);
			db.pop_front();
		}
	}
	return dc;
}

int main()
{
	for(int n,r;cin>>n>>r;){
		vector<int> a(n);
		iota(a.begin(),a.end(),0);
		
		while(r--){
			int c; cin>>c;
			a=shuffle(a,c);
		}
		
		cout<<a.back()<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define INF 1e9

bool comp(const pii& firstElof, const pii& secondElof) {
    return firstElof.second < secondElof.second;
}

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

    int N, M;
    cin >> N >> M;
    int P[M], Y[M];
    vector<pii> pair1;
    REP(i, M) {
        cin >> P[i] >> Y[i];
        pair1.push_back(make_pair(P[i], Y[i]));
    }
    sort(pair1.begin(), pair1.end(), comp);
    sort(pair1.begin(), pair1.end());

    int num = pair1[0].first;
    int itr = 1;
    map<int, int> pair2;
    REP(i, M) {
        if (num != pair1[i].first) {
            itr = 1;
        }
        num = pair1[i].first;
        pair2[pair1[i].second] = itr;
        itr++;
    }


    REP(i, M) {
        auto sec = pair2.find(Y[i]);
        printf("%06d%06d\n", P[i], sec->second);

    }
}

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
int a1,b1,a2,b2;
int main()
{
    scanf("%d%d",&a1,&b1);
    scanf("%d%d",&a2,&b2);
    if (a1!=a2) puts("1");
    else puts("0");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> mat(n, vector<int>(m));
	vector<int> vec(m);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> mat[i][j];
	for (int i = 0; i < m; i++)
		cin >> vec[i];
	vector<int> res(n);
	for (int i = 0; i < n; i++)
	{
		int sum = 0;
			for (int j = 0; j < m; j++)
				sum += mat[i][j] * vec[j];
		res[i] = sum;
	}
	for (int i = 0; i < n; i++)
		cout << res[i] << endl;
}


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

public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str = br.readLine();
		String strArray[] = str.split(" ", 0);
		int a = Integer.parseInt(strArray[0]);
		int b = Integer.parseInt(strArray[1]);
		int c = Integer.parseInt(strArray[2]);
		int tmp = 0;

		while(a <= b){

			if(c%a ==0){
				tmp++;
			}
			a++;
		}
		System.out.println(tmp);
	}

}

Measured memory_bytes: 17036
import numpy as np

N = int(input())
B = list( map(int,input().split()) )

A = np.zeros(N,dtype=int)
A[0] = B[0]
A[-1] = B[-1]

if N == 2:
    print(A.sum())
    exit(0)

for i in range(len(B)-1):
    A[i+1] = min(B[i],B[i+1])

print(A.sum())

Measured memory_bytes: 22056
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    int l,r,i,flag=0;
    scanf("%d%d",&l,&r);
    int ansl=l,ansr=r;
    for(i=0;i<m-1;i++)
    {
        scanf("%d%d",&l,&r);
        ansl=ansl>l?ansl:l;
        ansr=ansr<r?ansr:r;
        if(ansr<l) flag=1;
    }
    if(flag) printf("0\n");
    else
    printf("%d\n",ansr-ansl+1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int x[n];
	int s = 0;
	for(int i = 0;i<n;++i) {
		cin >> x[i];
		s += x[i];
	}	
	s/=n;
	int ans = 1e9;
	for(int k : {0,1}) {
		int ca=0;
		for(int i = 0;i<n;++i)
			ca+=(x[i] - s-k) * (x[i] - s-k);
		ans = min(ca, ans);
	}
	cout << ans << endl;
}


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

int main() {
   string s;
   cin >> s;
   if(s[0]=='9')cout<<1;
   else cout<<9;
   if(s[1]=='9')cout<<1;
   else cout<<9;
   if(s[2]=='9')cout<<1;
   else cout<<9;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    int a[100000];
    rep(i, n){
        cin >> a[i];
    }
    int q;
    cin >> q;
    int b[100000];
    rep(i, q){
        cin >> b[i];
    }

    int cnt = 0;
    rep(i, q){
        rep(j, n){
            if(b[i] == a[j]){
                cnt++;
                break;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3164
def solve():
    mod = 1000000007
    N = int(input())
    A = list(map(int, input().split()))

    x = 0
    y = 0
    z = 0
    ans = 1
    for n in A:
        T = 0
        found = False
        for m in [x, y, z]:
            if n == m:
                T += 1
        ans *= T

        if x == n:
            x += 1
            continue
        if y == n:
            y += 1
            continue
        if z == n:
            z += 1
            continue
    
    print(ans % mod)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 52952
#include <bits/stdc++.h>
using namespace std;
string s,y;
int x;
int main()
{
    cin>>y;
    s+=y;
    cin>>y;
    s+=y;
    cin>>y;
    s+=y;
    x=atoi(s.c_str());
    if(x%4==0)cout<<"YES";
    else cout<<"NO";
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
from math import sqrt, pi
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, K = getNM()
A = getList()

# 同じ列内でそれ以降に含まれるもの
same = [0] * N
for i in range(N):
    cnt = 0
    for j in range(i + 1, N):
        if A[i] > A[j]:
            cnt += 1
    same[i] = cnt

# 列内全体で 前の物も含む
roop = [0] * N
for i in range(N):
    cnt = 0
    for j in range(N):
        if A[i] > A[j]:
            cnt += 1
    roop[i] = cnt

ans = 0
for i in range(N):
    ans += ((same[i] * K) + (roop[i] * K * (K - 1) // 2)) % mod
    ans %= mod
print(ans % mod)

Measured memory_bytes: 84240
import java.io.*;
import java.util.*;

public class Main {
	public ArrayList<Integer> S;
	public ArrayList<Integer> T;
	public int n;
	public int q;
	public int count = 0;
	public static void main(String[] args) {
		Main m = new Main();
		m.init();
		for (int i = 0; i < m.q; ++i)
			m.biSearch(m.T.get(i));
		System.out.println(m.count);
	}
	public void init() {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			n = Integer.parseInt(reader.readLine());
			S = new ArrayList<>();
			StringTokenizer stS = new StringTokenizer(reader.readLine());
			while (stS.hasMoreTokens())
				S.add(Integer.parseInt(stS.nextToken()));
			q = Integer.parseInt(reader.readLine());
			T = new ArrayList<>();
			StringTokenizer stT = new StringTokenizer(reader.readLine());
			while (stT.hasMoreTokens())
				T.add(Integer.parseInt(stT.nextToken()));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void biSearch(int x, int left, int right) {
		int index = (left + right) / 2;
		if (x == S.get(index)) {
			++count;
			return;
		}
		if (left > right)
			return;
		if (x <= S.get(index))
			biSearch(x, left, index - 1);
		if (S.get(index) <= x)
			biSearch(x, index + 1, right);
	}
	public void biSearch(int x) {
		biSearch(x, 0, S.size() - 1);
	}
}



Measured memory_bytes: 54840
n, purpose = map(int, input().split(" "))

resultI = resultJ = resultK = -1

def combiValue(i, j, k):
  return 10000 * i + 5000 * j + 1000 * k

for i in range(n+1):
  for j in range(n+1-i):
    k = n - i - j
    if combiValue(i, j, k) == purpose:
      resultI = i
      resultJ = j
      resultK = k

print("{0} {1} {2}".format(resultI, resultJ, resultK))

Measured memory_bytes: 3060
function Main(input) {
	if(input<10){
		console.log(input);
	}else if(input<100){
		console.log(9)
	}else if(input<1000){
		console.log(input-90)
	}else if(input<10000){
		console.log(909)
	}else if(input<100000){
		console.log(input-9090)
	}else{
		console.log(90909)
	}
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=5e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int n,a,b;
vector<int>v[100010];
ll dp[100010][2];

P dfs(int now,int back){
	ll retw=1,retb=1;
	for(int u:v[now]){
		if(u==back)continue;
		P p=dfs(u,now);
		retw*=(p.fr+p.sc)%MOD;
		retb*=p.fr;
		retw%=MOD;
		retb%=MOD;
	}
	return P(retw,retb);
}

void input(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		a--,b--;
		v[a].eb(b);
		v[b].eb(a);
	}
	return;
}

void solve(){
	P p=dfs(0,0);
	cout<<(p.fr+p.sc)%MOD<<endl;
	return;
}

int main(){
	input();
	solve();
	return 0;
}

Measured memory_bytes: 12672
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < s.length()-1; i++) {
            if (i+2 > s.length()-1) break;

            String tmpStr = s.substring(i, i+3);
            int diff = Math.abs(753 - Integer.valueOf(tmpStr));
            min = Math.min(diff, min);
        }

        System.out.println(min);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int n;
std::string s[55][2];
bool done[55][22][2];
ll memo[55][22][2],c[55];

ll solve(int x, int p, int rev){
	int i,l,r;
	bool flag;
	if(done[x][p][rev]){
		return memo[x][p][rev];
	}
	done[x][p][rev] = true;
	memo[x][p][rev] = INFLL;
	// 回文判定
	flag = true;
	l = p; r = s[x][rev].l_ength()-1;
	while(l<r){
		if(s[x][rev][l]!=s[x][rev][r]){
			flag = false;
			break;
		}
		++l; --r;
	}
	if(flag){
		return memo[x][p][rev] = 0ll;
	}
	for(i=0; i<n; ++i){
		l = p; r = 0;
		flag = true;
		while(l<s[x][rev].l_ength() && r<s[i][1^rev].l_ength()){
			if(s[x][rev][l] != s[i][1^rev][r]){
				flag = false;
				break;
			}
			++l; ++r;
		}
		if(l == s[x][rev].l_ength()){
			memo[x][p][rev] = std::min(memo[x][p][rev],solve(i,r,1^rev)+c[i]);
		}
		if(r == s[i][rev^1].l_ength()){
			memo[x][p][rev] = std::min(memo[x][p][rev],solve(x,l,rev)+c[i]);
		}
	}
	return memo[x][p][rev];
}

int main(void){
	int i;
	ll ans = INFLL;
	std::cin >> n;
	for(i=0; i<n; ++i){
		std::cin >> s[i][0] >> c[i];
		s[i][1] = s[i][0];
		std::reverse(s[i][1].begin(),s[i][1].end());
	}
	for(i=0; i<n; ++i){
		ans = std::min(ans,solve(i,0,0)+c[i]);
	}
	std::cout << ((ans<INFLL)?ans:(-1ll)) << std::endl;
	return 0;
}


Measured memory_bytes: 3652
import sys
input = sys.stdin.readline

def main():
    N = int(input())

    check = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
    
    for i in range(N):
        b, f, r, v = map(int, input().split())
        check[b-1][f-1][r-1] += v
    
    for i in range(4):
        for j in range(3):
            for k in range(10):
                print("", check[i][j][k], end="")
            print()
        if i != 3:
            print("#"*20)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5640
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Patisserie ABC
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;

typedef long long ll;

const ll sxs[] = {  1, -1,  1, -1,  1, -1,  1, -1 };
const ll sys[] = {  1,  1, -1, -1,  1,  1, -1, -1 };
const ll szs[] = {  1,  1,  1,  1, -1, -1, -1, -1 };
const ll LINF = 1LL << 61;

/* typedef */

/* global variables */

ll dp[8][MAX_N + 1];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);

  for (int k = 0; k < 8; k++) {
    fill(dp[k], dp[k] + n + 1, -LINF);
    dp[k][0] = 0;
  }
  
  for (int i = 0; i < n; i++) {
    ll xi, yi, zi;
    scanf("%lld%lld%lld", &xi, &yi, &zi);

    for (int k = 0; k < 8; k++) {
      ll *dpk = dp[k];
      ll d = sxs[k] * xi + sys[k] * yi + szs[k] * zi;
      for (int j = i; j >= 0; j--)
	setmax(dpk[j + 1], dpk[j] + d);
    }
  }

  ll maxdp = -LINF;
  for (int k = 0; k < 8; k++) setmax(maxdp, dp[k][m]);
  printf("%lld\n", maxdp);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
using namespace std;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
ll n,m;
ll qm(ll a,ll b)
{
    ll ret=1;
    while(b)
    {
        if(b&1)
        {
            ret=(ret*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ret;
}
int main()
{
    scanf("%lld %lld",&n,&m);
    printf("%lld\n",qm(n,m));
    return 0;
}



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

int main() {
    string wds[] { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };

    string S;
    cin >> S;

    for (int i = 0; i < 7; ++i) {
        if (S == wds[i]) {
            cout << 7 - i << endl;
            return 0;
        }
    }

    return 0;
}


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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll graph[101][101] = {{}}, d[101] = {}, n;

void bfs(int v) {
  queue<int> q;
  q.push(v);
  ll u;
  for(int i = 1; i <= n; i++) d[i] = -1;
  d[v] = 0;
  while(!q.empty()) {
    u = q.front(); q.pop();
    for(int i = 1; i <= n; i++) {
      if(graph[u][i] == 0) continue;
      if(d[i] != -1) continue;
      d[i] = d[u] + 1;
      q.push(i);
    }
  }
}

signed main() {
	ll u, v, k;
  cin >> n;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v;
      graph[u][v] = 1;
    }
  }

  bfs(1);

  for(int i = 1; i <= n; i++) {
    cout << i << " " << d[i] << endl;
  }

	return 0;
}


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

using namespace std;
int main() {
	int n, otsuri;

	cin >> n;

	otsuri = n % 1000;

	if (otsuri == 0) {
		cout << 0 << endl;
	}
	else {
		cout << 1000 - otsuri << endl;
	}
}

Measured memory_bytes: 3636
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

s = input()
n = len(s)
dp = [[0] * 4 for _ in range(n+1)]
dp[0][0] = 1
for i,x in enumerate(s):
    for j in range(4):
        if x == '?':
            dp[i+1][j] = dp[i][j] * 3
        else:
            dp[i+1][j] = dp[i][j]
    if x == 'A' or x == '?':
        dp[i+1][1] += dp[i][0]
    if x == 'B' or x == '?':
        dp[i+1][2] += dp[i][1]
    if x == 'C' or x == '?':
        dp[i+1][3] += dp[i][2]
    for j in range(4):
        dp[i+1][j] %= mod
print(dp[-1][-1])

Measured memory_bytes: 89564
#include <cstdio>

int main() {
  //入力
  int x,y;
 
  for(int i = 0; i<3000 ;i++){
      scanf("%d %d",&x,&y);
      if(x==0 && y==0)
      break;

      else if(x <= y) 
      printf("%d %d",x,y);
    
      else if(y <= x) 
      printf("%d %d",y,x);

    
      printf("\n");
    
    
  }
  return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N), y(M);
  rep(i, N) cin >> x[i];
  rep(i, M) cin >> y[i];

  for (int z = X + 1; z <= Y; z++) {
    bool flg = true;
    rep(i, N) if (x[i] >= z) flg = false;
    rep(i, M) if (y[i] < z) flg = false;
    if (flg) {
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F(i, x, y) for (int i = (x); i <= (y); ++i)
#define Fr(i, x, y) for (int i = (x); i < (y); ++i)
using namespace std;
typedef long long ll;

const int N = 300000 + 5;
int n, A[N], cnt[N], B[N], Fl[N], Fr[N];

int tg[N];
void ad(int x, int t) {
	if (x < 0 || x >= n) return ;
	tg[x] += t;
}
void add(int l, int r) {
	if (l>r) return ;
//	cerr << "add: " << l << " " << r << '\n';
	ad(l, 1); ad(r+1, -1);
}
int main() {
	memset (Fl, -1, sizeof(Fl));
	memset (Fr, -1, sizeof(Fr));
	scanf ("%d", &n);
	Fr(i, 0, n) scanf ("%d", &A[i]), ++cnt[A[i]], Fr[A[i]] = i;
	for (int i = n-1; i >= 0; --i) Fl[A[i]] = i;
	Fr(i, 0, n) scanf ("%d", &B[i]), ++cnt[B[i]];
	if (*max_element(cnt, cnt + 300000) > n) return puts("No"), 0;
	Fr(i, 0, n) {
		// intersect: Fr = i initially Fr = Fr, i = 1
		// Fl = j, initially Fl = Fl, i = 1
		if (Fl[B[i]] == -1) continue;
		int stl = (i - Fr[B[i]] + n) % n, str = (i - Fl[B[i]] + n) % n;
		if (stl > str)	add(stl, n-1), add(0, str);
		else add(stl, str);
	}
	for (int i = 0; i < n; ++i) {
		if (i) tg[i] += tg[i - 1]; 
		if (!tg[i]){
			puts("Yes");
			int cur = i;
			for (int j = 1; j <= n; ++j) {
				printf("%d ", B[cur]);
				(cur += 1) %= n;
			}
			return 0; 
		}
	}
	puts("No");
	return 0;
}


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

int g[15][15];

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      g[i][j]=-1;
    }
  }
  for(int i=0;i<n;++i){
    int m;
    cin >> m;
    for(int j=0;j<m;++j){
      int a,x;
      cin >> a >> x;
      --a;
      g[i][a]=x;
    }
  }

  int ans=0;
  for(int i=0;i<1<<n;++i){
    vector<int> d(n);
    for(int j=0;j<n;++j) if(i>>j&1){
      d[j]=1;
    }
    bool ok=true;
    for(int j=0;j<n;++j){
      if(d[j]){
        for(int k=0;k<n;++k){
          if(g[j][k]==-1)continue;
          if(g[j][k]!=d[k]) ok=false;
        }
      }
    }
    if(ok) ans=max(ans,__builtin_popcount(i));
  }
  cout << ans << endl;
  return 0;
}


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


int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    for(int i=2;i<n;i++){
        string str = "";;
        str += s[i-2];
        str += s[i-1];
        str += s[i];
        if(str == "ABC") cnt++;
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
int main()
{
  int n;
  cin >> n;
  vecll a(n),b(n,0);
  ll sum = 0;
  REP(i,n) {
    cin >> a[i];
    sum += a[i];
  }
  b[0] = a[0];
  REP(i,n - 1){
    b[i + 1] = b[i] + a[i + 1];
  }
  ll ans = LLONG_MAX;
  for(int i = 0;i <= n - 2; i++){
    ans = min(ans,abs(sum-2*b[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int dp[200] = {0};
int h[200] , r[200];
int n,m;

int main(){
	while(cin >> n , n){
		rep(i,n)cin >> h[i] >> r[i];
		cin >> m;
		rep(i,m)cin >> h[n+i] >> r[n+i];
		int ans = 0;
		rep(i,200)dp[i] = 1;
		rep(x,n+m){
			rep(i,n+m)rep(j,n+m){
				if(h[j] < h[i] && r[j] < r[i]){
					dp[i] = max(dp[j]+1,dp[i]);
				}
			}
		}
		cout << *max_element(dp,dp+n+m) << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <stdio.h>

using namespace std;


map <string, int> cnt;

int main() {
	
	string firstWord;
	string secondWord;
	
	int maxCount = 0;
	int maxLength = 0;
	
	string s;
	while (cin >> s) {
		cnt[s] = cnt[s] + 1;
		if (cnt[s] > maxCount) {
			maxCount = cnt[s];
			firstWord = s;
		}
		
		if ((int) s.size() > maxLength) {
			maxLength = s.size();
			secondWord = s;
		}
	}
	
	cout << firstWord << ' ' << secondWord << "\n";
	
	return 0;
}

Measured memory_bytes: 3072
import sys
input = sys.stdin.readline

N,M = map(int, input().split())

penalty=[0]*N
correct=[False]*N

for i in range(M):

    p,s = input().split()
    p = int(p)

    if s=="AC":
        correct[p-1]=True

    else:
        if correct[p-1]==False:
            penalty[p-1] += 1

for i in range(N):
    if correct[i]==False:
        penalty[i]=0

print(sum(i == True for i in correct),sum(penalty))

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    vector<int> a(n),b(n);
    vector<bool> p(n,true);
    for(auto&i:a) in>>i;
    for(auto&i:b) in>>i;
    fr(i,n-n/2) p[i]=false;
    bool F{};
    int ans=1e9;
    do{
        vector<pair<int,int>> e,o,q(n);
        fr(i,n){
            //cout<<p[i]<<" ";
            if(p[i]) o.emplace_back(i%2?a[i]:b[i],i);
            else e.emplace_back(i%2?b[i]:a[i],i);
        }
        //cout<<endl;
        sort(o.begin(),o.end());
        sort(e.begin(),e.end());
        fr(i,n){
            if(i%2) q[i]=o[i/2];
            else q[i]=e[i/2];
            //cout<<q[i]<<" ";
        }
        //cout<<endl;
        bool f=true;
        fr(i,n-1) if(q[i].first>q[i+1].first) f=false;
        if(!f) continue;
        F=f;
        int cnt{};
        fr(i,n){
            fr(j,i) if(q[i].second<q[j].second) ++cnt;
        }
        ans=min(ans,cnt);
    }while(next_permutation(p.begin(),p.end()));
    if(F) cout<<ans<<endl;
    else cout<<-1<<endl;
}

Measured memory_bytes: 256
import collections
N = int(input())
S = [input() for _ in range(N)]
C = collections.Counter(S)
MAX = 0
L = []
for c in C.most_common():
    if c[1] > MAX:
        MAX = c[1]
        L = [c[0]]
    elif c[1] == MAX:
        L.append(c[0])
for l in sorted(L):
    print(l)

Measured memory_bytes: 45044
MOD = 10**9 + 7

fact_range = 10**6
facts = [1] * (fact_range + 1)
for i in range(0, fact_range):
    facts[i+1] = facts[i] * (i + 1) % MOD

ifacts = [1] * (fact_range + 1)
ifacts[fact_range] = pow(facts[fact_range], MOD - 2, MOD)
for i in range(fact_range, 0, -1):
    ifacts[i-1] = ifacts[i] * i % MOD

def comb(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return facts[n] * ifacts[n-k] % MOD * ifacts[k] % MOD



s = int(input())
ans = 0
for n in range(1, s+1):
    t = s - n * 3
    if t < 0:
        continue
    ans += comb(t+n-1, n-1)
    ans %= MOD
print(ans)
#dp = [0] * (s + 1)
#dp[0] = 1
#for x in range(3, s+1):
#    for si in range(x):
#        for to in range(si + x, s + 1, x):
#            dp[to] = (dp[to] + dp[to-x]) % MOD
#print(dp[s])

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

int main(){
  long long n, k; cin >> n >> k;
  vector<long long> v(n);
  for(int i = 0;i < n; i++){
    cin >> v.at(i);
  }
  long long out = 0;
  for(int i = 1; i < k + 1; i++){
    for(int j = 0; j < i + 1; j++){
      long long out_tmp = 0;
      vector<long long> tmp;
      if(i <= n){
        for(int l = 0; l < j; l++) tmp.push_back(v.at(l));
        for(int l = 0; l < i - j; l++) tmp.push_back(v.at(n - 1 - l));
      }else{
        for(int l = 0; l < n; l++){
          tmp.push_back(v.at(l));
        }
      }
      sort(tmp.begin(), tmp.end());
      for(int l = 0; l < tmp.size(); l++){
        out_tmp += tmp.at(l);
      }
      for(int l = 0; l < k - i; l++){
        if(l >= i) break;
        if(tmp.at(l) >= 0){
          break;
        }else{
          out_tmp -= tmp.at(l);
        }
      }
      if(out_tmp > out) out = out_tmp;
    }
  }
  cout << out;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))

a = Counter(a)
a = {key: val for key, val in a.items() if val >= 2}
a = dict(sorted(a.items(), reverse=True))

if len(a) == 0:
    print(0)
    exit()

side1 = max(a)
a[side1] -= 2

a = {key: val for key, val in a.items() if val >= 2}
a = dict(sorted(a.items(), reverse=True))

if len(a) == 0:
    print(0)
    exit()

side2 = max(a)

print(side1 * side2)


Measured memory_bytes: 79384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<string> W(N);
    map<string, int> check;
    rep(0, i, N)
    {
        cin >> W[i];
        if (check[W[i]] != 0)
        {
            cout << "No" << endl;
            return 0;
        }
        else
        {
            check[W[i]] = 1;
        }
        if ((i != 0) && (W[i - 1][W[i - 1].size() - 1] != (W[i][0])))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(ReadLine());
        }

        public static long[] Reads()
        {
            return ReadLine().Split().Select(long.Parse).ToArray();
        }

        
         public static long gcd(long x, long y)
        {
            if (x < y) gcd(y, x);
            while (y != 0)
            {
                var z = x;
                x = y;
                y = z % y;
            }
            return x;
        }

        public static long lcm(long x, long y)
        {
            return x * y / gcd(x, y);
        } 

        public static long C(long n, long k)
        {
            long x = 1;
            for (long i = 1; i <= k; i++)
            {
                x *= n - i + 1;
                x /= i;
            }
            return x;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var i = new long[5];
            i[0] = Read();
            i[1] = Read();
            i[2] = Read();
            i[3]= Read();
            i[4]= Read();

            if (n % i.Min() == 0)
                WriteLine(n / i.Min() + 4);
            else
                WriteLine(n / i.Min() + 5);


            Out.Flush();
        }
    }
}


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

int main(){
    long long n, x;
    cin >> n >> x;

    long long a[4000];
    long long b[4000];

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

    long long ans = LLONG_MAX;
    for(int p = 0;p < n;p++){
        long long tmp = x*p;
        for(int i = 0;i < n;i++){
            tmp += b[i];
        }

        ans = min(ans, tmp);

        for(int i = 0;i < n;i++){
            b[i] = min(b[i], a[(n+i-(p+1))%n]);
        }
    }

    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

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

  private void solve() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      String[] ln = in.readLine().split(" ");
      final int A = atoi(ln[0]);
      final int B = atoi(ln[1]);
      final int Q = atoi(ln[2]);

      long[] s = new long[A+1];
      for (int i = 0; i < A; i++) {
        s[i] = atol(in.readLine());
      }
      s[A] = 1L << 40;

      long[] t = new long[B+1];
      for (int i = 0; i < B; i++) {
        t[i] = atol(in.readLine());
      }
      t[B] = 1L << 40;

      for (int q = 0; q < Q; q++) {
        long x = atol(in.readLine());
        long dist = 1L << 50;

        for (int c = 0; c < 2; c++) {
          long[] af = c == 0 ? s : t;
          long[] as = c == 0 ? t : s;

          for (int i = 0; i < 2; i++) {
            int posF = binarySearch(af, x) + i;
            long df = af[posF];

            for (int j = 0; j < 2; j++) {
              int posS = binarySearch(as, x) + j;
              long ds = as[posS];
              
              long d = Math.abs(x - df);
              d += Math.abs(df - ds);
              dist = Math.min(dist, d);
            }
          }
        }

        out.println(dist);
      }
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  int atoi(String s) { return Integer.parseInt(s); }
  long atol(String s) { return Long.parseLong(s); }

  private int binarySearch(long[] arr, long x) {
    int left = 0;
    int right = arr.length;

    while(right - left > 1) {
      int mid = (left + right) / 2;
      if(arr[mid] <= x)  left = mid;
      else right = mid;
    }
    return left;
  }
}

Measured memory_bytes: 47728
#include <iostream>
#include <cmath>

using namespace std;

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

    int count = 0;

    while (N--)
    {
        float x, y;
        cin >> x >> y;

        if (sqrt(pow(x, 2) + pow(y, 2)) <= D)
        {
            // cout << "masuk\n";
            count++;
        }
    }

    cout << count << "\n";

    return 0;
}

Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int N, M;
vector<vector<int>> E;
vector<bool> visited;
vector<bool> tojo;


void dfs(int x){
    visited[x] = true;
    for(int i=0; i<E[x].size(); i++){
        if(!visited[E[x][i]]) dfs(E[x][i]);
    }
    return;
}


int main() {
    cin >> N >> M;
    E.resize(N);
    visited.resize(N);
    tojo.resize(N);
    for(int i=0; i<M; i++){
        int x, y, z; cin >> x >> y >> z;
        E[x-1].push_back(y-1);
        E[y-1].push_back(x-1);
        tojo[x-1] = true;
        tojo[y-1] = true;
    }
    
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(tojo[i] && !visited[i]){
            dfs(i);
            cnt++;
        }
    }

    for(int i=0; i<N; i++){
        if(!tojo[i]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 8832
#include<bits/stdc++.h>
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
int main(){
    speed;
    int a , check= 0;
    cin >> a ;
    vector<int>vc(a);
    vector<int>vc2;
    for ( int i = 0;i < a;i++){
        cin >> vc[i];
    }
    for ( int i = 0;i < a;i++){
        vc2.push_back(vc[i]);
    }
    sort(vc.begin(),vc.end());
    for ( int i = 0 ;i < a;i++ ){
        if (vc[i]!=vc2[i]){
            check++;
        }
    }
    if (check == 2 || check == 0){
        cout << "YES";
    }else{
        cout << "NO";
    }
}





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

using namespace std;

vector<int> SlideMinimum(vector<int>& data, int range) {
	vector<int> ret;
	deque<int> dq;
	for (int i = 0; i < data.size(); i++) {
		while (dq.size() && data[dq.back()] > data[i])dq.pop_back();
		dq.push_back(i);
		if (range <= i) {
			if (i - range == dq.front())
				dq.pop_front();
		}
		if (range - 1 <= i)
			ret.push_back(data[dq.front()]);
	}
	return ret;
}

vector<int> SlideMaximum(vector<int>& data, int range) {
	vector<int> ret;
	deque<int> dq;
	for (int i = 0; i < data.size(); i++) {
		while (dq.size() && data[dq.back()] < data[i])dq.pop_back();
		dq.push_back(i);
		if (range <= i) {
			if (i - range == dq.front())
				dq.pop_front();
		}
		if (range - 1 <= i)
			ret.push_back(data[dq.front()]);
	}
	return ret;
}

int N, K;
vector<int> p;
vector<vector<int>> E;
vector<int> visited;

void addE(int s, int t) {
	E[s].push_back(t), E[t].push_back(s);
}

void dfs(int pos, int bef) {
	for (int i = 0; i < E[pos].size(); i++)
		if (!visited[E[pos][i]])visited[E[pos][i]] = true, dfs(E[pos][i], pos);
}

int main() {
	
	cin >> N >> K;
	p.resize(N);
	E.resize(N), visited.resize(N);
	for (int i = 0; i < N; i++)cin >> p[i];

	if (K == N) {
		cout << 1 << endl;
		return 0;
	}

	auto sm = SlideMinimum(p, K + 1), sM = SlideMaximum(p, K + 1);

	for (int i = 0; i < sm.size(); i++) {
		if (p[i] == sm[i] && p[i + K] == sM[i])addE(i, i + 1);
	}
	
	int start = 0;
	vector<int> longerThanK;
	for (int i = 1; i < N; i++) {
		if (p[i - 1] < p[i]);
		else {
			if (i - start >= K) {
				longerThanK.push_back(start);
			}
			start = i;
		}
	}
	if(N - start >= K)longerThanK.push_back(start);

	for (int i = 0; i < (int)longerThanK.size() - 1; i++)addE(longerThanK[i], longerThanK[i + 1]);

	int ans = 0;
	for (int i = 0; i < N - K + 1; i++) {
		if (!visited[i]) {
			ans++;
			visited[i] = true;
			dfs(i, -1);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 20596
import java.io.PrintWriter

object Main extends App {
  val A, B, C, X, Y = MyPredef.nextInt
  val p = new PrintWriter(System.out)
  val normal = A * X + B * Y
  val ptn1 = {
    if (Y > X) {
      C * 2 * X + B * (Y - X)
    } else {
      C * 2 * X
    }
  }
  val ptn2 = {
    if (X > Y) {
      C * 2 * Y + A * (X - Y)
    } else {
      C * 2 * Y
    }
  }

  val ans = List(normal, ptn1, ptn2)

  p.println(ans.min)
  p.flush()
}

object MyPredef {
  @inline def rep(n: Int, f: => Unit): Unit = { var c = 0; while (c < n) { f; c += 1 } }
  @inline def rep(n: Int, f: Int => Unit): Unit = { var c = 0; while (c < n) { f(c); c += 1 } }

  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}


Measured memory_bytes: 25536
N = int(input())
A = list(map(int,input().split()))

C = [0 for _ in range(N)]
for a in A:
  a -= 1
  C[a] += 1
D = [0 for _ in range(N)]
for i in range(N):
  if C[i] >= 2:
    D[i] = C[i]*(C[i]-1)//2
s = sum(D)
for a in A:
  a -= 1
  if C[a] <= 2:
    print(s-D[a])
  else:
    print(s-D[a]+(C[a]-1)*(C[a]-2)//2)

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

using namespace std;

int main(){

    int a, b;
    cin >> a >> b;


    if (abs(a - b) >= 2){
        int mx = max(a, b);
        cout << mx + (mx - 1) << endl;
    } else {
        cout << a + b << endl;
    }

    
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

bool is_exponential(int a) {
  if(a == 1) return true;
  for(int b = 2; b * b <= a; b++) {
    for(int num = b * b;num <= a; num *= b) {
      if(num == a) {
        //cout << b << "**" << num << endl;
        return true;
      }
    }
  }

  return false;
}

int main(void) {
  int X;
  cin >> X;
  for(int i = X; i > 0; i--) {
    if(is_exponential(i)) {
      cout << i << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 888
h, w, k = map(int, input().split())
s = [input() for _ in range(h)]

ans = [[0] * w for _ in range(h)]
cnt, first = 1, -1
for i in range(h):
    tmp = 0
    if '#' in s[i]:
        if first == -1:
            first = i
        for j in range(w):
            if s[i][j] == '#':
                tmp += 1
                if tmp > 1:
                    cnt += 1
            ans[i][j] = cnt
        cnt += 1
    else:
        if i > 0:
            ans[i] = ans[i - 1][:]

for q in range(first):
    ans[q] = ans[first][:]

for i in range(h):
    print(*ans[i])


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long long> lucas;

    lucas.push_back(2);
    lucas.push_back(1);

    for(int i=2; i<=N; i++){
        lucas.push_back(lucas.at(i-1)+lucas.at(i-2));
    }

    cout << lucas.at(N) << endl;

    return 0;
}

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

int main()
{
	int h, a, b, n = 0;

	cin >> h >> a >> b;

	for (int i = 0; i <= b - a; i++) {
		if (h % (a + i) == 0)
			n++;
	}

	cout << n << endl;
	
	return 0;
}


Measured memory_bytes: 3120
n=int(input())
a=list(map(int, input().split()))

from collections import Counter
c=Counter(a)

ans_1=0
ans_2=0
for key in c:
    if c[key]>=2 and key>=ans_1:
        ans_1,ans_2=key,ans_1
    elif c[key]>=2 and key>=ans_2:
        ans_2=key
    if c[key]>=4 and key>=ans_2:
        ans_2=key

print(ans_1*ans_2)

Measured memory_bytes: 18216
#include <iostream>
using namespace std;
int main()
{ 
    long long int i, n, sum, input, min, max;
    
    cin >> n;
    cin >> input;
    sum = 0;
    min = input;
    max = input;
    for(i=1; i<=n; i++)
    {
        sum = sum + input;
        
        if(input > max)
           max = input;
        else if (input < min)   
           min = input;
        cin >> input;
    }
    cout << min << " " << max << " " << sum << endl;
}    


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int maxn = 111111;

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int ans = 0;
		for (int x = 1; x * x < i; x++) {
			for (int y = 1; y * y + x * x + x * y < i; y++) {
				int k = x + y, m = i - x * x - y * y - x * y;
				int z = (sqrt(1.0 * k * k + 4.0 * m) - k) / 2;
				if (x * x + y * y + z * z + x * y + x * z + y * z == i)
					ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using ll = long long;

template<typename T>
using vec2 = vector<vector<T>>;
template<typename T>
using vec3 = vec2<vector<T>>;
template<typename T>
using vec4 = vec3<vector<T>>;
template<typename T>
using vec5 = vec4<vector<T>>;
template<typename T>
using vec6 = vec5<vector<T>>;



int main(){
    ll N,Q;cin>>N>>Q;
    ll res = (N-2)*(N-2);
    int currenttate = N-2;
    int currentyoko = N-2;
    vector<ll> tate(N-2,N-2);
    vector<ll> yoko(N-2,N-2);
    for(int q = 0;q < Q;q++){
        int type;cin>>type;
        if(type == 1){//tate
            int t;cin>>t;t-=2;
            if(t < currenttate){
                res -= currentyoko;
                for(int i = currenttate-1;i >= t;i--){
                    tate[i] = currentyoko;
                }
                currenttate = t;
            }else{
                res-=tate[t];
            }
        }
        if(type == 2){
            int y;cin>>y;y-=2;
            if(y < currentyoko){
                res -= currenttate;
                for(int i = currentyoko - 1;i >= y;i--){
                    yoko[i] = currenttate;
                }
                currentyoko = y;
            }else{
                res-=yoko[y];
            }
        }
        // for(int i = 0;i < tate.size();i++)cout<<tate[i]<<" ";cout<<endl;
        // for(int i = 0;i < tate.size();i++)cout<<yoko[i]<<" ";cout<<endl;
        // cout<<"----"<<endl;
        
    }
    cout<<res<<endl;
    

}

Measured memory_bytes: 6424
#include <stdio.h>

int main(void)
{
	int a,b,d,r;
	double x,y,f;
	scanf("%d %d",&a,&b);
	d = a/b;
	r = a%b;
	x=a;
	y=b;
	f = x/y;
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 636