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

using namespace std;
#define MX 1e5+1
#define pb push_back
#define prr pair<int,int> 
#define int long long
#define fir first
#define sec second
int gcd(int a,int b){
    if(b==0){
        return a;
    }

    return gcd(b,a%b);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
    int n,k;
    cin>>n>>k;
    if(n==0){
        cout<<"0";
        return 0;
    }
    if(k==1){
        cout<<"0";
        return 0;
    }
    if(n<k){
        int ans=min(n,k-n);
        cout<<ans;
        return 0;    
    }
    int a1=n%k;
    int ans=min(a1,k-a1);  
    cout<<ans;
    // int a1=INT_MAX;
    // while(1){
    //     int d1=abs(n-k);
    //     n=d1;
    //     if(n<a1){
    //         a1=n;
    //     }else{
    //         break;
    //     }
    // } 
    // cout<<a1;
}










Measured memory_bytes: 256
import sys

n = int(input())
As = list(map(int, input().split()))
sort_as = sorted(As)
for i in range(len(sort_as)):
    if i == len(sort_as)-1:
        pass
    else:
        if sort_as[i+1] == sort_as[i]:
            print("NO")
            sys.exit()
        else:
            continue

print("YES")

Measured memory_bytes: 26808
using System;

namespace AtCoder {
	class Program {
		public static void Main() {
			string s = Console.ReadLine();
			int i = (s.Length) / 2 - 1;
			while (s.Remove(i) != s.Substring(i, i)) i --;
			Console.WriteLine(i * 2);
		}
	}
}


Measured memory_bytes: 13140
N,K = map(int,input().split())
ary1 = []
ary2 = []
if K % 2 == 1:
    for i in range(K,N+1,K):
        ary1 += [i]
    print(len(ary1)**3)
else:
    for i in range(1,N+1):
        if i % K == 0:
            ary1 += [i]
        elif i % (K//2) == 0:
            ary2 += [i]
    print((len(ary1) ** 3) + (len(ary2) ** 3))


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

int dp[1<<21];

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);
    int n;
    cin>>n;
    int arr[n][n];
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin>>arr[i][j];
    }
    //cout<<"f"<<endl;
    //int dp[1<<n];
    //dp[0] = 1;
    //cout<<1<<endl;
    memset(dp,0,sizeof(dp));
    dp[0] = 1;
    for(int i=1; i<(1<<n); i++)
    {
        //cout<<i<<endl;
        int s = __builtin_popcount(i);
        //cout<<i<<" "<<s<<endl;
        for(int j=0; j<n; j++)
        {
            if((i>>j)&1==1 && arr[s-1][j]==1)
            {
                dp[i] = (dp[i] + dp[(i ^ (1<<j))]) % 1000000007;
            }
        }
    }
    cout<<dp[(1<<n) - 1];
    return 0;
}

Measured memory_bytes: 16640
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextLine()){
			double[] stack=new double[80];
			int ptr=0;
			String[] str=sc.nextLine().split(" ");
			for(int i=0;i<str.length;i++){
				try{
					stack[ptr]=Double.parseDouble(str[i]);
					ptr++;
				}catch(NumberFormatException e){
					if(str[i].equals("+")){
						stack[ptr-2]+=stack[ptr-1];
						ptr--;
					}
					if(str[i].equals("-")){
						stack[ptr-2]-=stack[ptr-1];
						ptr--;
					}
					if(str[i].equals("*")){
						stack[ptr-2]*=stack[ptr-1];
						ptr--;
					}
					if(str[i].equals("/")){
						stack[ptr-2]/=stack[ptr-1];
						ptr--;
					}
				}
			}
			System.out.println(stack[0]);
		}
	}
}

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


//TEMPLATE
#define pb                push_back
#define mp                make_pair
#define ll                long long
#define ld                long double
#define pii               pair <ll, ll>
#define piii              pair <ll, pii>
#define F                 first
#define S                 second

#define newline           printf("\n")
#define minusone          printf("-1\n")
#define zeroo             printf("0\n")
#define scl1(a)           scanf("%lld", &a)
#define scl2(a, b)        scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)     scanf("%lld %lld %lld", &a, &b, &c)
#define prl1(a)           printf("%lld\n", a)
#define prl2(a, b)        printf("%lld %lld\n", a, b)
#define ssl1(s)           scanf(" %[^\n]", s)
#define scd1(a)           scanf("%lf", &a)
#define scd2(a, b)        scanf("%lf %lf", &a, &b)
#define prd(a)            printf("%lf\n", a)
#define prld(a)           printf("%Lf\n", a)
#define prcase(cs)        printf("Case %lld: ", cs)
#define cin1(a)           cin >> a
#define cin2(a, b)        cin >> a >> b
#define cin3(a, b, c)     cin >> a >> b >> c
#define cin4(a, b, c, d)  cin >> a >> b >> c >> d
#define cot1(a)           cout << a << "\n"
#define cot2(a, b)        cout << a << " " << b << "\n"
#define cot3(a, b, c)     cout << a << " " << b << " " << c << "\n"
#define cot4(a, b, c, d)  cout << a << " " << b << " " << c << " " << d << "\n"
#define cotline           cout << "\n"
#define cotminus          cout << "-1\n"
#define cot0              cout << "0\n"
#define cotyes            cout << "YES\n"
#define cotno             cout << "NO\n"
#define cotcase(cs)       cout << "Case " << cs << ": "

#define reversed(s)       reverse(s.begin(), s.end())
#define asort(s)          sort(s.begin(), s.end())
#define dsort(s)          sort(s.rbegin(), s.rend())
#define all(s)            s.begin(), s.end()
#define uniq(s)           s.resize(distance(s.begin(),unique(s.begin(), s.end())))
#define found(s, x)       (s.find(x) != s.end())

#define for0(i, n)        for (i = 0; i < n; i++)
#define for1(i, n)        for (i = 1; i <= n; i++)
#define fora(i, a, b)     for (i = a; i <= b; i++)
#define forb(i, b, a)     for (i = b; i >= a; i--)
#define fori(it, s)       for(auto it = s.begin(); it != s.end(); it++)

#define FR                ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(a, x)          memset(a, x, sizeof a)
#define bitcount(n)       __builtin_popcountll(n)

//#define pi              3.1415926536
#define pi                acos(-1)

const ll INF = LLONG_MAX;
const ll SZ = 4e5+5;
const ll mod = 1e9+7;


ll n;
//ll a[SZ];
//ll b[SZ];



int main() {
    FR;
    ll cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
//    ll a, b, d;
    string s, s1, s2;

    cin3(n, x, t);

    c = (n/x) + (n%x != 0);
    cot1(c*t);

    return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n;
  cin >> n;
  vector<pair<pair<string,int>,int>> p(n);
  for(int i = 0;i<n;i++)
  {
      string s;
      int a;
      cin >> s >> a;
      pair<string,int> P;
      P = make_pair(s,100-a);
      p[i] = make_pair(P,i+1);
  }
  sort(p.begin(),p.end());
  for(int i = 0;i<n;i++) cout << p[i].second << endl;
  return 0;
}



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

unsigned long long c=0;
int A[100000000];

void marge(int A[], int left, int mid, int right){
  int n1=0,n2=0;
  int L[500100];
  int R[500100];
  n1=mid-left;
  n2=right-mid;
  for(int i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=INT_MAX;
  R[n2]=INT_MAX;
  int j=0;
  int i=0;
  for(int k=left;k<right;k++){
    
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      
    }
    else {
      A[k]=R[j];
      j++;
      c=c+n1-i;
    }
  }
}

void margesort(int A[], int left, int right){
  int mid=0;
  if(left+1<right){
    mid=(left+right)/2;
    margesort(A,left,mid);
    margesort(A,mid,right);
    marge(A,left,mid,right);
  }
}

int main(){
  int n=0;
  int left=0,right=0;
  //int S[100000000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  left=0;
  right=n;
  margesort(A,left,right);
  /*for(int i=0;i<n;i++){
    if(i!=0)cout<<" ";
    cout<<A[i];
    }*/
  printf("%llu\n",c);
  
  return 0;
}


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

using namespace std;

#define int long long

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

    vector < int > a(n);

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

    int sum = 0;
    for(int i=0;i<n;i++)
        sum+=a[i];

    int left = 0;
    int right = sum;
    int ans = sum;
    for(int i=0;i<n;i++)
    {
        left+=a[i];
        right-=a[i];
        int temp = abs(left-right);
        ans = min(ans, temp);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int bubblesort(vector<pair<char,int>> &a,int n){
    int cnt=0,flag=1;
    while(flag){
        flag=0;
        for(int j=n-1;j>0;j--){
            if(a[j].second<a[j-1].second){
                swap(a[j],a[j-1]);
                flag=1;
                cnt++;
            }
        }
    }
    return cnt;
}

int selectionsort(vector<pair<char,int>> &a,int n){
    int cnt=0;
    for(int i=0;i<n;i++){
        int minj=i;
        for(int j=i;j<n;j++){
            if(a[j].second<a[minj].second){
                minj=j;
            }
        }
        if(a[i].second==a[minj].second)cnt--;
        swap(a[i],a[minj]);
        cnt++;
    }
    return cnt;
}
int main(){
    int n;
    cin >> n;
    vector<pair<char,int>>s(n);
    for(int i=0;i<n;i++){
        cin >> s[i].first >> s[i].second;
    }
    vector<pair<char,int>>b(n);
    b=s;
    int ans_s=selectionsort(s,n);
    int ans_b=bubblesort(b,n);
    for(int i=0;i<n;i++){
        cout << b[i].first << b[i].second;
        if(i<n-1)cout << " ";
    }
    cout << endl << "Stable" << endl;
    for(int i=0;i<n;i++){
        cout << s[i].first << s[i].second;
        if(i<n-1)cout << " ";
    }
    cout << endl;
    if(s==b){
        cout << "Stable" << endl;
    }
    else{
        cout << "Not stable" << endl;
    }
}



Measured memory_bytes: 3116
import std.stdio;
import std.algorithm;
import std.conv;
import std.array;
import std.string;
import std.math;
import std.functional;
import std.range;
import std.typecons;
import std.format;

void main(string[] args) {
  readln;
  solve(readln);
}

auto solve(string line1) {
  auto a = line1.split.map!(to!int).array;
  auto N = a.length;
  auto max_i = a.maxIndexAlt;
  auto min_i = a.minIndexAlt;
  
  (2 * N - 1).writeln;
  
  int x = abs(a[min_i]) < abs(a[max_i]) ? max_i : min_i;
  foreach(y; 0..N) {
    a[y] += a[x];
    "%d %d".format(x + 1, y + 1).writeln;
  }

  if (a.all!"a >= 0") {
    foreach(y; 1..N) {
      a[y] += a[y - 1];
      "%d %d".format(y - 1 + 1, y + 1).writeln;
    }
  } else {
    foreach(k; 1..N) {
      auto y = N - k - 1;
      a[y] += a[y + 1];
      "%d %d".format(y + 1 + 1, y + 1).writeln;
    }
  }
}

pure auto maxIndexAlt(T)(T[] arr) {
  auto max = arr.front;
  auto res = 0;
  foreach(int i; 0..cast(int)arr.length) {
    if (max < arr[i]) {
      max = arr[i];
      res = i;
    }
  }
  return res;
} unittest {
  assert([4, 6, 3, 0, 1].maxIndexAlt == 1);
}

pure auto minIndexAlt(T)(T[] arr) {
  auto min = arr.front;
  auto res = 0;
  foreach(int i; 0..cast(int)arr.length) {
    if (arr[i] < min) {
      min = arr[i];
      res = i;
    }
  }
  return res;
} unittest {
  assert([4, 6, 3, 0, 1].minIndexAlt == 3);
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    int n = s.nextInt();
	    int dig = n%10;
	    if(dig==2||dig==4||dig==5||dig==7||dig==9){
            System.out.println("hon");
        }
	    else if(dig==0||dig==1||dig==6||dig==8){
            System.out.println("pon");
        }
	    else{
            System.out.println("bon");
        }
    }
}


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

void Main() {
    int N;
    cin >> N;
    vector<int> d(N);
    for (auto& e : d) cin >> e;
    sort(d.begin(), d.end(), greater<int>());
    int ans = 1;
    int pre = d[0];
    for (auto e : d) {
        if (pre > e) {
            ans += 1;
            pre = e;
        }
    }
    cout << ans << endl;
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}

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

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);

    for (int i = 0; i < A.size(); ++i) {
        cin >> A[i];
    }

    sort(A.begin(), A.end());

    int s = 0;
    int e = A.size() - 1;

    int max = K - A[A.size() - 1] + A[0];
    for (int i = 1; i < A.size(); ++i) {
        if (max < A[i] - A[i - 1]) {
            max = A[i] - A[i - 1];
            s = i;
            e = i - 1;
        };
    }

    if (e < s) {
        cout << K - A[s] + A[e] << endl;
    } else {
        cout << A[e] - A[s] << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int A, B, C, D, E, F, sw, ans1 = 0, ans2 = 0;
  	float dens, max = 0;
  	vector<int> water, sugar;
  	cin >> A >> B >> C >> D >> E >> F;
  	for (int i = 0; i * 100 <= F; i++){
    	for (int j = 0; j * 100 <= F; j++){
        	int w; w = 100 * (A * i + B * j);
          	if (w <= F && find(water.begin(), water.end(), w) == water.end()){
            	water.push_back(w);
            }
        }
    }
  	for (int i = 0; i <= F; i++){
    	for (int j = 0; j <= F; j++){
        	int s; s = C * i + D * j;
          	if (s <= F && find(sugar.begin(), sugar.end(), s) == sugar.end()){
            	sugar.push_back(s);
            }
        }
    }
  	for (int i = 0; i < water.size(); i++){
    	for (int j = 0; j < sugar.size(); j++){
        	sw = water[i] + sugar[j];
          	if (sw> 0 && sw <= F && (float)sugar[j] * 100 <= water[i] * E){
            	dens = (float)sugar[j] / sw;
              	if (max <= dens){
                	max = dens;
                  	ans1 = sw;
                  	ans2 = sugar[j];
                }
            }
        }
    } 
  	cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int a,b,c=0,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,z;
  char x[2000000],y[2000000];

        scanf("%s %s",x,y);
       for(i=0;i<strlen(x);i++)
       {
           if(x[i]!=y[i]){c++;}
       }

    printf("%lld\n",c);

}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000000+7;

int main(void)
{
    ll N, K;
    cin >> N >> K;
    vector<int> A(2*N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll c1 = 0;
    ll c2 = 0;
    ll count = 0;
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                c1 += 1;
            }
        }
        c1 %= mod;
    }
    for (int i = 0; i < N; i++) {
        A[i+N] = A[i];
    }
    for (int i = 0; i < 2*N; i++) {
        for (int j = 2*N-1; j > i; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                c2 += 1;
            }
        }
        c2 %= mod;
    }

    count = (((K-1)*K/2)%mod) * c2;
    count %= mod;
    count += (K * c1) % mod;
    count %= mod;
    cout << count << endl;

    return 0;
}



Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

char A[1 << 20];

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

	VInt cnt(256, 0);
	int i;
	FOR(i, 0, n) ++cnt[A[i]];

	Int mod = 1e9 + 7;
	Int res = 1;
	FOR(i, 0, SIZE(cnt))
		res = res * (1 + cnt[i]) % mod;

	res = (res + mod - 1) % mod;
	printf("%lld\n", res);
	return 0;
};


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define REP(i, n) for(int i=0; i<n; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9+7;

struct edge{
    int to;
    int cost;
};
using graph = vector<vector<edge>>;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    bool approve = true;
    REP(i, n){
        cin >> a[i];
        if(a[i] % 2 == 0){
            if(a[i] % 3 == 0 || a[i] % 5 == 0){
                continue;
            }else{
                approve = false;
                break;
            }
        }
    }
    if(approve){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;



template<int Modulus> 
struct ModInt {
    long long x;
    ModInt(long long x = 0) :x((x%Modulus + Modulus)%Modulus) {}
    constexpr ModInt &operator+=(const ModInt a) {if ((x += a.x) >= Modulus) x -= Modulus; return *this;}
    constexpr ModInt &operator-=(const ModInt a) {if ((x += Modulus - a.x) >= Modulus) x -= Modulus; return *this;}
    constexpr ModInt &operator*=(const ModInt a) {(x *= a.x) %= Modulus; return *this;}
    constexpr ModInt &operator/=(const ModInt a) {return *this *= a.inverse();}

    constexpr ModInt operator+(const ModInt a) const {return ModInt(*this) += a.x;}
    constexpr ModInt operator-(const ModInt a) const {return ModInt(*this) -= a.x;}
    constexpr ModInt operator*(const ModInt a) const {return ModInt(*this) *= a.x;}
    constexpr ModInt operator/(const ModInt a) const {return ModInt(*this) /= a.x;}
    
    friend constexpr ostream& operator<<(ostream& os,const ModInt<Modulus>& a) {return os << a.x;}
    friend constexpr istream& operator>>(istream& is,ModInt<Modulus>& a) {return is >> a.x;}
    
    ModInt inverse() const {// x ^ (-1) 
        long long a = x,b = Modulus,p = 1,q = 0;
        while (b) {long long d = a/b; a -= d*b; swap(a,b); p -= d*q; swap(p,q);}
        return ModInt(p);
    }
    ModInt pow(long long N) {// x ^ N 
        ModInt a = 1;
        while (N) {
            if (N&1) a *= *this;
            *this *= *this;
            N >>= 1;
        }
        return a;
    }
};

using mint = ModInt<1000000007>;
//using mint = ModInt<998244353>;
struct Combination {
    int N;
    //using mint = ModInt<1000000007>;
    //using mint = ModInt<998244353>;
    vector<mint> fact,ifact,invs;
    Combination(int N): N(N) {
        fact.resize(N + 1); ifact.resize(N + 1);
        fact[0] = fact[1] = 1;
        ifact[0] = ifact[1] = 1;
        for (int i = 2;i < N + 1;++i) {fact[i] = fact[i - 1] * i;}
        ifact[N] = fact[N].inverse();
        for (int i = N;i >= 1;--i) {ifact[i - 1] = ifact[i] * i;}
    }
    void invs_build() {
        invs.resize(N + 1);
        invs[1] = 1;
        for (int i = 2;i < N + 1;++i) invs[i] = fact[i] * ifact[i - 1];
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n - k];
    }
    mint npk(int n,int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n - k];
    }
};

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

    int s;cin >> s;
    Combination comb(s);
    mint ans = 0;
    for (int i = 1;3*i <= s;++i) {
        ans += comb(s - 2*i - 1,i - 1);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3648
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
a = int(n ** (1/2))
ans = 0

while a * (a + 1) // 2 < n:
    #print(a)
    a += 1

print(a)


Measured memory_bytes: 5188
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
 
int main()
{
    int N; cin >> N;
    int s[N];
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> s[i];
        ans += s[i];
    }
    sort(s,s+N);
    if(ans%10 == 0){
        for (int i = 0; i < N; i++)
        {
            if(s[i]%10 != 0){
                cout << ans-s[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
        return 0;
    }
    else{
        cout << ans << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int ans = 0;
    string pre = "#";
    string cur = "";
    rep(i, 0, (int)s.size()) {
        cur += s[i];
        if (cur != pre) {
            ans++;
            pre = cur;
            cur = "";
        }
    }

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


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct structure{
        bool signal;int count;
};
int Min(int x,int y){
        if(x==0)return y;
        if(y==0)return x;
        return x<y?x:y;
}
int main(){
        int N;
        string str[51];
        map<char,int> used[51];
        map<char,structure> enable;
        cin >> N;
        for(int i=0 ; i<N ; i++ ){
                string s;
                cin >> s;
                for(int j=0 ; j<s.size() ; j++ )
                        used[i][s[j]]++;
        }string alpha="abcdefghijklmnopqrstuvwxyz";
        for(int i=0 ; i<alpha.size() ; i++ ){
                bool signal=true;
                int count=5000;
                for(int j=0 ; j<N ; j++ ){
                        signal*=used[j][alpha[i]];
                        count=Min(count,used[j][alpha[i]]);
                }if(signal){
                        enable[alpha[i]].signal=true;
                        enable[alpha[i]].count=count;
                }
        }string ans="";
        for(int i=0 ; i<alpha.size() ; i++ ){
                if(enable[alpha[i]].signal){
                        for(int j=0 ; j<enable[alpha[i]].count ; j++ ){
                                ans+=alpha[i];
                        }
                }
        }
        cout<<ans<<endl;
        return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
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)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

struct LazySegmentTree{
   private:
       int n;
       vector<ll> node,lazy;
   public:
       LazySegmentTree(int sz,ll init){
           n=1;
           while(n<sz)n*=2;
           node.resize(2*n-1,init);
           lazy.resize(2*n-1,0);
       }

       void eval(int k,int l,int r){
           if(lazy[k]!=0)node[k]+=lazy[k];
           if(r-l>1){
               lazy[2*k+1]+=lazy[k]/2;
               lazy[2*k+2]+=lazy[k]/2;
           }
           lazy[k]=0;
       }
       void add(int a,int b,ll x,int k=0,int l=0,int r=-1){
           if(r<0)r=n;
           eval(k,l,r);
           if(r<=a||b<=l)return;
           if(a<=l&&r<=b){
               lazy[k]+=(r-l)*x;
               eval(k,l,r);
           }
           else {
               add(a,b,x,2*k+1,l,(l+r)/2);
               add(a,b,x,2*k+2,(l+r)/2,r);
               node[k]=node[2*k+1]+node[2*k+2];
           }
       }
       //[a,b)での和を返す
       ll get(int a,int b,int k=0,int l=0,int r=-1){
           if(r<0)r=n;
           eval(k,l,r);
           if(r<=a||b<=l)return 0;
           if(a<=l&&r<=b)return node[k];
           ll xl=get(a,b,2*k+1,l,(l+r)/2);
           ll xr=get(a,b,2*k+2,(l+r)/2,r);
           return xl+xr;
       }
   };
int main(){
   int n,q;
   cin>>n>>q;
   LazySegmentTree sg(n,0);
   rep(i,q){
       int t;cin>>t;
       if(t){
           int a,b;
           cin>>a>>b;
           a--;
           cout<<sg.get(a,b)<<endl;
       }
       else {
           int a,b,c;
           cin>>a>>b>>c;
           sg.add(a-1,b,c);
       }
   }
   return 0;
}


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

int main(){
  
  int n,k;
  cin >> n >> k;
  
  vector<int> h(n);
  
  for ( int i = 0 ; i < n ; i++){
    cin >> h[i];
  }
  
  sort(h.begin(),h.end());
  
  int ans = 1000000001;
  
  for ( int i = 0; i <= n-k ; i++){
    //cout << ans << ' ' << abs(h[i]-h[i+k-1]) << endl;
    ans = min(ans,abs(h[i]-h[i+k-1]));
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
const ll limit=28;
ll a[limit];
ll b[limit];
bool G[limit][limit];
ll N,M;

ll dfs(ll v,bool visited[limit]){
  bool ALL=true;
  rep(i,N){
    if(visited[i]==false){
      ALL=false;
    }
  }

  if(ALL){
    return 1;//+1はすべてのdfsに共通に足される？
  }
  
  ll ret=0;
  
  rep(i,N){
    
    if(G[v][i]==true&&visited[i]==false){
      visited[i]=true;
      ret+=dfs(i,visited);
      visited[i]=false;
    }

  }
  
  return ret;
}
 
    
      
    
    
int main(){
  
  cin>>N>>M;
  
  rep(i,M){
cin>>a[i]>>b[i];
    
    G[a[i]-1][b[i]-1]=G[b[i]-1][a[i]-1]=true;
  }
  bool visited[limit];
rep(i,N){
  visited[i]=false;
  
}
 
  visited[0]=true;//0スタート固定？
  

  cout<<dfs(0,visited)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  ll a[N];
  ll b[N];
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i];
  }
  ll ans=0;
  for(int i=N-1;i>-1;i--){
    if((a[i]+ans)%b[i]!=0){
      ans+=b[i]-((a[i]+ans)%b[i]);
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

//--------------------------------------------------------------------

int fac(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    vector<int> P(n), Q(n);
    for(int i=0; i<n; i++) cin >> P[i]; 
    for(int i=0; i<n; i++) cin >> Q[i];
    int a = 0, b = 0;
	for (int i = 0; i < n-1; i++) {
		if (P[i] != 1) {
			a += (P[i] - 1) * fac(n - i - 1);
		}
		if (Q[i] != 1) {
			b += (Q[i] - 1) * fac(n - i - 1);
		}
		for (int j = i + 1; j < n; j++) {
			if (P[i] < P[j]) {
				P[j] -= 1;
			}
			if (Q[i] < Q[j]) {
				Q[j] -= 1;
            }
        }
    }
    int ans = std::abs(a-b);
    cout << ans << endl;




    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<long long>> vvll;
typedef long double ld;
typedef std::vector<long double> vld;
typedef std::vector<std::vector<long double>> vvld;
using namespace std;
void yesno(bool state);

void Main(){
    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];
    ll ans = 0;
    rep(i,N){
        if(i%2 == 0 && A[i] % 2 ==1)
            ans++;
    }
    cout << ans << endl;
}

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

void yesno(bool state){
    if(state)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<int> h(n+10);
    vector<int> dp(n+10,1e9);
    dp[0] = 0;
    rep(i,n){
        cin >> h[i];
    }
    rep(i,n){
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    cout << dp[n-1] <<endl; 
return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  
  if(u==NIL || k==u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
  
}

Node treeSuccessor(Node x){
  
  
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  

  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
while(x!=NIL){
    y=x;//親 設定
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
  if(y==NIL){
    root=z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else {
    y->right = z;
  }
  



}

void inorder(Node u){
  if(u->left!=NIL){
    inorder(u->left);
   
  }           
  printf(" %d",u->key);
  if(u->right != NIL){
    inorder(u->right);
  }
  
}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left!=NIL){
    preorder(u->left);
  }
  if(u->right != NIL){
    preorder(u->right);

  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll h, w, v[110][110],ct=0;
int main(){
	ll n,n2, ct = 1;
	cin >> n;
	n2 = n;
	while (n2 >= 10){++ct; n2 /= 10;}
	if (n % (ll)pow((ll)10, ct - 1) == pow(10, ct - 1) - 1)cout << 9 * (ct - 1) + n / (ll)pow((ll)10, ct - 1) << endl;
	else cout << 9 * (ct - 1) + n / (ll)pow((ll)10, ct - 1)-1 << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0]+list(map(int,input().split()))+[0]

money = 0
for i in range(n+1):
  money += abs(a[i+1]-a[i])

for i in range(1,n+1):
  print(money - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]))

Measured memory_bytes: 14044
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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


int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int ans = 1000000000;
    for (int i = -100; i <= 100; i++){
        int s = 0;
        rep(j, n){
            s += (a[j] - i) * (a[j] - i);
        }
        ans = min(s, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<ll,ll>;

ll ketasu(ll a){
   ll num=1;
   while(a/10){
       num++;
       a/=10;
   }
   return num;
}

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

ll kosuu(ll a){
    ll sum=0;
    for(ll i=1;i*i<=a;i++){
        if(a%i==0){
            if(a!=1&&i*i!=a){
            sum+=2;
            }else{
             sum++;   
            }
        }
    }
    return sum;
}






ll di[]={1,0,-1,0};
ll dj[]={0,-1,0,1};

struct UnionFind {
    vector<int>d;
    UnionFind(int n=0):d(n,-1){}
    int find(int x){
        if((d[x])<0)return x;
        return d[x]=find(d[x]);
    }
    bool unite(int x,int y){
        x =find(x);y=find(y);
        if(x==y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x]+=d[y];
        d[y]=x;
        return true;
    }
    bool same(int x,int y){return find(x)==find(y);};
    int size(int x){return -d[find(x)];};
};

int deg[100005];
vector<int> to[100005];





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint f(int n) {
    if(n==0)return 1;
    mint x=f(2/n);
    x*=x;
    if(n%2==1)x*=2;
    return x;
}

mint choose(int n,int a){
    mint x =1,y=1;
    rep(i,a){
      x*=n-i;
      y*=a+i;
    }
    return x/y;
}
const ll m=1000005;

int main()
{
 int n;
 cin>>n;
 vector<int>a(n);
 rep(i,n)cin>>a[i];
 vector<int>cnt(m);
 for (int x: a){
     if(cnt[x]!=0){
         cnt[x]=2;
         continue;
     }
     else{
         for(ll i=x;i<=m;i+=x){
             cnt[i]++;
         }
     }
 }
 ll ans=0;
 for(ll x:a){
     if(cnt[x]==1)ans++;
 }
 cout<<ans<<endl;
}
 




Measured memory_bytes: 10312
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let x: usize = itr.next().unwrap().parse().unwrap();
    let y: usize = itr.next().unwrap().parse().unwrap();

    if n >= k {
        println!("{}", (n - k) * y + k * x);
    } else {
        println!("{}", n * x);
    }
}


Measured memory_bytes: 2076
///age yekam bekeshi beham is no problem ._.
#include<bits/stdc++.h>
#define size(a) (int)a.size()
#define int long long
#define F first
#define S second
#define pb push_back
using namespace std;
const int maxn=1e5+7,INF=3e18+9237,mod=1e9+7;

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int q,h,s,d,n;cin>>q>>h>>s>>d>>n;
	cout<<((n/2)*min(min(8*q,4*h),min(2*s,d)))+((n%2)*min(min(2*h,4*q),s));
}

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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
flags = [False for _ in range(N)]
WAs = [0 for _ in range(N)]
pen = 0
for i in range(M):
    p, S = input().split()
    p = int(p)-1
    if S == 'AC' and not flags[p]:
        flags[p]=True
        pen += WAs[p]
    if not flags[p]:
        WAs[p] += 1
acc = flags.count(True)
print(acc, pen)

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

#define FOR(i, a, b) for(int i=a; i<b; i++)
typedef long long ll;
typedef vector<int> vi;

vector<vector<pair<ll, bool>>> dp[2];
int *a;

ll find2(int, int);

ll find1(int l, int r){
    if(l==r){
        return a[l];
    }
    if(dp[0][r][l].second){
        return dp[0][r][l].first;
    }
    ll x1=a[l]+find2(l+1, r);
    ll x2=a[r]+find2(l, r-1);
    dp[0][r][l]={max(x1, x2), 1};
    return dp[0][r][l].first;
}

ll find2(int l, int r){
    if(l==r){
        return -1*a[l];
    }
    if(dp[1][r][l].second){
        return dp[1][r][l].first;
    }
    ll x1=find1(l+1, r)-a[l];
    ll x2=find1(l, r-1)-a[r];
    dp[1][r][l]={min(x1, x2), 1};
    return dp[1][r][l].first;
}

int main(){
    ios_base::sync_with_stdio(false);
    int n;
    cin>>n;
    a=new int[n];
    dp[0].resize(n);
    dp[1].resize(n);
    FOR(i, 0, n){
        cin>>a[i];
        dp[0][i].resize(i+1, {0, 0});
        dp[1][i].resize(i+1, {0, 0});
    }
    cout<<find1(0, n-1)<<endl;
    return 0;
}

Measured memory_bytes: 143360
open System
open System.Collections.Generic

let ReadOne T = stdin.ReadLine()|> T
let ReadSplit T = stdin.ReadLine().Split()|>Array.map T
[<EntryPoint>]
let main argv =
    [for i in [0..3] do yield stdin.ReadLine()|>int]
    |>fun c -> (min c.[0] c.[1])+(min c.[2] c.[3])
    |>stdout.WriteLine
    0


Measured memory_bytes: 11348
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
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 COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}



int N;
string S;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while (cin >> N >> S) {
        int res = 0;
        for (int i = 0; i + 2 < N; ++i) {
            if (S.substr(i, 3) == "ABC") ++res;
        }
        cout << res << endl;
    }
}


















Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
#define LLINF 2000000000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

int dis(int a,int b = 0){
  if(a<b)return b-a;
  return a-b;
}

signed main(){
  int n,a,b;
  cin >> n >> a >> b;
  if((a-b)%2 == 0){
    cout << dis(a,b)/2 << endl;
  }
  else{
    cout << min((a+b-1)/2, min((2*n-a-b+1)/2, min(max(a,b)-1 , max(n-a,n-b)))) << endl;
  }
}


Measured memory_bytes: 256
# AGC039B - Graph Partition
def is_bipartite() -> bool:
    stack = [(1, 1)]
    color = [-1] * (N + 1)
    color[1] = 1
    while stack:
        v, cur_color = stack.pop()
        next_color = cur_color ^ 1
        for u in E[v]:
            if color[u] == cur_color:
                return False
            if color[u] == -1:
                color[u] = next_color
                stack.append((u, next_color))
    return True


def bfs(start) -> int:
    que = [start]
    dist = [-1] * (N + 1)  # dist[i] := distance from V_start to V_i
    dist[start] = 0
    while que:
        v = que.pop(0)
        cur = dist[v]
        for u in E[v]:
            if dist[u] == -1:
                dist[u] = cur + 1
                que.append(u)
    return max(dist)


def main():
    # if bipartite graph -> diameter of the graph + 1
    global N, E
    N, *S = open(0).read().split()
    N = int(N)
    E = [0] + [[i for i, flg in enumerate(s, 1) if flg == "1"] for s in S]
    if is_bipartite():
        ans = max(bfs(i) for i in range(1, N + 1)) + 1
        print(ans)
    else:
        print(-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
using System;
using System.Linq;
class Program{
  public static void Main(string[] args){
    long[] input = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
    long unit = input[1] + input[2];
    long rep = input[0] / unit;
    long count = unit * rep;
    long countB = input[1] * rep;
    if(count < input[0]){
      countB += Math.Min(input[0] - count, input[1]);
    }
    Console.WriteLine(countB);
  }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
	scanf("%d%d",&a,&b);
	if(a==0&&b>0){
		printf("%d",b);
	}else if(a==0&&b<0){
		printf("%d",-b+1);
	}else if(a>0&&b==0){
		printf("%d",a+1);
	}else if(a<0&&b==0){
		printf("%d",-a);
	}else if((a>0&&b<0)||(a<0&&b>0)){
		printf("%d",abs(abs(a)-abs(b))+1);
	}else if(a<b){
		printf("%d",abs(abs(a)-abs(b)));
	}else if(a>b){
		printf("%d",abs(abs(a)-abs(b))+2);
	}
}

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

int n;
int x[24],y[24],r[24],c[24];
bool memo[1<<24];

bool ok(int a,int bit){
    for(int i=0;i<a;i++){
        if(((bit>>i)&1)==0)continue;
        int dist=(x[i]-x[a])*(x[i]-x[a])+(y[i]-y[a])*(y[i]-y[a]);
        int sum=(r[i]+r[a])*(r[i]+r[a]);
        if(dist<sum)return false;
    }
    return true;
}

int dfs(int bit){
    memo[bit]=true;

    int ret=n;
    for(int i=0;i<n;i++)if((bit>>i)&1)ret--;

    for(int i=0;i<n;i++){
        if(((bit>>i)&1)==0||ok(i,bit)==false)continue;
        for(int j=i+1;j<n;j++){

            if(((bit>>j)&1)==0)continue;
            int to_bit=(bit^(1<<i))^(1<<j);
            if(c[i]==c[j]&&ok(j,bit)&&!memo[to_bit]){
                ret=max(ret,dfs(to_bit));
            }
        }
    }


    return ret;
}

void solve(){
    fill_n(memo,1<<n,false);

    cout<<dfs((1<<n)-1)<<endl;
}

bool input(){
    cin>>n;
    if(!n)return false;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>r[i]>>c[i];
    return true;
}



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

Measured memory_bytes: 17544
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n;
ll x;

ll gcd(ll a, ll b){
    if(!b) return a;
    return gcd(b, a % b);
}

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

ll solve(){
    cin >> n >> x;
    ll ans = x;
    for(int i = 1; i < n; ++i){
        cin >> x;
        ans = lcm(ans, x);
    }
    return ans;
}

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

    cout << solve() << "\n";
    
    return 0;
}


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

typedef long long LL;

const int OO = 1e9;
const int MOD = 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	double sum = 0.;
	for (int i = 0; i < n; ++i) {
		double a;
		cin >> a;
		sum += 1 / a;
	}
	cout.precision(6);
	cout << fixed;
	cout << 1 / sum << '\n';
}

int32_t main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// #endif

	// clock_t begin = clock();

	solve();

	// clock_t end = clock();
	// cerr << "\nELAPSED TIME: " << (double) (end - begin) / CLOCKS_PER_SEC;

	return 0;
}


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

int main(){
	string str,stri;
  int flag=1;
  cin >> str;
  int Q;
  cin >> Q;
  int i,j,k;
  for(i=0;i<Q;i++){
  	cin >> j ;
//    cout << str <<endl;
    if(j==1){
    	if(flag==1){
        	flag=2;
        }else{
        	flag=1;
        }
    }else{
   	cin >> k >> stri;
      	if((flag+k)%2==1){
        	str += stri;
        }else{
        	str.insert(0,stri);
        }
    }
  }
  if(flag==2){
  	reverse(str.begin(), str.end());
  }

  cout << str << endl;
	return 0;
}

Measured memory_bytes: 900