akhauriyash/Code-Regression huggingface dataset:
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List as List


solve :: Int -> Int -> Int -> Int -> Bool
solve a b c n
    | m == c = True
    | n > b = False
    | otherwise = solve a b c (n + 1)
    where
        m = (a * n) `mod` b

toYesNo :: Bool -> String
toYesNo True = "YES"
toYesNo _ = "NO"


main :: IO()
main = do
    (a:b:c:_) <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    putStrLn $ toYesNo (solve a b c 1)   

Measured memory_bytes: 380
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N;
	cin >> N;
	string c;
	cin >> c;

	int ans = 0;

	int l = 0;
	int r = N - 1;
	while (l < r) {
		while (l < N && c[l] != 'W') {
			++l;
		}
		while (r >= 0 && c[r] != 'R') {
			--r;
		}
		if (l >= N || r < 0 || l >= r) {
			break;
		}
		swap(c[l], c[r]);
		++ans;
		++l;
		--r;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3724
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[0].split(" ").map(Number)
    if (data[1] - data[0] === 0) {
        console.log('Yes')
    } else {
        console.log('No')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include<stdio.h>
#include<algorithm>
#include<utility>
using namespace std;
int n;
pair<int,int> a[111111];
int main(){
	scanf("%d",&n);
	for(int i=0; i<n; i++){
		scanf("%d",&a[i].first);
		a[i].second=i;
	}
	sort(a,a+n);
	int res=0;
	for(int i=0; i<n; i++)
		if(a[i].second%2!=i%2)
			res++;
	printf("%d\n",res/2);
	return 0;
}

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

struct TCoordinate
{
	double x;
	double y;
};

double GetCrossProduct(const TCoordinate& V1, const TCoordinate& V2)
{
	return V1.x * V2.y - V1.y * V2.x;
}

bool IsSameSide(const TCoordinate& T1, const TCoordinate& T2, const TCoordinate& L1, const TCoordinate& L2)
{
	TCoordinate VectorL1T1 = {T1.x - L1.x, T1.y - L1.y};
	TCoordinate VectorL1T2 = {T2.x - L1.x, T2.y - L1.y};
	TCoordinate VectorL1L2 = {L2.x - L1.x, L2.y - L1.y};
	return GetCrossProduct(VectorL1T1, VectorL1L2) * GetCrossProduct(VectorL1T2, VectorL1L2) > 0;
}

int main()
{
	while(true){
		TCoordinate A1, A2, A3, Ap;
		cin >> A1.x >> A1.y >> A2.x >> A2.y >> A3.x >> A3.y >> Ap.x >> Ap.y;
		if(cin.eof() == true) break;
		if(IsSameSide(A3, Ap, A1, A2) && IsSameSide(A1, Ap, A2, A3) && IsSameSide(A2, Ap, A3, A1)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
    
int main(){
  int n;
  double t,a;
  cin >> n >> t >> a;
  
  double T[n];
  rep(i,n){
    double h;
    cin >> h;
    T[i] = t-(h*0.006);
  }
  
  int ans = 0;
  rep(i,n) {
    if(abs(T[i]-a) < abs(T[ans]-a)) ans = i;
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import collections
n=int(input())
dp=collections.Counter(int(x) for x in input().split())
m=int(input())
tp=collections.Counter(int(x) for x in input().split())
ans="YES"
for k,v in tp.items():
    if dp[k]<v:
        ans="NO"
        break
print(ans)

Measured memory_bytes: 67808
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail
{
  template <typename T, std::size_t NDIMS>
  struct vector_builder
  {
    using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
      if (!dims.empty())
        dims.pop_back();
      return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
    }
  };

  template <typename T>
  struct vector_builder<T, 1>
  {
    using type = std::vector<T>;

    static type make(std::vector<std::size_t> dims, const T &v = {})
    {
      return type(dims.empty() ? 0 : dims.back(), v);
    }
  };
} // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T &v, SIZE_T... dims)
{
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T &data, vector<int> &iter)
{
  cout << data << " ";
}
template <typename T>
void dump(const vector<T> &data, vector<int> &iter)
{
  for (auto elem : data)
    dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>> &data, vector<int> &iter)
{
  for (auto elem : iter)
  {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++)
  {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T> &data, int dummy)
{
  for (int i = 0; i < data.size(); i++)
  {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T &data)
{ // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long L)
{
  double v = L;
  cout << v * v * v / 27 << endl;
}

int main()
{
  cout << setprecision(10);
  long long L;
  scanf("%lld", &L);
  solve(L);
  return 0;
}


Measured memory_bytes: 256
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][m];
        int[] sums = new int[m+1];
        
        for(int i=0; i < n; i++){
            for(int j=0; j < m; j++){
                a[i][j] = sc.nextInt();
            }
        }
        
        int sum = 0;        
        int total = 0;
        
        for(int i=0; i < n; i++){
            for(int j=0; j < m; j++){
                
                System.out.print(a[i][j] +" ");
                sum += a[i][j];
                
                if(j == m-1){
                    System.out.println(sum);
                    sum = 0;
                }
                
                sums[j] += a[i][j];
             
            }
        }
        
        for(int i=0; i<sums.length -1; i++){
            System.out.print(sums[i] + " ");
            total += sums[i];
        }
        
        System.out.println(total);
        
    }
}





Measured memory_bytes: 42100
N = int(input())
S = input()
P, Q = [], [] 
t = 0
for i in range(N-2):
  if S[i] not in P:
    P.append(S[i]) 
    for j in range(i+1, N-1):
      if S[j] not in Q:
        Q.append(S[j])
        t += len(set(S[j+1:]))
    Q.clear()
print(t)

Measured memory_bytes: 9192
N = int(input())
s = input()

def LieDetector(SW):
    SW = [SW[0]]+[0]*N+[SW[1]]
    for i in range(N):
        if s[i]=='o':
            if SW[i-1]=='S':
                if SW[i]=='S':
                    SW[i+1]='S'
                else:
                    SW[i+1]='W'
            else:
                if SW[i]=='S':
                    SW[i+1]='W'
                else:
                    SW[i+1]='S'
        else:
            if SW[i-1]=='S':
                if SW[i]=='S':
                    SW[i+1]='W'
                else:
                    SW[i+1]='S'
            else:
                if SW[i]=='S':
                    SW[i+1]='S'
                else:
                    SW[i+1]='W'
    return SW[0]==SW[N] and SW[N-1]==SW[N+1],SW

SW = [['S','S'],['S','W'],['W','S'],['W','W']]
for x in SW:
    ans = LieDetector(x)
    if ans[0]:
        break
if ans[0]:
    print(''.join(ans[1][:-2]))
else:
    print(-1)

Measured memory_bytes: 6356
//** aman**/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define dl          double
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define lb lower_bound
#define ub upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main(){
	int n,x;cin>>n>>x;
	int a[n];
	for(int i=0;i<n;i++)cin>>a[i];
	if(n==1)return cout<<abs(a[0]-x),0;
	sort(a,a+n);
	vi vv;
	for(int i=1;i<n;i++)vv.pb(a[i]-a[i-1]);
	int X=x-a[0];
	vi v;
	for(int i=1;i*i<=X;i++){
		if(X%i==0){
			v.pb(i);
			if(X/i!=i)v.pb(X/i);
		}
	}
	sort(all(v));
	reverse(all(v));
	for(int i=0;i<v.size();i++){
		int cnt=0;
		for(int j=0;j<vv.size();j++){
			if(vv[j]%v[i]==0)cnt++;
		}
		if(cnt==vv.size())return cout<<v[i],0;
	}
}

Measured memory_bytes: 1276
import Data.Ratio

solve :: Int -> Int -> Int -> Int
solve a b i
    | i > 1000 = -1
    | x && y = i
    | otherwise = solve a b (i+1)
        where
            x = (floor $ (i * 8) % 100) == a
            y = (floor $ (i * 10) % 100) == b

main = do
    [a,b] <- map read . words <$> getLine :: IO [Int]
    print $ solve a b 1

Measured memory_bytes: 1020
n, m = map(int, input().split())
bridge = list()

for i in range(0, m):
    a, b = map(int, input().split())
    bridge.append([a - 1, b - 1])

bridge = bridge[1:]
bridge = reversed(bridge)
result = []


parent = [-1] * n
size = [1] * n
def root(v):
    p = parent[v]
    if p >= 0:
        return root(p)
    return v

value = n * (n - 1) // 2
result.append(value)

for b in bridge:
    if value <= 0:
        result.append(0)
        continue
    p0 = root(b[0])
    p1 = root(b[1])
    if p0 == p1:
        result.append(value)
        continue
    s0 = size[p0]
    s1 = size[p1]
    if p0 < p1:
        parent[p1] = p0
        size[p0] += size[p1]
    else:
        parent[p0] = p1
        size[p1] += size[p0]
    value -= s0 * s1
    result.append(max(value, 0))

result = reversed(result)
for r in result:
    print(r)

Measured memory_bytes: 26000
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 2e5 + 5;
const int M = 1e5 + 5;
const ll OO = 1e18;
const int mod = 1e9 + 7;

int n,a[N],b[N];
vector<int> d[N];
deque<int> ans;
bool flag;

void seive() {

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

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

            d[j].pb(i);

        }

    }

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;

    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }
    
    seive();

    for (int i = n; i >= 1; --i) {

        if(b[i]!=a[i]) {

            for(auto divisor: d[i]) {

                b[divisor] ^= 1;

            }

            ans.push_front(i);

        }

    }

    if(flag) {
        cout << "-1\n";
        return 0;
    }

    cout << ans.size() << '\n';

    for(auto i:ans) cout << i << ' ';

    return 0;
}

Measured memory_bytes: 26872
N = int(input())
a = list(map(int,input().split()))

k = 0
ans = 0
for i in range(N):
    k += a[i]
find = k/N
now = 1000000
for i in range(N):
    if abs(a[i]-find) < now - 0.00001:
        ans = i
        now = abs(a[i]-find)
print(ans)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long x = sc.nextLong();

		if (a % x == 0) {
			System.out.print(b / x - a / x + 1);
		} else {
			System.out.print(b / x - a / x);
		}
	}

}

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

int main() {
    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl; 
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll e9 = 1e9;

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

vector<ll> a;
int main() {
    ll n, k, s;
    cin >> n >> k >> s;

    rep(i, k) {
        a.push_back(s);
    }

    for(int i=k; i<n; ++i) {
        if (s == e9) {
            a.push_back(1);
        } else { 
            a.push_back(s+1);
        }
    }

    rep(i, n) {
        cout << a[i] << " ";
    }
    cout << endl;
        
}



Measured memory_bytes: 2292
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
    vector<int> vec(3) ;
    REP(i,3){
        cin >> vec.at(i) ;
    }
    sort(ALL(vec)) ;
    REP(i,2){
        cout << vec.at(i)<<" " ;
    }
    cout <<vec.at(2)<<endl ;

  return 0 ;
}


Measured memory_bytes: 3160
#include <iostream>

int main(int argc, char* argv[])
{
  int K, S;
  std::cin >> K >> S;

  int ans = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      if (S - x - y >= 0 && S - x - y <= K) {
	ans++;
      }
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
//submitted by HimJ
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
const int mxn=1e5+1;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  ll t=1;
  //cin>>t;
    while(t--){
            int n,i;
            cin>>n;
            ll arr[n];
            fr(i,0,n)
            cin>>arr[i];
            ll ps[n];
            partial_sum(arr,arr+n,ps);
            map<ll,ll> cnt;
            ll ans=0;
            if(arr[0]==0)
                ans++;
            cnt[arr[0]]++;
            fr(i,1,n)
            {
                ll temp=ps[i-1];
                ans+=cnt[temp+arr[i]];
              //  cout<<cnt[temp+arr[i]]<<" ";
              //  ans+=cnt[-arr[i]];
                if(temp==-arr[i])
                ans++;
               // cout<<cnt[-arr[i]]<<"\n";
                cnt[ps[i]]++;
            }
            cout<<ans;

    }
  return 0;
  }



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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define present(t, x) (t.find(x) != t.end())
#define sz(a) int((a).size())
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mp make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int n,a[200000];

void inp(){
	cin>>n;
	ll sum[n+1];
	sum[0]=0;
	FOR(i,0,n){
		cin>>a[i];
		sum[i+1]=sum[i]+a[i];
	}
	ll res=0;
	FOR(i,0,n){
		res+=((a[i]%MOD)*((sum[n]-sum[i+1])%MOD))%MOD;
		res%=MOD;
	}
	cout<<res<<endl;
}
int main(){
	inp();
	return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,K; cin >> N >> K;
	vector<int> a(N);
	repp(i,0,N) cin >> a[i];
	vector<int> g(K+1,0);
	repp(i,1,K+1){
		repp(j,0,N){
			if(a[j] > i) break;
			if(!g[i-a[j]]) g[i] = 1;
		}
	}
	cout << (g[K]?"First":"Second") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vvi = vector<vector<int>> ;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, n) for(ll i = 0; i < n; i++)

int main(){
  ll x; cin >> x;

  ll y = 100;

  rep(i, 5000){
    y *= 1.01;
    if(y >= x){cout << i+1 << endl; break;}
  }
}

Measured memory_bytes: 3624
def alphabet_str(string):
    n = len(string)
    dict = ""
    for c in string:
        if dict.find(c) == -1:
            dict += c
    #print(dict)
    return dict


N = int(input())
S = input()

str = list(S)
str1 = ""
str2 = S

max = 0

for i in range(0,N-1):
    sum = 0
    str1 += str[i]
    str2 = str2[1:]
    dict1 = alphabet_str(str1)
    dict2 = alphabet_str(str2)
   # print("{0},{1}".format(dict1,dict2))
    for c in dict1:
        if dict2.find(c) >= 0:
            sum += 1
   # print(sum)
    if sum > max:
        max = sum
print(max)


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;

struct Tree {
  typedef int T;
  static constexpr T unit = 0; // f(unit, b) must equal b
  T f(T a, T b) {
    return max(a,b);
  }
  vector<T> s; int n;
  Tree(int n = 0, T def = unit) : s(2*n, def), n(n) {}
  void update(int pos, T val) {
    for (s[pos += n] = val; pos /= 2;)
      s[pos] = f(s[pos * 2], s[pos * 2 + 1]);
  }
  T query(int b, int e) { // query [b, e)
    T ra = unit, rb = unit;
    for (b += n, e += n; b < e; b /= 2, e /= 2) {
      if (b % 2) ra = f(ra, s[b++]);
      if (e % 2) rb = f(s[--e], rb);
    }
    return f(ra, rb);
  }
};

vi a(212345);
vvi g(212345);
Tree tr(212345);
vi out(212345);

void dfs(int u=1, int p=1) {
  int b4 = tr.query(a[u], a[u]+1);
  int lis = tr.query(0, a[u]);
  int upd = max(lis+1, b4);
  upd = max(upd, 1);
  tr.update(a[u], upd);
  out[u] = upd;
  out[u] = max(out[u], out[p]);
  for (auto v: g[u]) {
    if (v==p) continue;
    dfs(v, u);
  }
  tr.update(a[u], b4);
}

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  rep(i,1,n+1) cin >> a[i];
  set<int> s;
  rep(i,1,n+1) s.insert(a[i]);

  map<int, int> tr;
  int co = 0;
  for (auto x: s) {
    tr[x] = ++co;
  }
  rep(i,1,n+1) a[i] = tr[a[i]];

  rep(i,0,n-1) {
    int u, v;
    cin >> u >> v;
    g[u].pb(v);
    g[v].pb(u);
  }

  dfs();
  rep(i,1,n+1) cout << out[i] << '\n';
}

Measured memory_bytes: 45908
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/03/20 20:34:41
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  map<ll, int> A;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    ll a; cin>>a;
    ans += A[i-a];
    A[i+a]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 26332
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<stack>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;


int main()
{
	int k,s;cin >> k >> s;
	
	
	int ans = 0;
	REP(i,k+1)
	{
		REP(j,k+1)
		{
			if(i+j<=s&&i+j+k>=s)ans++;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

//{{{
#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
#ifdef LOCAL
#include "prettyprint.hpp"
#endif
// clang-format off
void _print() { cerr << "]\033[0m\n"; }
template <typename T> void __print(T x) { cerr << x; }
template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); }
#ifdef LOCAL
#define debug(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m["; _print(x)
#define debug_arr(x...) cerr << "\033[1;34m[" << #x << "] = \033[1;32m" << (x) << "\033[0m\n"
#else
#define debug(x...)
#define debug_arr(x...)
#endif
// clang-format on
//}}}

int T;

const int N = 5e3 + 10;

const LL inf = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;

int n, k;

LL p[N], c[N];
LL sum[N], cnt[N];
bool vis[N];

LL func(int pos)
{
    LL t = k;
    LL ret = 0;

    if (k > 100000 && t > 10 * cnt[pos])
    {
        if (sum[pos] > 0)
        {
            LL d = t / cnt[pos];
            assert(d >= 10);
            d -= 10;
            ret += d * sum[pos];
            t -= cnt[pos] * d;
        }
        else
            t = cnt[pos];
    }

    // if (sum[pos] > 0)
    //{
    // ret += t / cnt[pos] * sum[pos];
    // t = t % cnt[pos];
    //}
    // else
    //{
    // t = t % cnt[pos];
    // if (t == 0) t = cnt[pos];
    //}

    // if (t == 0) return ret;

    int cur = pos;
    LL val = c[p[cur]];
    cur = p[cur];

    LL v = val;
    for (int i = 2; i <= t; i++)
    {
        int nxt = p[cur];
        v += c[nxt];
        val = max(val, v);
        cur = nxt;
    }
    ret += val;

    return ret;
}

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
#endif

    while (cin >> n >> k)
    {
        for (int i = 1; i <= n; ++i) cin >> p[i];
        for (int i = 1; i <= n; ++i) cin >> c[i];

        clr(vis, false);
        for (int i = 1; i <= n; i++)
        {
            if (vis[i] == true) continue;

            set<int> st;
            LL cur = i;
            LL v = c[p[cur]];
            st.insert(p[cur]);

            cur = p[cur];

            for (int a = 2; a <= 2 * n; a++)
            {
                int nxt = p[cur];
                if (st.find(nxt) != st.end())
                {
                    break;
                }
                assert(a < n + 1);
                v += c[nxt];
                st.insert(nxt);
                cur = nxt;
            }

            for (auto idx : st)
            {
                vis[idx] = true;
                cnt[idx] = st.size();
                sum[idx] = v;
            }
        }

        LL ans = func(1);
        for (int i = 2; i <= n; i++)
        {
            LL v = func(i);
            ans = max(ans, v);
        }
        cout << ans << endl;
    }
}


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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N, M;
    cin >> N >> M;
    vll A(N), B(N), C(N);
    vll D(M), E(M), F(M);
    rep(i, N) cin >> A[i] >> B[i] >> C[i];
    rep(i, M) cin >> D[i] >> E[i] >> F[i];

    set<ll> xs = {0}, ys = {0};
    rep(i, N){
        xs.insert(A[i]);
        xs.insert(B[i]);
        ys.insert(C[i]);
    }
    rep(i, M){
        ys.insert(E[i]);
        ys.insert(F[i]);
        xs.insert(D[i]);
    }
    unordered_map<ll, ll> xm, ym;
    vll xv(xs.size()), yv(ys.size());
    ll idx = 0;
    for(ll x : xs){
        xm[x] = idx;
        xv[idx++] = x;
    }
    idx = 0;
    for(ll y : ys){
        ym[y] = idx;
        yv[idx++] = y;
    }

    vector<vector<bool>> m(ys.size()*2, vector<bool>(xs.size()*2, 0));
    rep(i, N) REP(j, xm[A[i]]*2, xm[B[i]]*2+1) m[ym[C[i]]*2][j] = 1;
    rep(i, M) REP(j, ym[E[i]]*2, ym[F[i]]*2+1) m[j][xm[D[i]]*2] = 1;

    ll cx = xm[0]*2, cy = ym[0]*2, a = 0;
    ll xmax = xs.size()*2 - 2, ymax = ys.size()*2 - 2;
    vvll dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    vll ws(xs.size()), hs(ys.size());
    rep(i, xs.size()-1) ws[i] = xv[i+1] - xv[i];
    rep(i, ys.size()-1) hs[i] = yv[i+1] - yv[i];
    queue<pair<ll, ll>> q;
    q.push({cx, cy});
    m[cy][cx] = 1;
    while(!q.empty()){
        auto p = q.front();
        q.pop();
        if(p.first==0 || p.first==xmax || p.second==0 || p.second==ymax){
            cout << "INF" << endl;
            return 0;
        }
        if(p.first%2==1 && p.second%2==1) a += ws[p.first/2] * hs[p.second/2];
        for(auto d : dirs){
            ll nx = p.first + d[0], ny = p.second + d[1];
            if(!m[ny][nx]) q.push({nx, ny}), m[ny][nx] = 1;
        }
    }
    cout << a << endl;
}


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


// 約数の列挙O(√n)
vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> div = divisor(M);
    long long ans = 1;
    for(auto g : div){
        if(M >= g * N)
            ans = max(ans, g);
    }
    cout << ans << endl;
    return 0;
}

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

int ans,n;
int gcd(int i, int j, int k) {
	int res;
	if (i > j) {
		int t = i;
		i = j;
		j = t;
	}
	if (i > k) {
		int t = i;
		i = k;
		k = t;
	}
	if (j > k) {
		int t = j;
		j = k;
		k = t;
	}
	for (register int a = 1; a <= i; ++a)
		if (i % a == 0 && j % a == 0)
			res = a;
	i = res;
	for (register int a = 1; a <=i ; ++a)
		if (i % a == 0 && k % a == 0)
			res = a;
	return res;
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			for (int k = 1; k <=  n; ++k)
				ans += gcd(i, j, k);
		printf("%d", ans);

	return 0;
}



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

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> mp;
  ll res = 0;
  rep(i, n) cin >> v[i];
  rep(i, n) mp[v[i]]++;
  rep(i, n) res += v[i];
  int q;
  cin >> q;
  vector<p> qs(q);
  rep(i, q) cin >> qs[i].first >> qs[i].second;

  for (int i = 0; i < q; ++i) {
    ll from = qs[i].first;
    ll to = qs[i].second;
    ll tmp1 = mp[from] * from;
    ll tmp2 = mp[from] * to;
    res += tmp2 - tmp1;
    cout << res << endl;
    mp[to] += mp[from];
    mp[from] = 0;
    // print(mp);
  }
}


Measured memory_bytes: 9564
# input
I = int(input())
n = []
append = n.append

for i in range(1, I + 1):
    # check
    if i % 3 == 0 and i % 5 == 0:
        # "FizzBuzz"
        pass
    elif i % 3 == 0:
        # Fizz
        pass
    elif i % 5 == 0:
        # Buzz
        pass
    else:
        append(i)

print(sum(n))


Measured memory_bytes: 30032
n=int(input())
if n<10:
  print(n)
else:
  L=list(map(int, list(str(n))))
  if(L.count(9)==len(L)) or (L[0]!=9 and L.count(9)==len(L) -1):
    print(sum(L))
  else :
    print(9*(len(L)-1)+int(L[0])-1)



Measured memory_bytes: 3060
using namespace std;
#include<string>
#include<cmath>
#include <map>
#include <unordered_map>
#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)

#define fr(i,a,b) for(ll i=a;i<b;i++)
#define ffr(i,a,b) for(ll i=a;i>=b;i--)
#include<bits/stdc++.h>
#include<vector>
#define vl vector<ll>
#define PI 3.141592654
const ll N = 1e9 + 1;
#include<iterator>






void solve() {
	ll n;
	cin >> n;
	if (n % 1000)
		cout << (1000 - (n % 1000));
	else cout << 0;
}



int main() {
	fio;
#ifndef ONLINE_JUDGE
	// for getting input
	freopen("input.txt", "r", stdin);
	//for writing output
	freopen("jout.txt", "w", stdout);
#endif

	ll t;
	if (1)
		t = 1;
	else
		cin >> t;
	while (t--) {
		solve();
		cout << '\n';
	}
	return 0;
}

Measured memory_bytes: 3640
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string a[255];
int check(int x, int y, int dx, int dy) {
	int ret = 0;
	while(0 <= x && x < n && 0 <= y && y < n) {
		if(a[y][x] == '0') return ret;
		x += dx, y += dy, ret++;
	}
	return ret;
}
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) cin >> a[i];
		int ret = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				for(int k = 0; k <= 3; k++) {
					ret = max(ret, check(j, i, k / 3 - 1, k % 3 - 1));
				}
			}
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3220
#include <stdio.h>

const int num = 10;

int ret_max_index(int input[]);

int main()
{

	int input[10] = {0};
	int index      = 0;
	int st_index   = 0;
	int height_max = 0;
	int height_2nd = 0;
	int height_3rd = 0;

	for ( index=0; index<num; index++ ) {
		// 0 < input < 10000
		scanf("%5d", &(input[index]));
	}

	st_index   = ret_max_index(input);
	height_max = input[st_index];
	input[st_index] = 0;

	st_index   = ret_max_index(input);
	height_2nd = input[st_index];
	input[st_index] = 0;

	st_index   = ret_max_index(input);
	height_3rd = input[st_index];
	input[st_index] = 0;

	printf("%d\n", height_max);
	printf("%d\n", height_2nd);
	printf("%d\n", height_3rd);
	
    return 0;
}


int ret_max_index(int input[])
{
	int index = 0;
	int stored_index = 0;
	int max = 0;
	
	for ( index=0; index<num; index++ ) {
		if ( max < input[index] ) {
			max = input[index];
			stored_index = index;
		}
	}

	return stored_index;
}

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

using namespace std;

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

  int n, m, x, a;
  cin >> n >> m >> x;
  vector<int> A(n, 0);
  for (int i = 0; i < m; ++i) {
    cin >> a;
    A[a] = 1;
  }

  int res1 = 0, res2 = 0;
  for (int i = 0; i < x; ++i) res1 += A[i];
  for (int i = x; i < n; ++i) res2 += A[i];
  cout << min(res1, res2) << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a;
	char b[20];
	scanf("%d",&a);
	getchar();
	scanf("%s",b);
	if(a<3200){
		printf("red\n");
	}else{
		printf("%s\n",b);
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
vector<T> enum_div(T n){
    vector<T> ret;
    for(T i=1;i*i<=n;i++){
        if(n%i==0){
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n/i);
        }
    }
    //sort(ret.begin(), ret.end());
    return ret;
}

template<typename T>
bool is_Prime(T n){
    if(n==1) return false;
    for(T i=2;i*i <= n;i++)
        if(n%i==0) return false;
    return true;
}

bool is_prime[1000000000];
template<typename T>
vector<T> enum_Prime(T n){
    vector<T> ret;
    for(int i=2;i<=n;i++) is_prime[i] = true;
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            if(n%i==0) ret.push_back(i);
            for(int j=2*i;j<=n;j+=i) is_prime[j] = false;
        }
    }
    return ret;
}

ll A, B;
int main(void){
    cin >> A >> B;
    ll C = gcd(A, B);
    vector<ll> V = enum_div(C);
    ll count = 0;
    for(auto i:V){
        if(is_Prime(i)) count++;
    }

    cout << 1 + count << endl;
    return 0;
}



Measured memory_bytes: 384
taro = hanako = 0
gets.to_i.times do
    card = gets.split
    if card[0] < card[1]
        hanako += 3
    elsif card[0] == card[1]
        taro += 1;hanako += 1
    else
        taro += 3
    end
end
puts "#{taro} #{hanako}"


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

#define pb push_back
#define pop_b pop_back
#define pf push_front
#define pop_f pop_front

typedef long long int ll;
typedef pair<int, int> ii; // are aligned to the right like this
typedef vector<ii> vii;  //vector pair
typedef vector<int> vi;   //vector integer
typedef vector<string> vs; //vector string


int main() 
{
    int n;
    cin>>n;
    int a[n][2];
    for(int i=0;i<n;i++)
    {
        cin>>a[i][0]>>a[i][1];
    }
    int c=0,x=1;
    for(int i=0;i<n;i++)
    {
        if(a[i][0]==a[i][1])
        {
            c++;
        }
        else
        {
            if(c>=3)
            {
                cout<<"Yes";
                x=0;
                break;
            }
            c=0;
        }
        
    }
    if(x==1 && c<3)
        cout<<"No";
    else if(x==1)
        cout<<"Yes";
}
 

/*
0
0
2
2
3
*/

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

int main(){
  long long N,K,key=0;
  cin>>N>>K;
  vector<pair<int,int> >v(N);
  for(int i=0;i<N;i++){
    cin>>v[i].first>>v[i].second;
  }
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++){
    key+=v[i].second;
    if(key>=K){
      cout<<v[i].first<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
from collections import Counter
n = int(input())
s = []
for i in range(n) :
  str = input()
  s.append(''.join(sorted(str)))
  
sd = Counter(s)

ans = 0
for v in sd.values():
    if v != 1 :
      ans += int(v*(v-1)*0.5)

print(ans)

Measured memory_bytes: 19820
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int u = 1;

    for(int i = 0; i < n; i++){
        int t,x,y;
        cin >> t >> x >> y;
        if(t < x + y){
            u = 0;
        }
        if(t % 2 == 0){
            if((x + y) % 2 != 0){
                u = 0;
            }
        }else{
            if((x + y) % 2 == 0){
                u = 0;
            }
        }
    }
    if(u == 1){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

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

int main(void){
	int n;
	int a[100000]={0};
	int i;
	long long int ans[100000]={0};
	int sum;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(i!=0){
			sum+=abs(a[i]-a[i-1]);
		}else{
			sum+=abs(a[i]);
		}
		if(i==n-1){
			sum+=abs(a[i]);
		}
	}
	for(i=0;i<n;i++){
		if(i==0){
			ans[i]=sum-(abs(a[i+1]-a[i])+abs(a[i]))+abs(a[i+1]);
		}else if(i==n-1){
			ans[i]=sum-(abs(a[i-1]-a[i])+abs(a[i]))+abs(a[i-1]);
		}else{
			ans[i]=sum-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]);
		}
	}
	for(i=0;i<n;i++){
		printf("%lld\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 2304
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <functional>
using namespace std;

typedef pair<int,int> pii;

int solve(int n, int m, int L, int k){
	int u, v, c, start, goal, b;
	vector<vector<pii> > G(n + 2);
	for(int i = 0; i < m; ++i){
		scanf("%d%d%d", &u, &v, &c);
		G[u].push_back(pii(c, v));
		G[v].push_back(pii(c, u));
	}
	scanf("%d%d", &start, &goal);
	G[0].push_back(pii(0, start));
	G[goal].push_back(pii(0, n + 1));

	vector<int> bnum(n + 2, -1);
	vector<int> use((n + 2) << L, 0);
	for(int i = 0; i < L; ++i){
		scanf("%d", &b);
		bnum[b] = i;
	}

	goal = ((n + 2) << L) - 1;


	priority_queue<pii,vector<pii>,greater<pii> > pq;
	vector<vector<int> > ds((n + 2) << L);
	pq.push(pii(0, 0));
	ds[0].push_back(0);
	while(!pq.empty()){
		pii p = pq.top();
		pq.pop();
		int d = p.first;
		int st = p.second;
		int now = st >> L;
		b = st & ((1 << L) - 1);

		if(use[st] >= ds[st].size() || ds[st][use[st]] != d){
			continue;
		}
		++use[st];

		for(size_t i = 0; i < G[now].size(); ++i){
			int next = G[now][i].second;
			int nd = d + G[now][i].first;
			int nb = b;
			if(bnum[next] != -1){
				nb |= 1 << bnum[next];
			}

			int nst = next << L | nb;
			int ord = upper_bound(ds[nst].begin(), ds[nst].end(), nd)
				- ds[nst].begin();

			ds[nst].push_back(0);
			for(int j = ds[nst].size() - 1; j > ord; --j){
				ds[nst][j] = ds[nst][j - 1];
			}
			ds[nst][ord] = nd;
			if(ds[nst].size() > k){
				ds[nst].pop_back();
			}

			if(ord != k){
				pq.push(pii(nd, nst));
			}
		}
	}

	return ds[goal].size() == k ? ds[goal].back() : -1;
}

int main(){
	int n, m, L, k;
	while(scanf("%d%d%d%d", &n, &m, &L, &k), n){
		int ans = solve(n, m, L, k);
		printf(ans < 0 ? "NA\n" : "%d\n", ans);
	}
}

Measured memory_bytes: 3108
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N; cin>>N;
  vector<pair <string, pair <ll,ll> > > v(N);

  rep(i,N) cin >> v[i].first >> v[i].second.first;
  rep(i,N) v[i].second.second = i + 1;
  rep(i,N) v[i].second.first = -v[i].second.first;

  SORT(v);
  rep(i,N) cout << v[i].second.second << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <math.h>
#include <stdio.h>
#define INF 1e9
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
struct station{
	double x;
	double y;
	double z;
	double r;
};
double a[101][101];
double d[101];
int p[101];
int color[101]; 
int n;

double solve(){
	double  res = 0;
	for(int i = 0;i < n;i++){
		d[i] = INF;
		color[i] = WHITE;
	}
	d[0] = 0;
	p[0] = -1;
	int u;
	while(1){
		double mincost = INF;
		for(int i = 0;i < n;i++){
			if(mincost > d[i] && color[i] != BLACK){
				mincost = d[i];
				u = i;
			}
		}
		if(mincost == INF)break;
		color[u] = BLACK;

		for(int v = 0;v < n;v++){
			if(color[v] != BLACK){
				if(a[u][v] < d[v]){
					d[v] = a[u][v];
					p[v] = u;
					color[v] = GRAY;
				}
			}
		}
	}
	for(int i = 0;i < n;i++)res += d[i];
	return res;
}
int main(){
	station sta[101];
	while(1){
		cin >> n;
		if(n == 0)break;
		for(int i = 0;i < n;i++){
			cin >> sta[i].x >> sta[i].y >> sta[i].z >> sta[i].r;
		}
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				if(i == j)a[i][j] = 0;
				a[i][j] = pow((sta[i].x - sta[j].x)*(sta[i].x - sta[j].x) + (sta[i].y - sta[j].y)*(sta[i].y - sta[j].y) + (sta[i].z - sta[j].z)*(sta[i].z - sta[j].z),0.5) - sta[i].r - sta[j].r;
				if(a[i][j] < 0)a[i][j] = 0;
			}
		}
		printf("%.3f\n",solve());
	}	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;
string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
cout.precision(10);

    string s;cin>>s;

    reverse(s.begin(),s.end());
    for(int i = 0;i<4;i++)
    {
        reverse(divide[i].begin(),divide[i].end());
    }

    bool can = true;
    for(int i = 0;i<s.size();)
    {
        bool can2 = false;
        for(int j = 0;j<4;j++)
        {
            string d = divide[j];
            if(s.substr(i,d.size()) == d)
            {
                can2 = true;
                i += d.size();
            }
        }
        if(!can2)
        {
            can = false;
            break;
        }
    }

    if (can)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <vector>
#include <cstring>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <map>
#include <stack>
#include <cmath>
#define LL long long 
using namespace std;

const int mod = 1e9+7;

string s;
int n,num;
int main()
{
	long long ans=1;
    int i,j,k;
    scanf("%d",&n);
    cin>>s;
    for(i=0;i<2*n;i++)
    {
    	if(!(((s[i]=='W')^num)&1))
	 		num++;
        else
		{ 
			ans=1ll*ans*num%mod;
			num--;
		}
	}
    if(num)
		cout<<"0\n";
	else
	{
		for(i=1;i<=n;i++)
			ans=1ll*ans*i%mod;
	    cout<<ans<<"\n";	
	}
}




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

typedef long long int   ll;
#define f(i,st,en)    for(int i=st;i<en;i++)
#define s(n)            scanf("%d",&n)
#define sc(n)           scanf("%c",&n)
#define sl(n)           scanf("%lld",&n)
#define sf(n)           scanf("%lf",&n)

using namespace std;


int main(){
    int n,m;
    cin>>n>>m;
    int sum=0;
    for(int i=0;i<m;i++){
        int x;
        cin>>x;
        sum+=x;
    }
    if(sum>n)cout<<-1;
    else cout<<n-sum;
}


Measured memory_bytes: 3608
#coding : utf8

string_list = [input().split() for i in range(2)]
arrayli = list(map(int,string_list[1]))

count = 0
flag = 0
for i in arrayli:
    for j in range(1,500000001):
        if( (i % pow(2,j)) == 0):
            count +=1
        else:
            break

print(count)


Measured memory_bytes: 4148
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	char now='a';
	int na,nb,nc;
	na=nb=nc=0;
	while(1){
		if(now=='a'){
			if(na==(a.size())){cout<<'A'<<endl;break;}
			now=a[na];
			na++;
		}else if(now=='b'){
			if(nb==(b.size())){cout<<'B'<<endl;break;}
			now=b[nb];
			nb++;
		}else if(now=='c'){
			if(nc==(c.size())){cout<<'C'<<endl;break;}
			now=c[nc];
			nc++;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int n, m, a, b, s[200005] = {};
	scanf("%d", &n);
	if (n % 111 == 0) {
		printf("%d", n);
		return 0;
	}
	m = n % 111;
	printf("%d", n+111-m);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int MAX_N = 2*(int)1e5 + 1;

map<int,int> D;

int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	D.clear();
	rep (i, N){
		int d; cin >> d;
		++D[d];
	} // end rep
	
	int M; cin >> M;
	rep (j, M){
		int t; cin >> t;
		--D[t];
	} // end rep


	bool ok = true;
	map<int,int>::iterator it = D.begin();
	for (; it != D.end(); ++it){
		int d = (*it).first;
		int c = (*it).second;
		if (c < 0){
			ok = false;
			break;
		} // end if
	} // end for

	cout << (ok ? "YES" : "NO") << endl;

	return 0;
}

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

void call(int n)
{
	int i = 1;
	do {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
			continue;
		}

		do {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		} while ( x );

	} while(++i <= n);
	cout << endl;
}

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

	return 0;
}

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

int main() {

  int N, K;
  cin >> N >> K;

  int num = 1;

  for (int i = 0; i < N; i++) {
    if ((num * 2) < (num + K)) {
      num *= 2;
    }
    else {
      num += K;
    }
  }

  cout << num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int N;
    cin >> N;

    int a[N]={};
    
    rep(i,0,N) {
        cin >> a[i];
    }

    bool ans;

    bool tmp = true;
    int target = 0;
    int num = 0;
    set<int> S;
    S.insert(0);
    while(tmp) {
        num++;
        target = a[target];
        if (S.count(target-1)) {
            ans = false;
            tmp = false;
        }
        if (target == 2) {
            ans = true;
            tmp = false;
        }
        target--;
        S.insert(target);
    }

    if (ans) {
        cout << num << endl;
    }

    else {
        cout << -1 << endl;
    }
}



Measured memory_bytes: 5376