akhauriyash/Code-Regression huggingface dataset:
import bisect

n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0

for i in range(n):
    for j in range(i + 1, n):
        bise = bisect.bisect_left(l, l[i] + l[j])
        if bise > j:
            ans += bise - (j + 1)
        else:
            pass

print(ans)


# import bisect
#
# N = int(input())
# Ls = list(map(int, input().split()))
# Ls.sort()
#
# # O(N^2 * logN)の全探索で解く
# ans = 0
# for a_i in range(N):
#     for b_i in range(a_i+1, N):
#         c_i = bisect.bisect_left(Ls, Ls[a_i]+Ls[b_i]) # 左側に境界がある右側のインデックスが帰ってくる
#         if c_i > b_i:
#             ans += c_i - b_i - 1
#         else:
#             pass
#
# print(ans)

# from itertools import combinations
# import numpy as np
#
# n = int(input())
# hoge = list(map(int, input().split()))
# hoge.sort()
#
# # hoge = np.sort(l)
# ll = []
# ans = 0
#
# def triangle(target, v1, v2):
#     return target < v1 + v2
#
# for i in range(len(hoge)):
#     for j in range(i + 1, len(hoge)):
#         left = hoge[j]
#         right = hoge[-1] + 1
#         while left + 1 < right:
#             mid = (left + right) / 2
#             if triangle(mid, hoge[i], hoge[j]):
#                 ans += len(hoge[hoge >= mid])
#                 break
#             else:
#                 left = mid
#
# print(ans)

"""3回目
# 事前の各要素xより大きい要素個数を求める
for v in hoge:
    ll.append([v, len(hoge[v <= hoge])])

# 事前にコンビネーションを確保する。ループはしない！
combi = np.array([[sum(v), v[1]] for v in combinations(hoge, 2)])

print(combi)
print(combi[:, 0])
print(ll)

# 要素のループをもう一度回し、各
for v, cnt in ll:
    print(v, cnt, len(combi[(v < combi[:, 0]) & (combi[] < v)]), sep=',')
    ans += cnt * len(combi[v < combi])

print(ans)

"""


"""2回目 comnbinationループがだめ
for v in combinations(hoge, 2):
    s = sum(v)
    ans += len(hoge[(v[1] < hoge) & (hoge < s)])

"""



"""1
これだとTLEが出る
combinationの全パターンを数え上げると遅すぎる
ソート済み配列 × なにかで組み合わせを数え上げる必要

from itertools import combinations

n = int(input())
l = map(int, input().split())

ans = 0

for v in combinations(l, 3): # combination を使ってループした時点ででn^2
    if v[0] < v[1] + v[2] and v[1] < v[0] + v[2] and v[2] < v[0] + v[1]:
        ans += 1

print(ans)
"""


Measured memory_bytes: 3188
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
void solve(){
    int x;
    cin >> x;
    int num = 0;
    if(x >= 2000){
        cout << 1 << endl;
    }
    else{
        num = x / 100;//商品の個数
        if(x % 100 <= 5 * num){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
}
int main(){
    solve();
    return 0;
}


Measured memory_bytes: 384
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut g: Vec<Vec<usize>> = vec![vec![]; n];
    let mut e = std::collections::HashMap::new();
    for i in 0..(n - 1) {
        let (a, b): (usize, usize) = parse!(it, 2);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
        e.insert((a - 1, b - 1), i);
        e.insert((b - 1, a - 1), i);
    }
    let m: usize = parse!(it);
    let get_path = |i: usize, j: usize| -> usize {
        let mut stack = vec![(i, 0)];
        let mut seen = vec![false; n];
        while let Some((u, mut path)) = stack.pop() {
            for &v in &g[u] {
                if !seen[v] {
                    seen[v] = true;
                    let path = path | 1 << e[&(u, v)];
                    if v == j {
                        return path;
                    }
                    stack.push((v, path));
                }
            }
        }
        unreachable!()
    };

    let mut paths = vec![];
    for _ in 0..m {
        let (a, b): (usize, usize) = parse!(it, 2);
        paths.push(get_path(a - 1, b - 1));
    }

    let mut whites = 0i64;
    for i in 1usize..(1 << m) {
        let positive = i.count_ones() % 2 == 1;
        let mut path = 0;
        for j in 0..m {
            if (i >> j) & 1 == 1 {
                path |= paths[j];
            }
        }
        whites += 2usize.pow((n - 1 - path.count_ones() as usize) as u32) as i64
            * if positive { 1 } else { -1 };
    }
    println!("{}", 2usize.pow((n - 1) as u32) - (whites as usize));
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        5
        1 2
        3 2
        3 4
        5 3
        3
        1 3
        2 4
        2 5
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
n,m=map(int,input().split())
stu=[]
poi=[]
for i in range(n):
    a,b=map(int,input().split())
    stu.append([a,b])
for i in range(m):
    a,b=map(int,input().split())
    poi.append([a,b])
for i in stu:
    ans=float("inf")
    ans_index=0
    ans_lis=[abs(i[0]-j[0])+abs(i[1]-j[1]) for j in poi]
    print(ans_lis.index(min(ans_lis))+1)

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    vector<string> s(3);
    for (int i = 0; i < 3; i++) cin >> s[i];
    for (int i = 0; i < 3; i++) cout << (char)(s[i].front() + 'A' - 'a');
    cout << '\n';
    return 0;
}


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

int main(void){
    int n, m, f = 0;
    vector<int> x;
    vector<int> a;

    cin >> n;
    x.resize(n);
    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    cin >> m;
    a.resize(m);
    for(int i = 0; i < m; i++){
        cin >> a[i];
    }

    for(int i = 0; i < m; i++){
        f = 0;
        if(x[a[i] - 1] + 1 != 2020){
            for(int j = 0; j < n; j++){
                if(x[a[i] - 1] + 1 == x[j]) f = 1;
            }
        }else{
            f = 1;
        }
        if(f == 0) x[a[i] - 1]++;
    }

    for(int i = 0; i < n; i++){
        cout << x[i] << endl;
    }

}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
const double PI = acos(-1);
int main()
{
    vector<int> h, w;
    int _h, _w;
    while (1)
    {
        cin >> _h >> _w;
        if (_h == 0 && _w == 0)
        {
            break;
        }
        h.push_back(_h);
        w.push_back(_w);
    }
    int n = h.size();
    rep(i, n)
    {
        string rect = "";
        rep(y, h[i])
        {
            rep(x, w[i])
            {
                rect += "#";
            }
            rect += "\n";
        }
    cout<<rect<<endl;        
    }
 //   system("pause");
    return 0;
}


Measured memory_bytes: 3184
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    int n,ans=0;
    vector<string> v;
    string c ="aaaaaaaaaaaaaa";
    string s;
    cin >> n;
    rep(i,n){
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    // rep(i,n){
    //     cout << v[i]<<endl;
    // }
    rep(i,n){
        if(c!=v[i]){
            ans ++;
        }
        c=v[i];
    }
    cout << ans << endl;
}


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

using namespace std;

#define int long long

const int INF = 1e18;

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

    int n;
    cin >> n;
    vector <int> a(n);
    for (int& it : a) {
        cin >> it;
    }
    vector <int> pref(n + 1, 0);
    for (int i = 1; i <= a.size(); ++i) {
        pref[i] = pref[i - 1] + a[i - 1];
    }
    int ans = INF;
    for (int i = 1; i + 2 < n; ++i) {
        int l = 0, r = i - 1;
        while (r - l > 2) {
            int m1 = l + (r - l) / 3;
            int m2 = r - (r - l) / 3;
            if (abs(pref[m1 + 1] - (pref[i + 1] - pref[m1 + 1])) < abs(pref[m2 + 1] - (pref[i + 1] - pref[m2 + 1]))) {
                r = m2;
            } else {
                l = m1;
            }
        }
        int lans;
        int val[3] = {
            abs(pref[l + 1] - (pref[i + 1] - pref[l + 1])),
            abs(pref[l + 1 + 1] - (pref[i + 1] - pref[l + 1 + 1])),
            abs(pref[r + 1] - (pref[i + 1] - pref[r + 1]))
        };
        int mini = min(val[0], min(val[1], val[2]));
        if (val[0] == mini) {
            lans = l;
        } else if (val[1] == mini) {
            lans = l + 1;
        }
        else {
            lans = r;
        }
        int sum1 = pref[lans + 1], sum2 = pref[i + 1] - pref[lans + 1];

        l = i + 1; r = n - 2;
        while (r - l > 2) {
            int m1 = l + (r - l) / 3;
            int m2 = r - (r - l) / 3;
            int lsum1 = pref[m1 + 1] - pref[i + 1];
            int lsum2 = pref[m2 + 1] - pref[i + 1];
            if (abs(lsum1 - ((pref[n] - pref[i + 1]) - lsum1)) < abs(lsum2 - ((pref[n] - pref[i + 1]) - lsum2))) {
                r = m2;
            } else {
                l = m1;
            }
        }
        int rans;
        int lsum = pref[l + 1] - pref[i + 1];
        int l1sum = pref[l + 2] - pref[i + 1];
        int rsum = pref[r + 1] - pref[i + 1];
        int val1[] = {
            abs(lsum - ((pref[n] - pref[i + 1]) - lsum)),
            abs(l1sum - ((pref[n] - pref[i + 1]) - l1sum)),
            abs(rsum - ((pref[n] - pref[i + 1]) - rsum))
        };
        mini = min(val1[0], min(val1[1], val1[2]));
        if (val1[0] == mini) {
            rans = l;
        } else if (val1[1] == mini) {
            rans = l + 1;
        }
        else {
            rans = r;
        }
        int sum3 = pref[rans + 1] - pref[i + 1], sum4 = (pref[n] - pref[i + 1]) - sum3;
        int res = max(max(sum1, sum2), max(sum3, sum4)) - min(min(sum1, sum2), min(sum3, sum4));
        ans = min(ans, res);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str;
		
		int[] blood = new int[4];
		
		while(scan.hasNext()){
			str = scan.next();
			String[] num = str.split(",", 0);
			if(num[1].equals("A"))blood[0]++;
			if(num[1].equals("B"))blood[1]++;
			if(num[1].equals("O"))blood[3]++;
			if(num[1].equals("AB"))blood[2]++;
		}
		for(int i = 0; i < 4; i++){
			System.out.println(blood[i]);
		}
	}
}

Measured memory_bytes: 25772
#define _CRT_SECURE_NO_WARNINGS 1
     
    #include <set>
    #include <map>
    #include <stack>
    #include <deque>
    #include <queue>
    #include <cmath>
    #include <ctime>
    #include <vector>
    #include <cstdio>
    #include <string>
    #include <iomanip>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
     
    using namespace std;
     
    #define LL long long
    #define pii pair<int,int>
    #define sd(x) scanf("%d",&x)
    #define slld(x) scanf("%lld",&x)
    #define pd(x) printf("%d\n",x)
    #define plld(x) printf("%lld\n",x)
    #define rep(i,a,b) for(int i = (a) ; i <= (b) ; i++)
    #define per(i,a,b) for(int i = (a) ; i >= (b) ; i--)
    #define mem(a) memset(a,0,sizeof(a))
    #define lson l , m , rt << 1
    #define rson m + 1 , r , rt << 1 | 1
    #define fast_io ios::sync_with_stdio(false)
     
    const int INF = 1e9;
    const LL mod = 1e9 + 7;
    const int maxn = 2e5 + 7;
     
    int a[maxn];
    int n,k;
     
    bool check(int mid) {
    	int res = 0;
    	rep(i,1,n) {
    		if(a[i] <= mid) continue;
    		res += a[i] / mid;
    	}
    	return res <= k;
    }
     
    int main() {
    	sd(n), sd(k);
    	rep(i,1,n) sd(a[i]);
    	int l = 1, r = INF;
    	int ans = 0;
    	while(l <= r) {
    		int mid = (l + r + 1) >> 1;
    		// cout << "mid = " << mid << endl;
    		if(check(mid)) {
    			ans = mid;
    			r = mid - 1;
    		} else {
    			l = mid + 1;
    		}
    	}
    	pd(ans);
    	return 0;
    }

Measured memory_bytes: 4412
#include <iostream>
#include <deque>

using namespace std;

int main() {
    int m, k;
    cin >> m >> k;
    if (m == 1) {
        if (k == 0)cout << "0 0 1 1" << endl;
        else cout << -1;
    } else {
        if (k < 1 << m) {
            deque<int> ret;
            ret.push_front(k);
            for (int i = 0; i < 1 << m; i++) {
                if (i == k)continue;
                ret.push_front(i);
                ret.push_back(i);
            }
            ret.push_back(k);

            for (int i = 0; i < ret.size(); i++) {
                if (i > 0)cout << " ";
                cout << ret[i];
            }
            cout << endl;
        } else cout << -1;
    }
    return 0;
}

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

using namespace std;

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

  for(int i = 0; 4 * i <= n; i++) {
    for(int j = 0; 7 * j <= n; j++) {
      if(4 * i + 7 * j == n) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }

  cout << "No" << endl;
}

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

ll a,b,n;

ll floor(ll N){
  ll fl1 = a*N/b;
  ll fl2 = N/b;
  ll sum = fl1 + a*fl2;
  return sum;
}

int main(){
  cin >>a >>b >>n;
  cout << floor(min(b-1,n)) << endl;
  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

template <typename T>
struct Edge {
  int from, to;
  T weight;
};

template <typename T>
class Graph {
 public:
  Graph(int n) : edges_(n) {}
  void AddEdge(int from, int to, T weight = T()) {
    edges_[from].push_back({from, to, weight});
  }
  const std::vector<Edge<T>>& Edges(int from) const { return edges_[from]; }
  int NumVertices() const { return edges_.size(); }

 private:
  std::vector<std::vector<Edge<T>>> edges_;
};

int main() {
  in(ll, n);
  Graph<ll> g(n);
  rep(i, n - 1) {
    in(ll, u, v, w);
    --u, --v;
    g.AddEdge(u, v, w);
    g.AddEdge(v, u, w);
  }
  vector<ll> color(n, -1);
  function<void(ll, ll, ll)> dfs = [&](ll node, ll parent, ll dist) {
    color[node] = dist % 2;
    for (const auto& e : g.Edges(node)) {
      if (e.to == parent) continue;
      if (color[e.to] != -1) continue;
      dfs(e.to, node, dist + e.weight);
    }
  };
  dfs(0, -1, 0);
  rep(i, n) out(color[i]);
}


Measured memory_bytes: 15868
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int R, G;

    scanf("%d%d", &R, &G);

    printf("%d\n", 2 * G - R);

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


/*
int N;
Graph G;

int main() {
  cin >>N;
  rep(i, N-1){
    int a,b; cin >>a >>b; a--; b--;
    G[a].push_back(b); G[b].push_back(a);
  }
}
*/

int main() {
  set<int> S;
  int a,b,c; cin >>a >>b >>c;
  S.insert(a); S.insert(b); S.insert(c);
  cout <<(S.size() == 1 ? "Yes" : "No") <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
int n, a[N];
vector <int> v[N];
int ser (int x, int fa) {
    for (int i = 0; i < v[x].size (); i ++)
		if (v[x][i] != fa && a[x] > a[v[x][i]] && !ser (v[x][i], x))
			return 1;
    return 0;
}
int main () {
    scanf ("%d", &n);
    for (int i = 1; i <= n; i ++)
		scanf ("%d", &a[i]);
    for (int i = 1; i < n; i ++) {
    	int x, y;
		scanf ("%d%d", &x, &y);
		v[x].push_back (y);
		v[y].push_back (x);
	}
    for (int i = 1; i <= n; i ++)
		if (ser (i, 0))
			printf ("%d ", i);
	return 0;
}

Measured memory_bytes: 10964
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define SORT(x) (sort(x.begin(),x.end()))
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll N,K,ans=0,A[2007];cin >> N >> K;
    ll t=(K+1)*K/2%MOD;
    ll u=K*(K-1)/2%MOD;
    rep(i,N){
        cin >> A[i];
    }
    rep(i,N){
        ll l=0,r=0;
        rep(j,N){
            if(j<i && A[j]<A[i]){
                l++;
            }
            if(j>i && A[j]<A[i]){
                r++;
            }
        }
        ans+=l*u%MOD;
        ans+=r*t%MOD;
    }
    cout << ans%MOD <<endl;
}

Measured memory_bytes: 888
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n;
  scanf("%lld", &n);
  if(n & 1) {
    printf("%lld\n", (n - 1) * (n - 1) / 2);
    for(i = 1; i < n; ++i) 
      for(j = i + 1; j <= n; ++j) if(i + j != n) printf("%lld %lld\n", i, j);
  } else {
    printf("%lld\n", n * (n - 2) / 2);
    for(i = 2; i < n; ++i) printf("1 %lld\n", i);
    for(i = 2; i < n; ++i)
      for(j = i + 1; j <= n; ++j) if(i + j != n + 1) printf("%lld %lld\n", i, j);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
 
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;
 
ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;
int n;
vector<vector<int>> tree(200010);
vector<int> gp(200010);
vector<int> parent(200010);
vector<set<int>> ntree(200010);
vector<int> color(200010);
int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(c - a - b >= 0 and 4 * a * b < (c - a - b) * (c - a - b)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 16640
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

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

    struct R {
        ll P, index;
        string S;
    };
    vector<R> rs(N);
    for (ll i = 0; i < N; i++) {
        cin >> rs[i].S >> rs[i].P;
        rs[i].index = i + 1;
    }

    sort(rs.begin(), rs.end(), [](R& lhs, R& rhs) {
        return lhs.S != rhs.S ? lhs.S < rhs.S : lhs.P > rhs.P;
    });

    for (const R& r : rs) {
        cout << r.index << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <set>
#include <cmath>
using namespace std;

template<typename X>
class LiChaoTree {
    // a*x+b
    struct Line {
        X a, b;
        Line(X a, X b) : a(a), b(b) {}
        X get(X x) const { return a * x + b; }
    };
    
    vector<X> xs;
    vector<Line> seg;
    int sz;

    void update(Line &x, int k, int l, int r) {
        int m = (l + r) / 2;
        bool lef = x.get(xs[l]) < seg[k].get(xs[l]);
        bool mid = x.get(xs[m]) < seg[k].get(xs[m]);
        if(mid) swap(seg[k], x);
        if(l + 1 >= r) return;
        else if(lef != mid) update(x, 2 * k + 1, l, m);
        else update(x, 2 * k + 2, m, r);
    }

public:
    // クエリで見たい座標リスト（昇順にソートされている必要がある）
    // INF: X 型で十分大きい値
    LiChaoTree(const vector<X> &x, X INF) : xs(x){
        sz = 1;
        while(sz < xs.size()) sz <<= 1;
        while(xs.size() < sz) xs.push_back(xs.back() + 1);
        seg.assign(2 * sz - 1, Line(0, INF));
    }
    
    // a*x+b を追加する
    void update(X a, X b){
        Line l(a, b);
        update(l, 0, 0, sz);
    }
    
    // 今までに追加された直線たち a_i*x+b_i に対して
    // min(a_i*x[k]+b_i) を返す
    X query(int k){
        const X x = xs[k];
        k += sz - 1;
        X ret = seg[k].get(x);
        while(k > 0) {
          k = (k - 1) >> 1;
          ret = min(ret, seg[k].get(x));
        }
        return ret;
    }
};

int main(){
    long long N, C;
    cin >> N >> C;
    vector<long long> h(N);
    for(int i=0; i<N; i++)
        cin >> h[i];
    LiChaoTree<long long> lct(h, 1<<30);
    vector<long long> dp(N);
    dp[0] = 0;

    for(int i=1; i<N; i++){
        lct.update(-2*h[i-1], dp[i-1]+h[i-1]*h[i-1]);
        dp[i] = h[i]*h[i]+C+lct.query(i);
    }
    cout << dp[N-1] << endl;
    return 0;
}


Measured memory_bytes: 14576
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll n;
ll a[3003];
ll dp[3003][3003][2];

ll solve(ll i, ll j, ll turn)
{
    if (i > j)
    {
        return 0;
    }

    if (dp[i][j][turn] != -1)
    {
        return dp[i][j][turn];
    }

    if (turn == 0)
    {
        dp[i][j][turn] = max(a[i] + solve(i + 1, j, 1), a[j] + solve(i, j - 1, 1));
    }
    else
    {
        dp[i][j][turn] = min(solve(i + 1, j, 0), solve(i, j - 1, 0));
    }

    return dp[i][j][turn];
}

int main()
{
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << 2 * solve(0, n - 1, 0) - sum << endl;
    return 0;
}

Measured memory_bytes: 144676
#include <iostream>
#include <vector>
#include <string>
#include <queue>

constexpr int X = 26;
constexpr int INF = 1 << 30;

void solve() {
    std::string s;
    std::cin >> s;

    int x = 0;
    std::vector<int> dist(1 << X, INF);
    dist[x] = 0;
    for (char c : s) {
        int d = c - 'a';
        x ^= (1 << d);

        for (int i = 0; i < X; ++i) {
            dist[x] = std::min(dist[x], dist[x ^ (1 << i)] + 1);
        }
    }

    if (x == 0) {
        std::cout << 1 << std::endl;
        return;
    }

    std::cout << (x == 0 ? 1 : dist[x]) << std::endl;
}

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

    solve();

    return 0;
}


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

int gcd(int a, int b){
    if(a < b) return gcd(b, a);
    int r;
    while((r = a%b)){
        a = b;
        b = r;
    }
    return b;
}

int main(){
    int n, x;
    cin >> n;
    vector<int> xs(n+1);
    rep(i,n+1) cin >> xs[i];

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

    if(n == 1) cout << xs[1] - xs[0] << "\n";
    else{

        rep(i,n) xs[i+1] -= xs[0];

        int prev = gcd(xs[1], xs[2]);
        for(int i = 3; i < n+1; i++){
            prev = gcd(prev, xs[i]);
        }
    cout << prev << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;
int main()
{
	long N,W;
	cin >> N >> W;
	vector<long> w(N),v(N);
	vector<vector<long>> NW(N+1,vector<long>(W+1));
	for(int i=0;i<N;i++)
	{	
		cin >> w[i] >> v[i];
	}
	for(int j=0;j<=W;j++)
	{
		NW[0][j]=0;
	}
	for(int i=1;i<=N;i++)
	{
		for(int j=0;j<=W;j++)
		{
			if(w[i-1]>j)
			{
				NW[i][j]=NW[i-1][j];
			}
			else
			{	
				NW[i][j]=max(NW[i-1][j],v[i-1]+NW[i-1][j-w[i-1]]);
			}
		}
	}
	cout << NW[N][W];
}


Measured memory_bytes: 80256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int sum = 0;
    rep(i, n){
        sum += a[i];
    }

    int ans = 0;
    rep(i, n){
        int x = abs(a[i] * n - sum);
        int y = abs(a[ans] * n - sum);
        if(x < y){
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	vector<int> vi(N);
	for (int i = 0; i < N; i++) {
		cin >> vi[i];
	}

	int max = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int sub = abs(vi[i] - vi[j]);
			if (max < sub) {
				max = sub;
			}
		}
	}

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <time.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
#include <memory.h>
#include <cstdlib>
#include <queue>
#include <iomanip>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for(int i = a; i < b; i++)
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;

int cost[] = {0,2,5,5,4,5,6,3,7,6};
int dp[MAX];
string ans = "";
int main()
{
    int n, m;
    cin >> n >> m;
    vector<P> A(m);
    rep(i, 0, m)
    {
        cin >> A[i].first;
        A[i].second = cost[A[i].first];
    }
    sort(A.rbegin(), A.rend());
    mset(dp, -1);
    dp[0] = 0;
    rep(i, 1, n+1){
        rep(j, 0, m){
            if(i >= A[j].second)
                dp[i] = max(dp[i], dp[i-A[j].second]+1);
        }
    }
    int tot = n;
    rep(i, 0, dp[n]){
        rep(j, 0, m){
            if(tot-A[j].second >= 0 && dp[tot - A[j].second] == dp[tot]-1){
                tot -= A[j].second;
                char c = A[j].first + '0';
                ans += c; 
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    work = {}
    for i in range(N):
        A, B = [int(n) for n in input().split()]
        if B not in work:
            work[B] = []
        work[B].append(A)
    times = list(work.keys())
    times.sort()
    cur = 0
    for t in times:
        for w in work[t]:
            cur += w
            if cur > t:
                print("No")
                return
    print("Yes")
main()

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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; }

template<typename T>
struct BIT{
    private:
        using Func = function<T(T, T)>;

        int n;
        vector<T> node;

        T init_v;
        Func func;

    public:

        BIT(vector<T> a, Func _func, T _init_v) {
            n = a.size() + 1;
            init_v = _init_v;
            func = _func;

            node.resize(n, init_v);
            for(int i=1; i<n; i++) if((i+(i&-i)) < n) node[i+(i&-i)] = func(node[i+(i&-i)], node[i]);
        }

        BIT() {}

        void add(int pos, T v) {
            while(pos < n){
                node[pos] = func(node[pos], v);
                pos += pos & -pos;
            }
        }

        T sum(int pos){
            T res = init_v;
            while(pos > 0){
                res = func(res, node[pos]);
                pos = pos & (pos-1);
            }
            return res;
        }
};

int func(int a, int b){
    return a+b;
}

int main(void){
    string s,s2; cin >> s;
    REP(i,s.size()){
        if(i<s.size()-1 && s[i]=='B' && s[i+1]=='C'){
            s2 += 'D';
            i++;
        }
        else s2 += s[i];
    }
    swap(s2,s);
    
    ll ans = 0;
    REP(i,s.size()){
        int nA = 0;
        while(i<s.size() && (s[i]=='A'||s[i]=='D')){
            if(s[i]=='A') nA++;
            else ans += nA;
            i++;
        }
    }

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

Measured memory_bytes: 776
import sys
input=sys.stdin.readline
n,t=map(int,input().split())
dp=[[0 for i in range(t)] for j in range(n+1)]
food=[list(map(int,input().split())) for i in range(n)]
foodmax=[0]*n
food.sort(key=lambda x:x[1],reverse=True)
food.sort(key=lambda x:x[0])
foodmax[-1]=food[-1][1]
for i in range(n-1)[::-1]:
  foodmax[i]=max(foodmax[i+1],food[i][1])
foodmax+=[0]
for i in range(n):
  for j in range(t):
    if j<food[i][0]:
      dp[i+1][j]=dp[i][j]
    else:
      dp[i+1][j]=max(dp[i][j],dp[i][j-food[i][0]]+food[i][1])
ans=0
for i in range(n):
  if ans<dp[i+1][t-1]+foodmax[i+1]:
    ans=dp[i+1][t-1]+foodmax[i+1]
print(ans)


Measured memory_bytes: 119388
import java.util.*;

public class Main{

    static class Room{
        int num;
        List<Room> joint = new ArrayList<>();
        int mark = -1;
        Room(int num){
            this.num = num;
        }
    }

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        List<Room> list = new ArrayList<>();
        for(int i = 0; i < n; i++){
            list.add(new Room(i + 1));
        }

        for(int i = 0; i < m; i++){
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;

            list.get(a).joint.add(list.get(b));
            list.get(b).joint.add(list.get(a));
        }

        ArrayDeque<Room> q = new ArrayDeque<>();
        q.add(list.remove(0));

        while(!q.isEmpty()){
            Room room = q.poll();

            for(Room i : room.joint){
                if(i.mark == -1){
                    i.mark = room.num;
                    q.add(i);
                }
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append("Yes");

        for(Room i : list){
            sb.append("\n").append(i.mark);
        }
        System.out.println(sb);

    }
}


Measured memory_bytes: 72436
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  vector<int> v;
  int tmp = s[0];
  int cnt = 1;

  if(s[0]=='0') {
    v.push_back(0);
  }

  for(int i = 1; i < s.length(); i++){
    if(tmp==s[i]){
      cnt++;
    }
    else{
      v.push_back(cnt);
      cnt=1;
      tmp=s[i];
    }
  }
 
  v.push_back(cnt);
  if(s.back()=='0') {
    v.push_back(0);
    }

  // for(auto a:v) cout<<a<<" ";
  
  //累積和
  vector<int>sum((int)v.size()+1,0);
  for(int i = 0; i < v.size(); i++){
    sum[i+1]=sum[i]+v[i];
  }


  int res = 0;
  for(int left = 0; left<sum.size(); left+=2){
    int right = min((int)sum.size()-1,left+k*2+1);
    res = max(sum[right]-sum[left],res);
    
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
int a,b,k;
int main()
{
    scanf("%d%d",&a,&b);
    for(int i=0;i<=a;i++)
    {
    	for(int j=0;j<=a;j++)
    	{
    		k=b-(i*10000+j*5000);
    		if(k%1000==0&&k>=0)
    		{
    			if(k/1000+i+j==a)
    			{
    				cout<<i<<" "<<j<<" "<<k/1000<<endl;
    				return 0;
				}
			}
		}
	}
	cout<<"-1 -1 -1\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int  a,b;
    scanf("%d %d", &a,&b);
    if (a>b) {
      printf("a > b\n"); 
    } else if (a<b) {   
      printf("a < b\n");
    } else {
      printf("a == b\n");
    }return 0;
}



Measured memory_bytes: 2028
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>

using namespace std;

auto readLikes() {
    unordered_set<int> output;
    int K;
    cin >> K;
    for (auto k = 0; k < K; k++) {
        int Ak;
        cin >> Ak;
        output.insert(Ak);
    }
    return output;
}

int numLikedBy(const unordered_map<int,int>& likes, int people) {
    int output = 0;
    for (auto p: likes) {
        if (p.second == people) output++;
    }
    return output;
}

int main()
{
    int people, foods;
    cin >> people >> foods;
    unordered_map<int,int> totalLikes;
    for (auto i = 0; i < people; i++) {
        auto likes = readLikes();
        for (auto l: likes) totalLikes[l]++;
    }
    cout << numLikedBy(totalLikes, people) << endl;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/


Measured memory_bytes: 256
# p(n) = 2^^n より大きい最小の素数 (ただし^^はクヌースの二重矢印記号) と定義したとき、
# x = (10^(p(n)-1)-1)/9 (mod p(n)) を求めよ
# 「フェルマーの小定理」
# pが素数ならば、a^p == a (mod p(n))
# とくに、aとpが互いに素 (gcd(a,p)=1) のとき
# a^p * a^-1 == a * a^-1 (mod p(n))
# a^(p-1) == 1 (mod p)
#
# 9とp(n)が互いに素ならば
# x * 9^-1 = 10^(p(n)-1)-1 (mod p(n))
# 10とp(n)が互いに素ならば
# 10^(p(n)-1) = 1 (mod p(n))
# ゆえに
# x * 9^-1 = 0 (mod p(n))
# p(n)は素数であるから、p(n)>10のとき9とp(n)および10とp(n)は互いに素でありx=0
n = int(input())
if n == 0:
    # 1 mod 2
    print(1)
elif n == 1:
    # 11 mod 3
    print(2)
elif n == 2:
    # 111 mod 5
    print(1)
else:
    print(0)

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


int main(){
char a[10],b[10],c[10];
scanf("%s%s%s",a,b,c);
if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0]){
	printf("YES\n");
	
}else{
	printf("NO\n");
	
}
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli dist[3000];
bool visA[3000];
bool visB[3000];

vector<pair<lli,lli>> G[3000];
vector<pair<lli,lli>> revG[3000];
void dfs(lli now){
    if(visA[now])return;
    visA[now]=true;

    for(auto e:G[now]){
        dfs(e.first);
    }
}

void revDfs(lli now){
    if(visB[now])return;
    visB[now]=true;

    for(auto e:revG[now]){
        revDfs(e.first);
    }
}

void func(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    dfs(0);
    revDfs(N-1);

    REP(i,0,N)dist[i]=INF;
    dist[0]=0;
    lli cnt = 0;
    bool noLoop = false;
    while(cnt < 3*M){
        bool update = false;
        REP(i,0,N){
            if(!visA[i] || !visB[i])continue;
            for(auto e:G[i]){
                if(dist[e.first] > dist[i] + e.second){
                    update = true;
                    dist[e.first] = dist[i]+e.second;
                }
            }
        }
        if(!update){
            noLoop = true;
            break;
        }
        cnt++;
    }

    if(!noLoop)cout<<-1<<endl;
    else cout<<max(0LL,-dist[N-1])<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long P;
    scanf("%lld",&P);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
        A[i]--,B[i]--;
        C[i] -= P;
        G[A[i]].push_back({B[i],-C[i]});
        revG[B[i]].push_back({A[i],-C[i]});
    }
    func(N, M, P, std::move(A), std::move(B), std::move(C));
    return 0;
}


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

int main(){
  
  int N, M;
  cin >> N >> M;
  
  vector<int> maru(N, 0);
  vector<int> P(N, 0);
  
  int ans = 0;
  int pena = 0;
  
  for (int i = 0; i < M; i++) {
    int p;
    string S;
    cin >> p >> S;
    
    if (maru[p] == 1) continue;
    else {
      
      if (S == "AC") {
        maru[p] = 1;
        pena += P[p];
        ans++;
      }
      
      else P[p]++;
      
    }
    
  }
  
  cout << ans << " " << pena << endl;
  
}

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

class state{
public:
	int vi, eij, d;
	state(int _vi, int _eij, int _d) : vi(_vi), eij(_eij), d(_d) {};
};
class edge{
public:
	int cost;
	size_t from, to;
	edge(int c, size_t f, size_t t){
		cost = c;
		from = f;
		to = t;
	}
};
using edges = vector<edge>;
using graph = vector<edges>;
void readgraph(graph &g, size_t E, bool D, bool C, bool Z){ // E:num_of_edges, D:directed, C:costed, Z:already 0-indexed
	for(size_t i=0; i<E; ++i){
		edge e(1, 0, 0);
		if(!C) cin >> e.from >> e.to;
		else cin >> e.from >> e.to >> e.cost;
		if(!Z){
			--e.from;
			--e.to;
		}
		g[e.from].push_back(e);
		if(!D){
			swap(e.from, e.to);
			g[e.from].push_back(e);
		}
	}
}
bool operator<(const edge &e, const edge &f){
	return e.cost != f.cost ? e.cost > f.cost : e.from != f.from ? e.from < f.from : e.to < f.to;
}
void dijkstra(const graph &g, size_t s, vector<int> &dist){
	size_t V = g.size();
	dist = vector<int>(V, 1e8);
	dist[s] = 0;
	priority_queue<edge> q;
	q.push(edge(0, s, s));
	while(!q.empty()){
		edge e = q.top(); q.pop();
		if(dist[e.to] < e.cost) continue;
		for(const edge f:g[e.to]){
			if(dist[f.to] > dist[e.to] + f.cost){
				dist[f.to] = dist[e.to] + f.cost;
				q.push(edge(dist[f.to], s, f.to));
			}
		}
	}
}

int v, e, tmax;
graph g;
vector<vector<int>> d, h;
using P = pair<int, int>;
vector<P> info;

void input(){
	cin >> v >> e;
	g.resize(v);
	readgraph(g, e, false, true, false);
	cin >> tmax;
	info.resize(tmax, P(-1, -1));
	for(int i=0; i<tmax; ++i){
		int nnew; cin >> nnew;
		if(nnew == 1){
			int id, dst; cin >> id >> dst; --dst;
			info[i] = P(id, dst);
		}
	}
}
void calc_h(){
	d.resize(v);
	for(int i=0; i<v; ++i) dijkstra(g, i, d[i]);
	h.resize(v, vector<int>(v, -1));
	for(int i=0; i<v; ++i)
		for(int j=0; j<v; ++j)
			for(size_t k=0; k<g[i].size(); ++k)
				if(h[i][j] == -1 || d[g[i][h[i][j]].to][j] > d[g[i][k].to][j])
					h[i][j] = k;
}
void solve(){
	state s(0, 0, 0);
	priority_queue<P> pq;
	for(int i=0; i<min(tmax, 10); ++i){
		if(info[i] != P(-1, -1)) pq.push(P(tmax-i, info[i].second));
		cout << -1 << "\n";
	}
	pq.push(P(tmax-9, 0));
	for(int i=10; i<tmax; ++i){
		if(i % 100 == 0) pq.push(P(tmax-i+100, 0));
		if(info[i] != P(-1, -1)) pq.push(P(tmax-i, info[i].second));
		if(pq.empty()){
			cout << -1 << "\n";
			continue;
		}
		P p = pq.top();
		if(s.vi == p.second){
			cout << -1 << "\n";
			if(!pq.empty()) pq.pop();
			continue;
		}
		if(s.d == 0) s.eij = h[s.vi][p.second];
		cout << g[s.vi][s.eij].to+1 << "\n";
		++s.d;
		if(s.d == g[s.vi][s.eij].cost){
			s.vi = g[s.vi][s.eij].to;
			s.eij = 0;
			s.d = 0;
		}
		if(s.vi == p.second && !pq.empty()) pq.pop();
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	calc_h();
	solve();
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
int main(){
	int n;
	cin>>n;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		int a;
		cin>>a;
		vec[i] = a;
	}
	long long res = 1e9;
	for(int a = -100; a <= 100; ++a){
		long long sum = 0;
		for(int j = 0;j < n; ++j){
			sum += abs(vec[j] - a) * abs(vec[j] - a);
		}
		res = min(sum, res);
	}
	cout<<res<<endl;
	return 0;
}


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

int main()
{
    int taka_t, taka_p, aoki_t, aoki_p;
    cin >> taka_t >> taka_p >> aoki_t >> aoki_p;

    while(true){
        aoki_t = aoki_t - taka_p;
        if(aoki_t <= 0) break;
        taka_t = taka_t - aoki_p;
        if(taka_t <= 0) break;
    }

    if(taka_t > aoki_t)
    {
        std::cout << "Yes" << endl;
    }else{
        std::cout << "No" << endl;
    }

}

Measured memory_bytes: 3592
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

D = [0] * N
L = [0]

D[0] = 1
t = 0
c = 2
while True:
  t = A[t] - 1
  L.append(t)
  if D[t] == 0:
    D[t] = c
    c += 1
  else:
    l = D[t] - 1
    n = c - D[t]
    break
  
if l - 1 >= K:
  g = K + 1
else:
  K -= l - 1
  K %= n
  if K != 0:
    g = l + K
  else:
    g = l + n

for i in range(N):
  if D[i] == g:
    print(i + 1)
    exit()

Measured memory_bytes: 103060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
int n,a,b; cin>>n>>a>>b;
cout << min(a,b) << " " << max(a+b-n,0) << endl;}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(" ");
            List<int> nums = new List<int>();
            foreach (string element in input)
            {
                nums.Add(int.Parse(element));
            }
            int sum = nums.Sum();
            Console.WriteLine(15 - sum);
        }
    }
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch)
{
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    long long sum = 0, p = 1, i;
    for (int i = 0; i < strlen(str); i++) {
        sum += p*getChar(str[i]);
        p *= 5;
    }
    return sum;
}

int h1(int key) 
{
    return key % M;
}

int h2(int key)
{
    return 1 + (key % (M - 1));
}

int find(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) {
            return 1;
        } else if (strlen(H[h]) == 0) {
            return 0;
        }
    }
    return 0;
}

int insert(char str[])
{
    long long key, i, h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) {
            return 1;
        } else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}


int main(int argc, char const *argv[])
{
    int i, n, h;
    char str[L], com[9];
    for (int i = 0; i < M; i++) {
        H[i][0] = '\0';
    }
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %s", com, str);
        
        if (com[0] == 'i') {
            insert(str);
        } else {
            if (find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }
        }
    }

    return 0;
}



Measured memory_bytes: 16096