akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#include <fstream>
#include <iterator>
// #include "prettyprint.hpp"

using namespace std;
using ll = long long;

int main()
{
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
a0 = np.array(list(map(int, input().split())))
a = a0.copy()
b = np.array(list(map(int, input().split())))
for i in range(n):
  c = a[i] - b[i]
  if c < 0:
    a[i] = 0
    a[i+1] = a[i+1] + c
    if a[i+1] < 0:
      a[i+1] = 0
  else:
    a[i] = a[i] - b[i]
print(sum(a0 - a))

Measured memory_bytes: 24928
n=int(input());d,x=map(int,input().split());res=0
for i in range(n):
    a=int(input())
    
    if a>d:
        #print(1)
        res+=1
    else:
        #print(d//a+1)
        if d%a!=0:
            res+=d//a+1
        else:
            res+=d//a
    
    #res+=1 if a>d else d//a
    #:res+=1 if d%a!=0
print(res+x)


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

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

  long long max = -9999999999;

  max = a * c;
  if (max < a * d) max = a * d;
  if (max < b * c) max = b * c;
  if (max < b * d) max = b * d;

  cout << max << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<unordered_set>
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
using namespace std;
int main()
{
    ios;    
    int n;
    cin >> n;
    unordered_set<string> s;
    string temp;
    for(int i = 0; i < n; i++)
    {
        cin >> temp;
        s.insert(temp);
    }
    cout << (int)s.size() << '\n';
}

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

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

    ll N;
    cin >> N;
    vector<string> Si(N);
    rep(i,N){
        cin >> Si[i];
    }
    
    sort(all(Si));
    vector<string> word_vec;
    vector<ll> count_vec;
    vector<string> result_vec;
    string temp = "";
    ll last = 0;
    rep(i,N){
        if(temp != Si[i]){
            word_vec.push_back(Si[i]);
            count_vec.push_back(1);
            temp = Si[i];
            last++;
        }
        else{
            count_vec[last-1]++;
        }
    }
    ll memo = 0;
    rep(i,word_vec.size()){
        memo = max(memo,count_vec[i]);
    }
    rep(i,word_vec.size()){
        if(count_vec[i] == memo){
            // cout << count_vec[i] << "\n";
            cout << word_vec[i] << "\n";
        }
    }
}

Measured memory_bytes: 16740
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 200005;
const int K = 25;
int p[N], sz[N], used[N];
int gt(int x){
    if (p[x] == x) return x;
    return p[x] = gt(p[x]);
}
void unite(int x, int y){
    x = gt(x);
    y = gt(y);
    if (sz[x] < sz[y]) swap(x, y);
    p[y] = x;
    sz[x] += sz[y];
    used[x] |= used[y];
}
vector < pair < int, pair < int, int > > > a;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, h, w;
    cin >> n >> h >> w;
    for (int i = 1; i <= n; i++){
        int u, v, w;
        cin >> u >> v >> w;
        a.pb({w, {u, v + h}});
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (int i = 1; i <= h + w; i++){
        p[i] = i;
        sz[i] = 1;
    }
    int ans = 0;
    for (auto i: a){
        int u = i.S.F;
        int v = i.S.S;
        int w = i.F;
        u = gt(u);
        v = gt(v);
        if (u == v){
            if (!used[v]){
                ans += w;
                used[v] = 1;
            }
        } else{
            if (used[u] && used[v]) continue;
            unite(u, v);
            ans += w;
        }
    }
    cout << ans;
}


Measured memory_bytes: 7152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
//#include<bits/stdc++.h>		
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define f first
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
#define vint vector<int>
const int mod = 1000000007;
using namespace std;
const int maxsize=3005;

int n;

void assignee(int &x, int ans)
{
	x += ans;
	x %= mod;
}

int multi(int a,int b){
	return (1LL*a*b)%mod;
}

struct M{
	vector<vector<int>> t;
	M(){
		t.resize(n, vector<int>(n));
	}
	
	M operator* (const M &b) const{
		
		M c = M();
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<n;k++){
					assignee(c.t[i][j], multi(t[i][k], b.t[k][j]));
				}
			}
		}
		return c;
	}
};


int main()
{
	cin >> n;
	ll k;
	cin >>k;
	vector<vector<int>> adj(n, vector<int>(n));
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			cin >> adj[i][j];
		}
	}
	M sec = M();
	sec.t = adj;
	
	M ans = M();
	for(int i=0;i<n;i++)
		ans.t[i][i]=1;
	
	while(k>0)
	{
		if(k%2 != 0)
		{
			ans = ans * sec;
		}
		sec=  sec*sec;
		k >>=1;
	}
	
	int fans=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++){
			assignee(fans, ans.t[i][j]);
		}
	}
	cout << fans << "\n";
	return 0;
}


Measured memory_bytes: 256
function Main(input: string) {
  const lines: string[] = input.split('\n');
  const params = lines[0].split(' ');

  const a = parseInt(params[0]); // 猫（既知）
  const b = parseInt(params[1]);
  const x = parseInt(params[2]);

  const n = x - a;

  let flag = false;
  for (let i = 0; i < b; i++) { //  
    if (i === n) {
      flag = true;
      break
    }
  }

  const msg = flag ? 'YES' : 'NO';

  console.log(msg);
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

int n;
int ar[100005];
int main(){
  cin>>n;
  REP(i,n) cin>>ar[i];

  int mini=1;
  lint res=0;
  REP(i,n){
    int d=(ar[i]-1)/mini;
    res+=d;
    ar[i]-=d*mini;
    if(ar[i]==mini && ar[i]>1 && d>0) --ar[i];
    if(ar[i]==mini) ++mini;
  }
  cout<<res<<endl;

  return 0;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> x(n);
  rep(i, n) cin >> x[i];

  ll ans = INF;
  int l = 0, r = k - 1;
  while (r < n) {
    ll res = max(abs(x[l]), abs(x[r]));
    if (x[l] * x[r] < (ll)0) res += 2 * min(abs(x[l]), abs(x[r]));
    ans = min(ans, res);
    l++, r++;
  }
  cout << ans << endl;

  
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif
 
#define int long long
// typedef __int128_t Int;
#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;
    const double PI = acos(-1);
    const double EPS = 1e-9;
    template <class T> bool chmax(T &a, const T &b) {
          if (a < b) {
                  a = b;
                      return true;
                        }
            return false;
    }
template <class T> bool chmin(T &a, const T &b) {
      if (a > b) {
              a = b;
                  return true;
                    }
        return false;
}
signed main() {
      cin.tie(0);
      ios::sync_with_stdio(false);
      cout << fixed << setprecision(12);

      int a,b,k;
      cin>>a>>b>>k;
      int c=a,d=b;
      set<int>s;
      loop(k){
         if(c<=a and a<=d) 
          s.insert(a++);
      }
      loop(k){
         if(c<=b and b<=d) 
          s.insert(b--);
      }
      for(auto x:s)cout<<x<<endl;
      return 0;
}


Measured memory_bytes: 256
# ABC141
from collections import Counter


def main():
    N, K, Q, *A = map(int, open(0).read().split())
    C = Counter(A)
    ans = []
    for i in range(1, N + 1):
        x = "Yes" if K - Q + C[i] > 0 else "No"
        ans.append(x)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Measured memory_bytes: 14544
//*INDENT-OFF*
#include<bits/stdc++.h>
using namespace std;
template<typename V>
bool tomin(V&x,V y){if(y<x){x=y;return true;}return false;}
template<typename V>
bool tomax(V&x,V y){if(x<y){x=y;return true;}return false;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
#pragma GCC optimize(3)
#define lowbit(x) ((x)&-(x))
//*INDENT-ON*
const int M=2e5+5;
int n,A[M];
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    int MX=INT_MIN,cnt=0;
    for(int i=1;i<=n;i++){
        if(tomax(MX,A[i]))cnt=1;
        else if(MX==A[i])cnt++;
    }
    int CMX=INT_MIN;
    for(int i=1;i<=n;i++)
        if(MX!=A[i])tomax(CMX,A[i]);
    for(int i=1;i<=n;i++){
        if(cnt>1){
            cout<<MX<<endl;
        }
        else{
            if(A[i]==MX)
                cout<<CMX<<endl;
            else cout<<MX<<endl;;
        }
    }
    return 0;

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e5;
typedef pair<ll,ll> P;
P p[MAX_N];
int N;
int main(){
	cin>>N;
	REP(i,N){
		ll a,b;
		cin>>a>>b;
		p[i]=P(a,b);
	}
	sort(p,p+N,[](const P &a,const P &b){
		return a.first+a.second<b.first+b.second;
	});
	ll ans=0;
	int sgn=1;
	for(int i=N-1;i>=0;i--){
		if(sgn==1){
			ans+=p[i].first;
		}else{
			ans-=p[i].second;
		}
		sgn*=-1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
import math

x = 0
y = 1
p1 = (0, 0)
p2 = (100, 0)
sin60 = math.sin(math.radians(60))
cos60 = math.cos(math.radians(60))

n = int(input())

def kock(n, p1, p2):
    if n == 0:
        return

    # p1, p2 から s, t, u を計算
    s = (0, 0)
    t = (0, 0)
    u = (0, 0)
    s = ((2 * p1[x] + 1 * p2[x]) / 3, (2 * p1[y] + 1 * p2[y]) / 3)
    t = ((1 * p1[x] + 2 * p2[x]) / 3, (1 * p1[y] + 2 * p2[y]) / 3)
    u = ((t[x] - s[x])*cos60 - (t[y] - s[y])*sin60 + s[x], (t[x] - s[x])*sin60 + (t[y] - s[y])*cos60 + s[y])

    kock(n-1, p1, s)
    print ('{:.8f} {:.8f}'.format(s[x], s[y]))
    kock(n-1, s, u)
    print ('{:.8f} {:.8f}'.format(u[x], u[y]))
    kock(n-1, u, t)
    print ('{:.8f} {:.8f}'.format(t[x], t[y]))
    kock(n-1, t, p2)


print ('{:.8f} {:.8f}'.format(p1[x], p1[y]))
kock(n, p1, p2)
print ('{:.8f} {:.8f}'.format(p2[x], p2[y]))


Measured memory_bytes: 5764
#include <bits/stdc++.h>
//#include "atcoder/all"
typedef long long int ll;
using namespace std;
// using namespace atcoder;
int main() {
    int n, k;
    cin >> n >> k;
    ll a[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll sum = 0;
    for (int i = k + 1; i <= n; i++) {
        if (a[i] > a[i - k]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 5188
package main

import "fmt"

type task struct {
	name string
	time int
}

func main() {
	var (
		n, q int
		tq   []task
	)
	fmt.Scan(&n, &q)
	tq = make([]task, n)

	for i := range tq {
		var (
			name string
			time int
		)
		fmt.Scan(&name, &time)
		tq[i] = task{name, time}
	}

	var totalTime = 0
	for len(tq) > 0 {
		var t task
		t, tq = tq[0], tq[1:]

		if t.time > q {
			totalTime += q
			t.time -= q
			tq = append(tq, t)
		} else {
			totalTime += t.time
			fmt.Println(t.name, totalTime)
		}
	}
}



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

using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define fi first
#define se second

ll A,n,ans[60][60][3000],x[100],ANS;

int main()
{
	cin >> n >> A;
	for(int i=0;i<n;i++)
		cin >> x[i];
	ans[0][0][0]=1;
	for(int last=0;last<n;last++)
	{
		if(last==0)
		{
			ans[1][last][x[last]]=1;
			continue;
		}
		for(int cnt=0;cnt<=last+1;cnt++)
		{
			if(cnt==0)
			{
				ans[0][last][0]=1;
				continue;
			}
			for(int sum=0;sum<=2500;sum++)
			{
				ans[cnt][last][sum]=ans[cnt][last-1][sum];
				if(x[last]<=sum)ans[cnt][last][sum]+=ans[cnt-1][last-1][sum-x[last]];
			}
		}
	}
	for(int cnt=1;cnt<=n;cnt++)
		ANS+=ans[cnt][n-1][cnt*A];
	cout << ANS;
	return 0;
}

Measured memory_bytes: 30336
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>
#include <cmath>
#include <iomanip>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N;
    cin >> N;
    vector<int> A(N); 
    for (auto & v : A)
        cin >> v;

    vector<vector<int64>> dp(N, vector<int64>(N, (1LL<<50)));
    vector<int64> pref(N);

    for (int i = 0; i < N; i++) {
        pref[i] = (!i ? A[i] : pref[i-1] + A[i]);
    }

    auto Sum = [&] (int l, int r) {
        return pref[r] - (l - 1 >= 0 ? pref[l - 1] : 0);
    };

    for (int i = 0; i < N; i++)
        dp[i][i] = 0;

    for (int l = 2; l <= N; l++) {
        for (int i = 0; i + l - 1 < N; i++) {
            int j = i + l - 1;
            for (int k = i; k < j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + Sum(i, j));
            }
        }
    }

    cout << dp[0][N-1] << "\n";

    return 0;
}


Measured memory_bytes: 1536
'use strict';

function Main(INPUT) {
    const input = INPUT.split("\n").map(n => Number(n));
    let N = input[0];
    let A = input[1];

    while (N >= 500) {
        N -= 500;
    }
    console.log(N - A <= 0 ? "Yes" : "No");
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11468
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main()
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var K = input[1];

            var result = 0L;
            while (N > 0L)
            {
                N /= K;
                result++;
            }
            Console.WriteLine($"{result}");
        }
    }
}

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

#define PI (acos(-1))
#define swap(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
long long gcd(long long a, long long b) { return b ? gcd(b,a%b) : a;}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }





vector<double> simequ(vector<vector<double>> a){
    int N=a.size();
    // 前進消去
    for (int k = 0; k < N -1; k++) {
        for (int i = k + 1; i < N; i++) {
            double d = a[i][k] / a[k][k];
            for (int j = k + 1; j <= N; j++)
                a[i][j] -= a[k][j] * d;
        }
    }

    // 後退代入
    for (int i = N - 1; i >= 0; i--) {
        double d = a[i][N];
        for (int j = i + 1; j < N; j++)
            d -= a[i][j] * a[j][N];
        a[i][N] = d / a[i][i];
    }

    // 結果出力
    vector<double> result;
    for (int k = 0; k < N; k++)
        result.push_back(a[k][N]);

    return result;
}




int main()
{
    ll n;
    cin >> n;
    if(n >777777753)n=777777753;
    ll c=0;
    for(ll i=357;i<=n;i+=2){
        ll a=i;
        bool is3=false,is5=false,is7=false;
        while(a){
            int b=a%10;
            if(b==3)is3=true;
            else if(b==5)is5=true;
            else if(b==7)is7=true;
            else {is3=false;break;}
            a/=10;
        }
        if(is3&&is5&&is7)c++;
    }



    cout << c << endl;


    return 0;
    
}






Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int a,b;cin>>a>>b;
  cout<<max({a+b,a-b,a*b})<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <string>

int main() {
    int N;
    std::cin >> N;
    std::unordered_set<std::string> a;
    for (int i=0; i<N; i++) {
        std::string s;
        std::cin >> s;
        a.insert(s);
    }
    std::cout << a.size() << std::endl;
}

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

#define ll long long
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define infl 1e18L+9
#define inf 1e9L+9
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()

const int mod=1e9L+7; 
const int nax=1e5+5; 

int a[nax]; 
int tr[nax<<2]; 
void build(int p, int l , int r){
  if(l==r){
    tr[p]=a[l]; 
  }
  else {
    int m=(l+r)>>1, c1=p<<1, c2=p<<1|1; 
    build(c1,l,m); 
    build(c2,m+1,r); 
    tr[p]=max(tr[c1],tr[c2]); 
  }
}
bool done; 
int val; 
void maxx(int p, int l, int r, int i, int j, int v, char d){
  if(done) return; 
  if(i<=l && r<=j) {
    if(tr[p]>v) {
      if(l<r){
        int m=(l+r)>>1, c1=p<<1, c2=p<<1|1; 
        if(d=='r'){
          maxx(c1,l,m,i,j,v,d); 
          maxx(c2,m+1,r,i,j,v,d); 
        }
        else {
          maxx(c2,m+1,r,i,j,v,d); 
          maxx(c1,l,m,i,j,v,d); 
        }
      }
      else {
        val=tr[p]; 
        done=1; 
      }
    }
    return; 
  }
  else if(j < l || i > r) return; 
  int m=(l+r)>>1, c1=p<<1, c2=p<<1|1; 
  if(d=='r'){
    maxx(c1,l,m,i,j,v,d);
    maxx(c2,m+1,r,i,j,v,d); 
  }
  else{
    maxx(c2,m+1,r,i,j,v,d); 
    maxx(c1,l,m,i,j,v,d);
  }
}

int pos[nax]; 
void solve(){
  int n; cin>>n; 
  for(int i=0;i<n;i++) {
    cin>>a[i];  
    pos[a[i]]=i; 
  }
  build(1,0,n-1); 
  ll ans=0; 
  int jr=0, jl=0, sr=1, sl=1; 
  for(int i=0;i<n;i++){
    jr=n, jl=-1; 
    sl=0, sr=0; 
    done=0; 
    maxx(1,0,n-1,i+1,n-1,a[i],'r'); 
    if(done){
      jr=pos[val]; 
      done=0; 
      maxx(1,0,n-1,jr+1,n-1,a[i],'r'); 
      if(done){
        sr=pos[val]-jr; 
      }
      else sr=n-jr; 
    }
    done=0; 
    maxx(1,0,n-1,0,i-1,a[i],'l'); 
    if(done){
      jl=pos[val]; 
      done=0; 
      maxx(1,0,n-1,0,jl-1,a[i],'l'); 
      if(done){
        sl=jl-pos[val]; 
      }
      else {
        sl=jl+1;  
      }
    }
//    cout<<" i jr sr jl sl "<<i<<" " <<jr<<" " <<sr<<" " <<jl<<" " <<sl<<endl; 
    ans+=(ll)a[i]*sr*(i-jl); 
    ans+=(ll)a[i]*sl*(jr-i); 
  }
  cout<<ans<<endl; 
}

int main()
{
	fast_io;
	clock_t beg=clock(); 
	solve(); 
	clock_t end=clock(); 
	fprintf(stderr,"%.2lf sec\n",(double)(end-beg)/CLOCKS_PER_SEC); 
	return 0;
}

Measured memory_bytes: 2048
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int k;
    cin>>k;
    int w;
    int sum=0;
rep(i,k){
    rep(j,k){
        rep(m,k){
             w=min(min(i,j),m)+1;
            for(int t=w;t>=1;t--){
                //cout<<i<<" "<<j<<" "<<m<<" "<<w<<endl;
                if((i+1)%(t)==0&&(j+1)%(t)==0&&(m+1)%(t)==0){
                    sum+=t;
                    break;
                }
            }
        }
    }
}
cout<<sum<<endl;
}


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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repd(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define for(i,a,b) for(ll i=(a);i<=(b);i++)
#define ford(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define size(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)



int main(void) {
    long double N,ans;
    cin >> N;
    ans = N *2 * 3.14159265358979323;
  
  
  

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

Measured memory_bytes: 3764
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	
	int y;
	cin >> y;
	if (y == 3 || y == 5 || y == 7)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;



}

Measured memory_bytes: 256
#include<stdio.h>

int n,A[50];

int solve(int i, int m){
  if(m==0)return 1;
  if(i>=n)return 0;

  int res = solve(i+1,m) || solve(i+1,m-A[i]);
  return res;
}


int main(){
  int q,m,i;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  
  scanf("%d",&q);
   
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(solve(0,m)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

Measured memory_bytes: 580
n = int(input())
a, b = map(int, input().split())
p = [int(i) for i in input().split()]
p_a = len([i for i in p if i <= a])
p_a_b = len([i for i in p if a < i <= b])
p_b = n - p_a - p_a_b
print(min(min(p_a, p_b), p_a_b))

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
ls=[0 for _ in range(N)]
for i in range(N):
  ls[A[i]-1]+=1
s=0
for i in range(len(ls)):
    m=ls[i]*(ls[i]-1)//2
    s+=m
for j in range(N):
  print(s-(ls[A[j]-1]-1))

Measured memory_bytes: 25716
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
ab = [0, 0]
is_alice = True
while len(A) != 0:
    now = A.pop()
    if is_alice:
        ab[0] += now
        is_alice = False
    else:
        ab[1] += now
        is_alice = True
print(ab[0] - ab[1])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
	string str;
	cin >> N >> str;
	vector<int> vec (N-1);
	string sa, sb;
	int ax, bx = 0;
	for(int i = 1;i < N;i++){
		ax = 0;
		sa = str.substr(0,i);
		sb = str.substr(i,str.size()-sa.size());
		sort(sa.begin(),sa.end());
		sort(sb.begin(),sb.end());
		for(int j = 0;j < sa.size();j++){
			if(j != 0 && sa.at(j-1) == sa.at(j)){
				continue;
			}
			for(int k = 0;k < sb.size();k++){
				if(sa.at(j) == sb.at(k)){
					ax++;
					break;
				}
			}
		}
		bx = max(ax,bx);
	}
	cout << bx << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main()
{
	int n, x = 0, y = 0, t = 0;
	cin >> n;
	bool flag = true;
	for(int i = 0; i < n; i++)
	{
		int ti, xi, yi;
		cin >> ti >> xi >> yi;
		int dt = ti - t;
		int dx = abs(xi - x);
		int dy = abs(yi - y);
		if (dx + dy > dt)
		flag = false;
		else if (dx > dy)
		{
			int r = dt - dx;
			if((r - dy) % 2 == 1)
				flag = false;
		}
		else
		{
			int r = dt - dy;
			if((r - dx) % 2 == 1)
				flag = false;
		}
		t = ti;
		x = xi;
		y = yi;
	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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


def solve(N: int, K: int):
    if K!=0:
        ans = 0
        for j in range(1,N+1): #10**5ループなのでいけるはず。
            if K <= j-1:
                ans += (j-K) * (N//j)
                if N%j >=K:
                    ans += N%j - K + 1
    else:
        ans = N * N

    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int p[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

    int k;
    cin >> k;

    cout << p[k - 1] << endl;

    return 0;
}

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

int main() {
  string s;
  cin>>s;
  
  int n = s.length();
  
  int i = 0;
  int ac = 0;
  long long ans = 0;
  
  while(i+1 < n) {
    if(s[i] == 'A') {
      ac++;
      i++;
     } 
    else if(s[i] == 'B' && s[i+1] == 'C') {
      ans+=ac;
      i+=2;
      }
    else if(s[i]!= 'A') {
      ac = 0;
      i++;
     } 
   } 
  cout<<ans;
  return 0;
  }


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    int N, M;
    cin >> N >> M;
    vector<LL> A(N);
    map<LL, LL> mp;
    REP0 (i, N)
    {
        cin >> A[i];
        mp[-A[i]] += 1;
    }
    sort(A.begin(), A.end());
    REP0 (i, M)
    {
        LL B, C;
        cin >> B >> C;
        mp[-C] += B;
    }

    LL sum = 0;
    LL rem = N;

    for (auto p : mp)
    {
        LL num = -p.first;
        LL cnt = p.second;
        if (cnt < rem)
        {
            sum += num * cnt;
            rem -= cnt;
        }
        else
        {
            sum += rem * num;
            break;
        }
    }
    cout << sum << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 13596
#include <stdio.h>
int main(){
    int a,b,d,r;
    double f;
    scanf("%d%d", &a,&b);
    d = a / b;
    r = a % b;
    f = (double)a / b;
    printf("%d %d %.8lf\n",d,r,f);
    return 0;
}


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


int main(){
  int n,q;
  cin >> n >> q;
  queue<pair<string,int>> que;
  pair<string,int> p;
  for(int i=0;i<n;i++){
    cin >> p.first >> p.second;
    que.push(p);
  }
  int keika = 0;
  while(!que.empty()){
    p=que.front();que.pop();
    if(p.second<=q){
      keika+=p.second;
      cout << p.first << ' ' << keika << endl;
    }else{
      keika+=q;
      p.second-=q;
      que.push(p);
    }
  }
     
}


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

using namespace std;

const int N = 105;

int n, a[N];

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    double ans = 0;

    for (int i = 1; i <= n; i++) ans += 1.0 / (double)a[i];
    ans = 1.0 / ans;
    cout << fixed << setprecision(9) << ans;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807

int main() {
  int N;

  scanf("%d", &N);

  int AC = 0;
  int WA = 0;
  int TLE = 0;
  int RE = 0;

  rep(i, N) {
    char input[4];
    scanf("%s", input);

    if (strcmp(input, "AC") == 0) {
      AC += 1;
    } else {
      if (strcmp(input, "WA") == 0) {
        WA += 1;
      } else {
        if (strcmp(input, "TLE") == 0) {
          TLE += 1;
        } else {
          if (strcmp(input, "RE") == 0) {
            RE += 1;
          }
        }
      }
    }
  }

  printf("AC x %d\n", AC);
  printf("WA x %d\n", WA);
  printf("TLE x %d\n", TLE);
  printf("RE x %d\n", RE);

  return 0;
}


Measured memory_bytes: 1732
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;
int main(){
    fastio
    int n , m ;
    cin >> n >> m ; 
    vector<pair<int,int> > v(m) ;
    for(int i = 0; i < m; i++){
        cin >> v[i].second >> v[i].first; 
    }
    sort(v.begin(), v.end()) ;
    stack<pair<int,int> > q ;
    int L = 1 , R = n ;
    int ans = 0 ;
    for(int i = 0; i < m; i++){
        int a = v[i].second , b = v[i].first ;
        if ( a >= L && b <= R ){
            L = b ; 
            ans++ ;
        }
    }
    cout << ans << endl;
    return 0 ;
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ll = long long;
using ii = pair<ll, ll>;

int32_t main(){
	ios::sync_with_stdio(0);
	int n, x;
	cin >> n >> x;
	vector<int> vs(n);
	int k = 1e9;
	for(auto &w:vs) cin >> w, x-=w, k = min(k, w);
       	int ans = n + x/k;
	cout << ans << endl;	

}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;

ll dp1[2019];
ll dp2[2019];

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

    for (int i = 0; i < 2019; i++) {
        dp1[i] = 0; dp2[i] = 0;
    }

    dp1[0] = 1;

    int su = 0;

    for (int i = 0; i < s.length(); i++) {
        // cout << (int)(s[i] - '0') << endl;
        for (int j = 0; j < 2019; j++) {
            int idx = (10 * j + s[i] - '0') % 2019;
            dp2[idx] += dp1[j];
        }

        for (int j = 0; j < 2019; j++) {
            dp1[j] = dp2[j];
            
            dp2[j] = 0;
            
        }
        su += dp1[0];
        dp1[0]++;

        // cout << dp1[0] << endl;
    }

    cout << su << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll N; cin >> N;

    //ll s[5000];
    ll t[5000];

    map<string, ll > mp; 
    for(ll i = 0; i < N; i++){
        string s; cin >> s;
        cin >> t[i];
        mp[s] = i;
    }
    string X; cin >> X;

    ll ans = 0;
    for(ll i = mp[X] + 1; i < N; i++){
        ans += t[i];
    }

    cout << ans << endl;

}

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

int main() {
  
string s;
cin>>s;
bool ans=false;
for(int i=0;i<3;i++){
  if(s[i]==s[i+1]){
    ans=true;

  }
}
if(ans){ cout<<"Bad"<<endl;

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


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int X;
bool DP[100004];

int main() {
  INCANT;
  cin >> X;
  DP[0] = true;
  rep(i, X) {
    rep(j, 6) {
      if (DP[i]) DP[i+100+j] = true;
    }
  }
  
  cout << DP[X] << "\n";
  return 0;
}


Measured memory_bytes: 384
def dfs(d, r):
    global l
    if d == 11:
        return
    l.append(int(r))
    for i in range(-1, 2):
        tmp = int(r[-1]) + i
        if 0 <= tmp <= 9:
            dfs(d + 1, r + str(tmp))


k = int(input())
l = []
for i in range(1, 10):
    dfs(1, str(i))
print(sorted(l)[k - 1])

Measured memory_bytes: 12856
N = int(input())
S_list = []
H_list=[]
C_list=[]
D_list=[]



for i in range(N):
    cards = input().split()
    if cards[0] == "S":
        S_list.append(cards[1])
    if cards[0] == "H":
        H_list.append(cards[1])
    if cards[0] == "C":
        C_list.append(cards[1])
    if cards[0] == "D":
        D_list.append(cards[1])

for i in range(1,14):
    if str(i) not in S_list:
        print("S" + " " + str(i))
for i in range(1,14):
    if str(i) not in H_list:
        print("H" + " " + str(i))
for i in range(1,14):
    if str(i) not in C_list:
        print("C" + " " + str(i))
for i in range(1,14):
    if str(i) not in D_list:
        print("D" + " " + str(i))



Measured memory_bytes: 5608
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
 
// ------------------------------------------------------------------------------------------------

ll a, b, k;

void func() {
    cin >> a >> b;
    k = a + b;
    if (k & 1) {
        cout << "IMPOSSIBLE" << endl;
        return;
    }
    k >>= 1;
    cout << k << endl;
}

int main() {
    fast_io; cout_precision;
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    string s;
    cin >> s;
    
    if (s[0] == s[1] && s[1] == s[2]) cout << "Yes" << endl;
    else if (s[1] == s[2] && s[2] == s[3]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=3e5;
const ll mod=1e9+7;
map<ll,ll> m;
ll f[maxn], a[maxn];
ll n, k, i, ans=0;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for ( i=1; i<=n; i++)
    {
        cin >>a[i];
        a[i] = a[i]-1+k;
        a[i]%=k;
    }
    f[0]=0;
    for ( i=1; i<=n; i++)
        f[i] = (f[i-1]+a[i])%k;
    for ( i=1; i<=n; i++)
    {
        ll x=i-k;
        if (x>0)
            m[f[x]]--;
        if (f[i]==0)
        {
            ans = ans+m[0];
            if (i<k) ans++;
        }
        else
            ans = ans+m[f[i]];
        m[f[i]]++;
    }
    cout << ans;
}


Measured memory_bytes: 16384
#include <iostream>

using namespace std;

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

  int N;
  cin >> N;
  char c;
  for (int i = 0; i < N; ++i) {
    cin >> c;
    if (c == 'Y') {
      cout << "Four\n";
      return 0;
    }
  }
  cout << "Three\n";

  return 0;
}


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

#include <iostream>
using namespace std;
int main() {
  int64_t n, y;
  cin >> n >> y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for (int a = 0; a <= n; ++a) {
    for (int b = 0; b <= n - a; b++) {
      int c = n - b - a;
      if (10000 * a + 5000 * b + 1000 * c == y) {
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
using namespace std;
 
int main(){
 
  int A,B,C,D ;
  
  cin >> A >> B >> C >> D;
  
  while(1){
    
    C-=B;
  
    if(C<=0){
      cout << "Yes";
      break;
    }
    
    A-=D;
    if(A<=0){
      cout << "No";
      break;
    }
  
    
  }
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }
    
    int cnt = 0;
    int light = 1;
    set<int> list;
    while (light != 2) {
        if (list.count(light) == 1) {
            cout << "-1" << endl;
            return 0;
        } else {
            list.insert(light);
            light = a.at(light - 1);
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 5376
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double t = sc.nextDouble();
        double x = sc.nextDouble();

        sc.close();

        //        long ans = 0;

        System.out.println(t / x);
    }
}


Measured memory_bytes: 23124
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  int x[M];
  int y[M];
  for (int i = 0; i < M; ++i) {
    cin >> x[i];
    cin >> y[i];
    --x[i];
    --y[i];
  }

  int balls[N];
  int red_balles[N];
  for (int i = 0; i < N; ++i) {
    balls[i] = 1;
    red_balles[i] = 0;
  }
  red_balles[0] = 1;

  for (int i = 0; i < M; ++i) {
    if (red_balles[x[i]] > 0)
      red_balles[y[i]] = 1;
    --balls[x[i]];
    ++balls[y[i]];
    if (balls[x[i]] == 0)
      red_balles[x[i]] = 0;
  }

  long long ret = 0;
  for (int i = 0; i < N; ++i)
    if (red_balles[i] > 0)
      ++ret;

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'

int main() {
  int n;
  string s;
  while(cin >> n){
  	cin >> s;
  	long long ans = 0, r = 0, g = 0, b = 0;
  	
  	for(int i = 0; i<n; i++){
  		if(s[i] == 'R') r++;
  		else if(s[i] == 'G') g++;
  		else b++;
  	}  	
  	ans = r * g * b;  	
  	for(int i = 0; i<n; i++){
  		for(int j = i+1; j<n; j++){
  			int k = j - i + j;
  			if(k < n && s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
				ans--;
		}
  	}
    cout << ans << endl;
  }
	return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

using namespace std;

int main() {

    int A, B, C, X;
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &X);
    int count = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                int x = 500 * i + 100 * j + 50 * k;
                if (x == X) count++;
            }
        }
    }
    printf("%d\n", count);

    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        public static void Main()
        {
            new Program().Solve();
        }

        void Solve()
        {
            var tmp = ReadIntArray();
            int h = tmp[0];
            int w = tmp[1];
            int d = tmp[2];
            var dict = new Dictionary<int, Position>();
            for (int i = 0; i < h; i++)
            {
                tmp = ReadIntArray();
                for (int j = 0; j < tmp.Length; j++)
                {
                    dict.Add(tmp[j], new Position(j, i));
                }
            }

            var total = new Dictionary<int, int>();
            for (int i = 1; i <= h * w; i++)
            {
                total.Add(i, 0);
            }

            for (int i = 1; i <= d; i++)
            {
                total[i] = 0;
                for (int next = i + d; next <= h * w; next += d)
                {
                    var diff = GetPower(dict[next - d], dict[next]);
                    total[next] = total[next - d] + diff;
                }
            }

            int q = int.Parse(Console.ReadLine());
            for (int i = 0; i < q; i++)
            {
                tmp = ReadIntArray();
                Console.WriteLine(total[tmp[1]] - total[tmp[0]]);
            }
        }

        int[] ReadIntArray()
        {
            return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        }

        int GetPower(Position a, Position b)
        {
            return Math.Abs(a.X - b.X) + Math.Abs(a.Y - b.Y);
        }

        struct Position
        {
            public int X { get; set; }
            public int Y { get; set; }
            public Position(int x, int y)
            {
                X = x;
                Y = y;
            }
        }
    }
}


Measured memory_bytes: 28216
#include <iostream>
#include <algorithm>
#include <iterator>
#include <iomanip>
#include <cmath>
#include <vector>
#include <numeric>
#include <cstdio>
#include <bitset>
#include <map>


using namespace std;

typedef vector<int> Row;
typedef vector<Row> Table;
int main()
{
    int r, c;
    cin >> r >> c;

    Table sheet(r+1, Row(c+1));

    //method 1
    // for (int i = 0; i < r; i++)
    //     for (int j = 0; j < c; j++)
    //     {
    //         cin >> sheet[i][j];
    //         sheet[i][c] += sheet[i][j];         
    //     }



    // for (int j = 0; j <= c; j++)
    //     for (int i = 0; i < r; i++)
    //     {
    //         sheet[r][j] += sheet[i][j];            
    //     }   


    // for (int i = 0; i <= r; i++)
    // {
    //     for (int j = 0; j <= c; j++)
    //     {
    //         cout << sheet[i][j] << (j==c? "": " ");       
    //     }
    //     cout << endl;        
    // }


    //method 2
    // for (int i = 0; i < r; i++)
    //     for (int j = 0; j < c; j++)
    //     {
    //         cin >> sheet[i][j];
    //         sheet[i][c] += sheet[i][j];
    //         sheet[r][j] += sheet[i][j];
    //         sheet[r][c] += sheet[i][j];                      
    //     }

    // for (int i = 0; i <= r; i++)
    // {
    //     for (int j = 0; j <= c; j++)
    //     {
    //         cout << sheet[i][j] << (j==c? "": " ");       
    //     }
    //     cout << endl;        
    // }


    //method 3
    for (int i = 0; i <= r; i++)
    {
        for (int j = 0; j <= c; j++)
        {
            if (i!=r && j!=c)
            {
            cin >> sheet[i][j];
            sheet[i][c] += sheet[i][j];
            sheet[r][j] += sheet[i][j];
            sheet[r][c] += sheet[i][j];                
            }
            cout << sheet[i][j] << (j==c? "": " ");                       
        }
        cout << endl;         
    }



        
}


Measured memory_bytes: 3132
#include <stdio.h>

void swap(int *i, int *j)
{
	*i += *j;
	*j = *i - *j;
	*i -= *j;
}

int main(void)
{
	int score[100];
	int i, j;
	int a, b, c, d;
	int n;
	int no[100];
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		score[i] = no[i] = 0;
	}
	
	for (i = 0; i < n * (n - 1) / 2; i++){
		scanf("%d %d %d %d", &a, &b, &c, &d);
		
		if (c == d){
			score[a - 1]++;
			score[b - 1]++;
		}
		else if (c < d){
			score[b - 1] += 3;
		}
		else {
			score[a - 1] += 3;
		}
		no[a - 1] = score[a - 1];
		no[b - 1] = score[b - 1];
	}
	
	for (i = 0; i < n; i++){
		for (j = i + 1; j < n; j++){
			if (score[i] < score[j]){
				swap(&score[i], &score[j]);
			}
		}
	}
	
	for (i = n - 1; i >= 0; i--){
		if (score[i] == score[i - 1]){
			score[i] = -1;
		}
	}
	
	for (i = 0; i < n; i++){
		for (j = 0; j < n; j++){
			if (no[i] == score[j]){
				printf("%d\n", j + 1);
			}
		}
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

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

int main(){
  int a,b;
  cin >> a >> b;
  int sum = a+b;
  int mai = a-b;
  int kake = a*b;
  cout << max({sum,mai,kake}) << endl;
} 

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

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

        int N = sc.nextInt();
        int M = sc.nextInt();
        int[][] A = new int[N][];
        for (int i = 0; i < A.length; ++i) {
            int K = sc.nextInt();
            A[i] = new int[K];
            for (int j = 0; j < A[i].length; ++j) {
                A[i][j] = sc.nextInt();
            }
        }

        System.out.println(solve(A, M));

        sc.close();
    }

    static int solve(int[][] A, int M) {
        int[] counts = new int[M];
        for (int[] Ai : A) {
            for (int Aij : Ai) {
                ++counts[Aij - 1];
            }
        }

        return (int) Arrays.stream(counts).filter(count -> count == A.length).count();
    }
}

Measured memory_bytes: 38668
#include<cstdio>
#include<algorithm>
#include<queue>
#include<functional>
using namespace std;
const int MAX = 100000 + 10;
int rec[MAX];
priority_queue<int, vector<int>, greater<int>> q;

int main() {
    int n, m;

    scanf("%d %d", &n, &m);
    for(int i = 0 ; i < m ; i++) {
        scanf("%d", &rec[i]);
    }
    sort(rec, rec+m);
    for(int i = 1 ; i < m ; i++) {
        q.push(rec[i] - rec[i-1]);
    }
    
    int ans = 0;
    while(q.size() >= n) {
        ans += q.top();
        q.pop();
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1276