akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t a, b, c;
  std::cin >> a >> b >> c;
  std::cout << c - std::min(a - b, c) << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const int INF=1000100010;
int main(){
int n,m;cin>>n>>m;
int s[n],c[n];
set<int> set1,set2,set3;
int ans=0;
rep(i,m){
    cin>>s[i]>>c[i];
   if(s[i]==1)set1.insert(c[i]);
   if(s[i]==2)set2.insert(c[i]);
   if(s[i]==3)set3.insert(c[i]);
}
if(set1.size()>1||set2.size()>1||set3.size()>1){
    cout<<-1<<endl;
    return 0;
}
if(n==3){
if(set1.size()==0)set1.insert(1);
if(set2.size()==0)set2.insert(0);
if(set3.size()==0)set3.insert(0);
if(*set1.begin()==0){
    cout<<-1<<endl;
    exit(0);
}
ans=*set1.begin()*100+*set2.begin()*10+*set3.begin();
}
if(n==2){
if(set1.size()==0)set1.insert(1);
if(set2.size()==0)set2.insert(0);
if(*set1.begin()==0){
    cout<<-1<<endl;
    exit(0);
}
if(set3.size()>0){
    cout<<-1<<endl;
    exit(0);
}
ans=*set1.begin()*10+*set2.begin();
}
if(n==1){
if(set1.size()==0)set1.insert(0);
if(set2.size()>0){
    cout<<-1<<endl;
    exit(0);
}
if(set3.size()>0){
    cout<<-1<<endl;
    exit(0);
}
ans=*set1.begin();
}
cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
constexpr long long MOD = 1e9 + 7;
constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    for (size_t i = 0; i < s.size(); i++)
    {
        cout << "x";
    }
    cout << "\n";

    return 0;
}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, m, x;
    int a[100] = {};
    cin >> n >> m >> x;
    for (int i = 0; i < m; i++)
    {
        int tp;
        cin >> tp;
        a[tp] = 1;
    }
    int mn = INF;
    int tmp = 0;
    for (int i = x - 1; i > 0; i--)
    {
        if (a[i])
            tmp++;
    }
    mn = min(mn, tmp);

    tmp = 0;
    for (int i = x + 1; i < n; i++)
    {
        if (a[i])
            tmp++;
    }
    mn = min(mn, tmp);

    cout << mn << endl;
}


Measured memory_bytes: 256
def padd(x, ans):
    if x==1:
        ans += 300000
    elif x==2:
        ans += 200000
    elif x==3:
        ans += 100000
    return ans

def main():
    x, y = map(int, input().split())
    ans = 400000 if x==1 and y==1 else 0
    ans = padd(x, ans)
    ans = padd(y, ans)
    print(ans)

main()

Measured memory_bytes: 3060
/**
 * Watch.cpp
 * Create:20180417
 * Description:秒数の入力に対しh:m:sの形式に変換して出力する。
 */
#include <iostream>

int main(int argc, char* argv[]){
  int sec;  //秒数

  std::cin >> sec;

  int hour = sec / (60 * 60);
  sec %= (60 * 60);

  int minute = sec / 60;
  sec %= 60;

  std::cout << hour << ":" << minute << ":" << sec << std::endl;

  return 0;
}



Measured memory_bytes: 3124
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int A,P;
  cin >> A >> P;
  int ans=(A*3+P)/2;
  cout << ans << endl;
  
}

Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>

using namespace std;

#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define Str(x) to_string(x)
#define len(s) (int)s.size()
#define int long long
typedef long long ll;
typedef long double lld;
typedef string str;
typedef unsigned long long ull;

main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    vector <int> v(n);

    multiset <int> st;
    for (auto &it : v)
    {
        int x;
        cin >> x;
        st.insert(x);
    }
    while (m && len(st))
    {
        int x = *st.rbegin();
        st.erase(st.find(x));
        x /= 2;
        if (x)
        {
            st.insert(x);
        }
        m--;
    }
    int sum = 0;
    for (auto it : st)
        sum += it;
    cout << sum;
    return 0;
}

Measured memory_bytes: 5760
integer n
integer(16),allocatable,dimension(:)::a,l,r
integer ans
read*,n
allocate(a(n),L(0:N),R(1:N+1) )
read*,a

l(1)=a(1)
do i=2,N
  l(i)=getgcd( l(i-1),a(i) )
end do

r(N)=a(N)
do i=N-1,1,-1
  r(i)=getgcd( r(i+1),a(i) )
end do
l(0)=r(2)
r(N+1)=l(N-1)
ans=1
do i=1,N
  ans=max(ans,getgcd(l(i-1),r(i+1) ) )
end do

print"(I0)",ans
contains
pure function getgcd(a,b)
integer(16),intent(in)::a,b
integer(16) getgcd
integer(16) s,t
s=a+b
getgcd=b

t=mod(a+b,b)
do while(t/=0)
  s=getgcd
  getgcd=t
  t=mod(s,getgcd)
end do
end function getgcd
end

Measured memory_bytes: 5504
module practiceA
   sub Main(ByVal args() as String)
     dim x,a,b as integer
     dim ret as integer
 dim num as integer
     x=Console.ReadLine()
 a=Console.ReadLine()
 b=Console.ReadLine()
 
 Dim test As Double = Math.Floor((x - a) / b)
 Dim test2 As Integer = CType(test , Integer)
 ret = (x - a) - test2 * b
     Console.WriteLine(ret)
   end sub
 end module

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>k(m),p(m);
    vector<vector<int>>s(m);
    for(int i=0;i<m;i++){
        cin>>k[i];
        s[i].resize(k[i]);
        for(int j=0;j<k[i];j++)
            cin>>s[i][j],s[i][j]--;
    }
    for(int i=0;i<m;i++)
        cin>>p[i];
    int ans=0;
    for(int S=0;S<1<<n;S++){
        bool ok=true;
        for(int i=0;i<m;i++){
            int on=0;
            for(int j=0;j<k[i];j++)
                if(S&1<<s[i][j])
                    on++;
            if(on%2!=p[i])
                ok=false;
        }
        if(ok)
            ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,t;cin>>n>>t;
    vl a(n);rep(i,n)cin>>a[i];

    ll diff_max=0;
    ll mi=LINF;
    rep(i,n){
        chmin(mi,a[i]);
        chmax(diff_max,a[i]-mi);
    }

    ll hi_cnt=0;
    set<ll> hi;
    rep(i,n){
        if(hi.count(a[i]-diff_max))++hi_cnt;
        hi.insert(a[i]);
    }

    ll lo_cnt=0;
    set<ll> lo;
    rrep(i,n){
        if(lo.count(a[i]+diff_max))++lo_cnt;
        lo.insert(a[i]);
    }

    cout<<min(hi_cnt,lo_cnt)<<endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define all(x) x.begin(), x.end()
#define VI vector<int>
#define VS vector<string>
#define ll long long
#define INF 2e9
#define fir first
#define sec second
using namespace std;

void Main() {
    int N;
    cin >> N;
    VI D(N);
    rep(i, 0, N) { cin >> D[i]; }
    sort(all(D));  // 難易度昇順に並び替える。
    // ARCの一番簡単な問題とABCの一番難しい問題の差がKとなる。
    int diff = D[N / 2] - D[N / 2 - 1];
    cout<<diff<<endl;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15) << endl;
    Main();
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
//#include <ext/numeric>


using namespace std;
//using namespace __gnu_cxx;

const int MAXN = (int)1e3 + 5;
const int MAXM = (int)1e4 + 5;

const int MOD = 1000000007;

long long mul(long long a , long long b) {
    return a * b % MOD;
}

long long power(long long a , long long b) {
    if (!b) return 1;
    long long r = power(a , b / 2);
    r = mul(r , r);
    if (b&1) return mul(r , a);
    return r;
}

long long mod_inv(long long x) {
    return power(x , MOD - 2);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    vector<map<int, int>> vmp(n);
    map<int, int> lcm;
    map<pair<int, int>, int> mp;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        for (int j = 2; 1LL * j * j <= x; ++j) {
            int cnt = 0;
            while (x % j == 0) {
                x /= j;
                ++cnt;
            }
            if (cnt > 0) {
                vmp[i][j] = cnt;
                lcm[j] = max(lcm[j], cnt);
                mp[{j, cnt}]++;
            }
        }
        if (x > 1) {
            vmp[i][x] = 1;
            lcm[x] = max(lcm[x], 1);
            mp[{x, 1}]++;
        }
    }


    int x = 1;
    for (auto it : lcm) {
        int p = it.first;
        int cnt = it.second;
        x = mul(x, power(p, cnt));
    }

    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        int tmp = x;
        for (auto it : vmp[i]) {
            int p = it.first;
            int cnt = it.second;
            tmp = mul(tmp, mod_inv(power(p, cnt)));
        }
        ans += tmp;
        ans %= MOD;
    }


    cout << ans << '\n';


    return 0;
}

Measured memory_bytes: 5948
#include<iostream>
using namespace std;
int main()
{
	const int MAX = 101;
	int table[MAX][MAX];
	int rowSum[MAX] = { 0 };
	int colSum[MAX] = { 0 };
	int r, c;
	cin >> r >> c;
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			int t;
			cin >> t;
			table[i][j] = t;
			rowSum[i] += t;
			colSum[j] += t;
		}
		table[i][c] = rowSum[i];
	}
	for (int i = 0; i < c; i++)
		table[r][i] = colSum[i];
	int rowTotal = 0;
	for (int i = 0; i < r; i++)
		rowTotal += rowSum[i];
	table[r][c] = rowTotal;
	for (int i = 0; i <= r; i++)
	{
		for (int j = 0; j <= c; j++)
			if (j != c)
				cout << table[i][j] << " ";
			else
				cout << table[i][j];
		cout << endl;
	}
}


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

#define int long long
#define ci(m)     for(int i=0;i<m;i++)
#define cj(m)     for(int j=0;j<m;j++)
#define ck(m)     for(int k=0;k<m;k++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
int solve(int n)
{
    int ans=1;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            int cnt=0;
            while(n%i==0)
            {
                n=n/i;
                cnt++;
            }
            ans*=(cnt+1);
        }
    }
    if(n!=1)
        ans*=2;
    return ans;
}
int32_t main() {
    nitin;
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n-1;i++)
    {
        ans+=solve(n-i);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define INF 1000000000
const int maxn = 1e5 + 5;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
    int n;
    cin >> n;
    int c_500 = n/500; // This let us how many 500 yens
    int remaning = n%500; 
    int c_5 = remaning/5;
    cout << c_500*1000+c_5*5 << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<vector<bool>> honest(n, vector<bool>(n)), unkind(n, vector<bool>(n));
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int x, y;
      cin >> x >> y;
      x--;
      if (y == 1) {
        honest.at(i).at(x) = true;
      } else {
        unkind.at(i).at(x) = true;
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 1 << n; i++) {
    bool good = true;
    int count_honest = 0;
    for (int j = 0; j < n; j++) {
      if ((i & (1 << j)) == 0) continue; // unkind
      count_honest++;
      for (int k = 0; k < n; k++) {
        if (i & (1 << k)) { // honest
          if (unkind.at(j).at(k)) {
            good = false;
          }
        } else { // unkind
          if (honest.at(j).at(k)) {
            good = false;
          }
        }
      }
    }
    if (good) {
      ans = max(ans, count_honest);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            var ans = "AC";
            var S = GetStr().ToCharArray();
            if (S[0] != 'A') { ans = "WA"; }
            if (S.Count(c => c == 'C') != 1) { ans = "WA"; }
            if (S[1] == 'C' || S.Last() == 'C') { ans = "WA"; }
            if(S.Count(c=>'A'<=c && c <= 'Z') != 2) { ans = "WA"; }


            Console.WriteLine(ans);
            Console.ReadKey();
        }

        static void Solve()
        {
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

Measured memory_bytes: 13268
#!/usr/bin/env python3
import sys


def main():
    N, M = map(int, input().split())
    red = [0] * N
    red[0] = 1
    num = [1] * N

    for i in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if red[x]:
            red[y] = 1
            
        num[x] -= 1
        num[y] += 1
        if num[x] == 0:
            red[x] = 0
    print(sum(red))

if __name__ == '__main__':
    main()


Measured memory_bytes: 4596
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int n;
    cin >> n;

    int a[1001][1001] = {};
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n-1; j++)
        {
            cin >> a[i][j];
            a[i][j]--;
        }
            
    }
    
    int current[1001] = {};
    int res = 0;
    
    while (true)
    {
        int done = 0;
        bool doneEachPlayer[1001] = {};
        for (int j = 0; j < n; j++)
        {
            if (doneEachPlayer[j] == true) continue;
            if (current[j] == n-1) continue;

            int opponent_of_j = a[j][current[j]];
            if (doneEachPlayer[opponent_of_j] == true) continue;

            if (a[opponent_of_j][current[opponent_of_j]] == j) {
                current[j]++;
                current[opponent_of_j]++;
                doneEachPlayer[j] = true;
                doneEachPlayer[opponent_of_j] = true;
                done = 1;
            }
        }

        int break_flag = 1;
        for (int j = 0; j < n; j++)
        {
            if (current[j] != n-1) {
                break_flag = 0;
                break;
            }
            
        }
        res++;
        if (break_flag == 1) break;

        if (done==0) {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << res << endl;


    return 0;
}

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

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

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

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

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

N, L = getNM()
A = getList()
max_len_knot, max_len = -1, 0
for i in range(N - 1):
    if A[i] + A[i + 1] > max_len:
        max_len_knot = i
        max_len = A[i] + A[i + 1]
if max_len < L:
    print('Impossible')
else:
    print('Possible')
    for i in range(max_len_knot):
        print(i + 1)
    for i in range(N - 2, max_len_knot, -1):
        print(i + 1)
    print(max_len_knot + 1)


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

const int INF = INT_MAX>>2;
vector<int> dist;
vector<pair<int,int>> a_inv;
int h,w,d;
int calc_dist(int l) {
    if(l < d) return 0; 
    if(dist[l] != INF) return dist[l];
    int x = a_inv[l].first;
    int y = a_inv[l].second;
    int nx = a_inv[l-d].first;
    int ny = a_inv[l-d].second;
    return dist[l] = calc_dist(l-d) + abs(x-nx) + abs(y-ny);
}
int main(){
    ios::sync_with_stdio(false);
    cin >> h >> w >> d;
    vector<vector<int>> a(h,vector<int>(w));
    a_inv.resize(h*w);
    dist.assign(h*w, INF);
    rep(y,h) rep (x,w) {
        cin >> a[y][x];
        a[y][x]--;
        a_inv[a[y][x]] = make_pair(x,y);
    }
    int q;
    cin >> q;
    rep(i,q) {
        int l,r;
        cin >> l >> r;
        l--;r--;
        cout << calc_dist(r) - calc_dist(l) << endl;
    }
}

Measured memory_bytes: 6784
import java.util.*;

class Main{

  public static boolean[][] cards=new boolean[4][13];
  static String a;
  static int b;
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
      int total = sc.nextInt();
      for (int i=0; i<total; i++) {
        a = sc.next();
        b = sc.nextInt();
        if (b == 0) {
          break;
          }
        cards[BoolChanger(a)][b-1] = true;
        }
      int j=0;
      while (j < 4) {
        for (int i=0; i<13; i++) {
          if (!cards[j][i]) {System.out.println(MarksChanger(j) + " " + (i+1));}
        }
          j++;
        } 
  }

  public static String MarksChanger(int k){
		switch(k){
		case 0:return "S";
		case 1:return "H";
		case 2:return "C";
		case 3:return "D";
		default:return null;
		}
  }
           
  public static int BoolChanger(String k){
		switch(k){
		case "S":return 0;
		case "H":return 1;
		case "C":return 2;
		case "D":return 3;
		default:return 0;
		}   
  }
}


Measured memory_bytes: 26288
/*
g++ -std=c++14 -O2 -Wall a.cpp -o a && a
*/

//  io
#include <iostream>
//#include <fstream> //http://www.cplusplus.com/reference/fstream/fstream/
//#include <cstdio>
#include <iomanip> //http://www.cplusplus.com/reference/iomanip/
#include <limits>
//  util
#include <string>
#include <cstring>
#include <algorithm>
//#include <utility>
//#include <functional> //http://www.cplusplus.com/reference/functional/
//#include <cstdlib>
#include <cmath>
//#include <complex>
//#include <random>
//#include <bitset>
//  containers https://en.cppreference.com/w/cpp/container
#include <vector>
//#include <queue>
#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//  time
//#include <ctime>
//#include <chrono>
//                  https://en.cppreference.com/w/cpp/header/chrono
//                  http://www.cplusplus.com/reference/chrono/

using namespace std;
typedef vector<int> arri;
typedef vector<float> arrf;
typedef pair<int, int> pairi;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 0x7fffffffffffffff;
const ll infneg = -0x7fffffffffffffff;

//file input routed to stdinout
/*
std::ifstream inFile("input.txt");
std::ofstream outFile("output.txt");
std::cin.rdbuf(inFile.rdbuf());
std::cout.rdbuf(outFile.rdbuf());
*/

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

    int n;
    cin >> n;

    cout << n * n * n;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    ll all = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        all ^= a[i];
    }
    for(int i = 0; i < n; i++){
        cout << (int)(all^a[i]) << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3964
// In The Name Of God
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define mp make_pair
#define pb push_back
#define int long long
#define ll long long
#define for2(a,b,c) for(int (a) = (b); (a) < (c); (a)++)
#define setp cout << fixed << setprecision(15)
#define endl "\n"
#define minit(a,b) a = min(a,b)
#define maxit(a,b) a = max(a,b)
#define PII pair<int,int>
#define Vec vector<int>
#define error(x) cerr << #x << " = " << (x) << endl;
#define all(x) (x).begin() , (x).end()



int32_t main()
{
    int n; cin >> n;
    if(n == 3){
        cout << "2 "<< "5 "<< "63" << endl;
        return 0;
    }
    vector<int> v;
    v.pb(2);
    v.pb(3);
    v.pb(4);
    v.pb(9);
    n -= 4;
    vector<int> one;
    for(int i = 6; i <= 30000; i += 6) one.pb(i);
    vector<PII> two;
    for(int i = 8; i <= 30000; i += 6){
        two.pb({i,i+2});
    }
    for(int i = 15; i <= 30000; i += 12){
        two.pb({i,i+6});
    }
    while(n>1 && two.size()){
        n -= 2;
        v.pb(two.back().F);
        v.pb(two.back().S);
        two.pop_back();
    }
    while(n){
        n--;
        v.pb(one.back());
        one.pop_back();
    }
    sort(all(v));
    for(auto x : v) cout << x << ' ';
    cout << endl;
    return 0;

}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    ll d[n][n];
    rep(i,n)rep(j,n) cin>>d[i][j];
    rep(k,n)rep(i,n)rep(j,n){
        if(i>=j)continue;
        if(chmin(d[i][j],d[i][k]+d[k][j])){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll res=0;
    rep(i,n)rep(j,n){
        if(i>=j)continue;
        bool jud=false;
        rep(k,n){
            if(i==k||j==k)continue;
            if(d[i][j]==d[i][k]+d[k][j]){
                jud=true;
                break;
            }
        }
        if(!jud)res+=d[i][j];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if(a+b >= 24) ans = (a+b)%24;
  else ans = a+b;
  cout << ans << endl;
}

Measured memory_bytes: 3604
from math import sqrt
from copy import deepcopy


def Calc_Divisors(num):
    divisors = []
    for i in range(1, int(sqrt(num)) + 1):
        if num % i == 0:
            divisors.append(i)
            if i != num // i:
                divisors.append(num//i)
    divisors.sort(reverse=True)
    return divisors


if __name__ == "__main__":
    n, start = map(int, input().split())
    x = list(map(int, input().split()))

    for i in range(n):
        x[i] = abs(x[i] - start)

    # まずx[0]の約数を列挙する
    div = Calc_Divisors(x[0])

    # 大きい約数から順に割っていき、割れなかったら消す
    for i in range(n):
        tmp = deepcopy(div)
        for d in tmp:
            if x[i] % d != 0:
                div.remove(d)

    print(div[0])


Measured memory_bytes: 14612
#include <cstdio>
#include <vector>
#include <algorithm>
#define INF 1000000000

using namespace std;

int main() {
    int n, ans = 0;
    scanf("%d", &n);
    vector<int> b(n + 1, INF);
    for (int i = 1; i < n; ++i) scanf("%d", &b.at(i));
    for (int i = 0; i < n; ++i) ans += min(b.at(i), b.at(i + 1));
    printf("%d\n", ans);
    return 0;
}


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

int main(){
	int n, m;
	cin >> n >> m;
	vector<bool> ju(n);
	vector<int> num(n);

	rep(i, m){
		int s, c;
		cin >> s >> c;
		if(ju.at(s-1) && num.at(s-1) != c){
			cout << -1 << endl;
			return 0;
		}else if(s == 1 && c == 0 && n!=1){
			cout << -1 << endl;
			return 0;
		}else{
			ju.at(s-1) = true;
			num.at(s-1) = c;
		}
	}

	if(num.at(0) == 0 && n != 1) num.at(0) = 1;
	rep(i, n) cout << num.at(i);
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (k, q) = readLine()!!.split(' ').map(String::toLong)
    val dList = readLine()!!.split(' ').map(String::toLong).toLongArray()
    val dSize = dList.size
    for (i in 1..q) {
        val (n, x, mod) = readLine()!!.split(' ').map(String::toLong)
        val max = (n - 1).toInt()
        val ddList = dList.map { it % mod }.toLongArray()
        val ddSum = ddList.sum()
        val first = x % mod
        val times = max / dSize
        val start = (times * dSize + 1)
        val left = (start..max).map { ddList[(it - 1) % dSize] }.sum()
        val timesSum = first + ddSum * times + left
        val revTimes = timesSum / mod
        val leftZero = (start..max).count { ddList[(it - 1) % dSize] == 0L }
        val countZero = ddList.count { it == 0L } * times + leftZero
        val ans = max - revTimes - countZero
        println(ans)
    }
}

Measured memory_bytes: 123212
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,a[200000],x[200000];

ll binsearch(ll start,ll d){
    ll lb = -1,ub = n + 1;//[lb,ub)?????¢?´¢??????

    while(ub - lb > 1){
        ll mid = (lb + ub) / 2;
        if((x[(mid + start) % (n + 1)] - x[start] + 3 * x[n]) % x[n] >= d)ub = mid;
        else lb = mid;
    }

    return ub;
}



bool C(ll mid){
    REP(i,n){
        ll p = binsearch(i,mid);
        if(p == n + 1)
            continue;
        ll q = binsearch((p + i) % (n + 1),(x[(p + i) % (n + 1)] - x[i] + 3 * x[n]) % x[n]);
        if(p + q > n + 1)
            continue;
        ll r = binsearch((q + p + i) % (n + 1),(x[(p + i) % (n + 1)] - x[i] + 3 * x[n]) % x[n]);
        if(p + q + r > n + 1)
            continue;
        return true;
    }
    return false;
}

ll binsearch_i_max(){
    ll lb = 0,ub = x[n] / 3 + 1;//[lb,ub)?????¢?´¢??????

    while(ub - lb > 1){
        ll mid = (lb + ub) / 2;
        if(C(mid))lb = mid;
        else ub = mid;
    }

    return lb;
}

int main(){
    scanf("%lld",&n);
    REP(i,n)
        scanf("%lld",a + i);
    x[0] = 0;
    REP(i,n)
        x[i + 1] = x[i] + a[i];

    printf("%lld\n",binsearch_i_max());
    return 0;
}

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

static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int col) {
	color[r] = col;
	for (int i = 0; i < G[r].size(); i++) {
		int v = G[r][i];
		if (color[v] == NIL) {
			dfs(v, col);
		}
	}
}

void assignColor() {
	int col = 0;
	for (int i = 0; i < n; i++) {
		color[i] = NIL;
	}
	for (int i = 0; i < n; i++) {
		if (color[i] == NIL) {
			dfs(i, col++);
		}
	}
}

int main() {
	int m, q, f, s;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> f >> s;
		G[f].push_back(s);
		G[s].push_back(f);
	}

	assignColor();

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> f >> s;
		if (color[f] == color[s]) cout << "yes" << endl;
		else cout << "no" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 10184
import java.util.Scanner;

public class Main {    
    public static void main(String[] args) {
      Scanner s = new Scanner(System.in);
      s.useDelimiter("\n");
      int n = s.nextInt();
      
      String ans = "No";
        for (int i = 1; i < 10; i++) {
            for(int m = 1; m < 10; m++) {
                if (i * m == n) ans = "Yes";
            }
        }
        
        System.out.println(ans);
    }
}



Measured memory_bytes: 22228
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

typedef long long ll;

int main(){
  int n;
  int op[105];
  int i,j,s;
  int b[105];
  int cnt = 1;
  int flag = 0;

  scanf("%d", &n);
  for(i = 1;i <= 104;i++) b[i] = -1;
  for(i = 1;i <= n;i++){
    scanf("%d", &b[i]);
  }

  for(i = 1;i <= n;i++){
    cnt = 1;
    for(j = 1;j <= n;j++){
      if(cnt == b[j]){
        s = j;
      }

      if(b[j] != -1) cnt++;
    }

    op[i] = b[s];
    b[s] = -1;
  }

  for(i = 1;i <= n;i++) if(b[i] != -1) flag = 1;

  if(flag != 1){
    for(i = n;i >= 1;i--) printf("%d\n", op[i]);
  }

  else printf("-1\n");

  return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int x, a;
    cin >> x >> a;

    if (x < a) {
        cout << 0 << endl;
    } else {
        cout << 10 << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int n,x,a[100000],i,last;
    long long num;
    scanf("%d %d",&n,&x);
    num=0;
    last=0;
    for(i=0;n>i;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]+last>x)
        {
            num=num+a[i]+last-x;
            last=x-last;
        }
        else
        {
            last=a[i];
        }
    }
    printf("%lld",num);
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	int n, m;
	cin >> n >> m;
	vi x(n);
	rep(i, n)cin >> x[i];
	sort(all(x));

	vi modm(m, 0);
	vi same(m, 0);
	int k = 1;

	rep(i, n) {
		modm[x[i] % m]++;
		if (i == 0)continue;
		if (x[i - 1] == x[i])k++;
		else {
			same[x[i - 1] % m] += k / 2;
			k = 1;
		}
	}
	same[x[n - 1] % m] += k / 2;

	int ans = 0;

	rep(i, m) {
		if (i == 0 || i * 2 == m) { ans += modm[i] / 2;continue; }
		if (i * 2 > m)continue;

		ans += min(modm[i], modm[m - i]);
		if (modm[i] >= modm[m - i])ans += min(same[i], (modm[i] - modm[m - i]) / 2);
		else ans += min(same[m - i], (modm[m - i] - modm[i]) / 2);

	}

	cout << ans << endl;

}

Measured memory_bytes: 1408
n, m = map(int, input().split())
drink = {}
for _ in range(n):
    a, b = map(int, input().split())
    if a in drink:
        drink[a] = drink[a]+b
    else:
        drink[a] = b
drink = list(drink.items())
drink.sort()

num = m
cost = 0
for i in range(n):
    p = min(num, drink[i][1])
    cost += drink[i][0]*p
    num -= p
    if num == 0:
        break
print(cost)

Measured memory_bytes: 22608
import java.util.*;
class Main{
	public static void main(String args[]){
		Scanner s = new Scanner(System.in);
		String indata = s.next();
		int height = Integer.parseInt(indata);
		indata = s.next();
		int waid = Integer.parseInt(indata);
		System.out.println(height*waid +" "+ (height*2+waid*2));
	}
}

Measured memory_bytes: 25960
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<algorithm>
#include<iterator>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#define lli long long int
#define mp make_pair
#define ULTRA_INSTINCT ios_base::sync_with_stdio(false); cin.tie(0)
#define PI  3.141592653589793
#define fo(i,n) for(lli i=0;i<(n);i++)
#define FO(i,x,n) for(lli i=(x);i<(n);i++)
#define pb push_back
#define FI first
#define SE second
#define vi vector<lli>
#define pi pair<lli,lli>
#define vii vector<pi >
#define Endl endl
#define ITA 200005
#define ROH 100005
using namespace std;
lli mod = 1e9 +7,test; 
lli max(lli a,lli b){return a>b?a:b;}
lli min(lli a,lli b){return a>b?b:a;}

lli gcd(lli a, lli b) { 
   if (b == 0) return a; 
   return gcd(b, a % b);  
} 

lli n,k;
vi a(401);

vector<vi > dp;
vi sum(402);
lli f(lli i ,lli j){
    if(i==j){ return 0;}
    if(i>j){return 0;}
    if(dp[i][j] != -1){return dp[i][j];}
    dp[i][j] = mod * 1e5;
    lli tot = (sum[j] - (i>0 ?  sum[i-1] : 0));
    for(lli k = i;k<j;k++){
        dp[i][j] = min(dp[i][j] ,f(i,k) + f(k+1,j) + tot);
    }
    return dp[i][j];
}


void solve(){
    cin>>n;
    fo(i,n){
        cin>>a[i];
    }
    sum[0] = a[0];
    FO(i,1,n){
        sum[i] = sum[i-1] + a[i];
    }
    dp.resize(n+1 ,vi(n+1 , -1));

    cout<<f(0,n-1)<<endl;


}

int main(){
    ULTRA_INSTINCT;
    lli t =1;
    // cin>>t;
    fo(i,t){
        solve();
    }
    return 0;

}

Measured memory_bytes: 1536
from collections import defaultdict


def main():
    D = defaultdict(list)
    names = set()
    N = int(input())
    for i in range(1, N+1):
        inp = input().split()
        s = inp[0]
        p = inp[1]
        names.add(s)
        D[s].append((p, i))
    names = sorted(list(names))
    for n in names:
        D[n].sort(key=lambda x: int(x[0]), reverse=True)
        for x in D[n]: print(x[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//=====main=====

func main() {
	sc.Split(bufio.ScanWords)

	n := scanInt()
	s := scanText()

	ans := 0

	for i := 0; i < n-2; i++ {
		if s[i]=='A' && s[i+1]=='B' && s[i+2]=='C' {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

ll mod_pow(ll x,ll n,ll mod){
  if(!n)return 1;
  ll res=mod_pow(x*x%mod,n/2,mod);
  if(n&1)res=res*x%mod;
  return res;
}

void extended_euclid(ll x,ll y,ll *c,ll *a,ll *b){
  ll a0,a1,a2,b0,b1,b2,r0,r1,r2,q;r0=x;r1=y;a0=1;a1=0;b0=0;b1=1;
  while(r1>0){q=r0/r1;r2=r0%r1;a2=a0-q*a1;b2=b0-q*b1;r0=r1;r1=r2;a0=a1;a1=a2;b0=b1;b1=b2;}
  *c=r0;*a=a0;*b=b0;
}

ll get_inv(ll n, ll p){
  ll a,b,c;
  extended_euclid(n,p,&c,&a,&b);
  if(a<p) a+=p;
  return a%p;
}

ll d[1111111];

void Main() {
  ll n;
  R n;
  ll a[n];
  rep(i,n) {
    R a[i];
    ll x=a[i];
    for(ll j=2; j*j<=x; j++) {
      ll c=0;
      while(x%j==0) {
        x/=j;
        c++;
      }
      d[j]=max(d[j],c);
    }
    d[x]=max(d[x],1LL);
  }
  ll s=1;
  REP(i,1,1111111) {
    if(d[i]) {
      s*=mod_pow(i,d[i],MAX);
      s%=MAX;
    }
  }
  ll ans=0;
  rep(i,n) {
    ll x=a[i];
    ll y=s;
    for(ll j=2; j*j<=x; j++) {
      while(x%j==0) {
        x/=j;
        y*=get_inv(j,MAX);
        y%=MAX;
      }
    }
    y*=get_inv(x,MAX);
    y%=MAX;
    ans+=y;
    ans%=MAX;
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 8320
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#ifndef debug_on
#define debug_on 0
#endif

#define dbg \
    if(debug_on) cerr << "DEBUG:"
#define ast(cond)           \
    do {                    \
        if((cond) == false) \
        {                   \
            if(debug_on)    \
            cerr << "ASSERT" << #cond " failed at line:" << __LINE__ << endl;   \
            exit(1);        \
        }                   \
    }while(0)
const int MAX_N = 2 * 100000 + 3;
int N;
int A[MAX_N];
int main(int, char *[])
{
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> A[i];
    bool ng = false;
    if(A[0] != 0)
        ng = true;
    if(!ng)
    {
        for(int i = 1; i < N; ++i)
            if(A[i-1] + 1 < A[i])
            {
                ng = true;
                break;
            }
    }

    int64_t count = 0;
    if(!ng)
    {
#if 1
        for(int i = 1; i < N; ++i)
        {
            if(A[i-1] + 1 == A[i])
                ++count;
            else
                count += A[i];
        }
#else
        for(int i = N-1; i >= 1; --i)
        {
            if(A[i] == 0)
                continue;
            if(A[i] == A[i - 1] + 1)
            {
                ++count;
                //prev_val = A[i-1];
            }
            else
            {
                count += A[i] - prev_val;
                //prev_val = A[i] - 1;
            }
        }
#endif
    }

    cout << (ng ? -1 : count) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ff first
#define ss second
typedef long long ll;
ll power(ll a, ll b){//a^b
    ll res=1;
    a=a%MOD;
    while(b>0){
        if(b&1){res=(res*a)%MOD;b--;}
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        ll a[n];
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        ll l=1;
        ll r=1e9;
        ll ans=0ll;
        while(l<=r){
            ll mid=(l+r)/2;
            ll val=0ll;
            for(int i=0;i<n&&val<=k;i++){
                val+=a[i]/mid+((a[i]%mid)!=0)-1;
            }
            if(val<=k){
                r=mid-1;
                ans=mid;
            }
            else
                l=mid+1;
        }
        cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 5076
#include <stdio.h>

int main(){
	int n,i;
	long long int data[200000]={0},a=0,b=0,t1=0,t2=0;
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%lld",&data[i]);
		b+=data[i];
	}
	
	for(i=0;i<n-1;i++){
		a+=data[i];	
		b-=data[i];
		if(a>b){
			t1=a-b;	
		}else{
			t1=b-a;	
		}
		if(i==0){
			t2=t1;
		}else if(t2>t1){
			t2=t1;	
		}
	}
	
	printf("%lld\n",t2);
	
return 0;
}

Measured memory_bytes: 1664
import java.util.PriorityQueue
import java.util.Comparator

fun main(args: Array<String>)
{
    val (n, m) = readLine()!!.split(" ").map{ it.toInt() }
    val a = readLine()!!.split(" ").map{ it.toInt() }

    val q = PriorityQueue<Int>(n) { o1: Int, o2: Int -> o2 - o1 }
    q.addAll(a)

    var maximum: Int
    for (i in 1..m) {
        maximum = q.poll()
        q.add(maximum / 2)
    }

    var sum: Long = 0L
    for (i in 1..n) {
        sum += q.poll().toLong()
    }

    println(sum)
}


Measured memory_bytes: 74188