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

int main(){
    int n;
    scanf("%d",&n);
    int arr[n*n];
    for(int row = 0; row < n; row++){
        for(int clm = 0; clm < n; clm ++){
            scanf("%d",&arr[row*n + clm]);
        }
    }
    int S[(n+1)*(n+1)];
    for(int i = 0; i < n+1; i++){
        S[i] = 0;
        S[i*(n+1)] = 0;
    }
    for(int row = 1; row < n+1; row++){
        for(int clm = 1; clm < n+1; clm ++){
            S[row*(n+1) + clm] = S[row*(n+1) + clm-1] + S[(row-1)*(n+1) + clm] - S[(row-1)*(n+1) + clm-1] + arr[(row-1)*n + clm-1];
        }
    }
    /*
    for(int i = 0; i < (n+1)*(n+1); i++){
        if(i % (n+1) == 0){
            printf("\n");
        }
        printf("%d ",S[i]);
    }
    printf("\n");
    */
    int maxs = S[n+2],maxe;
    for(int rowf = 1; rowf < n+1; rowf++){
        for(int clmf = 1; clmf < n+1; clmf++){
            for(int rowt = rowf; rowt < n+1; rowt++){
                for(int clmt = clmf; clmt < n+1; clmt++){
                    if(rowf == rowt && clmf == clmt){
                        maxe = S[rowt*(n+1) + clmt] - S[rowt*(n+1) + clmf-1] - S[(rowf-1)*(n+1) + clmt] + S[(rowf-1)*(n+1) + clmf-1];
                    }else{
                        maxe = max(maxe,S[rowt*(n+1) + clmt] - S[rowt*(n+1) + clmf-1] - S[(rowf-1)*(n+1) + clmt] + S[(rowf-1)*(n+1) + clmf-1]);
                    }
                    maxs = max(maxs,maxe);
                    //printf("maxe %d\n",maxe);
                    //printf("maxs %d\n",maxs);
                }
            }
        }
    }
    printf("%d\n",maxs);
}

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

using namespace std;

#define int long long

void solve() {
    int ans = 1e18;
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i <= 100; ++i) {
        int val = 0;
        for (int j = 0; j < n; ++j) {
            val += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans, val);
    }
    cout << ans;
}

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int i,j,k;
  int mat[100][100]={{}};
  int ve[100]={};
  cin >> n >> m;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin >> mat[i][j];
    }
  }
  for(j=0;j<m;j++) cin >> ve[j];
  for(i=0;i<n;i++){
    int x=0;
    for(j=0;j<m;j++) x+=mat[i][j]*ve[j];
    cout << x << endl;             
  }
   
  return 0;
}


Measured memory_bytes: 3156
N,A,B = map(int,input().split())
if A%2 == B%2:
    print(int((abs(A-B))//2))
else:
    if A-1 < N-B :
        print(A + (B-A-1)//2)
    else:
        print(N-B+1 + (B-A-1)//2)

Measured memory_bytes: 3060
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

ll A[100010] = {};
ll cum[100010] = {};

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

  int N;
  cin >> N;
  ll total = 0;

  REP(i, N) {
    cin >> A[i + 1];
    total += abs(A[i] - A[i + 1]);
  }
  total += abs(A[N] - 0);

  REP(i, N) {
    cout << total - abs(A[i] - A[i + 1]) - abs(A[i + 2] - A[i + 1]) + abs(A[i] - A[i + 2]) << endl;
  }

  return 0;
}


Measured memory_bytes: 2048
import math

def Sosu(N) :
    for i in range(2, int(math.sqrt(N))+1) :
        if N % i == 0 :
            return 'F'
    return 'T'
    

n = int(input())
ans = 0
for j in range(n) :
    a = int(input())
    if Sosu(a) == 'T' :
        ans += 1

print(ans)


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

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

    int N, K;
    cin >> N >> K;
    vector<int> A;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    int total = accumulate(A.begin(), A.end(), 0);
    for (int i = total; i > 0; i--) {
        if (total % i != 0) continue;
        vector<int> R;
        for (int j = 0; j < N; j++) {
            R.push_back(A[j] % i);
        }
        sort(R.begin(), R.end());
        vector<int> S1, S2;
        for (int j = 0; j < N; j++) {
            if (j == 0) {
                S1.push_back(R[j]);
                S2.push_back(0);
            } else {
                S1.push_back(S1.back() + R[j]);
                S2.push_back(S2.back() + i - R[N - j]);
            }
        }
        bool flag = false;
        for (int j = 0; j < N; j++) {
            int s1 = S1[j], s2 = S2[N - j - 1];
            if (max(s1, s2) > K) continue;
            if (s1 - s2 != 0) continue;
            flag = true;
            break;
        }
        if (flag) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

int n,ans=0,k;

signed main(){
    cin>>n>>k;
    vector<ll> a(n+1),sum(n+1),cnt(n+1);
    sum[0]=0;cnt[0]=0;
    rep(i,0,n){
        cin>>a[i];
        sum[i+1]=sum[i]+a[i];
        cnt[i+1]=cnt[i]+max(a[i],0LL);
    }
    
    repe(i,0,n-k){
        ans=max(ans,cnt[i]+(cnt[n]-cnt[k+i]));
        ans=max(ans,cnt[i]+(sum[i+k]-sum[i])+(cnt[n]-cnt[k+i]));
    }
    cout<<ans<<endl;
    
    
    return 0;
}

Measured memory_bytes: 2560
module Main (main) where

import Control.Monad
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Char
import Data.List
import Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  xs <- replicateM n readStrings
  print . solve $ concat xs

solve :: [String] -> Int
solve = sum . map (f . length) . group . sort . map sort
  where
    f n = fromIntegral $ (n * (n-1)) `div` 2 

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

Measured memory_bytes: 107900
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
int ans,q,n,m;
int a[50],b[50],c[50],d[50];
vector<int> res;
void solve()
{
    int sum=0;
    for(int i=0;i<q;++i)
    {
        if(res[b[i]-1]-res[a[i]-1]==c[i])
            sum+=d[i];
    }
    ans=max(ans,sum);
}
void dfs(int a,int sz)
{
    if(sz==n+1)
    {
        solve();
        return;
    }
    for(int i=a;i<=m;++i)
    {
        res.pb(i);
        dfs(i,sz+1);
        res.pop_back();
    }
}
signed main()
{
    SPEED;   
    cin>>n>>m>>q;
    for(int i=0;i<q;++i)
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    dfs(1,1);
    cout<<ans;
}



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

long double dist(int x1, int y1, int x2, int y2){
    return pow(((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)), 0.5);
}

int x[10], y[10];

int main(){
    int n;
    cin >> n;
    rep(i, n){
        cin >> x[i] >> y[i];
    }

    long double ave = 0;

    int array[n];
    rep(i, n) array[i] = i;

    int cnt = 0;
    do{
        rep(i, n-1) {
            ave += dist(x[array[i]], y[array[i]], x[array[i+1]], y[array[i+1]]);
        }
        cnt++;
    }while(next_permutation(array, array+n));

    cout << fixed << setprecision(10) <<  ave / cnt << endl;

    return 0;
}


Measured memory_bytes: 4272
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int N, L;
    string ans = "";
    cin >> N >> L;
    vector<string> S(N);
    for(int i = 0; i < N; i++){
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    for(int i = 0; i < N; i++){
        ans += S[i];
    }
    cout << ans << endl;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> primes;
	vector<int> is_prime(55556, -1);
	for (int i = 2; i <= 55555; i++) {
		if (is_prime[i] != -1) continue;
		primes.push_back(i);
		is_prime[i] = 1;
		for (int j = i+i; j <= 55555; j+=i) {
			is_prime[j] = 0;
		}
	}
	int k = 0;
	for (int x: primes) {
		if (k == n) break;
		if (x % 5 == 1) {
			cout << x << " ";
			k++;
		}
	}
	cout << endl;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int L = s.length();
        String A = s.substring(0, L/2);
        String A2 = s.substring(((L+3)/2)-1, L);
        if(A.equals(A2)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 35760
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


const int N=3005;

ll a[N][N];
ll dp[N][N][4];

void solve()
{
    ll r,c,k;
    cin>>r>>c>>k;
    // clr(a);
    ll i,j;
    for(i=0;i<k;i++)
    {
        ll x,y,v;
        cin>>x>>y>>v;
        a[x][y]=v;
    }
    // clr(dp);

    for(i=1;i<=r;i++)
    {
        for(j=1;j<=c;j++)
        {
            for(ll ii=0;ii<=3;ii++)
            {
                dp[i][j][ii]=max(dp[i][j][ii],dp[i][j-1][ii]);
            }
            for(ll ii=1;ii<=3;ii++)
            {
               dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][ii]+a[i][j]);
               dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][ii]);
            }
            for(ll ii=1;ii<=3;ii++)
            {
               dp[i][j][ii]=max(dp[i][j][ii],dp[i][j-1][ii-1]+a[i][j]);  
               dp[i][j][ii-1]=max(dp[i][j][ii-1],dp[i][j-1][ii-1]);
            }
            
        }
    }
    
    ll res=0;
    for(i=1;i<=3;i++)
    {
        res=max(res,dp[r][c][i]);
    }
    cout<<res<<"\n";

}


int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 355664
require 'matrix'
n, m = gets.chomp.split(' ').map(&:to_i)
a = []
n.times do
  a << gets.chomp.split.map(&:to_i)
end
b = []
m.times do
  b << gets.chomp.split.map(&:to_i)
end
res = Matrix.rows(a) * Matrix.rows(b)
res.each {|e| puts e}

Measured memory_bytes: 7048
#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 FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	ll n, m;
	cin >> n >> m;
	ll ans = 0;

	if (m / 2 >= n){
		ans += n;
		m -= n * 2;
	}
	else {
		cout << m / 2 << endl;
		return 0;
	}

	ans += m / 4;

	cout << ans << endl;


}


Measured memory_bytes: 256
// g++ -std=c++14
#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(c) c.begin(),c.end()
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)

#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

int main(){
  _
  int n, m, tot = 0;
  cin >> n >> m;
  vector<int> arr(n);
  for(int i = 0; i < n; i++){
  	cin >> arr[i];
  	tot += arr[i];
  }
  sort(all(arr));
  reverse(all(arr));
  if(4 * arr[m - 1] * m >= tot){
  	cout << "Yes\n";
  }
  else{
  	cout << "No\n";
  }
  return 0;
}


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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int ans = 0;
  for(int i = 1; i <= n; ++i){
    int res = 0;
    int temp = i;
    res += temp/10000;
    temp = temp%10000; 
    res += temp/1000;
    temp = temp%1000; 
    res += temp/100;
    temp = temp%100; 
    res += temp/10;
    temp = temp%10;
    res += temp/1;
    temp = temp%1;  
    if(res >= a && res <= b) ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
	T val=0;
	char c;
	
	bool neg=false;
	while((c=gc()) && !(c>='0' && c<='9')) {
		neg|=c=='-';
	}

	do {
		val=(val*10)+c-'0';
	} while((c=gc()) && (c>='0' && c<='9'));

	return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
	IO;
	double a,b,h,m;
	cin>>a>>b>>h>>m;
	m=60*h+m;
	cout<<fixed<<setprecision(15)<<sqrt(a*a+b*b-2*a*b*cos(2*PI/360*(0.5*m-6*m)))<<"\n";;
	return 0;
}


Measured memory_bytes: 4240
let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}

var n = arr[0]
var l = arr[1]
var i = 0
var min : Int
var o = 0

min = abs( l )
for i in 1...n {
  o += l + i - 1
  if( abs( l + i - 1)  < abs(min) ) { min = l + i - 1   }
}

print( o - min )

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

int main()
{
	int n;cin >> n;
	vector<int> num(n);
	for (int i=0;i<n;i++) cin >> num[i];
	int q;cin >>q;
	vector<int> sec(q);
	for (int i=0;i<q;i++) cin >> sec[i];
	int ans=0;
	for (int i=0;i<q;i++)
	{
		auto itr=num.begin();
		itr=lower_bound(num.begin(),num.end(),sec[i]);
		if (*itr==sec[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3256
#include<stdio.h>

int n, g[1000],top = 1,cnt=0;

void add()
{
	while(g[top]*3+1<n)
	{
		top++;
		g[top]=g[top-1]*3+1;
	}
}

void sort(int a[], int g)
{
	int i,j,v;
	
	for (i = g+1;i<= n;i++)
	{
		v = a[i];
		
        j = i - g;
		
		while (j >= 1 && a[j] > v)
		{
			
              a[j+g] = a[j];
              j-= g;
              cnt++;
			  
		}
		a[j+g]=v;
	}
}


int main(void){
    int i;
    scanf("%d",&n);
	int a[n];
    g[1]=1;
	
    for(i=1;i<=n;i++)
        scanf("%d ",&a[i]);
    add();
	
    for(i=top;i>=1;i--)
        sort(a,g[i]);
    printf("%d\n",top);
	
    for(i=top;i>=1;i--)
        printf("%d ",g[i]);
    	printf("\n");
    	printf("%d\n",cnt);
	
    for(i=1;i<=n;i++)
        printf("%d\n",a[i]);
	
    return 0;
}



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

#define rep(i,cc,n) for(int i=cc;i<=n;++i)

#define mod 1000000007



using namespace std;

class CompareFirst

{

public:

  bool operator()(pair<int,int> n1,pair<int,int> n2) {

    return n1.first>n2.first; //>:desc <:asc

  }

};





int main(){
  string s,t,ss;
  int i,j,k,l,n,ans;
  vector<string> vs;
  vector<int> v[26];
  pair<int,int> pr;
  //unordered_map<string,int> mp;
  //priority_queue<int> pq; // default ‘å‚«‚¢‡
  //priority_queue<pair<int,int>,vector<pair<int,int>>,CompareFirst> pq

  cin >> n;
  int a[n];
  int max=0,smax=-1;
  rep(i,0,n-1){
    cin >> a[i];
    if(max <= a[i]){
      smax = max;
      max = a[i];
    }else if(smax < a[i]){
      smax = a[i];
    }
  }
  
  rep(i,0,n-1){
    if(a[i] == max)cout << smax << endl;
    else   cout << max << endl;
  }

  return 0;

}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)

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

    int n, m, c;
    int result = 0;
	cin >> n >> m >> c;
    vi bs(m);
    rep(i, m) cin >> bs[i];
    rep(i, n){
        int now = 0;
        rep(j, m){
            int temp;
            cin >> temp;
            now += temp * bs[j];
        }
        if(now + c  > 0){
            result++;
        }
    }


    
	
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,count=0;
  char s[50];
  scanf("%d", &n);
  scanf("%s", s);
  for(int i=0;i<n-2;i++){
    if(s[i]=='A'){
      if(s[i+1]=='B'){
	if(s[i+2]=='C'){
	  count++;
	}
      }
    }
  }
  printf("%d", count);
  return 0;
}

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

int main()
{
    string s;
    int l,i,c=0;
    cin>>s;
    l=s.size();
    for(i=0; i<l/2; i++)
    {
        if(s[i]!=s[l-i-1])
            c++;
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> dish(5);
  vector<int> dif(5);
  int dish_ceil;
  int ceil_sum = 0;
  for (int i=0; i<5; i++){
    cin >> dish.at(i);
    //cout << dish.at(i);
    dish_ceil = (dish.at(i) + 9) / 10 * 10;
    ceil_sum += dish_ceil;
    dif.at(i) = dish_ceil- dish.at(i);
  }
  sort(dif.begin(), dif.end());
  cout << ceil_sum - dif.at(4) << endl;
}

Measured memory_bytes: 256
/* Redemptioner - Prem Bhawnani */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
						
#define fast_cin() ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define endl '\n'
#define int long long

const int N = 2e5 + 5;

int h[N], a[N], dp[N];
int n, f[N];

void update(int idx, int val) {
	while (idx < N) {
		f[idx] = max(f[idx], val);
		idx += (idx & -idx);
	}
}

int get(int idx) {
	int res = 0;
	while (idx > 0) {
		res = max(res, f[idx]);
		idx -= (idx & -idx);
	}
	return res;
}
				
int32_t main() {
	fast_cin();
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		dp[h[i]] = max(dp[h[i]], a[i] + get(h[i] - 1));
		update(h[i], dp[h[i]]);
		ans = max(ans, dp[h[i]]); 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6528
import sys
import math
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MAT(h): return [list(map(int, input().split())) for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = INT()
    A = LIST()
    L = [0] * N
    R = [0] * N
    M = [0] * N
    for i in range(N - 1):
        L[i + 1] = gcd(L[i], A[i])
        R[N - i - 2] = gcd(R[N - i - 1], A[N - i - 1])
    maxv = 0
    for i in range(N):
        M[i] = gcd(L[i], R[i])
        if maxv < M[i]:
            maxv = M[i]
    print(maxv)

if __name__ == '__main__':
    main()


Measured memory_bytes: 63984
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N, K;
int x[100], y[100];

bool check(int top, int bottom, int right, int left) {
  int cnt = 0;
  rep(k, 0, N) {
    int cx = x[k];
    int cy = y[k];
    if (left <= cx && cx <= right && bottom <= cy && cy <= top) {
      ++cnt;
    }
  }

  return cnt >= K;
}

int dummy[1000000];

int main() {
  cin >> N >> K;
  rep(i, 0, N) { cin >> x[i] >> y[i]; }

  for (ll i = 0; i <= 1000000000; ++i) {
    dummy[i % 1000000] = i;
  }

  ll ans = numeric_limits<ll>::max();
  rep(i, 0, N) {
    rep(j, i, N) {
      rep(k, j, N) {
        rep(l, k, N) {
          ll top = max(y[i], max(y[j], max(y[k], y[l])));
          ll bottom = min(y[i], min(y[j], min(y[k], y[l])));
          ll left = min(x[i], min(x[j], min(x[k], x[l])));
          ll right = max(x[i], max(x[j], max(x[k], x[l])));

          if (check(top, bottom, right, left)) {
            chmin(ans, (top - bottom) * (right - left));
          }
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 7532
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <deque>
#include <map>
using namespace std;

#define ii pair <int, int>
#define lli long long
#define pb push_back
#define X first
#define Y second

const int Mod = 1E9 + 7;
const int Inf = 1E9 + 7;
const int N = 2E5 + 10;

void Input()
{

}

void Solve()
{
    int n, x, t;
    cin >> n >> x >> t;
    cout << t * ((n - 1) / x + 1);
}

#define task "test"
int main()
{
    if (fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    int testcase = 1;
    /// cin >> testcase;
    while (testcase--) {
        Input();
        Solve();
    }
}



Measured memory_bytes: 3148
import sys

input = sys.stdin.readline
P = 2019


def main():
    S = input().rstrip()

    count = [0] * P
    count[0] += 1
    T = 0
    d = 1
    for s in reversed(S):
        T = (T + int(s) * d) % P
        count[T] += 1
        d = (d * 10) % P

    ans = 0
    for k in count:
        ans += k * (k - 1) // 2
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9196
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let mut c = vec![vec![0; 3]; 3];

    for i in 0..3 {
        for j in 0..3 {
            c[i][j] = read::<i32>();
        }
    }

    let mut a = vec![0; 3];
    let mut b = vec![0; 3];
    a[1] = c[0][1] - c[0][0];
    a[2] = c[0][2] - c[0][0];
    b[1] = c[1][0] - c[0][0];
    b[2] = c[2][0] - c[0][0];
    for i in 1..3 {
        if !(c[i][1] - c[i][0] == a[1] && c[i][2] - c[i][0] == a[2]) {
            println!("No");
            return;
        }
    }
    for i in 1..3 {
        if !(c[1][i] - c[0][i] == b[1] && c[2][i] - c[0][i] == b[2]) {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 4352
n = int(input())
lis = [chr(ord('a') + i) for i in range(26)]

i=1
while True:
    if n <= 26**i:
        break

    else:
        n -= 26**i
        i += 1

ans = []

for j in range(i-1, -1, -1):
    s1 = n // (26**j)
    s2 = n % (26**j)
    if s2 == 0:
        s1 -= 1
    if j > 0:
        if s1 >= 26:
            s1 = 25
            ans.append(lis[-1])
        else:
            ans.append(lis[s1])
        n -= (26**j) * s1
    elif j == 0:
        ans.append(lis[n-1])

print(''.join(ans))

Measured memory_bytes: 9216
#include <iostream>
#include <cmath>
#include <map>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
/*
int num(int n)
{
    int x=n,tmp;
    if(n==1)return 1;
    int cnt=2;
    for(int i=2; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            if(i==sqrt(n)&&n/i==i)cnt++;
            else cnt+=2;
        }
    }
    return cnt;
}
*/
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m,ans=0;
    cin>>n;
    For(i,1,n)
    {
        m=n/i;
        ans+=(m+1)*m*i/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3636
// Example program
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
int main()
{
  int a;
 int b;
 int c;
 cin >> a;
 cin >> b;
 cin >> c;
 
 vector<int>v{a,b,c};
 sort(v.begin(),v.end());
 cout << v[0] << " " << v[1] << " " << v[2] << endl;
}

Measured memory_bytes: 3148
N, A, B = map(int, input().split())
if (A-B)%2==0:
    if (A-B)>=0:
        print((A-B)//2)
    else:
        print((A-B)//-2)

else:
    if A>B:
        if (N-A)<(B-1):
            print((N-(B+(N-A))+1)//2+(N-A))
        else:
            print((A-(B-1))//2+(B-1))
    else:
        if (N-B)<(A-1):
            print((N-(A+(N-B))+1)//2+(N-B))
        else:
            print((B-(A-1))//2+(A-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  vector<vector<int>> A(3,vector<int>(3));
  vector<vector<int>> OK(3,vector<int>(3));
  string res = "No";
  
  rep(i, 3){
    rep(j, 3){
      cin >> A.at(i).at(j);
      OK.at(i).at(j) = 0;
    }
  }
  
  int N;
  cin >> N;
  vector<int> b(N);
  rep(i, N){
    cin >> b.at(i);
    rep(j, 3){
      rep(k, 3){
        if(A.at(j).at(k) == b.at(i)) OK.at(j).at(k) = 1;
      }
    }
  }
  

  rep(i, 3){
    if(OK.at(i).at(0) == 1 && OK.at(i).at(1) == 1  && OK.at(i).at(2) == 1) res = "Yes";
    if(OK.at(0).at(i) == 1 && OK.at(1).at(i) == 1  && OK.at(2).at(i) == 1) res = "Yes";
  }
   
   if(OK.at(0).at(0) == 1 && OK.at(1).at(1) == 1  && OK.at(2).at(2) == 1) res = "Yes";
   if(OK.at(2).at(0) == 1 && OK.at(1).at(1) == 1  && OK.at(0).at(2) == 1) res = "Yes";
   
  
  cout << res;
  
}

Measured memory_bytes: 256
n = 0

def format_input(filename = None):
	global n
	if filename == None:
		n = int(input())

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 10**12)
		print(n)

def judge(n, k):
	if n % k == 0:
		return judge(n // k, k)
	else:
		return (n % k == 1)

def get_answer():
	answer = 2
	if n == 2:
		return 1
	for i in range(2, int(n ** 0.5) + 1):
		if (n - 1) % i == 0:
			answer += 2
			if n - 1 == i ** 2:
				answer -= 1
		elif judge(n, i):
			answer += 1
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
int main(void) {
    int a;
    scanf("%d", &a);

    if (a >= 400 && a <= 599) printf("8");
    else if (a>=600&& a<= 799)printf("7");
    else if (a >=800 && a <=999 )printf("6");
    else if (a >=1000 && a <=1199 )printf("5");
    else if (a >=1200 && a <=1399 )printf("4");
    else if (a >=1400 && a <=1599 )printf("3");
    else if (a >=1600 && a <= 1799)printf("2");
    else if (a >=1800 && a <= 1999)printf("1");
    return 0;
}


Measured memory_bytes: 2056
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
Scanner sc = new Scanner(System.in);
// 3つの文字の固まりをそれぞれ整数値と想定して読み込む
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if (a < b) {
if (b < c) {
System.out.printf("%d %d %d\n", a, b, c);
} else if (a < c) {
    System.out.printf("%d %d %d\n", a, c, b); // ... 以降を書き足そう！
}else {
    System.out.printf("%d %d %d\n", c, a, b);
}
} else { // ... 以降を書き足そう！
if (a < c) {
    System.out.printf("%d %d %d\n", b, a, c);
    } else if (b < c) {
        System.out.printf("%d %d %d\n", b, c, a); // ... 以降を書き足そう！
    }else {
        System.out.printf("%d %d %d\n", c, b, a);
    }
}
}
}


Measured memory_bytes: 26220
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2018");
            WillReturn.Add("218");
            //Yes
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("2763");
            WillReturn.Add("0");
            //No
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("37");
            WillReturn.Add("514");
            //Yes
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);
        int A = int.Parse(InputList[1]);

        int Rest = N % 500;

        if (A >= Rest) {
            Console.WriteLine("Yes");
        }
        else {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (ll i=1; i<=(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N,M; cin >> N >> M;
    vector <pair<ll,ll>> A(N+1);
    rep(i,N){
        ll a,b; cin >> a >> b;
        A[i]=make_pair(a,b);
    }
    sort(A.begin(),A.end());
    ll sum=0;
    ll cnt=0;
    
    rep(i,N){
        if(M-cnt>=A[i].second){
            sum+=A[i].first * A[i].second;
            cnt+=A[i].second;
        }
        else{
            sum+=A[i].first * (M-cnt);
            break;
        }
    }
    cout << sum;
}

Measured memory_bytes: 1792
import           Control.Monad
import           Data.List
import           Data.Maybe
import qualified Data.ByteString.Char8         as C8

main :: IO ()
main = do
    [n, m] <- fmap (map read . words) getLine :: IO [Int]
    cs     <-
        replicateM n
            $ fmap (map (fst . fromJust . C8.readInt) . C8.words) C8.getLine :: IO
            [[Int]]
    print . purchase m $ sortOn fst . map (\[a, b] -> (a, b)) $ cs

purchase :: Int -> [(Int, Int)] -> Int
purchase m ((a, b) : cs) | m <= b    = m * a
                         | otherwise = a * b + purchase (m - b) cs
purchase _ [] = 0


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

int N;
int A[100];

int main() {
  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  sort(A, A + N, greater<int>());
  
  int ans[2] = {};
  for(int i = 0; i < N; ++i) {
    ans[i % 2] += A[i];
  }
  cout << ans[0] - ans[1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, n) revi(i, 0, n)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

int main() {
  int N, M, X;
  ci(N, M, X);
  ve<int> A(M);
  int c = 0, a = 0;
  rep(i, M){
    ci(A.at(i));
    if(A.at(i) < X){
      c++;
    }
    else if(A.at(i) > X){
      a++;
    }
  }
  co(min(a, c));
}


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

int main() {
    string s;
    cin >> s;
    char c = s.back();
    if (c == 's') {
        cout << s + "es" << endl;
    } else {
        cout << s + "s" << endl;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvii;
typedef pair<int, int> ii;
typedef vector<ii> vii;

////////////////////////////////

void solve() {
	
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin >> t;
	string str = to_string(t);
	t = str[str.size() - 1] - '0';
	if (t == 3) cout << "bon" << endl;
	else if (t == 2 || t == 4 || t == 5 || t == 7 || t == 9) {
		cout << "hon" << endl;
	} else {
		cout << "pon" << endl;
	}
	return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
	int n, a, b;
  	int ans = 0;
  	cin >> n >> a >> b;
  	for(int i = 1; i <= n; i++) {
    	string s = to_string(i);
      	int cnt = 0;
      	for(char c: s) {
        	cnt += (c-'0');
        }
      	if (cnt >= a && cnt <= b) {
        	ans += i;
        }
    }
  	cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Set<Integer> set = new HashSet<>();
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int n = sc.nextInt();
    int[] p = new int[n];
    for(int i = 0; i < n; i++)
      p[i] = sc.nextInt();
    
    Arrays.sort(p);
    int diff = 0, flag = 0, res = 0;
    while(flag == 0) {
      if(Arrays.binarySearch(p, x-diff) < 0) {
        res = x - diff;
        flag = 1;
      } else if(Arrays.binarySearch(p, x+diff) < 0) {
        res = x + diff;
        flag = 1;
      }
      diff++;
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 35784
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int dr[] = {-1,  0, 0, 1};
int dc[] = { 0, -1, 1, 0};

int h, w;
int board[30][30];

char tmpS[50];

int connects[450][450];

int main()
{
	scanf("%d%d\n", &h, &w);
	
	for (int r = 1 ; r <= h ; r++) {
		scanf("%s\n", tmpS);
		
		for (int c = 1 ; c <= w ; c++) {
			if (tmpS[c - 1] == '#')
				board[r][c] = 0;
			else
				board[r][c] = 1;	//想象下周围一圈围墙 
		}
	}
	
	for (int i = 0 ; i < 450 ; i++) {
		for (int j = 0 ; j < 450 ; j++)
			connects[i][j] = 900000;
		connects[i][i] = 0;
	}
			
	for (int r = 1 ; r <= h ; r++) {
		for (int c = 1 ; c <= w ; c++) {
			if (board[r][c] != 1)
				continue;
			
			int oldPos = (r - 1) * w + (c - 1) + 1;
			for (int d = 0 ; d < 4 ; d++) {
				int nr = r + dr[d];
				int nc = c + dc[d];
				if (board[nr][nc] != 1)
					continue;
				
				int newPos = (nr - 1) * w + (nc - 1) + 1;
				connects[oldPos][newPos] = 1;
				connects[newPos][oldPos] = 1;
			}
		}
	}
		
	int left = 1;
	int right = h * w;
	for (int k = left ; k <= right ; k++) {
		for (int i = left ; i <= right ; i++) {
			if (k == i)
				continue;
			
			for (int j = left ; j <= right ; j++) {
				if (k == j)
					continue;
				if (i == j)
					continue;
					
				if ((connects[i][k] + connects[k][j]) < connects[i][j]) {
					connects[i][j] = connects[i][k] + connects[k][j];
				}
			}
		}
	}
	
	int maxDist = 0;	
	for (int i = left ; i <= right ; i++) {
		for (int j = left ; j <= right ; j++) {
			if ((connects[i][j] != 900000) && (maxDist < connects[i][j]))
				maxDist = connects[i][j];
		}
	}
	
	printf("%d\n", maxDist);

	
	
	return 0;
}



Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
long long n,a[1000000],x,y,mi,an;
int main(){
	cin>>n;
	for(x=0;x<n;x++){
		cin>>a[x];
			if(x==1){
			   an=a[x]-a[x-1];		    
			}
		    if(x==0){
				mi=a[x];
			}
			if(an<a[x]-mi){
				an=a[x]-mi;
			}
			if(mi>a[x]){
				mi=a[x];
			}		
	 }  
	cout<<an<<endl;
}



Measured memory_bytes: 4644
def c_repsept_totient():
    def euler_phi(n):
        """正整数 n に対して、n と互いに素な n 以下の正整数の個数"""
        ret = n
        for i in range(2, int(n**0.5) + 1):
            if n % i == 0:
                ret = ret // i * (i - 1)
                while n % i == 0:
                    n //= i
        if n > 1:
            ret -= ret // n
        return ret

    def divisor_list(n):
        """n の正の約数のリスト"""
        ret = set()
        for k in range(1, int(n**0.5) + 1):
            if n % k == 0:
                ret.update({k, n // k})
        return sorted(ret)

    K = int(input())
    L = 9 * (K // 7 if K % 7 == 0 else K)

    for d in divisor_list(euler_phi(L)):
        if pow(10, d, L) == 1:
            return d
    return -1

print(c_repsept_totient())

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

int main()
{
  long long h, w;
  cin >> h >> w;

  for (int i = 0; i < h; i++)
  {
    for (char j = 'A'; j < 'A' + w; j++)
    {
      string tmp;
      cin >> tmp;
      if (tmp == "snuke")
      {
        cout << j << i+1 << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair< int , int >
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(auto x : c )cout << x << " ";
#define ol(c , s , e ) for(int pos=s; pos<e ; pos++) cout << c[pos] << " ";
#define PI acos(-1l)
const int M = 1000000007;
const int N=3e3+5;
const long long INF = 1e9+5;
//#define rohit
#ifdef rohit
template<typename... T >
void bug(T... __VA_ARGS__) {
    ((cerr << __VA_ARGS__ << " ") , ...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__) , cerr << endl;
#endif
const int MOD = 2019;
void solve(){
    string s;
    cin >> s;
    int pot = 1;
    int n = s.length();
    int suf  = 0 , ans = 0;
    vector< int > preSuf(MOD , 0);
    preSuf[0]++;
    for(int i = n-1 ; i>=0 ; i--){
        suf = (suf + (s[i] - '0')*pot)%MOD;
        pot = (10*pot )%MOD;
        ans+=preSuf[suf];
        preSuf[suf]++;
    }
    cout << ans << endl;
}

signed main(){
    FAST;
    //TODO: check test cases.
    int tc=1;
//    cin >> tc;
    for(int t = 1 ; t <= tc ; t++){
        solve();
    }
}
/* Extra Cares
 * 1)In graphs or dp problems sometimes long long creates MLE.
 * 2)Check whether int to long long typecasting is commented or not?
 * 3)Check overflows.
*/



Measured memory_bytes: 3684
def parse(l):
    name, time = l.split()
    a = [name, int(time)]
    return a


n, quantum = map(int, input().split())
queue = []
for i in range(n):
    queue.append(parse(input()))
head = 0


def enqueue(x):
    global queue
    queue.append(x)


def dequeue():
    global head
    head += 1


total_time, count = 0, 0
while count < n:
    y = queue[head][1] - quantum
    if y <= 0:
        print(str(queue[head][0]) + " " + str(total_time + queue[head][1]))
        dequeue()
        total_time += y
        count += 1
    else:
        queue[head][1] -= quantum
        enqueue(queue[head])
        dequeue()

    total_time += quantum



Measured memory_bytes: 13932
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int h, w, n;
char M[1000][1000];
int dy[4] = {1, 0, -1, 0};
int dx[4] = {0, 1, 0, -1};
pair<int, int> point[10];


int bfs(){
    int reach[h][w];

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                reach[y][x] = -1;
            }
        }
        
        int sy = point[i].first;
        int sx = point[i].second;
        int goaly = point[i+1].first;
        int goalx = point[i+1].second;
        
        queue < pair <int, int> > Q;
        Q.push(make_pair(sy, sx));
        reach[sy][sx] = 0;
        
        int v, z;
        bool arrive = false;
        while(!Q.empty()){
            v = Q.front().first;
            z = Q.front().second;
            Q.pop();

            for(int k = 0; k < 4; k++){
                int ny = v + dy[k];
                int nx = z + dx[k];
                if(ny < 0 || ny >= h || nx < 0 || nx >= w || reach[ny][nx] != -1 || M[ny][nx] == 'X'){
                    continue;
                }
                
                reach[ny][nx] = reach[v][z] + 1;
                Q.push(make_pair(ny, nx));
                if(ny == goaly && nx == goalx){
                    arrive = true;
                    ans += reach[ny][nx];
                }

            }
            
            if(arrive){
                break;
            }
            
        }
        
    }

    
    return ans;
}


int main(void){
    // Your code here!
    cin >> h >> w >> n;
    int sy, sx;
    char tmp;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> tmp;
            if(tmp == 'S'){
               point[0].first = i;
               point[0].second = j;
            }
            
            if(1 <= tmp - '0' && tmp - '0' <= n){
                point[tmp-'0'].first = i;
                point[tmp-'0'].second = j;
            }
            M[i][j] = tmp;
        }
    }
    
    cout << bfs() << endl;
    
    return 0;
}



Measured memory_bytes: 7996
#include<stdio.h>
int main(){
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	int lifespan_t = A / D + (A % D > 0 ? 1 : 0);
	int lifespan_a = C / B + (C % B > 0 ? 1 : 0); 
	if(lifespan_t >= lifespan_a)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 1672
def solve():
    n,a,b,c,d = map(int,input().split())
    mx = n-1
    for i in range(n):
        if a-d*i+c*(mx-i) <= b<=a-c*i+d*(mx-i):
            print('YES')
            return
    print('NO')
if __name__=='__main__':
    solve()

Measured memory_bytes: 3064
def resolve():
    import sys
    input = sys.stdin.readline
    N = int(input())
    Ss = [''.join(sorted(input().rstrip())) for _ in range(N)]

    import collections
    Co = collections.Counter(Ss)
    Su = 0
    for _, c in Co.most_common():
        if c < 2:
            break
        Su += (c - 1) * c

    print(Su // 2)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 72028
def choose2(n):
    return n * (n - 1) // 2

a = int(input())
A = list(map(int, input().split()))  
d = {}
for k in A:
  if k in d:
    d[k] += 1
  else:
    d[k] = 1
 
res = 0
for k in d.values():
  res += choose2(k)

for k in A:
  temp = res
  m = d[k]
  temp -= choose2(m)

  d[k] -= 1
  temp += choose2(d[k])
  print(temp)
  d[k] += 1


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,m,k;cin >> n>>m>>k;
    lint ans=0;
    vector<lint> a(n), b(m),x(n+1),y(m+1);
    REP(i,n){
        cin >> a[i];
    }
    REP(i, m)
    {
        cin >> b[i];
    }
    REP(i, n)
    {
        x[i + 1] = x[i] + a[i];
    }
    REP(i, m)
    {
        y[i + 1] = y[i] + b[i];
    }
    REP(i,n+1){
        lint cnt = i;
        lint t = k - x[i];
        if(t<0){
            continue;
        }
        auto ii = lower_bound(ALL(y), t+1);
        //cout << ii - y.begin() << "\n";
        cnt += (int)(ii - y.begin())-1;
        ans = max(ans, cnt);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9596