akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size() - 2; ++i) {
		if (s.substr(i, 3) == "ABC")ans++;
	}

	cout << ans << endl;
	system("pause");
	return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;}

const char newl = '\n';

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) cin >> b[i];
    for (int i = 0;i < n;++i) cin >> c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll ans = 0;
    for (int i = 0;i < n;++i) {
        ans += (ll)(lower_bound(a.begin(),a.end(),b[i])-a.begin())*(c.end()-upper_bound(c.begin(),c.end(),b[i]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ctype.h>

#define INF 100000000

using namespace std;

int main()
{
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i += 2)
    {
        cout << s[i];
    }
    cout << "\n";
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> S(M);
    vector<int> p(M);
    rep(i, M){
        int k; cin >> k;
        rep(j, k){
            int s;
            cin >> s;
            s--;
            S.at(i).push_back(s);
        }
    }
    rep(i, M){cin >> p.at(i);}

    int cnt = 0;
    for (int bit = 0; bit < (1<<N); ++bit) { // 1を左に2回シフトすると100
        set<int> on_switches;
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                on_switches.insert(i);
            }
        }

        bool flag = true;
        rep(i, M){
            int tmp = 0;
            for (auto s: S.at(i)){
                if (on_switches.find(s) != on_switches.end()){tmp += 1;}
            }
            if (tmp % 2 != p.at(i)){flag = false; break;}
        }
        if (flag){cnt += 1;}
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string.h>

using namespace std;
const int INF =1001001001;
#define rep(i,n) for(int i=0;i<n;i++)
const int MAX_T = 1002*1002;
int M;



int main(){
	while(1){
		int N,M;
		int P[1002];
		scanf("%d %d",&N,&M);
		if(N==0&&M==0)return 0;
		rep(i,N)scanf("%d",&P[i]);
		P[N]=0;//投げない場合
		//2回の合計の場合をだす
		int P2[MAX_T];
		int T=-1;
		rep(i,N+1)rep(j,N+1)P2[++T]=P[i]+P[j];
		sort(P2,P2+T+1);
		//二分探索
		int ans=0;
		rep(i,T+1){
			int q=M-P2[i];
			int a=0,b=T+1;
			if(q<0)continue;
			else{
				do{
				int c=(b+a)/2;
				if(P2[c]>q){b=c;}
				else if(P2[c]==q){a=c;break;}
				else{a=c;}
				}while(b-a>1);
				ans=max(P2[i]+P2[a],ans);					
			}
		}
		printf("%d\n",ans);
	}
return 0;	
}

Measured memory_bytes: 4964
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
        
    // }
    string s;
    cin>>s;
    ll cnt=0,ans=0;
    for(int i=0;i<3;i++)
    {
        if(s[i]=='R')
        cnt++;
        else
        cnt=0;
        ans=max(cnt,ans);
    }
    cout<<ans;
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    cout << min(n*a,b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  int i;
 
  for(i = 0 ; i < 10000; i++){
    scanf("%d", &n);
    if(n == 0) break;

    printf("Case %d: %d\n", i+1, n);
  }

  return 0;
}


Measured memory_bytes: 1980
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define mp make_pair
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
static const ll INF = 1e17;

ll dp[3010][3010][4];

int main(){
  int r, c; cin >> r >> c;
  vector<vector<ll>> jem(r, vector<ll>(c, 0));
  ll k; cin >> k;
  rep(i, k) {
    int a, b; ll v;
    cin >> a >> b >> v;
    --a; --b;
    jem[a][b] = v;
  }

  rep(i, r){
    rep(j, c){
      for(int k = 2; k >= 0; k--){
        chmax(dp[i][j][k+1], dp[i][j][k] + jem[i][j]);
        /*デクリメントなのは複数回拾うとまずいから*/
      }
      rep(k, 4){
        chmax(dp[i+1][j][0], dp[i][j][k]);
        chmax(dp[i][j+1][k], dp[i][j][k]);
      }
    }
  }

  ll ans = 0;
  rep(i, 4) chmax(ans, dp[r-1][c-1][i]);
  cout << ans << endl;
}


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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;

    while (t--)
    {
        int a[5];
        for (int i = 0; i < 5; ++i)
            cin >> a[i];
        int ans = 0;
        for (int i = 0; i < 5; ++i)
            if (a[i] == 0)
            {
                ans = i + 1;
                break;
            }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3612
#include <stdio.h>
int main(void)
{
	int a,b,c,n;
	scanf("%d",&n);
	for(;n > 0;n--)
		{
			scanf("%d %d %d",&a,&b,&c);
			if(a*a == b*b+c*c){
					printf("YES\n");
				    }
		else	if(b*b == a*a+c*c){
					printf("YES\n");
				    }
		else    if(c*c == a*a+b*b){
					printf("YES\n");
				    }
		else                {
					printf("NO\n");
				    }
		}

	return 0;
}

Measured memory_bytes: 580
mod = pow(10,9) + 7
S = int(input())

dp = [0] * (S+1)

dp[0] = 1

for i in range(S+1):
  for j in range(0,(i-3)+1):
    dp[i] += dp[j]
    dp[i] %= mod

print(dp[-1] % mod)

Measured memory_bytes: 9144
// https://atcoder.jp/contests/abc174/tasks/abc174_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll K;
  cin >> K;

  if (7 % K == 0) drop(1);

  ll cur = 7 % K;
  ll res = 1;

  rep(i, 1e6) {
    res++;
    cur = 10 * cur + 7;
    if (cur % K == 0) drop(res);
    cur %= K;
  }

  drop(-1);
}


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

int n;
ll a[101010];

int main()
{
    cin >> n;
    rep(i, n) cin >> a[i];
    ll xx = 0;
    rep(i, n)
    {
        if(i % 2 == 0) xx += a[i];
        else xx -= a[i];
    }
    cout << xx << " ";
    xx /= 2;
    for(int i = 1; i < n; i++)
    {
        xx = a[i - 1] - xx;
        cout << xx * 2 << ((i == n - 1)? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 2048
fun main() {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val K = sc.next().toInt()

        var ans = 0L
        repeat(K) { i ->
            repeat(K) { j ->
                val ij = gcd(i + 1, j + 1)
                repeat(K) { k ->
                    ans += gcd(ij, k + 1)
                }
            }
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 36392
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b, c, d, e, f = sc.nextInt

    // 水の重さのパターンを列挙
    val waterWeights = ArrayBuffer[Int]()
    for (i <- 0 until f; j <- 0 until f) {
      val waterWeight = 100 * a * i + 100 * b * j
      if (waterWeight <= f) {
        waterWeights += waterWeight
      }
    }

    // 砂糖の重さのパターンを列挙
    val sugarWeights = ArrayBuffer[Int]()
    for (i <- 0 until f; j <- 0 until f) {
      val sugarWeight = c * i + d * j
      if (sugarWeight <= f) {
        sugarWeights += sugarWeight
      }
    }

    // 砂糖水の重さを探索
    var maxDense = 0d
    var maxSugarWaterWeight = 0
    var maxSugarWeight = 0
    for (waterWeight <- waterWeights.distinct; sugarWeight <- sugarWeights.distinct) {
      val sugarWaterWeight = waterWeight + sugarWeight

      if (sugarWaterWeight > 0 && sugarWaterWeight <= f && sugarWeight <= (waterWeight * e / 100)) {
        val dense = sugarWeight.doubleValue * 100 / sugarWaterWeight.doubleValue
        if (maxDense <= dense) {
          maxDense = dense
          maxSugarWaterWeight = sugarWaterWeight
          maxSugarWeight = sugarWeight
        }
      }
    }

    println(maxSugarWaterWeight + " " + maxSugarWeight)
  }

}


Measured memory_bytes: 42620
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    N, W = map(int, input().split())
    vw = [list(map(int, input().split())) for _ in range(N)]

    # 重さiの場合の最大価値
    dp = [0]*(W+1)

    for i in range(1, W+1):
        for j in range(N):
            v_j = vw[j][0]
            w_j = vw[j][1]
            if i-w_j>=0:
                dp[i] = max(dp[i-w_j]+v_j, dp[i])

    print(dp[W])

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 5924
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define mk(arr,n,type)      type *arr=new type[n];
#define dbg(x) cerr << #x << " is " << x << endl;
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
clock_t beg = clock();
const int inf=1e18;const int mod=1e9+7;const int N=2e5+9;
const double pi = 3.1415926535897932384626433;
void FILE_IO(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}

void JH(){
    int d=0,e=0,f=0,g=0,p=0,w=0,flag=0,ans=0,res=0,cnt=0,sum=0;double f1=0.0,f2=0.0,f3=0.0;
    int n,k;cin>>n>>k;int a[n];
    fo0(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    fo0(i,k){
        sum+=a[i];
    }
    cout<<sum;
}

int32_t main()
{
    FILE_IO();FAST_IO;int t=1;
    // cin>>t;
    while(t--){JH();}cerr<<(double)(clock()-beg)/1000<<"s ";
}

Measured memory_bytes: 3816
import numpy as np
n = int(input())
A = [int(i) for i in input().split()]
A.sort()
dp = np.array([True for _ in range(A[-1]+1)])
A = np.array(A)
prev = 0
for a in A:
  if dp[a]:
    if prev == a:
      dp[a] = False
    for i in range(A[-1]//a+1):
      if i > 1:
        dp[i*a] = False
  prev = a
print(dp[A.tolist()].sum())

Measured memory_bytes: 51804
N, A, B = gets.split.map(&:to_i)

if N == 1
    if A == 1 && B == 1
        print 1
    else
        print -1
    end

elsif N == 2
    if A == 2 && B == 1
        print '1 2'
    elsif A == 1 && B == 2
        print '2 1'
    else
        print -1
    end

# 1 2 3 4 5 ...
elsif B == 1
    if A == N
        print (1..N).to_a.join(' ')
    else
        print -1
    end

#####   middle = 3, wide = 13
#####
###
#
#
elsif A + B - 1 <= N && N <= A * B 
    stairs = Array.new(B){Array.new()}
    middle = (N - A + B - 2) / (B - 1)
    wide = N - A + middle
    wide.times do |i|
        stairs[i % B].unshift(N - i)
    end
    stairs[0] = (1..(N - wide)).to_a + stairs[0]
    result = []
    stairs.each do |stair|
        result.concat(stair)
    end
    print result.join(' ')

else
    print -1 
end


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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  int ans = 0;
  rep(i, s.size()) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3856
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

const int limit = 50;
int n, m;
int a[limit], b[limit];
bool graph[limit][limit]; 
bool visited[limit];

void dfs(int v){
  visited[v] = true;
  rep(v2, n){
    if (graph[v][v2] == false) continue;
    if (visited[v2] == true) continue;
    dfs(v2);
  }

}

int main(void){
  cin >> n >> m;
  rep (i, m){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  int ans = 0;
  rep(i, m){
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    rep(j, n) visited[j] = false;
    dfs(0);
    bool bridge = false;
    rep(j, n) if (visited[j] == false) bridge = true;

    //cout <<"bridge: " << bridge << endl;
    if (bridge) ans += 1;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
   string s;
   cin>>s;
   int oddW=0 , evenW=0;
   for(int i=0;i<s.length();i++)
   {
       if( i%2==0 && s[i] =='1')
       {
           evenW++;
       }
       if( i%2==1 && s[i]=='1')
           oddW++;

   }
   int ans =0;
   if( oddW >= evenW )
   {
       ans +=( s.length()/2 - oddW);
       ans+= evenW;
   } else
   {
       if( s.length()%2==0 )
       {
           ans += (s.length()/2 - evenW);
           ans+= oddW;
       } else
       {
           ans += ( s.length()/2 +1 - evenW);
           ans+= oddW;
       }
   }
   cout<<ans;

}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
/* (๑╹◡╹) */
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll MOD = 1000000007;
template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
 /* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)*/
template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
/* (๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹)(๑╹◡╹) */
///////////////////////////////////////////////
const int MAX = 510000;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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



int main() {
	int ans = 0;
	int N,M;	cin >> N >> M;
	vector<vector<int>> V(100002);

	for (int i = 0; i < N; i++)
	{
		int a,b;	cin >> a >> b;
		V[a].PB(b);
	}
	priority_queue<int> que;
	for (int i = 1; i <= M; i++)
	{
		for (int j = 0; j < V[i].size(); j++) //queにi日感かかる仕事を突っ込む
		{
			que.push(V[i][j]);
		}
		if(!que.empty()){
			ans += que.top();
			que.pop();
		}

	}
	
	
	
	

	cout << ans << endl;
}


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

using namespace std;

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

    int n;
    cin >> n;

    int m = n + 1;
    vector<int> bad(m) , heroes(n);
    for (int i = 0 ;i < m ;i++)
        cin >> bad[i];

    long long ans = 0;
    for (int i = 0 ;i < n ;i++) {
        cin >> heroes[i];
        if (heroes[i] <= bad[i])
            ans += heroes[i];
        else {
            ans += bad[i];
            heroes[i] -= bad[i];
            ans += min(heroes[i] , bad[i + 1]);
            bad[i + 1] -= min(heroes[i] , bad[i + 1]);
        }
    }

    cout << ans;
}

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define MX 1e5


void solve() {
    int n;
    cin >> n;
    vector<int> v(n+1, 0);
    for (int i = 1; i < n+1; i++) {
        cin >> v[i];
    }
    int cnt = 0;
    int x = 1;
    while(x != 2 && cnt < n+1) {
        x = v[x];
        cnt++;
    }
    cout << (cnt == n+1 ? -1 : cnt) << "\n";
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  //cin >> t;
  //if(13<=a)cout << b << endl;
  //else if(6<=a&&a<=12)cout << b/2 << endl;
  //else cout << 0 << endl;
  cout << (3*a+b)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  string a;
  string b;
  int c;
  cin >> n >> a >> c;
  for(int i=0;i<n;i++){
    if(a[i]=='1'){
      b+='1';
    }
    else{
      if(c!=0){
	b+='1';
	c--;
      }
      else b+='0';
    }
  }
  if(c>0){
    for(int i=n-1;i>=0;i--){
      if(b[i]=='1'&&a[i]=='1'){
	b[i]='0';
	c--;
	if(c==0)break;
      }
    }
  }
  cout << b << endl;
  return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    string s; cin>>s;
    bool YYMM=0,MMYY=0;
    if(s[2]=='0'&&('1'<=s[3]&&s[3]<='9')) YYMM=1;
    if(s[2]=='1'&&('1'<=s[3]&&s[3]<='2')) YYMM=1;
    if(s[0]=='0'&&('1'<=s[1]&&s[1]<='9')) MMYY=1;
    if(s[0]=='1'&&('1'<=s[1]&&s[1]<='2')) MMYY=1;
    if(YYMM&&MMYY) cout<<"AMBIGUOUS"<<endl;
    else if(YYMM) cout<<"YYMM"<<endl;
    else if(MMYY) cout<<"MMYY"<<endl;
    else cout<<"NA"<<endl;
    return 0;
}


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

int main() {
	long long x, sum;
  	cin >> x;
  	sum = 100;
  	long long i;
  	i = 0;
  	while (x > sum) {
      	sum *= 1.01;
      	i++;
    }
  	cout << i << endl;
  	
}

Measured memory_bytes: 3600
from bisect import bisect_left

n = int(input())
s = list(input())
q = int(input())
query = [input() for _ in range(q)]

p = [[] for _ in range(26)]

for i, x in enumerate(s):
    p[ord(x) - ord('a')].append(i)

for x in query:
    a, b, c = x.split()
    #print(c)
    if a == '1':
        b = int(b) - 1
        if s[b] == c:
            continue
        d = ord(s[b]) - ord('a')
        e = ord(c) - ord('a')
        temp = bisect_left(p[d], b)
        p[d].pop(temp)
        temp = bisect_left(p[e], b)
        p[e].insert(temp, b)
        s[b] = c
    else:
        b = int(b) - 1
        c = int(c) - 1
        #print(b, c)
        ans = 0
        for i in range(26):
            L = bisect_left(p[i], b)
            if L >= len(p[i]):
                continue
            if p[i][L] <= c:
                ans += 1
        print(ans)


Measured memory_bytes: 30600
#include<iostream>
#include<cmath>
int main()
{
	int cnt[2] = { 0,0 };
	while (true)
	{
		int a, b, c;
		char foo;
		std::cin >> a >> foo >> b >> foo >> c;
		if (std::cin.eof())
		{
			break;
		}
		if (c == hypot(a, b))
		{
			cnt[0]++;
		}
		else if (a == b)
		{
			cnt[1]++;
		}
	}
	std::cout << cnt[0] << std::endl;
	std::cout << cnt[1] << std::endl;
	return 0;
}


Measured memory_bytes: 3060
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, k = input_int_list()
    ans = 0
    if k == 0:
        print(n * n)
        return
    #  bを固定し、aとしてあり得る範囲をO(1)で求める。

    for b in range(k + 1, n + 1):
        ans += (b - k) * (n // b)
        if n % b >= k:
            ans += n % b - (k - 1)

    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 64176
N, x = map(int,input().split())
a = list(map(int,input().split()))
res = 0
if a[0]>x:
    res += a[0]-x
    a[0] = x
if a[-1]>x:
    res += a[-1]-x
    a[-1] = x

for i in range(1,N):
    tmp = a[i]+a[i-1]
    if tmp>x:
        res += tmp-x
        a[i] -= tmp-x
print(res)
    

Measured memory_bytes: 14052
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using usize = std::size_t;

template<typename T, size_t MAX_N>
class BIT
{
	public:
		BIT(size_t n) : _bit(), _n(n) {}

		T sum(size_t i)
		{
			T r = 0;
			while (i > 0)
			{
				r += _bit[i];
				i &= (i - 1);
			}
			return r;
		}

		void add(size_t i, T x)
		{
			while (i <= _n)
			{
				_bit[i] += x;
				i += i & -i;
			}
		}

	protected:
		T _bit[MAX_N + 1];
		size_t _n;
};

i32 a[500001];
i32 ans[500000];
i32 last_appear[500001];

using range = std::pair<i32, i32>;
using query = std::pair<i32, range>;

std::vector<query> vq;

auto main() -> i32 {
	i32 n, q;
	scanf("%d%d", &n, &q);
	BIT<i32, 500004> bit(n);
	for (i32 i = 0; i < n; ++i) {
		scanf("%d", a + i + 1);
	}
	for (i32 i = 0; i < q; ++i) {
		i32 l, r;
		scanf("%d%d", &l, &r);
		vq.emplace_back(i, range(l, r));
	}
	std::sort(vq.begin(), vq.end(), [](const auto& a, const auto& b) { return a.second.second < b.second.second; });

	i32 rindex = 1;
	for (auto& q : vq) {
		auto [l, r] = q.second;
		while (rindex <= r) {
			if (last_appear[a[rindex]] != 0) {
				bit.add(last_appear[a[rindex]], -1);
			}
			last_appear[a[rindex]] = rindex;
			bit.add(rindex, 1);
			rindex += 1;
		}
		i32 res = bit.sum(r) - bit.sum(l - 1);
		ans[q.first] = res;
	}

	for (i32 i = 0; i < q; ++i) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


Measured memory_bytes: 17508
//Choose Integers

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    int a,b,c;cin>>a>>b>>c;
    int aa = a;
    bool flag = false;
    int i = 0,g = 0;
    for(;true;i++){
        if(i==0)g=a%b;
        if(aa%b==c){
            flag = true;
            break;
        }
        aa += a;
        if(i>0&&aa%b==g)break;
    }
    cout << (flag?"YES":"NO")<<nnn;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <deque>
#include <vector>
using namespace std;

#define FILL(a, n, x) memset((a), (x), sizeof ((a)[0]) * (n))
#define FILLA(a, x) memset((a), (x), sizeof (a))
#define COPY(a, n, b) memcpy((b), (a), sizeof ((a)[0]) * (n))
#define COPYA(a, b) memcpy((b), (a), sizeof (a))

typedef unsigned long long lu;
const int mod = 1e9 + 7;

inline int Add(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline int Sub(int x) { return x < 0 ? x + mod : x; }
inline void Sub(int &x, int y) { x = Sub(x - y); }
inline int Mul(int x, int y) { return (int)((lu)x * y % mod); }
inline int Mul(int x, int y, int z) { return (int)((lu)x * y % mod * z % mod); }

int Pow(int x, int y) {
  int z = 1;
  for (; y; y >>= 1) {
    if (y & 1) z = Mul(z, x);
    x = Mul(x, x);
  }
  return z;
}

int Inv(int x) { return Pow(x, mod - 2); }

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

typedef long long li;
const li infl = ~0LLU >> 2;

template <class T> inline void Min(T &x, T y) { if (y < x) x = y; }
template <class T> inline void Max(T &x, T y) { if (y > x) x = y; }

const int maxn = 50;

int n;
li budget, amount;
li cost[maxn];
li value[maxn];
int par[maxn];
int ord[maxn];

vector<li> Tran(vector<li> a, li C, int V, li N) {
  vector<li> b(a.size() + V * N, 0);
  for (int rem = 0; rem < V; ++rem) {
    deque< pair<int, li> > que;
    for (int i = rem; i < b.size(); i += V) {
      int id = i / V;
      if (i < a.size()) {
        // insert
        li val = a[i] - C * id;
        while (!que.empty() && que.back().second >= val) {
          que.pop_back();
        }
        que.push_back(make_pair(id, val));
      }
      if (que.empty()) {
        b[i] = infl;
      } else {
        b[i] = que.front().second + id * C;
      }
      if (!que.empty() && que.front().first <= id - N) {
        // remove
        que.pop_front();
      }
    }
  }
  return b;
}

vector<li> Solve1(int sp) {
  vector<li> ans(1, 0);
  for (int i = 0; i < n; ++i) {
    ans = Tran(ans, cost[i], (int)value[i], sp);
  }
  return ans;
}

int main(void) {
  scanf("%d%lld%lld", &n, &budget, &amount);
  scanf("%lld", cost + 0);
  for (int i = 1; i < n; ++i) {
    scanf("%lld%d", cost + i, par + i);
    --par[i];
  }
  fill(value, value + n, 1);
  for (int i = n - 1; i >= 1; --i) {
    value[par[i]] += value[i];
    cost[par[i]] += cost[i];
  }

  int sp = (int)min<li>(n, amount);
  vector<li> A = Solve1(sp);

  for (int i = 0; i < n; ++i) {
    ord[i] = i;
  }
  sort(ord, ord + n, [](int i, int j) {
      return cost[i] * value[j] < cost[j] * value[i];
    });

  li ans = 0;
  for (int i = 0; i < A.size(); ++i) {
    li rest = budget - A[i], got = i;
    if (rest < 0) break;
    for (int j = 0; j < n; ++j) {
      int x = ord[j];
      li unit_cost = cost[x], unit_value = value[x];
      li total = (x == 0 ? infl : amount) - sp;
      li rep = min(total, rest / unit_cost);
      rest -= rep * unit_cost;
      got += rep * unit_value;
    }
    Max(ans, got);
  }

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


Measured memory_bytes: 2244
//B

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

int n;
vector<int> v;

int main(){
	cin >> n;
	int mx = 0;
	int mi = INT_MAX;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		mx = max(mx, a);
		mi = min(mi, a);
		v.push_back(a);
	}
	if (mx - mi > 1){
		puts("No");
		return 0;
	}
	int cnt_mx = 0;
	int cnt_mi = 0;
	for (int i = 0; i < n; i++){
		if (mx == v[i]){
			cnt_mx++;
		}
		if (mi == v[i]){
			cnt_mi++;
		}
	}
	if (mx == mi){
		if (mx == n - 1){
			puts("Yes");
			return 0;
		}
		if (n/mx >= 2){
			puts("Yes");
			return 0;
		}
		puts("No");
		return 0;
	}
	int ONE = cnt_mi;
	int TWO = n - ONE;
	if (mx>ONE&&TWO >= 2 * (mx - ONE)){
		puts("Yes");
	}
	else{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 892
from collections import deque
S = input()
Q = int(input())
a = deque([])
for i in S:
    a.append(i)

# is_reverse: 反転しているか
is_reverse = False
for i in range(Q):
    query = input().split()
    if query[0] == "1":
        is_reverse = not is_reverse
    else:
        if query[1] == "1":
            if is_reverse:
                a.append(query[2])
            else:
                a.appendleft(query[2])
        else:
            if is_reverse:
                a.appendleft(query[2])
            else:
                a.append(query[2])
if is_reverse:
    while len(a)>0:
        print(a.pop(), end="")
else:
    while len(a)>0:
        print(a.popleft(), end="")
print()

Measured memory_bytes: 104024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << x << '\n'
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
//---------------------------------------------------------------------------------------------------
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void solve()
{
}

//---------------------------------------------------------------------------------------------------
signed main()
{
  lli a = 0, b = 0, c = 0, h = 0, k, n = 0, w = 0, ans = 0, count = 0;
  string s = "", t = "";
  vector<pair<lli, lli>> pr;
  map<lli, lli> mp;
  set<lli> st;

  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> a >> b >> c;
  cin >> k;
  ans = k;
  lli A, B = b, C = c;

  if (c > b && b > a && c > a)
  {
    out("Yes");
    return 0;
  }

  while (ans > 0)
  {
    if (B > a)
    {
      // cout << "ans2: " << ans << " B: " << B << endl;
      while (ans > 0)
      {
        if (C > B)
        {
          out("Yes");
          return 0;
        }
        else
        {
          C = C * 2;
          ans--;
          if (C > B)
          {
            out("Yes");
            return 0;
          }
          // cout << "ans3: " << ans << " B: " << B << endl;
        }
      }
    }
    else
    {
      B = B * 2;
      ans--;
      // cout << "ans: " << ans << " B: " << B << endl;
    }
  }

  out("No");
}

Measured memory_bytes: 3644
N, K = list(map(int, input().split()))
d=[0] * K
A=[0] * K
okashi_sunuke = list()
for i in range(K):
    d[i] = int(input())
    A[i] = list(map(int, input().split()))
    okashi_sunuke += A[i]

sunuke = 0
for i in range(1,N+1):
    if i in okashi_sunuke:
        sunuke +=1

print(N-sunuke)






Measured memory_bytes: 9184
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


//Hang in there!

using namespace std;


int main() {
	int K, S;
	cin >> K >> S;
	int ans = 0;
	for (int i = 0; i <= K; i++) {
		for (int j = 0; j <= S - i && j <= K; j++) {
			if (S - i - j <= K) {
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " is " << x << endl

int main()
{
    ll N, R = 0, G = 0, B = 0;
    string S;
    cin >> N >> S;

    for (int i = 0; i < S.size(); i++)
    {
        if (S.at(i) == 'R')
        {
            R++;
        }
        else if (S.at(i) == 'G')
        {
            G++;
        }
        else
        {
            B++;
        }
    }

    ll ans = R * G * B;

    rep(i, N)
    {
        for (int j = 1; j < N; j++)
        {

            if (i + 2 * j >= N)
            {
                continue;
            }

            if (S.at(i) != S.at(i + j) && S.at(i + j) != S.at(i + 2 * j) && S.at(i + 2 * j) != S.at(i))
            {
                ans -= 1;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();
		int N = c.length;
		int ans = 0;
		for(int i=0; i<N; i++){
			int tmp = 0;
			for(int j=i; j<N; j++){
				if(c[j] == 'A' || c[j] == 'T' || c[j] == 'C' || c[j] == 'G'){
					tmp++;
				}else{
					tmp = 0;
				}
				if(ans < tmp)ans = tmp;
			}
		}
		
		System.out.println(ans);
		
		
		
		sc.close();
	}

	
}


Measured memory_bytes: 21972
import sys

input = sys.stdin.readline


def gcd(*args):
    a = max(args)
    b = min(args)
    while b != 0:
        a, b = b, a % b
    return a


def main():
    A, B, C, D = [int(i) for i in input().split()]
    # X : AとBの間の整数の数
    X = B - A + 1
    # Y : AとBの間でCの倍数の数
    Y = (B // C) - ((A - 1) // C)
    # Z : AとBの間でDの倍数の数
    Z = (B // D) - ((A - 1) // D)
    # V : CとDの最小公倍数
    V = (C * D) // gcd(C, D)
    # W : AとBの間でVの倍数の数
    W = (B // V) - ((A - 1) // V)
    print(X - Y - Z + W)


if __name__ == "__main__":
    main()

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int[] cs = new int[26];

        Arrays.fill(cs, 0);
        for (int i = 0; i < s.length(); i++) {
            cs[s.charAt(i) - 'a']++;
        }

        for (int i = 0; i < cs.length; i++) {
            if (cs[i] > 1) {
                System.out.println("no");
                return;
            }
        }

        System.out.println("yes");
    }
}


Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.setf(ios::fixed);
	cout.precision(5);
	int a, b;
	cin>>a>>b;
	cout<<(a/b)<<' '<<(a%b)<<' '<<((double)a/b)<<'\n';
	return 0;
}



Measured memory_bytes: 3296
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n ; i++){
            BigInteger a = new BigInteger(br.readLine());
            BigInteger b = new BigInteger(br.readLine());
            BigInteger c = a.add(b);
            String s = c.toString();
            if (s.length() > 80){
                System.out.println("overflow");
            }else{
                System.out.println(a.add(b));
            }
        } 
        
    }
}

Measured memory_bytes: 24368
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



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

    string S;cin >> S;
    int Q;cin >> Q;
    vector<int> query(Q);
    vector<pair<int,char>> add;
    int reverseCount = 0;
    for(int i = 0;i<Q;i++){
        int type;cin >> type;
        if(type == 1){
            query.at(i) = type;
            reverseCount++;
        }
        else{
            query.at(i) = type;
            int F;char C;cin >> F >> C;
            add.push_back(make_pair(F,C));
        }
    }
    if(reverseCount % 2 == 1) reverse(S.begin(),S.end());
    deque<char> DQ;
    for(int i = 0;i<S.size();i++) DQ.push_back(S.at(i));
    int addCount = 0;
    for(int i = 0;i<Q;i++){
        int type = query.at(i);
        if(type == 1){
            reverseCount--;
        }
        else{
            int where = add.at(addCount).first;char C = add.at(addCount).second;
            addCount++;
            if(where == 1 && reverseCount % 2 == 0){
                DQ.push_front(C);
            }
            else if(where == 1 && reverseCount % 2 == 1){
                DQ.push_back(C);
            }
            else if(where == 2 && reverseCount % 2 == 0){
                DQ.push_back(C);
            }
            else if(where == 2 && reverseCount % 2 == 1){
                DQ.push_front(C);
            }
        }
    }
    for(char OUTPUT : DQ) cout << OUTPUT;
    cout << endl;
}

Measured memory_bytes: 6312
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=73,INF=1<<30;
vector<string> S(MAX);
string dp[MAX][MAX];
int H,W;

string DFS(int h,int w){
    if(h==H) return "";
    if(w==W) return "";
    if(dp[h][w]!="") return dp[h][w];
    
    string res;
    if('0'<=S[h][w]&&S[h][w]<='9') res+=S[h][w];
    else return "";
    
    string A=DFS(h+1,w),B=DFS(h,w+1);
    
    if(A.size()>B.size()) swap(A,B);
    
    if(A.size()==B.size()) return dp[h][w]=res+max(A,B);
    else return dp[h][w]=res+B;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(1){
        cin>>W>>H;
        if(H+W==0) break;
        
        for(int i=0;i<H;i++) S.clear();
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                dp[i][j]="";
            }
            cin>>S[i];
        }
        string ans="";
        
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                string res=DFS(i,j);
                while(res.size()>=1&&res[0]=='0') res=res.substr(1);
                if(ans.size()==res.size()) ans=max(ans,res);
                else if(ans.size()<res.size()) ans=res;
            }
        }
        
        cout<<ans<<endl;
    }
}




Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s;
    cin>>s;
    if(s[s.size()-1]=='s'){
        for(ll i=0;i<s.size();i++)    cout<<s[i];
        cout<<"es";
    }else{
        for(ll i=0;i<s.size();i++)    cout<<s[i];
        cout<<"s";
    }
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int n,dp[100005];
int main()
{
    cin>>n;
    int ar[n+5];
    for(int i=1;i<=n;i++) cin>>ar[i];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(ar[2]-ar[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(ar[i]-ar[i-1]),dp[i-2]+abs(ar[i]-ar[i-2]));
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 4344