akhauriyash/Code-Regression huggingface dataset:
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
typedef pair<LL, LL> pii;
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

LL k;

LL calc(LL x){
    LL y = x + 1;
    string v = to_string(y);
    map<LL, bool>cand;
    for(int i = v.size();i > 0;i--){
        LL a = 0,b = 1, c;
        REP(j, i - 1){
            a *= 10;
            a += v[j] - '0';
        }
        for(int j = i - 1;j < (int)v.size(); j++){
            a *= 10;
            b *= 10;
        }
        b /= 10;
        c = b - 1;
        for(int j = v[i - 1] - '0'; j <= 9;j++){
            cand[a + j * b + c] = true;
        }
    }
    vector<pair<double, LL>> w;
    for(auto it = cand.begin();it != cand.end(); it++){
        w.emplace_back(make_pair((double)it->first/d_sum(it->first), it->first));
    }
    sort(ALL(w));
    return w[0].second;
}

int main(){
    INIT;
    cin >> k;
    LL num = 0;
    while(k > 0){
        num = calc(num);
        cout << num << endl;
        k--;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
 long long int a,b,c,k;
  cin >> a >>b >>c >>k;
  if(k<=a) cout << k <<endl;
  else if(k<=(a+b)) cout << a <<endl;
  else cout << a-(k-(a+b)) <<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no { cout << -1; return; }

void solve() {
    int n; cin >> n;
    cout << n + n * n + n * n * n;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3636
program main
  implicit none
  integer :: n, res, i
  integer, allocatable :: a(:)

  read (*, *) n
  allocate (a(n))
  read (*, *) a(:)

  res = a(1)
  do i = 2, n
    res = gcd(res, a(i))
  end do

  write (*, "(i0)") res

  contains

  function gcd(x, y) result(a)
    integer, intent(in) :: x, y
    integer :: a, b, r
    a = max(x, y)
    b = min(x, y)
    do while (b > 0)
      r = mod(a, b)
      a = b
      b = r
    end do
  end function gcd
end program main


Measured memory_bytes: 1152
#include <iostream>
#include <map>
#include <iomanip>

using namespace std;

int main()
{
	unsigned int n, m;

	cin >> n >> m;

	map<unsigned int, unsigned int> year;

	unsigned int p[100001];
	unsigned int y[100001];

	for (unsigned int i = 1; i < m + 1; ++i)
	{
		cin >> p[i] >> y[i];
		year[y[i]] = i;
	}

	int id[100001];
	int size[100001] = {};

	for (auto itr = year.begin(); itr != year.end(); ++itr)
	{
		size[p[itr->second]]++;
		id[itr->second] = size[p[itr->second]];
	}

	for (unsigned int j = 1; j < m + 1; ++j)
	{
		cout << setfill('0') << right << setw(6) << p[j];
		cout << setfill('0') << right << setw(6) << id[j];
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


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

 if(A == B)
 {
    cout << C << endl;
 }
 else if(A == C)
 {
    cout << B << endl;
 }
 else if(B == C)
 {
    cout << A << endl;
 }
}

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

temp = []

for i in range(len(H)):
    t = T - H[i] * 0.006
    t = abs(t - A)

    temp.append(t)

print(temp.index(min(temp)) + 1)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int N;
	long long int sum=0;
	cin >> N;
	 for(int i=1;i<=N;i++)
	 {
	 	if(i%3==0 || i%5==0)
		{
			sum=sum;
		}
		else{
			sum=sum+i;
		}
	 }
	 cout << sum << endl;
     return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>

int main(void){
    int n,m;
    scanf("%d %d",&n,&m);
    int a[n];
    for(int i = 0;i < n;i++)scanf("%d",&a[i]);
    int sum = 0;
    int cnt = 0;
    for(int i = 0;i < n;i++)sum += a[i];
    for(int i = 0;i < n;i++)if(a[i] * 4 * m >= sum)cnt++;
    puts(cnt>=m?"Yes":"No");
    return 0;
}


Measured memory_bytes: 128
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    string s, t;
    cin >> s >> t;
    n = s.length();
    m = t.length();
    int best = m;
    for(i=0;i<n-m+1;i++) {
        ans = 0;
        for(j=0;j<m;j++) {
            if(t[j] != s[i+j]) ans++;
        }
        best=min(best,ans);
    }
    cout<<best<<endl;
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;
lint p=1e9+7;

int main(){
  int N;
  cin>>N;
  int A[N];
  REP(i,N)cin>>A[i];
  lint ans=1;
  int M[3]={0};
  REP(i,N){
    int counter=0;
    REP(j,3){
      if(A[i]==M[j]){
        if(counter==0)M[j]++;
        counter++;
      }
    }
    ans*=counter;
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
N = input()
S = input()
L = [0]+[]
for x in S:
    if x == 'W':
        L.append(0)
    else:
        L.append(1)
for i in range(len(L)-1):
    L[i+1] += L[i]
ans =[]
for i in range(len(L)-1):
    cnt = i - L[i]
    try :cnt += L[len(L)-1] - L[i+1]
    except : break
    ans.append(cnt)
print(min(ans))


Measured memory_bytes: 27400
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		//String t= sc.next();
		//int n = sc.nextInt();
		//int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		long count1=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		/*for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(t.substring(i,i+1))) {
				count++;
			}
		}*/

		if(s.equals("SUN")) {//SUN,MON,TUE,WED,THU,FRI,SAT
			System.out.println(7);
		}else if(s.equals("MON")){
			System.out.println(6);
		}else if(s.equals("TUE")){
			System.out.println(5);
		}else if(s.equals("WED")){
			System.out.println(4);
		}else if(s.equals("THU")){
			System.out.println(3);
		}else if(s.equals("FRI")){
			System.out.println(2);
		}else if(s.equals("SAT")){
			System.out.println(1);
		}

		//System.out.println(n*n);
	}
}




Measured memory_bytes: 25300
#include<stdio.h>

int main(){
  int i, j, s, f, d, sum;

  while(scanf("%d", &d) != EOF){
    sum = 0;
    for(i=d, j=1; i<600; i+=d, j++){
      s = j * d;
      f = s * s;
      sum += (d * f);
    }

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

  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
 
char c ;
 
int main(void){
    
    scanf ("%s",&c) ;
    
    if ( c=='a' || c=='e' || c=='i' || c=='o' || c=='u' ){
        printf ("vowel\n") ;
        
    } else {
        printf ("consonant\n") ;
        
    }

    return 0 ;
}

Measured memory_bytes: 128
using System;
class ABC065
{
    static void Main(string[] args)
    {
        string line = Console.ReadLine();
        string[] daysStr = line.Split(' ');
        int x = int.Parse(daysStr[0]);
        int a = int.Parse(daysStr[1]);
        int b = int.Parse(daysStr[2]);
        if(b > a + x){
            Console.WriteLine("dangerous");
        }else{
            if(b > a){
                Console.WriteLine("safe");
            }else{
                Console.WriteLine("delicious");
            }
        }
    }
}

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

int main()
{
  int t=1,n;
  string s;
  //cin>>t;
  while(t--)
  {
    cin>>n>>s;
    int c=0,c1=0;
    for(int i=0;i<n;i++) if(s[i]=='W') c++;
    for(int i=n-1;i>=n-c;i--) if(s[i]=='R') c1++;
    cout<<c1<<endl;
  }
}

Measured memory_bytes: 3784
s = input()

a = int(s[:2])
b = int(s[2:])

if (a > 12 or a == 0) and b >= 1 and b <= 12:
    print('YYMM')
elif a >= 1 and a <= 12 and (b > 12 or b == 0):
    print('MMYY')
elif a >= 1 and a <= 12 and b >= 1 and b <= 12:
    print('AMBIGUOUS')
else:
    print('NA')


Measured memory_bytes: 3060
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();

    int n;cin >> n;
    int m;
    map<int,int> mp;

    for(int i=0;i<n+1;++i)
    {
        int a; cin >> a;

        if(mp.count(a))
        {
            m = i-mp[a]-1;
        } else
        {
           mp[a]=i;
        }
    }
    m=n-1-m;
    for(int k=1;k<=n+1;++k)
    {
        ll ans=0;

        ans += COM(n-1,k);
        //cout << m << " ";
        ans += 2*COM(n-1,k-1) - COM(m,k-1) + MOD;
        ans %= MOD;
        ans += COM(n-1,k-2);
        ans %= MOD;

        cout << ans << endl;
    }

}

Measured memory_bytes: 17792
import std.stdio, std.string, std.conv, std.algorithm, std.array;

struct Team {
  int l;
  int u;
  int a;
  int p;

  this( int l, int u, int a, int p ) {
	this.l = l;
	this.u = u;
	this.a = a;
	this.p = p;
  }

  int opCmp( Team t ) {
	if ( a != t.a ) return t.a - a;
	else if ( p != t.p ) return p - t.p;
	else return l - t.l;
  }
}

void main() {
  while ( true ) {
	int n = to!int( strip( readln ) );
	if ( n == 0 ) break;
	Team[] ts = new Team[]( n );
	int[ int ] table;
	foreach ( i; 0 .. n ) {
	  auto tokens = map!( to!int )( split( strip( readln ) ) );
	  ts[ i ] = Team( tokens[ 0 ], tokens[ 1 ], tokens[ 2 ], tokens[ 3 ] );
	  table[ ts[ i ].u ] = 0;
	}
	sort( ts );
	int count = 0;

	foreach ( t; ts ) {
	  if ( count < 10 ) {
		if ( table[ t.u ] < 3 ) {
		  writeln( t.l );
		  table[ t.u ] += 1;
		  count++;
		}
	  } else if ( count < 20 ) {
		if ( table[ t.u ] < 2 ) {
		  writeln( t.l );
		  table[ t.u ] += 1;
		  count++;
		}
	  } else if ( count < 26 ) {
		if ( table[ t.u ] < 1 ) {
		  writeln( t.l );
		  table[ t.u ] += 1;
		  count++;
		}
	  }
	}
  }  
}

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

using namespace std;

const int N = 4027;

int cnt[N][N], a[N][N]; 

int get(int x, int y)
{
	if (x < 0 || y < 0)
		return 0;

	return cnt[x][y];
}              

int take(int l1, int r1, int l2, int r2)
{
	int sm = get(l2, r2) - get(l2, r1 - 1) - get(l1 - 1, r2) + get(l1 - 1, r1 - 1);

	return sm;
}

int main()
{
	int n, k;
	
	cin >> n >> k;
                          	
	for (int i = 0; i < n; i++)
	{
		int x, y;
		char c;

		cin >> x >> y >> c;
	
		if (c == 'W')
			y += k;
	
		x %= 2 * k;
		y %= 2 * k;
		
		a[x][y]++;	
	}
        
	for (int i = 0; i < 4 * k; i++)
	{
		for (int j = 0; j < 4 * k; j++)
		{
			int x = a[i % (2 * k)][j % (2 * k)];
			
			cnt[i][j] = x + get(i - 1, j) + get(i, j - 1) - get(i - 1, j - 1); 
		}
	}
	
	int ans = 0;	

	for (int i = 0; i < 2 * k; i++)
	{
		for (int j = 0; j < 2 * k; j++)
		{
			int sm = take(i, j, i + k - 1, j + k - 1) + take(i + k, j + k, i + (2 * k) - 1, j + (2 * k) - 1);
			ans = max(sm, ans);
		}
	}   
	
	cout << ans;
	  	
	return 0;
}


Measured memory_bytes: 97280
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	sl := make([][]int, n+1)
	sl[0] = []int{0, 0, 0}
	for i := 1; i <= n; i++ {
		sl[i] = make([]int, 3)
		fmt.Scan(&sl[i][0], &sl[i][1], &sl[i][2])
	}

	for i := 1; i <= n; i++ {
		d := int(math.Abs(float64(sl[i][1]-sl[i-1][1])) + math.Abs(float64(sl[i][2]-sl[i-1][2])))
		t := sl[i][0] - sl[i-1][0]
		if t < d || t%2 != d%2 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
int dmin(int x,int y,int z){
  if(x<=y && x<=z){
    return x;
  }
  else if(y<=x && y<=z){
    return y;
  }
  else if(z<=x && z<=y){
    return z;
  }
}
int main() {
  int p,q,r;
  cin >> p>> q>>r;
  int ans;
  ans =dmin(p+q,q+r,r+p);
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  long long N,ans=1e15;
  cin >> N;
  long long a[N],SUM=0;
  FOR(i,0,N){
    cin >> a[i];
    SUM += a[i];
    if(i)a[i] += a[i-1];
  }
  FOR(i,0,N-1){
    ans = min(ans,abs(SUM-2*a[i]));
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdbool.h>
 struct Card{
   char suit;
   char value;
 };
 void bubble(struct Card A[],int N){
  int i,j;
   for(i=0;i<N;i++){
     for(j=N-1;j>=i+1;j--){
       if(A[j].value<A[j-1].value){
        struct Card t=A[j];
         A[j]=A[j-1];
         A[j-1]=t;
       }
     }
   }
 }

void selection(struct Card A[],int N){
int i,j;
  for(i=0;i<N;i++){
    int minj=i;
    for(j=i;j<N;j++){
      if(A[j].value<A[minj].value)minj=j;
    }
struct Card t=A[i];
A[i]=A[minj];
A[minj]=t;
  }
}

void print(struct Card A[],int N){
int i;
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%c%c",A[i].suit,A[i].value);
  }
printf("\n");
}
bool isS(struct Card C1[],struct Card C2[],int N){
int i;
for(i=0;i<N;i++){
  if(C1[i].suit != C2[i].suit)return false;
}
return true;
}

int main(){
  struct Card C1[100],C2[100];
  int N,i;
  char ch;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf(" %c %c",&C1[i].suit,&C1[i].value);
  }
for(i=0;i<N;i++)C2[i]=C1[i];
bubble(C1,N);
selection(C2,N);

print(C1,N);
printf("Stable\n");
print(C2,N);
if(isS(C1,C2,N)){
  printf("Stable\n");
}
else{
  printf("Not stable\n");
}
return 0;
}



Measured memory_bytes: 2112
# dpA
def main():
    n = int(input())
    A = tuple(map(int, input().rstrip().split()))
    dp = [0] + [float("inf")] * (n - 1)
    for i in range(1, n):
        for j in range(1, 3):
            if i - j >= 0:
                dp[i] = min(dp[i], dp[i - j] + abs(A[i] - A[i - j]))
    print(dp[-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 53752
n = gets.chomp.to_i
p_array = gets.chomp.split.map(&:to_i)
sort_p = p_array.sort
count = 0
p_array.each_with_index do |p_item, i|
  count += 1 if p_item != sort_p[i]
end
if count <= 2
  print("YES\n")
else
  print("NO\n")
end

Measured memory_bytes: 1788
h, w = gets.split.map(&:to_i)

if h == 1 || w == 1
  puts 1
  exit
end

if w.even?
  first_line = w / 2
  second_line = w / 2
else
  first_line = (w / 2) + 1
  second_line = w / 2
end

if h.even?
  first_line_nums = h / 2
  second_line_nums = h / 2
else
  first_line_nums = (h / 2) + 1
  second_line_nums = h / 2
end

puts first_line * first_line_nums + second_line * second_line_nums


Measured memory_bytes: 1788
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;
int n;
int ar[200005];

bool sign[200005];
bool check(int k){//check if answer will be greater
  int m=2*n-1;
  REP(i,m) sign[i]=(ar[i]>=k);

  int lef=INF,rig=INF;
  int lc,rc;
  REP(i,m-1) if(sign[i]==sign[i+1]){
    int j=i+1;
    while(j<m && sign[j]==sign[i]) ++j;
    if(i<=n-1 && n-1<j){
      return sign[n-1];
    }else if(j<=n-1){
      lef=n-1-(j-1);
      lc=sign[i];
    }else{
      if(rig==INF){
        rig=i-(n-1);
        rc=sign[i];
      }
    }
    i=j-1;
  }
  if(lef==INF && rig==INF){
    return sign[n-1]^((n-1)&1);
  }else if(lef<rig){
    return lc;
  }else return rc;
}

  
int main(){
  cin>>n;
  REP(i,n*2-1) scanf("%d",&ar[i]);

  int lb=1,ub=2*n;
  while(ub-lb>1){
    int md=(lb+ub)>>1;
    if(check(md)) lb=md;
    else ub=md;
  }
  cout<<lb<<endl;


  return 0;
}





Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n,x,m;
  cin>>n>>x>>m;
  vector<ll> a={x};
  set<ll> st={x};
  ll tgt;
  while (true) {
    ll b=a.back();
    ll tmp=st.size();
    a.push_back(b*b%m);
    st.insert(b*b%m);
    if (st.size()==tmp) {
      tgt=a.back();
      break;
    }
  }
  ll j=0;
  ll ans=0;
  for (int i = 0; i < a.size(); ++i)
  {
    if (a[i]==tgt) {
      j=i;
      ans+=tgt;
      break;
    }
    ans+=a[i];
  }
  a.erase(a.begin(),a.begin()+j+1);
  ll cycle = a.size();
  ll sum=accumulate(a.begin(), a.end(),0LL);
  n-=j+1;
  ans+=n/cycle*sum;
  for (int i = 0; i < n%cycle; ++i)
  {
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5948
///usr/bin/g++ -O2 $0 -o ${0%.cpp} && echo "----------" && ./${0%.cpp}; exit;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int N = 1e5 + 10; 
int n, a[N]; 

vector<ii> get(vector<int> c) {
    int m1 = 0, m2 = 0, c1 = 0, c2 = 0; 
    for(int i = 0; i < N; ++i) {
        if(c[i] > c2) {
            c2 = c[i]; 
            m2 = i; 
        }
        if(c2 > c1) {
            swap(c1, c2); 
            swap(m1, m2); 
        }
    }
    return {{m1, c1}, {m2, c2}};
}
int main(int argc, char const *argv[]) {
    scanf("%d", &n); 
    for(int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]); 
    }

    vector<int> c1(N, 0), c2(N, 0); 
    for(int i = 1; i <= n; i += 2) ++c1[a[i]]; 
    for(int i = 2; i <= n; i += 2) ++c2[a[i]]; 

    int a = (n + 1) / 2, b = n - a, ans = 1e9; 
    
    vector<ii> m1 = get(c1); 
    vector<ii> m2 = get(c2); 

    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < 2; ++j) {
            if(m1[i].first != m2[j].first) {
                ans = min(ans, a - m1[i].second + b - m2[j].second); 
            }
        }
    }
    printf("%d\n", ans); 
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    for(int i=0;i<n;i++)
    cin>>l[i];
    int max_l=0;
    int64_t sum=0;
    for(int i=0;i<n;i++){
        if(max_l<l[i])
        max_l=l[i];
        sum+=l[i];
    }
    if(sum-max_l>max_l)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ll long long int
#define INF 1e13
using namespace std;
ll findmin(ll a, ll b) {if(a < b) return a;return b;}
vector<vector<ll>> dp(105, vector<ll>(1e5+5,-1));
ll func(ll i, ll val, vector<ll> &w, vector<ll> &v, ll n)
{
    if(val == 0)
        return 0;
    if(i == n || val < 0)
        return INF;
    if(dp[i][val] != -1)
        return dp[i][val];
    ll ans = findmin(func(i+1,val-v[i],w,v,n)+w[i], func(i+1,val,w,v,n));
    dp[i][val] = ans;
    return ans;
}
int main()
{
    ll n, W;
    cin >> n >> W;
    vector<ll> w(n);
    vector<ll> v(n);
    ll sum = 0;
    for(ll i = 0; i < n; i++)
    {
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    ll maxv = sum;
    ll ans = 0;
    for(ll val = sum; val >= 0; val--)
    {
        ll minreqwt = func(0,val,w,v,n);
        if(minreqwt <= W)
        {
            ans = val;
            break;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 83328
// include
// ----------------------------------------------------------------------------
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>

// repetition
// ----------------------------------------------------------------------------
#define FOR(i, a, b) for (i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// memory clear
// ----------------------------------------------------------------------------
#define CLRNUM(a) memset((a), 0, sizeof(a))
#define CLRBOOL(a, flag) memset((a), flag, sizeof(a))
#define CLRCHAR(a) memset((a), '\0', sizeof(a))

// debug
// ----------------------------------------------------------------------------
#define DEBUGINT(x) printf("%d\n", x);
#define DEBUGFLOAT(x) printf("%f\n", x);
#define DEBUGCHAR(x) printf("%c\n", x);
#define DEBUGSTR(x) printf("%s\n", x);
#define DEBUGFORINT(i, a, b, x) FOR(i, a, b){ printf("%d ", x[i]); }
#define DEBUGFORFLOAT(i, a, b,x ) FOR(i, a, b){ printf("%f ", x[i]); }
#define DEBUGFORCHAR(i, a, b, x) FOR(i, a, b){ printf("%c ", x[i]); }
#define DEBUGREPINT(i, n, x) REP(i, n){ printf("%d ", x[i]); }
#define DEBUGREPFLOAT(i, n, x) REP(i, n){ printf("%f ", x[i]); }
#define DEBUGREPCHAR(i, n, x) REP(i, n){ printf("%c ", x[i]); }

// other
// ----------------------------------------------------------------------------
#define PUTNL printf("\n")

// constant
// ----------------------------------------------------------------------------
#define INF 1000000000

int main(void)
{
    int weight;
    int binary[10];
    int i;
    bool put;

    while(scanf("%d", &weight) != EOF){
        put = false;

        memset(binary, 0, sizeof(binary));

        for (i = 0; i < 10; ++i){
            binary[i] = weight % 2;
            weight /= 2;
        }

        for (i = 0; i < 10; ++i){
            if (put == false){
                if (i != 9){                    
                    if (binary[i] == 1){
                        printf("%d", (int)pow(2, i));
                        put = true;
                    }
                }
                else if (i == 9){
                    if (binary[i] == 1){
                        printf("%d\n", (int)pow(2, i));
                    }
                }
            }
            else if (put == true){
                if (i != 9){
                    if (binary[i] == 1){
                        printf(" %d", (int)pow(2, i));
                    }
                }
                else if (i == 9){
                    if (binary[i] == 1){
                        printf(" %d\n", (int)pow(2, i));
                    }
                    else {
                        printf("\n");
                    }
                }
            }
        }
    }
    
    return 0;
                   
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  string s, t;
  cin >> n >> s >> t;
  string ans = "";
  rep(i, n) {
    ans += s[i];
    ans += t[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
s = input()
k = int(input())

if len(set(s)) == 1:
    print(len(s) * k // 2)
    exit()

s += "🐧"

wow = 0
yeah = []
for i in range(len(s)-1):
    if s[i] != s[i+1]:
        wow += 1
        yeah.append((s[i], wow))
        wow = 0
    else:
        wow += 1

ans = sum(c // 2 for _, c in yeah) * k

if s[0] == s[-2]:
    katakuna = yeah[0][1]
    ijippari = yeah[-1][1]
    te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
    ans -= te * (k - 1)

print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
		    int begin = sc.nextInt();
		    int end = sc.nextInt();
		    int size = end - begin;
		    int[] tmp = new int[size];
		    System.arraycopy(arr, begin, tmp, 0, size);
		    for (int j = 0; j < size; j++) {
		        arr[begin + j] = tmp[size - j - 1];
		    }
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
		    if (i > 0) {
		        sb.append(" ");
		    }
		    sb.append(arr[i]);
		}
		System.out.println(sb);
	}
}



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

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define fst first
#define snd second

int main()
{
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
        cin >> a[i];

    vector<int> b;
    for(int i = 0; i < n; i++)
    {
        if(i < n - 1)
            b.pb(a[i + 1] - a[i]);
        else
            b.pb(k + a[0] - a[n - 1]);
    }
    int ans = -1e9;
    for(int i = 0; i <= n; i++)
        ans = max(ans, b[i]);

    cout << k - ans;

    return 0;
}


Measured memory_bytes: 2168
import math
import statistics

n = int(input())
a = [int(i) for i in input().split()]
for i in range(n):
    a[i] -= i
mc = math.ceil(statistics.median(a))
mf = math.floor(statistics.median(a))
ac = [0 for i in range(n)]
af = [0 for i in range(n)]
for i in range(n):
    ac[i] = abs(a[i]- mc)
    af[i] = abs(a[i]- mf)

print(min([sum(ac),sum(af)]))

Measured memory_bytes: 28916
#include<stdio.h>
#include<string.h>

char S[10010];
int N;
int ans = 0;

int main()
{
	scanf("%d", &N);
	scanf("%s", S);


	if (N % 2 != 0) {
		ans = 1;
	}else {
		for (int i = 0; i < N / 2; i++) {
			if (S[i] != S[i + N / 2]){
				ans = 1;
			}
		}
	}

	if (ans != 0) {
		printf("No");
	}
	else {
		printf("Yes");
	}

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if (a+b<c&&4LL*a*b<1LL*(c-a-b)*(c-a-b)) puts("Yes");else puts("No");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var N = line[0];
            var M = line[1];
            var X = line[2];
            var Y = line[3];
            var x = consoleReader.SplitInt32().OrderByDescending(i => i).ToArray();
            var y = consoleReader.SplitInt32().OrderBy(i => i).ToArray();



            return Math.Max(X, x[0]) < Math.Min(Y, y[0]) ? "No War" : "War";
        }

        public const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int32() => int.Parse(String()); public long Int64() => long.Parse(String()); public ulong UInt64() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray(); public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt32(int count) { for (int i = 0; i < count; i++) yield return Int32(); } public IEnumerable<long> RepeatInt64(int count) { for (int i = 0; i < count; i++) yield return Int64(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt32(int count) { for (int i = 0; i < count; i++) yield return SplitInt32(); } }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    string s;
    cin >> s;
    int a[4];
    rep(i,4){
        a[i]=int(s[i]-'0');
    }
    rep(i,8){
        int tmp=a[0];
        rep(j,3){
            if(i>>j &1){
                tmp+=a[j+1];
            }else tmp-=a[j+1];
        }
        DEBUG{cout << "tmp : " << tmp << endl;}
        if(tmp==7){
            cout << a[0];
            rep(j,3){
                if(i>>j&1)cout << '+';
                else cout << '-';
                cout << a[j+1];
            }
            cout << "=7" << endl;
            return 0;
        }
    }
    return 0;
}


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


signed main() {
  int n; cin >> n;
  bool ap = true;
  for(int i = 0; i < n;i++) {
    int x; cin >> x;
    if(x % 2 == 0 ) {
      if(x%3 != 0 && x%5 != 0) ap = false;
    }
  }
  if(ap) {cout << "APPROVED\n";}
  if(!ap) {cout << "DENIED\n";}

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <numeric>
#include <string>

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl

using namespace std;
using i64 = long long;

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

    vector<int> kuku(150, 0);
    for (int i = 1; i < 10; i++)
    {
        for (int j = 1; j < 10; j++)
        {
            kuku[i * j] = 1;
        }
    }

    if (kuku[n] == 1)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 1e5 + 10;
 
struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
  map<string, int> m;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++){
    string s; cin >> s;
    m[s]++;
  }
  int mx = -INF;
  for (auto it : m){
    mx = max(it.second, mx);
  }
  vector<string> curr;
  for (auto it : m){
    if (it.second == mx)
      curr.push_back(it.first);
  }
  sort(curr.begin(), curr.end());
  for (auto it : curr)
    cout << it << endl;
}

Measured memory_bytes: 25584
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, A;
    cin >> H >> A;
    int add = 0;
    if (H % A != 0) add = 1;
    ll ans = H / A  + add;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

ll N, K;
vll P, M, Z;

// x(<0)以下の積の個数 >= K かどうかチェック
bool check1(ll x) {
    ll sum = 0;
    for(auto p : P) {
        ll y = (x - p + 1) / p; // x < 0 に注意
        sum += upper_bound(M.begin(), M.end(), y) - M.begin();
    }
    return sum >= K;
}

// x(>0)以下の積の個数 >= K かどうかチェック
bool check2(ll x) {
    ll sum = 0;
    rep(i, P.size()) {
        ll y = x / P[i];
        ll tmp = upper_bound(P.begin(), P.end(), y) - P.begin();
        if(i < tmp) tmp--; //自身を除く
        sum += tmp;
    }
    rep(i, M.size()) {
        ll y = x / M[i];
        ll tmp = upper_bound(M.begin(), M.end(), y) - M.begin();
        if(i < tmp) tmp--; //自身を除く
        sum += tmp;
    }
    sum /= 2;
    return sum >= K;
}

int main() {
    cin >> N >> K;
    rep(i,N) {
        ll a;
        cin >> a;
        if(a > 0) P.push_back(a);
        if(a < 0) M.push_back(a);
        if(a == 0) Z.push_back(a);
    }

    ll cp = P.size(), cm = M.size(), cz = Z.size();
    ll minus = cp*cm;
    ll zero = cz*(cp+cm) + cz*(cz-1)/2;

    if(K <= minus) {
        sort(P.begin(), P.end());
        sort(M.begin(), M.end());

        ll ng = -1e18-1, ok = 0;
        while(ok - ng > 1) {
            ll mid = ng + (ok - ng) / 2;
            if(check1(mid)) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
    else if(K <= minus + zero) {
        cout << 0 << endl;
    }
    else {
        K -= minus + zero;
        sort(P.begin(), P.end());
        rep(i, M.size()) M[i] = -M[i];
        sort(M.begin(), M.end());

        ll ng = -1, ok = 1e18+1;
        while(ok - ng > 1) {
            ll mid = ng + (ok - ng) / 2;
            if(check2(mid)) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }

}


Measured memory_bytes: 5412
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	H := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&H[i])
	}
	val := 0
	ans := 0
	for i := 0; i < N-1; i++ {
		if H[i] >= H[i+1] {
			val++
			if ans < val {
				ans = val
			}
		} else {
			val = 0
		}
	}
	fmt.Print(ans)
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long int
#define MAXN 1000001
using namespace std;
ll spf[MAXN];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXN; i++) 
        spf[i] = i; 
    for (ll i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXN; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
void get(map<ll,ll> &ma,ll a[],ll n){
//	ll f=0;
	for(ll i=0;i<n;i++){
        while (a[i] != 1) 
        { 
	        ma[spf[a[i]]]++; 
	        ll temp = spf[a[i]];
	       // cout<<temp<<endl;
	        while(spf[a[i]]==temp){
	        	a[i] = a[i]/spf[a[i]];
			}
        } 
	}
	ll gcd = 1,f=0;
	map<ll,ll> :: iterator it;
	for(it=ma.begin();it!=ma.end();it++){
		ll d = (it->second)/n;
	//	cout<<it->first<<" "<<it->second<<" "<<d<<endl;
		if(d!=0)
		gcd = gcd*(it->first);
		if(it->second!=1){
			f=1;
		}
	}
	if(f==0){
		cout<<"pairwise coprime"<<endl;
	}
	else if(gcd==1){
		cout<<"setwise coprime"<<endl;
	}
	else{
		cout<<"not coprime"<<endl;
	}
}
int main(){
	 sieve();
     ll n;
     cin>>n;
     ll a[n];
     map<ll,ll> ma;
     for(ll i=0;i<n;i++){
     	cin>>a[i];
	 }
	 get(ma,a,n);
}

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

template <int MOD_> struct modnum {
	static constexpr int MOD = MOD_;
	static_assert(MOD_ > 0, "MOD must be positive");

private:
	using ll = long long;

	int v;

	static int minv(int a, int m) {
		a %= m;
		assert(a);
		return a == 1 ? 1 : int(m - ll(minv(m, a)) * ll(m) / a);
	}

public:

	modnum() : v(0) {}
	modnum(ll v_) : v(int(v_ % MOD)) { if (v < 0) v += MOD; }
	explicit operator int() const { return v; }
	friend std::ostream& operator << (std::ostream& out, const modnum& n) { return out << int(n); }
	friend std::istream& operator >> (std::istream& in, modnum& n) { ll v_; in >> v_; n = modnum(v_); return in; }

	friend bool operator == (const modnum& a, const modnum& b) { return a.v == b.v; }
	friend bool operator != (const modnum& a, const modnum& b) { return a.v != b.v; }

	modnum inv() const {
		modnum res;
		res.v = minv(v, MOD);
		return res;
	}
	modnum neg() const {
		modnum res;
		res.v = v ? MOD-v : 0;
		return res;
	}

	modnum operator- () const {
		return neg();
	}
	modnum operator+ () const {
		return modnum(*this);
	}

	modnum& operator ++ () {
		v ++;
		if (v == MOD) v = 0;
		return *this;
	}
	modnum& operator -- () {
		if (v == 0) v = MOD;
		v --;
		return *this;
	}
	modnum& operator += (const modnum& o) {
		v += o.v;
		if (v >= MOD) v -= MOD;
		return *this;
	}
	modnum& operator -= (const modnum& o) {
		v -= o.v;
		if (v < 0) v += MOD;
		return *this;
	}
	modnum& operator *= (const modnum& o) {
		v = int(ll(v) * ll(o.v) % MOD);
		return *this;
	}
	modnum& operator /= (const modnum& o) {
		return *this *= o.inv();
	}

	friend modnum operator ++ (modnum& a, int) { modnum r = a; ++a; return r; }
	friend modnum operator -- (modnum& a, int) { modnum r = a; --a; return r; }
	friend modnum operator + (const modnum& a, const modnum& b) { return modnum(a) += b; }
	friend modnum operator - (const modnum& a, const modnum& b) { return modnum(a) -= b; }
	friend modnum operator * (const modnum& a, const modnum& b) { return modnum(a) *= b; }
	friend modnum operator / (const modnum& a, const modnum& b) { return modnum(a) /= b; }
};
using num = modnum<998244353>;

const int MAXN = 2.1e5;
const int MAXV = 1.1e6;
const int V = int(1e6) + 100;
int N;
int A[MAXN];

num tots[MAXV];
int phi[MAXV];
num weight[MAXV];


int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	num ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		ans -= A[i];
		tots[A[i]] += num(A[i]);
	}

	for (int i = 1; i <= V; i++) {
		phi[i] = i;
		weight[i] = 1/num(i);
	}

	for (int p = 2; p <= V; p++) {
		if (phi[p] == p) {
			for (int j = p; j <= V; j += p) {
				phi[j] -= phi[j] / p;
			}
			for (int j = V / p * p; j >= p; j -= p) {
				tots[j / p] += tots[j];
				weight[j] -= weight[j / p];
			}
		}
	}

	for (int v = 1; v <= V; v++) {
		ans += tots[v] * tots[v] * weight[v];
	}
	cout << ans / 2 << '\n';


	return 0;
}


Measured memory_bytes: 13952
import numpy as np

N = int(input())
S = list(input())

if len(S) % 2 == 1:
  print('No')
else:
  array = np.array(S).reshape(2, int(N/2))
  array1 = array[0]
  array2 = array[1]
  # Trueが1、Falseが0
  C = np.sum(array1 == array2)
  if C == int(N/2):
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 12496
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s.size() < 4){
        print("No");
    }else{
        if(s.substr(0,4) == "YAKI"){
            print("Yes");
        }else{
            print("No");
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int p[10010], d1[10010], d2[10010];
    for (int i = 0; i < n; i++) {
      cin >> p[i] >> d1[i] >> d2[i];
    }
    int pos = 0;
    for (int i = 0; i < n; i++) {
      if (d1[i] + d2[i] <= d1[pos] + d2[pos]) continue;
      pos = i;
    }
    cout << p[pos] << " " << d1[pos] + d2[pos] << endl;
  }

  return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod



signed main(){

    string S; cin >> S;
    vec v;
    REP(i, SZ(S)){
        v.pb(S[i] - '0');
        while(SZ(v) >= 2 && v[SZ(v) - 1] != v[SZ(v) - 2]){
            v.pop_back();
            v.pop_back();
        }
    }
    //vdebug(v);
    cout << SZ(S) - SZ(v) << endl;

    return 0;
}


Measured memory_bytes: 1480
#include <bits/stdc++.h>
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

    vector<int> count(N, 0);

    repd(i, 1, N)
    {
        if (S[i - 1] == 'A' && S[i] == 'C')
        {
            count[i] = count[i - 1] + 1;
        }
        else
        {
            count[i] = count[i - 1];
        }
    }

    rep(j, Q)
    {
        int l, r;
        cin >> l >> r;
        cout << count[r - 1] - count[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1408
import java.util.*;

public class Main{

    public static void main(String args[]){

        // スキャナーの宣言
        Scanner sc = new Scanner(System.in);
        // 整数の入力
		int n = sc.nextInt();
        // スペース区切りの整数の入力
        int d = sc.nextInt();
        int[][] p = new int[n][d];
        int count = 0;
        // for文
        for(int i = 0; i < n; i++){
            for(int j = 0; j < d; j++){
                p[i][j] = sc.nextInt();
            }
        }

        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                int dis = 0;
                for(int k = 0; k < d; k++){
                    dis += Math.abs(p[i][k] - p[j][k]) * Math.abs(p[i][k] - p[j][k]);
                }
                if(Math.sqrt(dis) == Math.round(Math.sqrt(dis))) count++;
            }
        }

        // 出力
        System.out.println(count);

    }

}


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

using namespace std;

int main(){

  int n;
  map <string,int> mapa;

  cin >> n;

  for(int i=0;i<n;i++){
    string s;
    cin >> s;

    if(!mapa.count(s)){
      mapa[s] = 1;
    }else{
      mapa[s]++;
    }
  }

  map <string,int> :: iterator it;
  int maior = 0;

  for(it = mapa.begin();it!=mapa.end();it++){
    int f = it->second;
    maior = max(maior, f);
  }

   for(it = mapa.begin();it!=mapa.end();it++){
    int f = it->second;
    string s = it->first;
    
    if(f == maior){
      cout << s << endl;
    }
    
  }
 

  return 0;
}

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

int main()
{
	int n;
	int side[3];

	cin >> n;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 3; j++){
			cin >> side[j];
		}
		sort(side, side + 3);
		if (side[2] * side[2] == side[1] * side[1] + side[0] * side[0]){
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	return (0);
}

Measured memory_bytes: 1168
#input
N = int(input())
H = list(map(int, input().split()))

act = 0
max_act = 0
for i in range(1, len(H)):
    if H[i-1] >= H[i]:
        act += 1
    else:
        act = 0
    if max_act < act:
        max_act = act

print(max_act)

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 
int l[100005] = {};
vector<vector<int>> g(100005);

int main() {
  int l,r,d;
  cin >> l >> r >>d;
  int c = 0;
  for(int i = l ;i<r+1;i++){
    if(i%d == 0){
      c++;
    }
  }
  cout << c;
}


Measured memory_bytes: 5484
#include <iostream>
#include <vector>
#include <array>

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

  int fib[100];
  fib[0] = 1;
  fib[1] = 1;
  for (int i=2; i<=n; ++i)
    fib[i] = fib[i-1] + fib[i-2];
  std::cout << fib[n] << std::endl;
}



Measured memory_bytes: 3104