akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int main()
{
    long long int n, x;
    cin >> n >> x;
    long long int a[100001], b[100001];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    long long int ans1 = 0, ans2 = 0;
    for(int i = 1; i < n; i++){
        if(a[i - 1] + a[i] > x){
            long long int tmp = a[i - 1] + a[i] - x;
            ans1 += tmp;
            if(a[i] < tmp){
                a[i - 1] -= tmp - a[i];
                a[i] = 0;
            } else {
                a[i] -= tmp;
            }
        }
    }
    for(int i = n - 1; i > 0; i--){
        if(b[i] + b[i - 1] > x){
            long long int tmp = b[i - 1] + b[i] - x;
            ans2 += tmp;
            if(b[i - 1] < tmp){
                b[i] -= tmp - b[i - 1];
                b[i - 1] = 0;
            } else {
                b[i - 1] -= tmp;
            }
        }
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int a, b, c, sum, future_sum, add;
  	cin >> a >> b >> c;
  	sum = a + b + c;
  	future_sum = max({a, b, c}) * 3;
  	add = future_sum - sum;
  	if (add % 2 == 0){
    	cout << add / 2;
    } else {
    	cout << (add + 3) / 2;
    }
}

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

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

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <cstdlib>
#include <stdlib.h>
#include <math.h>
int cmp1(const void*a,const void *b){
    return (*(int*)a-*(int*)b);
}
int n,h,i,w_max,t_damage,c_index,count;
int a[100001],b[100001],c[100001];
int main(){
    scanf("%d %d",&n,&h);
    for (i=1;i<=n;i++){
        scanf("%d %d",&a[i],&b[i]);
        if (w_max<a[i]){
            w_max=a[i];
        }
    }
    for (i=1;i<=n;i++){
        if (b[i]>w_max){
            c[++c_index]=b[i];
        }
    }
    qsort(&c[1],c_index,sizeof(int),&cmp1);
    for (i=c_index;i>0;i--){
        count++;
        h-=c[i];
        if (h<1){
            printf("%d\n",count);
            return 0;
        }
    }
    count+=h / w_max;
    if (h % w_max > 0){
        count++;
    }
    printf("%d\n",count);
    return 0;
}



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

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

  int val = 0;
  rep(i,n){
    if(s[i] != s[i+1]) val++;
  }
  cout<<val<<endl;
  return 0;
}

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

const int ADD = 1e4, N = ADD << 1;

int x, y, cnt;
string s;
vector<int> X, Y;
bitset<N> b;

bool can(vector<int> vec, int want, bool B = false) {
	b.reset();
	b[ADD] = true;
	for (int i = 0; i < vec.size(); i++) {
		if(i == 0) {
			if(B)
				b <<= vec[i];
			else
				b = (b << vec[i]) | (b >> vec[i]);
		}
		else
			b = (b << vec[i]) | (b >> vec[i]);
	}
	return b[ADD + want];
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> s >> x >> y;
	s.push_back('T');
	for (char c: s)
		if(c == 'F')
			cnt++;
		else {
			if(X.size() <= Y.size())
				X.push_back(cnt);
			else
				Y.push_back(cnt);
			cnt = 0;
		}
	
	cout << (can(X, x, true) && can(Y, y)? "Yes": "No");
	return 0;
}

Measured memory_bytes: 384
/* 
      Life before Death
      Strength before Weakness
      Journey before Destination
*/
                           
#include <bits/stdc++.h>
using namespace std;
                 
typedef long long ll;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define per(i,n,a) for (ll i=n;i>a;i--)
#define te ll t; std::cin >> t; while(t--)
#define SZ 500010
//# define M_PIl  3.141592653589793238462643383279502884L 
/*------Just DO IT--------------------------------------*/

ll solve(){
   ll n,s=0;
   cin>>n;
  ll a[n];
  rep(i,0,n) cin>>a[i] ,s+=a[i];
  ll ma = *max_element(a,a+n);
  s= s - ma + ma/2;
  cout<<s<<endl;
  }

int main() {
  fastio;
   solve();
}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 15
B = [[INF for _ in range(N)] for _ in range(N)]

for k in range(N):
  for i in range(N):
    for j in range(N):
      B[i][j] = min(B[i][j], A[i][k] + A[k][j])
#print("B:", B)

for i in range(N):
  if A[i] != B[i]:
    print(-1)
    exit()
    
C = [[1 for _ in range(N)] for _ in range(N)]
for i in range(N):
  for j in range(i + 1, N):
    for k in range(N):
      if i != k and j != k:
        if A[i][k] + A[k][j] == A[i][j]:
          C[i][j] = 0
#print("C:", C)   

answer = 0
for i in range(N):
  for j in range(i + 1, N):
    answer += C[i][j] * A[i][j]
print(answer)

Measured memory_bytes: 46684
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

string maxs(string s, string t) {
  if(s.size() > t.size()) return s;
  if(s.size() < t.size()) return t;
  if(t > s) return t;
  return s;
}

int main() {
  int n, m;
  cin >> n >> m;
  vi a(m);
  rep(i, m) cin >> a[i];
  vi b = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  vs dp(n + 1, "");
  rep(j, n) rep(i, m) {
    if(j != 0 && dp[j] == "") continue;
    int nj = j + b[a[i]];
    if(nj <= n) dp[nj] = maxs(dp[nj], dp[j] + (char)('0' + a[i]));
  }
  cout << dp[n] << endl;
}

Measured memory_bytes: 43648
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
#define db long double
#define all(a) a.begin(),a.end()
#define pb push_back
#define f(i,l,u) for(ll i=l;i<u;i++)
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll,ll> 
ll fac[1000001];
void powe(ll p)
{
     fac[0] = 1; 

     
    for (ll i = 1; i <= 1000000; i++) 
        fac[i] = (fac[i - 1] *i) % p; 
  
}
 
 
        
      long long power( long long x, 
                         ll y, ll p) 
{ 
   long long res = 1; // Initialize result 
  
    x = x % p; 
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
 long long modInverse( long long n, ll p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
 long long nCrModPFermat( long long n, 
                                 ll r, ll p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
       return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
 ll gcd(ll a,ll b)
 {
     if(b==0)
     return a;
     return gcd(b,a%b);
 }
  
int main() {
   ll t=1;

   //cin>>t;
  
   while(t--)
   {
  ll ct=0;
  ll n;
  cin>>n;
  ll a[n];
  f(i,0,n)
  cin>>a[i];
  f(i,0,n-2)
  {
      f(j,i+1,n-1)
      {
          f(k,j+1,n)
          {
              if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
              {
                  ll val=max(a[i],a[j]);
                  val=max(val,a[k]);
                  if(a[i]+a[j]+a[k]-val>val)
                  ct++;
              }
              
          }
      }
  }
   
    
    cout<<ct<<endl;
   }
  
   

      

return 0;    
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#define INF 1000000009
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	vector<int> cnt(n);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		cnt[a[i] - 1]++; cnt[b[i] - 1]++;
	}
	for (int i = 0; i < n; i++) {
		if (cnt[i] & 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main()
{
  int a[3], b[3], c[3];
  int n, i, k, j;
  int ans;
  
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  scanf("%d %d %d", &b[0], &b[1], &b[2]);
  scanf("%d %d %d", &c[0], &c[1], &c[2]);
  scanf("%d", &n);
  
  i = 0;
  while(i < n)
  {
    scanf("%d", &k);
    j = 0;
    while(j < 3)
    {
      if(a[j] == k)
        a[j] = 1;
      if(b[j] == k)
        b[j] = 1;
      if(c[j] == k)
        c[j] = 1;
      j++;
    }
    i++;
  }
  
  if((a[0] == 1 && a[1] == 1 && a[2] == 1) || (b[0] == 1 && b[1] == 1 && b[2] == 1) ||
     (c[0] == 1 && c[1] == 1 && c[2] == 1) || (a[0] == 1 && b[1] == 1 && c[2] == 1) ||
     (c[0] == 1 && b[1] == 1 && a[2] == 1) || (a[0] == 1 && b[0] == 1 && c[0] == 1) ||
     (a[1] == 1 && b[1] == 1 && c[1] == 1) || (a[2] == 1 && b[2] == 1 && c[2] == 1))
    printf("Yes");
  else
    printf("No");
  return(0);
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    A = list(map(int,input().split()))

    s = N*(N + 1)//2
    tot = sum(A)
    if tot%s == 0:
        cnt = tot//s
    else:
        print('NO')
        return
    
    A.append(A[0])
    x = 0
    for i in range(N):
        diff = A[i + 1] - A[i]
        if cnt - diff < 0:
            print('NO')
            return
        if (cnt - diff)%N == 0:
            x += (cnt - diff)//N
        else:
            print('NO')
            return
    print('YES' if x == cnt else 'NO')
if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vector<int>> mi;
typedef vector<vector<pair<int, int>>> w_graph;
typedef vector<vector<int>> uw_graph;

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	#ifdef DEBUG
		freopen("out.txt", "w", stdout);
	#endif

	ll dp[(int)1e5 + 5];
	int h[(int)1e5 + 5];
	for (int i = 0; i < 1e5 + 5; i++) dp[i] = 1e20;
	
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		cin >> h[i];
	}
	h[0] = 1e7;
	dp[1] = 0;
	for (int i = 1; i <= n; i++){
		for (int j = 1; i + j <= n && j <= k; j++){
			dp[i + j] = min(dp[i + j], abs(h[i] - h[i + j]) + dp[i]);
		}
	}

	cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 1408
import itertools
n,m,q=(int(i) for i in input().split())
l=[]
r=[i+1 for i in range(m)]
point=0
def checker(x,l):
  p=0
  for i in range(len(l)):
    if x[l[i][1]]-x[l[i][0]]==l[i][2]:
      p+=l[i][3]
  return p
for i in range(q):
  a,b,c,d=(int(i) for i in input().split())
  a-=1
  b-=1
  l.append([a,b,c,d])
for i in itertools.combinations_with_replacement(r,n):
  p=checker(i,l)
  if p>point:
    point=p
print(point)

Measured memory_bytes: 9240
N, M = gets.split(" ").take(2).map(&:to_i)
Graph = M.times.map{ gets.split(" ").take(2).map(&:to_i).map(&:pred) }
Pathes = Graph.inject(N.times.map{[]}){|r, (a, b)|
  r.tap{ r[a] << b;  r[b] << a }
}

def f(pathes)
  total = 0
  visited = [true]+[false]*(pathes.size-1)

  g = lambda{|curr|
    if visited.all?
      total += 1
      return
    end
    pathes[curr].each{|to|
      next if visited[to]
      visited[to] = true
      g.(to)
      visited[to] = false
    }
  }

  g.(0)
  total
end

puts f(Pathes)

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n , k;
int h[ N ];
int dp[ N ];

int solve( int idx ) {
        if( idx == n ) return 0;
        if( idx > n ) return inf;
        if( dp[idx] != -1 ) return dp[idx];
        int ret = inf;
        for( int i = 1; i <= k; i++ ) {
               ret = min( ret , solve( idx + i ) + abs( h[idx+i] - h[idx] ) );
        }
        return dp[idx] = ret;
}
int main( ) {
        IO;
        #ifdef LOCAL
            freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        cin >> n >> k;
        for( int i = 1; i <= n; i++ ) cin >> h[i];
        memset( dp , -1 , sizeof( dp ) );
        cout << solve( 1 ) << endl;
        return 0;
}






Measured memory_bytes: 5760
#include <stdio.h>
  
int main()
{
    int a, x;
    a = 1;
  
        while(1)
        {
            scanf("%d", &x);
            if(x == 0) break;
 
            printf("Case %d: %d\n", a, x);
            a = a + 1;
        }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
input:
    string s, t;
    cin >> s >> t;
    ll a, b;
    cin >> a >> b;
    string u;
    cin >> u;

    if (s == u) {
        a--;
    } else {
        b--;
    }

    cout << a << " " << b << endl;

calculate:
    return 0;
}



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

using namespace std;
int main()
{
    std::vector<int> v;
    std::vector<int> w;
    int a,b,k;
    cin>>a>>b>>k;
    for(int i = 1;i <= a ; ++i){
        if(a % i == 0) v.push_back(i);
    }
    for(int i = 0; i < v.size(); ++i){
        if(b % v[i] == 0) w.push_back(v[i]);
    }    
    sort(w.begin(),w.end(),greater<int>());
    cout<<w[k-1]<<endl;
    return 0;
}

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

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;

    while(a>0 && c>0)
    {
        c = c-b;
         a = a-d;
    }
    if(c<=0)
    {
        cout<<"Yes"<<endl;
    }
    else
    cout<<"No"<<endl;

    return 0;

}


Measured memory_bytes: 3612
#include <algorithm>
#include <cmath>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

using namespace std;

vector<int> calc(int n, const vector<int> &b){
  vector<int> ret(n);
  REP(i,n) ret[i] = i;
  REP(i,b.size()) swap(ret[b[i]], ret[b[i] + 1]);
  return ret;
}

int compress(const vector<int> &b){
  const int n = b.size();
  int ret = 1;
  int prev = 0;

  for(int i = 1; i < n; i++){
    for(int j = prev; j < i; j++){
      if(std::abs(b[i] - b[j]) <= 1){
        ret++; prev = i;
        break;
      }
    }
  }

  return ret;
}

int main(){
  const int n = getInt();
  const int m = getInt();

  vector<int> pos(m);
  REP(i,m) pos[i] = getInt() - 1;

  const vector<int> exp = calc(n, pos);

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

  int ans = m;
  do{
    if(calc(n, pos) == exp)
      ans = min(ans, compress(pos));
  }while(next_permutation(pos.begin(), pos.end()));

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 1064
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  int tmp = 0;
  int ind = 0;
  REP(i, N){
    cin >> tmp ;
    if(tmp == 1){
      ind = i;
      break;
    }
  }
  int l = ind;
  int r = N - ind - 1;
  int ans = 0;
  ans = l/(K - 1) + r/(K - 1) + (l%(K - 1) > 0 )*1 + (r%(K - 1) > 0 )*1;
  // if(l%(K -1) != 0){
  //   ans ++;
  // }
  // if(r%(K -1) != 0){
  //   ans ++;
  // }
  if(l%(K - 1) != 0 &&r%(K - 1) != 0 && l%(K - 1) + r%(K - 1) <= (K - 1)){
    ans --;
  }
  cout << min(ans, N/(K - 1) + (N%(K - 1) > 0)) << endl;
  // cout << (l%(K - 1) > 0 )<< endl;
  // cout << (l%(K - 1) > 0 )*1<< endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0; i<N; i++)
    cin >> A[i];
  cout << int(ceil(1.0 * (N-1) / (K-1))) << endl;
  return 0;
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

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

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    set<char> st;
    inc(i, 0, n){
        char c;cin >> c;
        st.insert(c);
    }
    if(st.size() == 3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N, M; cin >> N >> M;
	set<int>st;
	int pen = 0;
	int ac = 0;
	map<int, int>wa;
	loop(M) {
		int p; cin >> p;
		string s; cin >> s;
		if (st.count(p))continue;
		if (s == "WA") {
			wa[p]++;
		}
		else {
			st.insert(p);
			pen += wa[p];
		}
	}

	cout << st.size() << " " << pen << endl;
	return 0;
}


Measured memory_bytes: 11264
//libs

#include <bits/stdc++.h>

//other stuff

using namespace std;

//function call

//main

int main(){
	long long koft, goh, sik, an, n, minn1, minn2;
	cin >> koft >> goh >> sik >> an >> n;
	minn1 = min(4 * koft, min(2 * goh, sik));
	minn2 = min(minn1 * 2, an);
	cout << (n / 2) * minn2 + (n % 2) * minn1 << endl;
return 0;
}

//functions



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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;

    int k = sqrt(2*n + 0.01) + 1;
    if(k * (k-1) == 2*n){
        cout << "Yes" << endl;
        cout << k << endl;
        vector<vector<int>> S(k, vector<int>());
        int N = 1;
        for(int i=0; i<k; i++){
            for(int j=i+1; j<k; j++){
                S[i].push_back(N);
                S[j].push_back(N);
                N++;
            }
        }
        for(int i=0; i<k; i++){
            cout << k-1;
            for(int j=0; j<k-1; j++){
                cout << " " << S[i][j];
            }
            cout << endl;
        }

    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(void){
    string S;
    cin >> S;
    
    if(S=="RRR"){
        cout << 3 << endl;
    }
    else if(S=="RRS" or S=="SRR"){
        cout << 2 << endl;
    }
    else if(S=="SSS"){
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }
}


Measured memory_bytes: 3636
#include<iostream>

#include<cstdlib>
using namespace std;
int main(void){
  string a,b,ans;
  int num;

  cin >> a >> b;
  if(a <= b){
	num = atoi(b.c_str());
	ans = a;
  }
  else{
	num = atoi(a.c_str());
	ans = b;
  }
  for(int x=0; x<num; x++)
	cout << ans;
  cout << endl;
}


Measured memory_bytes: 256
# 計算量を絞らずに実験
A=int(input())
B=int(input())
C=int(input())
X=int(input())

A_i=min(X//500,A)+1
B_i=min(X//100,B)+1
C_i=min(X//50,C)+1

ans=0

for i in range(0,A+1):
    for j in range(0,B+1):
        for k in range(0,C+1):
            if i*500+j*100+k*50==X:ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int h, w, k;
    cin >> h >> w >> k;

    vector<string> field(h);
    rep (i, h) cin >> field[i];

    int ans = 0;
    rep (ii, 1 << h)
    {
        rep (jj, 1 << w)
        {
            int cnt = 0;
            rep (i, h)
            {
                rep (j, w)
                {
                    if (field[i][j] == '#')
                    {
                        if (!(((ii >> i) & 1) | ((jj >> j) & 1)))
                        {
                            ++cnt;
                        }
                    }
                }
            }
            if (cnt == k) ++ans;
        }
    }

    cout << ans << "\n";
    return 0;
}



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

using namespace std;

typedef long long LL;
typedef double LF;

#define clr(x, y) memset(x, y, sizeof(x))

const int MAXN = 5e3 + 15;

set <string> s;
string ch, tmp; int k;

void work(){
	cin >> ch >> k;
	for(int i = 0; i < ch.size(); i ++){
		tmp.clear();
		for(int j = i; j < i + k && j < ch.size(); j ++){
			tmp += ch[j];
			s.insert(tmp);
		}
	}
	set <string> ::iterator it;
	for(it = s.begin(); ; it ++){
		k --; if(!k){cout << *it <<endl; return ;}
	}
}

int main(){
	work();
	return 0;
}

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


// Code from Geeksforgeeks https://www.geeksforgeeks.org/queries-number-distinct-elements-subarray/
const int MAX = 1000001; 
  
// structure to store queries 
struct Query 
{ 
    int l, r, idx; 
}; 
  
// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
  
// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
  
// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
  
void answeringQueries(vector<int> arr, int n, vector<Query> queries, int q) 
{ 
    // initialising bit array 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
  
    // holds the rightmost index of any number 
    // as numbers of a[i] are less than or equal to 10^6 
    int last_visit[MAX]; 
    memset(last_visit, -1, sizeof(last_visit)); 
  
    // answer for each query 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        // If last visit is not -1 update -1 at the 
        // idx equal to last_visit[arr[i]] 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
  
        // Setting last_visit[arr[i]] as i and updating 
        // the bit array accordingly 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
  
        // If i is equal to r of any query  store answer 
        // for that query in ans[] 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = 
                     query(queries[query_counter].r + 1, bit, n)- 
                     query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
  
    // print answer for each query 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
}
void solve()
{
  int n,q;
  cin >> n >> q;
  vector<int>arr(n);
  vector<Query>queries(q);
  for (int c=0;c<n;c++)
    cin >> arr[c];
  for (int c=0;c<q;c++)
    cin >> queries[c].l >> queries[c].r,queries[c].idx=c,queries[c].l--,queries[c].r--;
    sort(queries.begin(),queries.end(),cmp);
    answeringQueries(arr,n,queries,q);
}
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);     
    int t;
    //cin >> t;
    t=1;
    for (int tt=0;tt<t;tt++)
        {
            solve();
        }    
        return 0;
}

Measured memory_bytes: 27140
"use strict"
 
function Main(input) {
  input = input.trim().split(' ').map(Number);
  const A = input[0];
  const B = input[1];
 
  let ret = 0;
  let tmp = 0;
  while(true){
    if(tmp >= B || B === 0 || B === 1) break;
    if(ret === 0) {
      tmp += A;
    } else {
      tmp += A-1;
    }
    ret++
  }
  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8584
def gcd(x,y)
  return gcd(y,x) if y > x
  y == 0 ? x : gcd(y,x%y)
end

N,X = gets.split.map(&:to_i)
Xs = gets.split.map{ |x| (x.to_i - X).abs }
p Xs[1..-1].reduce(Xs[0]){ |a,b| gcd(a,b) }

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        Person[] arr = new Person[N];
        for (int i = 0; i < N; ++i) {
            int A = in.nextInt();
            arr[i] = new Person();
            for (int j = 0; j < A; ++j) {
                arr[i].add(in.nextInt(), in.nextInt());
            }
        }

        int ans = 0;
        for (int i = 1; i < (1<<N); ++i) {
            if (check(arr, i)) {
                ans = Math.max(ans, count(i));
            }
        }

        System.out.println(ans);
    }

    private static boolean check(Person[] arr, int m) {
        int n = arr.length;
        for (int i = 0; i < n; ++i) if (((1<<i) & m) > 0) {
            for (Pair p: arr[i].li) {
                int x = p.f;
                int y = p.s;

                int value = ((1 << (x - 1)) & m) != 0 ? 1 : 0;
                if (value != y) return false;
            }
        }

        return true;
    }

    private static int count(int n) {
        int count = 0;
        while(n > 0) {
            count += n % 2;
            n >>= 1;
        }
        return count;
    }
}

class Person {
    public List<Pair> li;
    public Person() {
        li = new ArrayList<>();
    }

    public void add(int f, int s) {
        li.add(new Pair(f, s));
    }
}

class Pair {
    int f, s;
    public Pair(int f, int s) {
        this.f = f;
        this.s = s;
    }
}


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

int dp[512][512][10][3][2];
char look[512];
int mod;
int len;

int min(int a, int b)
{
    return (b > a ? a : b);
}

int memo(int digits, int div, int now, int upd, int same)
{
    int i, j;
    int ans;
    
    if (digits == (int)strlen(look)){
        return (!div);
    }
    
    if (dp[digits][div][now][upd][same] >= 0){
        return (dp[digits][div][now][upd][same]);
    }
    
    ans = 0;
    if (upd == 2){
        if (digits != (int)strlen(look) - 1){      // if all digits of number equals to zero, that isn't a zig-zag number
            ans += memo(digits + 1, div * 10 % mod, now, 2, same && (look[digits] - '0') == 0);
            ans %= 10000;
        }
        for (i = now + 1; i <= (same ? look[digits] - '0' : 9); i++){
            ans += memo(digits + 1, (div * 10 + i) % mod, i, 1, same && (look[digits] - '0') == i);
            if (digits != (int)strlen(look) - 1){ // 1-digit number will be same at two status, up and down
                ans += memo(digits + 1, (div * 10 + i) % mod, i, 0, same && (look[digits] - '0') == i);
            }
            ans %= 10000;
        }
    }
    else if (upd == 0){ //increase
        for (i = now + 1; i <= (same ? look[digits] - '0' : 9); i++){
            ans += memo(digits + 1, (div * 10 + i) % mod, i, upd ^ 1, same && (look[digits] - '0') == i);
            ans %= 10000;
        }
    }
    else {              //decrease
        for (i = min(now - 1, same ? look[digits] - '0' : now - 1); i >= 0; i--){
            ans += memo(digits + 1, (div * 10 + i) % mod, i, upd ^ 1, same && (look[digits] - '0') == i);
            ans %= 10000;
        }
    }
    
    return (dp[digits][div][now][upd][same] = ans % 10000);
}

int ZigZag(char *str)
{
    int len = strlen(str);
    int up;
    int i;
    
    if (len == 1){
        return (1);
    }
    if (len == 2){
        return (str[0] != str[1]);
    }
    up = str[0] < str[1];
    for (i = 1; i < len; i++){
        if (up && str[i] > str[i - 1]){
            up ^= 1;
        }
        else if (!up && str[i] < str[i - 1]){
            up ^= 1;
        }
        else {
            return (0);
        }
    }
    return (1);
}

int main(void)
{
    int first, next;
    char start[512], end[512];
    
    scanf("%s", start);
    scanf("%s", end);
    scanf("%d", &mod);
    
    memset(dp, -1, sizeof(dp));
    
    sprintf(look, "0%s", start);
    len = strlen(look);
    first = memo(0, 0, 0, 2, 1);
    
    memset(dp, -1, sizeof(dp));
    
    sprintf(look, "0%s", end);
    len = strlen(look);
    next = memo(0, 0, 0, 2, 1);
    
    printf("%d\n", (next - first + ZigZag(start) + 10000) % 10000);
    
    return (0);
}

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

int main(){
  int n,sum=1;
  cin>>n;
  vector<int> mochid(n);
  for(int i=0;i<n;i++){
    cin>>mochid.at(i);
  }
 sort(mochid.begin(),mochid.end());
 
  for(int i=1;i<n;i++){
		if(mochid.at(i)!=mochid.at(i-1)){
          sum++;
        }else{

  
        }
        }
  cout<<sum<<endl;
}

Measured memory_bytes: 3636
N=int(input())

H=list(map(int,input().split()))
A=[0 for i in range(N)]
if N==1:
  print(0)
else:
  if H[0]>=H[1]:
  	A[0]+=1
  if N>=3:
    for i in range(1,N-1):
      if H[i]>=H[i+1]:
        A[i]+=A[i-1]+1
  print(max(A))

Measured memory_bytes: 14228
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Pavel Mavrin
 */
public class Main {

    private void solve() throws IOException {
        int n = nextInt();
        int k = nextInt();
        String s = next();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = s.charAt(i) == 'B' ? 1 : 0;
        }
        int j = 0;
        while (k > 0) {
            if (j == n) {
                if (n % 2 == 1) {
                    if (k % 2 == 0) {
                        for (int i = 0; i < n; i++) {
                            out.print("AB".charAt(i % 2));
                        }
                    } else {
                        out.print("B");
                        for (int i = 1; i < n; i++) {
                            out.print("AB".charAt(i % 2));
                        }
                    }
                } else {
                    for (int i = 0; i < n; i++) {
                        out.print("BA".charAt(i % 2));
                    }
                }
                return;
            } else {
                if ((a[j] + j) % 2 == 0) {
                    a[j] = 1 - a[j];
                } else {
                    j++;
                }
                k--;
            }
        }
//        System.out.println(j + " " + Arrays.toString(a));
        for (int i = 0; i < n; i++) {
            int q;
            if (j + i >= n) {
                q = (n + i + 1) % 2;
            } else {
                q = (a[j + i] + j) % 2;
            }
            out.print("AB".charAt(q));
        }
        out.println();
    }

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    PrintWriter out = new PrintWriter(System.out);

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

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

    private void run() throws IOException {
        solve();
        out.close();
    }

}


Measured memory_bytes: 27684
a = int(input())
b = [int(i) for i in input().split(" ")]
count = 0
iti = 1
while iti == 1:
    for i in range(a):
        if b[i]%2 == 0:
            b[i]=b[i]//2
            iti = 1
        else :
            print(count)
            iti = 0
            break
    count = count+1

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    map<int, int> mp2;
    rep(i, 0, k)
    {
        int d;
        cin >> d;
        mp2[d]++;
    }
    map<int, int> mp;
    rep(i, 0, 10)
        if (mp2[i] == 0)
            mp[i]++;
    vector<int> dp(10, -1);
    auto curr = mp.begin();
    rep(i, 0, 10)
    {
        if (i <= curr->first)
            dp[i] = curr->first;
        else
        {
            curr++;
            if (curr == mp.end())
                break;
            dp[i] = curr->first;
        }
    }
    string s = to_string(n);
    string res;
    if (dp[s[0] - '0'] == -1)
        res = to_string(dp[1]) + string(s.size(), to_string(dp[0])[0]);
    else if (dp[s[0]-'0'] > s[0]-'0')
        res = to_string(dp[s[0]-'0']) + string(s.size()-1, to_string(dp[0])[0]);
    else 
    {
        res = to_string(dp[s[0]-'0']);
        rep(i, 1, s.size())
        {
            if (dp[s[i] - '0'] != -1)
                res += to_string(dp[s[i] - '0']);
            else 
            {
                if (i == 1)
                    res += string(s.size(), to_string(dp[0])[0]);
                else 
                {
                    res[i-2] = res[i-1];
                    res[i-1] = to_string(dp[0])[0];
                    res += string(s.size()-i+1, to_string(dp[0])[0]);
                }
                break;
            }
        }
    }
    cout << res << endl;
    return 0;
}

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

int main() {
	int n, a, b, c, d;
	string s;
	cin >> n >> a >> b >> c >> d >> s;
	int x = 0, o = 0, X = 0, Y = 0, O = 0;
	if (s[b - 2] == '.'&&s[b] == '.' || c < d || s[d - 2] == '.'&&s[d] == '.')
		O = 3;
	for (int i = b; i <= d; i++) {
		if (s[i - 1] == '#')
			x++, o = 0, X = max(X, x);
		else
			o++, x = 0, O = max(O, o);
	}
	x = 0;
	for (int i = a; i <= c; i++) {
		if (s[i - 1] == '#')
			x++, Y = max(Y, x);
		else x = 0;
	}
	cout << (X < 2 && Y < 2 && O>2 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

ll a = 0, b = 0, c, d, n, k = 0, ans = 0;
string s, t;


int main()
{
	ll n, k; cin >> k >> n;
	ll a[200000];
	rep(i, n)cin >> a[i];

	ll sa = a[0] + k - a[n - 1];
	ll sa1 = 0;
	for (ll i = 1; i < n; i++)
	{
		b = a[i] - a[i - 1];
		sa1 = max(sa1, b);
	}
	cout << k - max(sa, sa1) << endl;


	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define chmin(i, j) i = min(i, j);
#define chmax(i, j) i = max(i, j);
#define rep(i, n) for(int i=0;i<n;i++)
int main() {
  int x, y, z, K;
  cin >> x >> y >> z >> K;
  vector<ll> a(x), b(y), c(z);
  rep(i, x) cin >> a[i];
  rep(i, y) cin >> b[i];
  rep(i, z) cin >> c[i];
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  vector<ll> ans;
  rep(i, x) rep(j, y) rep(k, z) {
    if((i+1) * (j+1) * (k+1) <= K) ans.emplace_back(a[i]+b[j]+c[k]);
    else break;
  }
  sort(ans.rbegin(), ans.rend());
  rep(i, K) cout << ans[i] << endl;
  return 0;
}



Measured memory_bytes: 1404
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int x, y;
  cin >> x >> y;
  for (int i = 0; i <= x; i++) {
    int j = x - i;
    if (i * 4 + j * 2 == y) {
      cout << "Yes" << '\n';
      return;
    }
  }
  cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

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

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

int main(){
    int N; cin >> N;
    string s; cin >> s;
    if(N%2!=0){
        cout << "No" << endl;
        return 0;
    } 
    string s1 = s.substr(0,N/2);
    string s2 = s.substr(N/2, N/2);
    if(s1 == s2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
  ll N;
  cin >> N;
  ll ans = 1e15;
  for (ll i = 1; i * i <= N; i ++) {
    if (N % i == 0) {
      ll kj = i + (N / i) - 2;
      if (ans > kj) ans = kj;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;
int h,w,n;
int a[10010];
int g[100][100];

int main()
{

    cin >> h >> w;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ci = 0;
    for(int i = 0; i < h; i++)
    {
        if(i%2)
        {
            for(int j = 0; j < w; j++)
            {
                if(!a[ci])
                    ci++;
                g[i][j] = ci;
                a[ci]--;
            }
        }
        else
        {
            for(int j = w-1; j >= 0; j--)
            {
                if(!a[ci])
                    ci++;
                g[i][j] = ci;
                a[ci]--;
            }
        }
    }
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cout << g[i][j]+1 << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
n,k=map(int,input().split())
s=list(range(0,n+1))
cs=[]
mod=10**9+7
sum=0
for i in range(n+1):
	sum+=s[i]
	cs.append(sum)
cnt=0
for i in range(k,n+1):
	mini=cs[i-1]
	maxi=cs[n]-cs[n-i]
	cnt+=(maxi-mini+1)%mod
	cnt%=mod
print((cnt+1)%mod)

Measured memory_bytes: 27332
using System;
using System.Collections.Generic;
using System.Linq;


namespace _004_Simultaneous_Equation
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int[] tmp = inputStr.Split (' ').Select (str => int.Parse (str)).ToArray ();
				int a = tmp[0];
				int b = tmp[1];
				int c = tmp[2];
				int d = tmp[3];
				int e = tmp[4];
				int f = tmp[5];

				double X = (double) (c * e - b * f) / (a * e - b * d);
				double Y = (double) (f * a - c * d) / (a * e - d * b);
				Console.WriteLine ("{0:0.000} {1:0.000}", X, Y);
			}
		}
	}
}

Measured memory_bytes: 9708
#include<bits/stdc++.h>
using namespace std;
#define inf 1e18
#define int long long
signed main()
{
	int n;
	int ans=inf;
	scanf("%lld",&n);
	for(int i=1;i<=sqrt(n);i++)
		if(n%i==0)
			ans=min(ans,n/i+i);
	printf("%lld",ans-2);
	return 0;
}

Measured memory_bytes: 256
//
//
//  ad-algoD.cpp - created by us162022
//
#include <iostream>
using namespace std;
int find(int join[],int x){
  if(x==join[x])
    return x;

  return find(join,join[x]);
}
int main(int argc, char *argv[])
{
  int n,m,join[100000],num[100000],s,t;
  cin >> n >> m;

  for(int i=0; i<n; i++){
    join[i] = i;
    num[i] = 0;
  }

  for(int i=0; i<m; i++){
    cin >> s >> t;
    s = find(join,s);
    t = find(join,t);

    if(s!=t){
      if(num[s] < num[t])
	join[s] = join[t];
      
      else{
	join[t]=join[s];
	if(num[s]==num[t])
	  num[s]++;
      }

    }
  }

  int q;
  cin >> q;

  for(int i=0; i<q; i++){
    cin >> s >> t;

    if(find(join,s)==find(join,t))
      cout << "yes\n";

    else
      cout << "no\n";
  }
}

Measured memory_bytes: 3868
#include <stdio.h>

int main() {
  int num[30];
  int i = 0;
  int n = 0;
  for(i = 0; i < 30; ++i) {
    num[i] = 0;
  }
  for(i = 0; i < 28; ++i) {
    scanf("%d", &n);
    num[n - 1] = 1;
  }
  for(i = 0; i < 30; ++i) {
    if(num[i] == 0) printf("%d\n", i + 1);
  }
  return 0;
}

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

public class Main{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            int n = in.nextInt();
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            Arrays.sort(a);

            int x = n / 2;
            int y = n % 2;
            long sum = 0;
            if(y == 0){
                sum = sum + a[x] - a[x - 1];
                for (int i = 0; i < (x - 1); i++) {
                    sum = sum + a[n - 1 - i] * 2 - a[i] * 2;
                }
                System.out.println(sum);
            }else{
                for (int i = 0; i < (x - 1); i++) {
                    sum = sum + a[n - 1 - i] * 2 - a[i] * 2;
                }
                long t = Long.max((a[x + 1] * 2 - a[x] - a[x - 1]), (a[x + 1] + a[x] - a[x - 1] * 2));
                sum += t;
                System.out.println(sum);
            }
        }
    }
}


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

int main() {
	
	int N;
	char S[50];
	int ans = 0;

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

	for (int i = 0; i < N; i++) {
		if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
			ans += 1;
		}
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
    int a,b;cin>>a>>b;
    int x=a+b;
    if(x%2==0)cout<<x/2;
    else cout<<x/2+1;
    
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int H,W; cin >> H >> W;
    REP(i,H){
        string s; cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 3540
#include <iostream>
#define ll long long
using namespace std;

const int INF = (1<<31)-1, MAX_N = 1<<17;

int N, dat[2*MAX_N -1];

void init( int n_ )
{
    N = 1;
    while( N < n_ )
        N <<= 1;
 
    for(int i=0; i < 2*N-1; i++)
        dat[i] = INF;
 
    return;
}
 

void update(int k, int a){
    k += N - 1;
    dat[k] = a;
    while(k > 0){
        k = ( k - 1 ) / 2;
        dat[k] = min(dat[ k * 2 + 1 ], dat[ k * 2 + 2 ]);
    }
    return;
}

int query(int a, int b, int k, int l, int r){
    if( r <= a || b <= l ){
        return INF;
    }
    if( a <= l && r <= b ){
        return dat[k];
    }else{
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}

int main(void){
    int n, q;
    
    cin >> n >> q;
    init(n);
    
    for(int i=0; i<q; i++){
        ll com, x, y;
        cin >> com >> x >> y;
        
        if(com == 0){
            update(x, y);
        }else{
            cout << query(x, y+1, 0, 0, N) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<limits>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i = 0;i < (n); ++i)

int main() {
	int n;ll k;
	cin >> n >> k;
	vector<int>a(n);
	rep(i, n)cin >> a.at(i);

	int move=0;
	vector<int>move_point_count(n, 0);
	vector<int>obserb;
	vector<int>obserb2;

	while (true) {
		move_point_count.at(move)++;
		if (move_point_count.at(move) == 2) {
			break;
		}
		obserb.push_back(move);
		move = a.at(move)-1;
	}
	int move_memo = move;
	while (true) {
		obserb2.push_back(move);
		move = a.at(move) - 1;
		if (move_memo == move)break;
	}

	int obserber = obserb.size() - obserb2.size();
	if (obserber == 0)cout << obserb.at(k % obserb.size())+1 << endl;
	else if (k <= obserber)cout << obserb.at(k) +1<< endl;
	else {
		k -= obserber;
		cout << obserb2.at(k % obserb2.size())+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 6964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  string S; cin>>S;
  ll N=S.size(), MOD=2019;
  //桁数のMOD用意
  vector<ll> X(N,0);
  X[0]=1%MOD;
  for(int i=1; i<N; i++){
    X[i]=X[i-1]*10;
    X[i]=X[i]%MOD;
  }
  //1桁目からN桁目までのあまりを用意
  vector<ll> Y(N,0);
  Y[0]=(S[N-1]-'0')*X[0];
  for(int i=1; i<N; i++){
    Y[i]=(S[N-1-i]-'0')*X[i] + Y[i-1];
    Y[i]=Y[i]%MOD;
  }
  //1桁目からN桁目まで、都度和をとる
  ll ans=0;
  vector<ll> DP(2019,0);
  DP[0]=1;
  for(int i=0; i<N; i++){
    ans+=DP[Y[i]];
    DP[Y[i]]++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6692