akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]

use std::cmp;
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::stdin;
use std::ops::*;
use std::process::exit;
use std::str::FromStr;

#[macro_export]
macro_rules! minimum {
    ($($e:expr),+) => {
        {
            let mut res = Vec::new();
            $(
                res.push($e);
            )+
            res.into_iter().min().unwrap()
        }
    };
}

pub const MOD: usize = 1000000007;

fn main() {
    let n: String = input();
    let mut ans = 0;
    for c in n.chars() {
        if c == '2' {
            ans += 1;
        }
    }
    println!("{}", ans);
}

pub fn input<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

pub fn input_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect::<Vec<_>>()
}

pub fn input_lines<T: FromStr>(l: usize) -> Vec<T> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input());
    }
    res
}

pub fn input_lines_two<T: FromStr, U: FromStr>(l: usize) -> Vec<(T, U)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_two());
    }
    res
}

pub fn input_lines_three<T: FromStr, U: FromStr, V: FromStr>(l: usize) -> Vec<(T, U, V)> {
    let mut res = Vec::new();
    for _i in 0..l {
        res.push(input_three());
    }
    res
}

pub fn input_two<T: FromStr, U: FromStr>() -> (T, U) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
    )
}

pub fn input_three<T: FromStr, U: FromStr, V: FromStr>() -> (T, U, V) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse::<T>().ok().unwrap(),
        s[1].parse::<U>().ok().unwrap(),
        s[2].parse::<V>().ok().unwrap(),
    )
}

pub fn input_four<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let s: Vec<&str> = buf.split_whitespace().collect();
    (
        s[0].parse().ok().unwrap(),
        s[1].parse().ok().unwrap(),
        s[2].parse().ok().unwrap(),
        s[3].parse().ok().unwrap(),
    )
}


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

using namespace std;

typedef pair< int, int > Pi;
struct edge
{
  int to, cost;
};
typedef vector< vector< edge > > Graph;
const int INF = 1 << 30;

vector< int > min_cost;
int Dijkstra(Graph& graph, int s)
{
  min_cost.assign(graph.size(), INF);
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.push(make_pair(0, s));
  min_cost[s] = 0;
  while(!que.empty()) {
    int now = que.top().second;
    int cost = que.top().first;
    que.pop();
    if(cost > min_cost[now]) continue;
    for(int i = 0; i < graph[now].size(); i++) {
      edge& e = graph[now][i];
      if(cost <= e.cost && e.cost < min_cost[e.to]) {
        min_cost[e.to] = e.cost;
        que.push(make_pair(min_cost[e.to], e.to));
      }
    }
  }
  return(-1);
}

int main()
{
  int N, M;
  cin >> N >> M;
  Graph g(N), rg(N);
  for(int i = 0; i < M; i++) {
    int A, B, C;
    cin >> A >> B >> C;
    --A, --B;
    g[A].push_back((edge){B, C});
    rg[B].push_back((edge){A, C});
  }
  Dijkstra(g, 0);
  int ret = -1;
  for(auto& e : rg[N - 1]) {
    if(min_cost[e.to] < INF && min_cost[e.to] <= e.cost) {
      ret = max(ret, e.cost);
    }
  }
  cout << ret << endl;
}

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

#define INF ((1<<31)-1)  //int32_t
#define MOD 1000000007
#define MOD2 1000000007

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

bool greater_paircmp(const pair<int,int> &a,const pair<int,int> &b){
    return a.first > b.first;
}

int main(){
    bool flag=true;
    ll ans=0,sum=0;
    
    int n,m;
    cin >>n>>m;
    vector<int> a(n);
    vector<pii> op(m),ideal;

    for (int i = 0; i < n; i++)cin>>a[i];

    for (int i = 0; i < m; i++){
        int b,c;
        cin >>b>>c;
        op[i] = mkp(c,b);
    }

    sort(all(a));
    sort(all(op),greater_paircmp);

    int pos = 0;
    int p=0;

    while(p < m){
        int c=op[p].first;
        int b=op[p].second;

        pos += b;
        
        if(pos >= n){
            ideal.pb(mkp(c,n));
            break;
        }

        ideal.pb(mkp(c,pos));
        p++;
    }

    int count=0;
    
    for (int i = 0; i < (int)ideal.size(); i++){
        
        //std::cout << "to::"<<ideal[i].second<< '\n';
        while (count < ideal[i].second)
        {
            ans += max(a[count],ideal[i].first);
            //std::cout <<count<<"::"<<a[count]<<"vs"<<ideal[i].first<< '\n';
            count++;
        }
    }

    while (count < n)ans += a[count++];
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 2044
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int d;
ll c[26], s[370][26], last[370][26], t[370];


ll calc(ll dl){
        ll score = 0;
        REP(i, 1, dl+1){
                REP(j, 0, 26){
                        if(j==t[i]-1){
                                score += s[i][j];
                                last[i][j] = i;
                        }else last[i][j] = last[i-1][j];
                        score -= c[j] * (i - last[i][j]);
                }
        }
        return score;
};

int main(){
        scanf("%d", &d);
        REP(i, 0, 26) scanf("%ld", &c[i]);
        REP(i, 1, d+1) REP(j, 0, 26) scanf("%ld", &s[i][j]);
        REP(i, 1, d+1) t[i] = 0;
        REP(i, 0, 1+d) REP(j, 0, 26) last[i][j] = 0;

        REP(i, 1, d+1){
                ll score = calc(i);
                REP(j, 0, 26){
                        ll prev = t[i];
                        t[i] = j;
                        ll newscore = calc(i);
                        if(newscore > score) score = newscore;
                        else t[i] = prev;
                }
        }

        REP(i, 1, d+1) printf("%ld\n", t[i]);
        return 0;
}

Measured memory_bytes: 3984
from itertools import permutations

def getval():
    n,m = map(int,input().split())
    g = [[] for i in range(n)]
    for i in range(m):
        a,b = map(int,input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)
    return n,m,g

def main(n,m,g):
    ans = 0
    for p in permutations(range(n-1)):
        flag = True
        idx = 0
        for i in p:
            if not i+1 in g[idx]:
                flag = False
                break
            idx = i+1
        if flag:
            ans += 1
    print(ans)

if __name__=="__main__":
    n,m,g = getval()
    main(n,m,g)

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  vector<string> vec(7);
  vec={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string s;
  cin >> s;
  for(int i=0;i<7;i++){
    if(s==vec[i]){
      cout << 7-i << endl;
    }
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
 
using namespace std;
 
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;}
 
const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin >> a[i];
        b[i]=a[i];
    }
    ll ans=0;
    if(n==1){
        cout << a[0]/2 << endl;
        return 0;
    }
    rep(i,n-1){
        ll p=(a[i+1]+a[i])/2;
        ans+=p;
        ll q=max(2*p-a[i],0LL);
        a[i+1]-=q;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();  //人数
      int K = sc.nextInt(); //初期ポイント
      int Q = sc.nextInt(); //正解数
      int[] A = new int[Q]; //正解者リスト
      for(int i=0; i<Q; i++) A[i] = sc.nextInt();
      int[] menber = new int[N];
      for(int i=0; i<N; i++) menber[i] = K - Q; //初期ポインツ
      
      for(int i=0; i<Q; i++){
        int ans = A[i] - 1;
        menber[ans]++;
      }
      for(int i=0; i<N; i++){
        if( menber[i] > 0) System.out.println("Yes");
        else System.out.println("No");
      }
	}
}

Measured memory_bytes: 56924
#include <bits/stdc++.h>
 #include <string> 
 #include <math.h>
 #include <bitset>
 #include <numeric>
 
 using namespace std;

 int main(){
    int H[3];
    int M[3];
    int K;

    cin >> H[1];
    cin >> M[1];
    cin >> H[2];
    cin >> M[2];
    cin >> K;

    cout << ((H[2]-H[1])*60+(M[2]-M[1])-K) << endl;

    return 0;
 }



Measured memory_bytes: 3624
import sys
sys.setrecursionlimit(4100000)

_input = [i for i in open(0).read().split('\n') if i]
n, k = [int(i) for i in _input[0].split()]
edge = tuple([tuple([int(p) for p in i.split()]) for i in _input[1:n]])

factorial = [0] * (k + 1)
inverse = [0] * (k + 1)
MOD = 1000000007

# Ref: http://keita-matsushita.hatenablog.com/entry/2016/12/05/175024
def mod_pow1(n, k, mod):
    a = 1
    while k:
        if (k & 1) == 1:
            a = (a * n) % mod
        n = (n * n) % mod
        k >>= 1
    return a

# Ref: https://www.smartbowwow.com/2018/10/mod1097.html
def mod_pow2(n, k, mod):
    if k == 0:
        return 1
    if k % 2 == 0:
        a = mod_pow2(n, k // 2, mod)
        return (a * a) % mod
    else:
        return (n * mod_pow2(n, k - 1, mod)) % mod

#mod_pow = mod_pow1
# It's better to use built-in function for speed.
mod_pow = pow

def mod_factorial_inverse(k, mod):
    factorial[0] = 1
    inverse[0] = 1

    # Ref: http://keita-matsushita.hatenablog.com/entry/2016/12/05/184011
    for i in range(1, k + 1):
        factorial[i] = ((i * factorial[i - 1]) % mod) # factrial[i]
        inverse[i] = mod_pow(factorial[i], mod - 2, mod) # inverse[i]
 
total = 1

if not edge:
    print(k)
else:
    all_edge = tuple([[] for _ in range(n + 1)])
    for e in edge:
        all_edge[e[0]].append(e[1])
        all_edge[e[1]].append(e[0])
    all_edge = [set(v) for v in all_edge]

    if [v for v in all_edge if len(v) >= k]:
        print(0)
    else:
        mod_factorial_inverse(k, MOD)

        root = edge[0]
        total = (factorial[k] * inverse[k - len(all_edge[root[0]]) - 1]) % MOD

        def dfs(current, from_):
            global total
            child = all_edge[current]
            if len(child) - 1 > 0:
                total = (total * factorial[k - 2] * inverse[k - 2 - (len(child) - 1)]) % MOD
            for c in child:
                if c != from_:
                    dfs(c, current)
        for c in all_edge[root[0]]:
            dfs(c, root[0])
        print(total)


Measured memory_bytes: 168876
n = int(input())
a = list(map(int, input().split()))
cum = [0]
for i in range(n):
    cum.append(cum[i] + a[i])
#print(cum)

ans = int(1e10)
for i in range(1,n):
    dif = abs(cum[i] - (cum[n]- cum[i]))
    if ans > dif:
        ans = dif
print(ans)

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;cin >> n;
    vector<ll> a(n);rep(i,n)cin >> a[i];
    vector<ll> ruiseki(n);
    ll temp = 0;
    rep(i,n)
    {
        temp += a[i];
        ruiseki[i] = temp;
    }
    map<ll,ll>mp;
    rep(i,n)
    {
        mp[ruiseki[i]]++;
    }
    ll ans = 0;
    for (auto &&i : mp)
    {
        if(i.first==0)
        {
            ans += i.second * (i.second + 1) / (ll)2;
            continue;
        }
        ans += i.second*(i.second-1)/(ll)2;
    }
    cout << ans << endl;
    


}

Measured memory_bytes: 18712
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  string S, T;
  cin>>S>>T;
  int ns = S.size();
  int nt = T.size();
  if(ns<nt){
    cout<<"UNRESTORABLE"<<endl;
    return 0;
  }


  bool cinc;
  for(int i = ns-nt; i>-1; --i){
    cinc=true;
    REP(j, nt){
      if(S[i+j] != T[j] && S[i+j] != '?') {
        cinc=false;
        break;
      }
    }
    if(!cinc) continue;
    REP(j, ns){
      if(j<i || j>=i+nt){
        if(S[j]=='?') cout<<'a';
        else cout<<S[j];
      }
      else{
        cout<<T[j-i];
      }
    }
    cout<<endl;
    return 0;
  }

  cout<<"UNRESTORABLE"<<endl;
  return 0;
}


Measured memory_bytes: 256
import math , sys

N  = int( input() )

A = list(map(int, input().split() ) )

def Prime(x):
    ub=int(math.sqrt(x))+2
    if x==2 or x==3 or x==5 or x==7:
        return True
    for i in range(2,ub):
        if x%i==0:
            return False
    return True

y = N
while not Prime(y):
    y+=1

def h1(x):
    return x % y
def h2(x):
    return 1+ x%(y-1)
def h(x,i):
    return (h1(x) + i*h2(x)) % y

def insert(T,x):
    i=0
    while True:
        j=h(x,i)
        if T[j][0]== -1:
            T[j][0]=x
            T[j][1]=1
            return j
        elif x ==T[j][0]:
            T[j][1]+=1
            return j
        else:
            i+=1

def search(T,x):
    i=0
    while True:
        j=h(x,i)
        if T[j][0] == x:
            return T[j][1]
        elif T[j][0] == -1:
            return -1
        else:
            i+=1

T = [[-1,0] for _ in range(y)]
for i in range(N):
    insert(T , i + A[i])
ans =0
        
for j in range(N):
    if j - A[j]>=0:
        s = search(T, j - A[j])
        if s >=0:
            ans+=s
print(ans)

Measured memory_bytes: 117140
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 3010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

ll MOD = MODBASE;

ll add(ll a, ll b) {
    return (a + b) % MOD;
}

ll sub(ll a, ll b) {
    return (a - b + MOD) % MOD;
}

ll mul(ll a, ll b) {
    return a * b % MOD;
}

int n, m;
ll dp[MAXN][MAXN][2];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(j,0,n) dp[0][j][j == 0] = 1;
    FOR(i,0,m-1)
        FOR(j,0,n) 
            FOR(k,0,1) {
                if (!dp[i][j][k]) continue;
                if (j + 1 <= n) {
                    // RR
                    dp[i+1][j+1][k | (j+1 == 0)] = add(dp[i+1][j+1][k | (j+1 == 0)], dp[i][j][k]);
                    // RB
                    dp[i+1][j][k | (j+1 == 0)] = add(dp[i+1][j][k | (j+1 == 0)], dp[i][j][k]);
                }
                if (j - 1 >= 0) {
                    // BR
                    dp[i+1][j][k | (j-1 == 0)] = add(dp[i+1][j][k | (j-1 == 0)], dp[i][j][k]);
                    // BB
                    dp[i+1][j-1][k | (j-1 == 0)] = add(dp[i+1][j-1][k | (j-1 == 0)], dp[i][j][k]);
                }
            }
    ll res = 0;
    FOR(j,0,n) res = add(res, dp[m][j][1]);
    cout << res;
    return 0;
}


Measured memory_bytes: 144732
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	long long n, m;
	cin >> n >> m;
	long long ans = 1;
	for (long long i = 1; i*i <= m; i++) {
		if (m%i != 0)
			continue;
		long long r = m/i;
		if ((r/n) >= 1)
			ans = max(i, ans);
		
		if ((i/n) >= 1)
			ans = max(r, ans);
	}
	if (n == 1)
		ans = m;
	cout << ans << endl;
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846
 
typedef long long ll;
typedef pair< int, int > P;   
typedef pair< int, P > PP;

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

string s;
int x, y;
vector<int> vec[2]; //0 -> x, 1 -> y
bitset<50000> bit[2];

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

	cin >> s >> x >> y;
	int i = 0, cnt = 0, t = 0;
	while(i < (int)s.size() && s[i] != 'T') i++, x--;
	i++;
	x += 25000, y += 25000;
	while(i < (int)s.size()) {
		while(i < (int)s.size() && s[i] != 'T') cnt++, i++;
		vec[t].pb(cnt);
		cnt = 0;
		t = 1 - t;
		i++;
	}

	bit[0].set(25000);
	bit[1].set(25000);

	REP(i, 2) {
		for (auto j: vec[i]) {
			bit[i] = (bit[i] << j) | (bit[i] >> j);
			//cout << j << endl;
		}
		//cout << i << endl;
	}
	if (bit[1][x] && bit[0][y]) cout << "Yes" << endl;
	else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

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

		Main main = new Main();
		// 桁数
		int l;
		// 答え
		int N = 0;

		for(l = 1; l < 11;l++) {
			main.output(false, (int)Math.pow(10,l));
			if(main.input(scan) == 0) {
				break;
			}
		}

		if(l != 11) {
			int nMin = (int)Math.pow(10, l - 1);
			int nMax = (int)Math.pow(10, l) - 1;

			while(nMin != nMax) {
				int n = (nMin + nMax) / 2;
				main.output(false, (n * 10L));
				if(main.input(scan) == 0) {
					nMin = n + 1;
				} else {
					nMax = n;
				}
			}
			N = nMin;
		} else {
			for(l = 0; l < 10;l++) {
				main.output(false, (int)Math.pow(10,l) * 2);
				if(main.input(scan) == 1) {
					N = (int)Math.pow(10,l);
					break;
				}
			}
		}
		main.output(true, N);
	}

	private void output(boolean answerFlag, long n) {
		if(answerFlag) {
			System.out.println("! " + n);
		} else {
			System.out.println("? " + n);
		}
		System.out.flush();
	}

	private int input(Scanner scan) throws Exception {
		String input = scan.next();

		if("Y".equals(input)) {
			return 1;
		} else
		if("N".equals(input)) {
			return 0;
		} else {
			throw new Exception();
		}
	}
}


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


int main() {

    int w, h, x, y;
    cin >> w >> h >> x >> y;
    if (w == 2*x && h == 2*y) {
        cout << (double)w*h/2 << " " << 1 << endl;
    } else {
        cout << (double)w*h/2 << " " << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var data = input.split( "\n" );
  var n = data[0];
  var tscore = 0;
  var hscore = 0;
  for( var i=1; i<=n; i++ ) {
    var taha = data[i].split( ' ' );
    if( taha[0] < taha[1] ) {
      hscore += 3;
    } else if( taha[1] < taha[0] ) {
      tscore += 3;
    } else {
      hscore += 1;
      tscore += 1;
    }
  }
  console.log( tscore+' '+hscore );
});

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

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

using namespace std;
using ll = long long;


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

    map<int,int> memo;
    int n,a;
    cin >> n;
    rep(i,n-1){
        cin >> a;
        if(memo.count(a)){
            memo.at(a)++;
        }else{
            memo[a] = 1;
        }
    }
    for(int i = 1;i <= n; ++i){
        cout << memo[i] << endl;
    }
}

Measured memory_bytes: 13040
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int N;
  cin >> N;
  vector<long long> num(N);
  for(int i = 0; i < N; i++) cin >> num[i];
  sort(num.begin(),num.end(),greater<int>());
  long long prev = -1;
  long long cnt=0;
  long long  len[2] = {0};
  for(int i = 0; i < N; i++){
  //  cout << num[i] << endl;
    if(prev == num[i]){
    //  cout << num[i] << ' ' << prev << endl;
      len[cnt] = num[i];
      cnt++;
      prev = -1;
      if(cnt == 2) break;
      continue;
    }
    prev = num[i];
  }

  if(cnt == 2){
    cout << len[1] * len[0] << endl;
  }else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 1024
# https://www.youtube.com/watch?v=ENSOy8u9K9I&feature=youtu.be
# https://twitter.com/tempura_cpp/status/1259483252919635969

n, k = gets.to_s.split.map{|e|e.to_i}
a = [0] + gets.to_s.split.map{|e|e.to_i}

cur = 1
while k > 0

  cur = a[cur] if k[0] == 1
  
  # a = Array.new(n+1){ |i| a[a[i]] }
  a = a.map{|t| a[t] }
  
  k >>= 1
end

puts cur

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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}
template<typename S>
void print(S a){
    cout<<a<<endl;
}


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

    ll n,m;
    cin>>n>>m;
    ll a=0;
    int tmp;
    rep(i,m){
        cin>>tmp;
        a+=tmp;
    }
    if(a>n){
        fin(-1);
    }else{
        fin(n-a);
    }
}


Measured memory_bytes: 3672
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int main()
{
    ll n, a, b, h[112345] = {0};
    cin >> n >> a >> b;
    REP(i, n)
    cin >> h[i];

    ll l = 0, r = 1000000000;
    while (r - l > 0)
    {
        ll m = (r + l) / 2; // ceil((r + l) / 2.0);

        /*
        ll h_[112345] = {0};
        REP(i, n)
        {
            h_[i] = h[i] - b * m;
        }

        ll ans_ = 0;
        sort(h_, h_ + 112345);
        int i = 112344;
        while (h_[i] > 0)
        {
            ans_ += ceil((float)h_[i] / (float)(a - b));

            //cout << ceil((float)h_[i] / (float)(a - b)) << endl;

            i--;
        }
        */
        ll ans = 0;
        REP(i, n)
        {
            if (h[i] - b * m > 0)
            {
                ans += (h[i] - m * b - 1) / (a - b) + 1;
            }
        }

        //cout << l << " " << r << " " << m << " " << ans_ << endl;

        if (ans > m)
        {
            l = m + 1;
        }
        else
        {
            r = m;
        }
    }

    cout << l << endl;

    return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_Challenge
{
    class _004_C
    {
        static void Main(string[] args)
        {
            Method(args);
            ReadLine();
        }

        static void Method(string[] args)
        {
            int[] hw = ReadInts();
            int h = hw[0];
            int w = hw[1];
            bool[,] grid = new bool[h, w];
            bool[,,] res = new bool[h, w, 2];
            for (int i = 0; i < w; i++) res[0, i, 0] = true;
            Read();
            for(int i = 1; i < h-1; i++)
            {
                string s = Read();
                int index = i % 2 == 0 ? 0 : 1;
                res[i, 0, 0] = true;
                res[i, w - 1, 1] = true;
                for(int j = 1; j < w-1; j++)
                {
                    res[i, j, index] = true;
                    res[i, j, (index + 1) % 2] = s[j] == '#';
                }
            }
            Read();
            for(int i = 0; i < h; i++)
            {
                for(int j = 0; j < w; j++)
                {
                    Write(res[i, j, 0] ? '#' : '.');
                }
                WriteLine();
            }
            WriteLine();
            for (int i = 0; i < h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    Write(res[i, j, 1] ? '#' : '.');
                }
                WriteLine();
            }
        }

        private static string Read() { return ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1000;
const int MOD = 1e9+7;

int n, m, dp[MAXN+10][MAXN+10];
char board[MAXN+10][MAXN+10];

int main()
{
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int i, j;

    scanf("%d%d", &n, &m);
    for(i=1; i<=n; i++) scanf("%s", board[i]+1);

    dp[1][1]=1;
    for(i=1; i<=n; i++) for(j=1; j<=m; j++)
    {
        if(i==1 && j==1) continue;
        if(board[i][j]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    }

    printf("%d", dp[n][m]);
    return 0;
}


Measured memory_bytes: 5248
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

int main()
{
	int x = 0;
	scanf("%d", &x);

	int ans = 0;
	if (x == 0) {
		ans = 1;
	} else {
		ans = 0;
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int D = A + B;
  int E = A + C;
  int F = B + C;
  if (D <= E && D <= F) {
    cout << D;
  }
  else if (E <= D && E <= F) {
    cout << E;
  }
  else if (F <= D && F <= E) {
    cout << F;
  }
}


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

using int64 = long long;
using PII = pair<int64,int64>;

int main() {
  int64 h, w, n;
  cin >> h >> w >> n;
  vector<int64> a(n), b(n);
  for (int64 i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }

  map<PII, int64> mp;
  for (int64 i = 0; i < n; ++i) {
    for (int64 dr = -2; dr <= 0; ++dr) {
      int64 r = a[i] + dr;
      if (r < 1 || r > h - 2)
        continue;
      for (int64 dc = -2; dc <= 0; ++dc) {
        int64 c = b[i] + dc;
        if (c < 1 || c > w - 2)
          continue;
        mp[PII(r, c)] = mp[PII(r, c)] + 1;
      }
    }
  }
  
  vector<int64> ret(10, 0);
  ret[0] = (h - 2) * (w - 2);
  for (auto&& m : mp) {
    ++ret[m.second];
    --ret[0];
  }
  for (auto& r : ret)
    cout << r << "\n";

  return 0;
}


Measured memory_bytes: 58112
#include <iostream>

using namespace std;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int N, Y;
  cin >> N >> Y;
  for (int i=0; i<=N; ++i) {
    for (int j=0; j<=N-i; ++j) {
      int k=N-i-j;
      if (Y == (10000*i + 5000*j + 1000*k)) {
        cout << i << " " << j << " " << k << "\n";
        return 0;
      }
    }
  }
  cout << "-1 -1 -1\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
bool ok;
int n,m=1e9;
char b[510][510];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%s",b[i]+1);
    ok=0;
    for(int i=1;i<=n;++i)
        for(int j=1;j<=n;++j)
            ok|=b[i][j]=='#';
    if(!ok){puts("-1");return 0;}
    for(int i=1;i<=n;++i)
    {
        int t=ok=0;
        for(int j=1;j<=n;++j)
            ok|=b[j][i]=='#';
        for(int j=1;j<=n;++j)
            if(b[i][j]=='.')
                t+=1+!ok,ok=1;
        m=std::min(m,t);
    }
    for(int i=1;i<=n;++i)
    {
        ok=1;
        for(int j=1;j<=n;++j)
            ok&=b[j][i];
        m-=ok;
    }
    printf("%d\n",m+n);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  ll ma = -INF;
  ll mi = INF;
  rep(i, n){
    ll r; cin >> r;
    chmax(ma, r-mi);
    chmin(mi, r);
  }

  cout << ma << endl;

  return 0;
}










Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main()
{

        int a,b;
        cin>>a>>b;
        
        if(a>=13)
        { cout<<b;}
        
        else if((a<13)&&(a>=6))
        { cout<<b*0.5;}
        
        else cout<<"0";
    }


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    a, b, c, k = map(int, input().split())
    ans = 0
    if a >= k:
        print(k)
        return
    k -= a
    if b >= k:
        print(a)
        return
    k -= b
    print(a-k)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 61780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    string s; cin >> s;
    int l=s.length();
    auto s2=s;
    reverse(all(s2));
    auto fo=s.substr(0,l/2);
    auto fo2=fo;
    reverse(all(fo2));
    auto f=s.substr((l/2)+1,l/2);
    auto f2=f;
    reverse(all(f2));
    if(s==s2 && fo2==fo && f==f2) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

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

using namespace std;

#define INPUT_OUTPUT { \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout); \
}

int main()
{
    // INPUT_OUTPUT;
    int n, i, m, s = 0, j;
    cin >> n;
    int t[n];
    for(i = 0; i < n; i++) {
        cin >> t[i];
    }
    cin >> m;
    int p, x;
    for(i = 0; i < m; i++) {
        cin >> p >> x;
        for(j = 0; j < n; j++) {
            if(j == (p-1)) s += x;
            else s += t[j];
        }
        cout << s << endl;
        s = 0;
    }
    return 0;
}

Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

int n;
vvi dp;
void f(int l,int r,int t){
	if(r-l<=1)return;
	int h=(l+r)/2;
	loop(i,l,h)loop(j,h,r)dp[i][j]=dp[j][i]=t;
	f(l,h,t+1);f(h,r,t+1);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n;
	dp=vvi(n,vi(n));
	f(0,n,1);
	rep(i,n-1){loop(j,i+1,n)cout<<dp[i][j]<<" ";cout<<endl;}
}


Measured memory_bytes: 2432
import sys

N = sys.stdin.readline().strip()
A = [int(x) for x in sys.stdin.readline().strip().split(' ')]

for a in A:
    if a % 2 != 0:
       continue 
    if a % 3 != 0 and a % 5 != 0:
        print "DENIED"
        break
else:
    print "APPROVED"


Measured memory_bytes: 2568
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    ll a[n];
    for(int i=0; i<n; i++)
        scanf("%lld",&a[i]);
    sort(a,a+n);
    ll c,k;
    int f=1;
    for(int i=n-1; i>=0; i--)
    {
        if(a[i]==a[i-1]&&f==1)
        {
            c=a[i];
            f=3;
            i-=2;
        }
        if(a[i]==a[i-1]&&f==3)
        {
            k=a[i];
            break;
        }
    }
    if(f==3)
        printf("%lld\n",c*k);
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>

using namespace std;

int main(){
   int n;
   cin >> n;
   int a[n];
   for( int i = 0 ; i < n; i++ ) cin >> a[i];
   long long ans1=0;
   long long sum1=0;
   for( int i= 0 ; i < n; i++ ){
      sum1+=a[i];
      if( i%2 == 0  && sum1 <= 0 ){
         ans1 += 1-sum1;
         sum1 =1;
      }
      else if( i%2 ==1 && sum1 >= 0 ){
         ans1 += 1+sum1;
         sum1 = -1;
      }  
   }
   long long ans2 =0;
   long long sum2=0;
   for( int i= 0 ; i < n; i++ ){
      sum2+=a[i];
      if( i%2==1 && sum2 <= 0 ){
         ans2+=1-sum2;
         sum2=1;
      }
      else if( i%2 ==0 && sum2 >= 0 ){
         ans2 += 1+sum2;
         sum2 = -1;
      }  
   }
   cout << min(ans1, ans2) << endl;
   return 0;
}


Measured memory_bytes: 640
<?php
fscanf(STDIN, "%d", $target);
echo getColKey($target-1);

function getColKey($target) {
    for($i = 0; $i < 26; $i++){
        $alphabet[] = chr(ord('a') + $i);
    }
    $one = fmod($target, 26);
    $result = $alphabet[$one];
    $carry = ($target - $one) / 26;
    while($carry != 0) {
        $one = fmod($carry - 1, 26);
        $result = $alphabet[$one].$result;
        $carry = ($carry - 1 - $one) / 26;
    }
    return $result;
}


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

using namespace std;

using ll = long long;
#define long long long

int main(void) {
    ll n, x;
    cin >> n >> x;
    vector<ll> a(n);
    for(auto &e: a) cin >> e;

    vector<ll> b(n, 2e9);

    ll r = 1e18;
    for(ll i=0; i<n; i++) {
        for(ll j=0; j<n; j++)
            b[j] = min(b[j], a[(j+n-i)%n]);
        ll s = 0;
        for(ll j=0; j<n; j++)
            s += b[j];
        r = min(r, s + i*x);
    }
    cout << r << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll 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);
  return (ret);
}

signed main() {
  init();
  ll N, K;
  cin >> N >> K;

  vector<P> ans;
  rep2(i, 1, N - 1) {
    rep2(j, i + 1, N) {
      ans.pb({i, j});
    }
  }

  if ((ll)ans.size() < K) {
    COUT(-1);
    return 0;
  }

  ll count = (N - 1) + (ans.size() - K);
  COUT(count);

  rep(i, N - 1) {
    cout << 1 << " " << i + 2 << endl;
  }
  rep(i, ans.size() - K) {
    P p = ans[i];
    cout << p.first + 1 << " " << p.second + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ll long long
#define test(t) int t ; cin>>t ; while(t--)
ll mulmod(ll a, ll b, ll mod){ll res = 0;a = a % mod;while (b > 0){if (b % 2 == 1)res = (res + a) % mod;a = (a * 2) % mod;b /= 2;}return res % mod;}
ll n;
int main(){
    BOOST;
    cin >> n;
    ll arr[n];
    for(int i = 0 ; i < n ; ++i){
        cin >> arr[i];
    }
    sort(arr,arr+n);
    cout << arr[n-1] - arr[0] ;
    return 0;
}

Measured memory_bytes: 256
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
ans = []
line = [0 for i in range(w)]
ad = ["." for i in range(w+2)]

for i in range(h):
    s[i].insert(0,".")
    s[i].append(".")
s.insert(0,ad)
s.append(ad)



for i in range(1,h+1):
    for j in range(1,w+1):
        cnt =[]
        if s[i][j] =="#":
            line[j-1] = "#"
        else:
            for k in range(3):
                for l in range(3):
                    cnt.append(s[i-1+k][j-1+l])
            line[j-1] = str(cnt.count("#"))
        del cnt
    ans.append("".join(line))
for i in range(h):
    print(ans[i])


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){

	int n;
	cin>>n;
	int a[n];
	long long int ans=0;
	
	for(int i=0;i<n;i++){
	
		cin>>a[i];
	}
	for(int i=1;i<n;i++){
	
		if(a[i]<a[i-1]){
		
			ans+=a[i-1]-a[i];	
			a[i]+=a[i-1]-a[i];
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4344
/*
 * sto RainAir orz
 * 感谢真神wyh无私的教诲。
 * 膜吴队者处处阿克，只因大师wyh在他背后。
 * 不膜大师者违背了真神的旨意，真神必将降下天谴，使其天天爆零
 * 我不由自主地膜拜真神wyh。
 * Author: Shq
 */

#include <bits/stdc++.h>

#ifndef __HEADERS__
#define __HEADERS__

#define up(i,j,k) for (int i = j; i <= k; i++)
#define down(i,j,k) for (int i = j; i >= k; i--)

#define lb long double
#define ll long long
#define ull unsigned long long

#define mp std::make_pair
#define pb push_back

#define all(x) x.begin(), x.end()
#define lowbit(x) ((x) & (-x))
#define mem(a) memset(a, 0, sizeof(a))
#define File(x)                       \
    freopen("" #x ".in", "r", stdin); \
    freopen("" #x ".out", "w", stdout);

#endif

#define int long long

inline int read() {
	int data = 0, w = 1; char ch = 0;
	while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar(); if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); }
	return data * w;
}

inline void print (ll v) {
    if (v < 0) { putchar('-'); v = -v; }
    if (v > 9) print(v / 10);
    putchar(v % 10 + '0');
}

const int N = 3500 + 10;

int a;

signed main () {
    a = read();
    up (h, 1, N) up (w, 1, N) {
        int down = 4 * h * w - a * (w + h);
        int up = a * h * w;
        if (down <= 0) continue;
        if (up % down) continue;
        return printf("%lld %lld %lld", h, w, up / down), 0;
    }
    return 0;
}



Measured memory_bytes: 256
n, m = map(int, input().split())

hasAC, pena = [0] * n, [0] * n

for i in range(m):
    li = input().split()
    p = int(li[0]) - 1
    s = li[1]
    if hasAC[p]: continue
    if s == 'AC': hasAC[p] = 1
    else: pena[p] += 1
AC, pena_sum = 0, 0
for i in range(n):
    AC += hasAC[i]
    if hasAC[i]: pena_sum += pena[i]
print(AC, pena_sum)

Measured memory_bytes: 4596
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    sr--; sc--;
    string S, T;
    cin >> S >> T;

    int left = 0;
    int right = W - 1;
    for (int i = N - 1; i >= 0; i--) {
        if (T[i] == 'R') left = max(0LL, left - 1);
        if (T[i] == 'L') right = min(W - 1, right + 1);
        if (S[i] == 'R') right--;
        if (S[i] == 'L') left++;

        if (left > right) break;
    }

    if (!(left <= sc && sc <= right)) {
        cout << "NO" << endl;
        return 0;
    }

    left = 0;
    right = H - 1;
    for (int i = N - 1; i >= 0; i--) {
        if (T[i] == 'D') left = max(0LL, left - 1);
        if (T[i] == 'U') right = min(H - 1, right + 1);
        if (S[i] == 'D') right--;
        if (S[i] == 'U') left++;
        if (left > right) break;
    }

    if (!(left <= sr && sr <= right)) {
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;

    return 0;
}

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

const int maxN = 305, mod = 1e9 + 7;

int n, m;
int f[maxN + 1][maxN + 1][maxN + 1];

inline int ADD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }

int main()
{
	scanf("%d %d", &n, &m);

	if(m < n) { puts("0"); return 0; }
	
	f[0][1][1] = 1;
	for(int i = 0; i < m; i++)
		for(int j = 1; j <= n && j <= i + 1; j++)
			for(int k = 1; k <= j; k++)
			{
				if(!f[i][j][k]) continue;
				f[i + 1][j][k] = ADD(f[i + 1][j][k], 1ll * f[i][j][k] * (j - k) % mod);
				f[i + 1][j + 1][k] = ADD(f[i + 1][j + 1][k], 1ll * f[i][j][k] * (n - j) % mod);
				f[i + 1][j][j] = ADD(f[i + 1][j][j], 1ll * f[i][j][k] * k % mod);
			}
	
	printf("%d", f[m][n][n]);
	return 0;
}


Measured memory_bytes: 108800
n = int(input())
A = list(map(int, input().split()))
A.sort()

l = [False]*(A[n-1] + 1)
fix = []
for i in A:
    if l[i]:
        fix.append(i)
    l[i] = True
    
for i in range(A[n-1]+1):
    if l[i]:
        for j in range(i*2, A[n-1]+1, i):
            l[j] = False

for i in fix:
    l[i] = False
    
ans = [i for i in range(A[n-1] + 1) if l[i]]

print(len(ans))


Measured memory_bytes: 125212