akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    long[] Pow;
    int[] Normal;
    int[] NoZero;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        Pow = new long[19];
        Pow[0] = 1;
        for(int i=1;i<19;i++){
            Pow[i] = 10*Pow[i-1];
        }
        Normal = new int[19];
        NoZero = new int[19];
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                if(i != 0){
                    NoZero[j-i+9]++;
                }
                Normal[j-i+9]++;
            }
        }
        long count = 0;
        long D = long.Parse(Console.ReadLine());
        for(int i=0;i<19;i++){
            count += Calc(D,i,true);
        }
        sb.Append(count+"\n");
    }
    long Calc(long N,int M,bool b){
        if(M == 0){
            return N == 0 ? 1 : 0;
        }
        if(M == 1){
            if(N == 0){
                return b ? 9 : 10;
            }
            else{
                return 0;
            }
        }
        long mo = Pow[M-1]-1;
        long count = 0;
        for(int i=-9;i<10;i++){
            if((N - mo*i) % 10 == 0){
                count += (b ? NoZero[i+9] : Normal[i+9])*Calc((N - mo*i) / 10,M-2,false);
            }
        }
        return count;
    }
}

Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int SIZE=200050;
//int arr[SIZE]={};
//↓座標圧縮：vectorを入れると対応関係をmap[旧座標]=新座標で返す
map<int,int> comp(vector<int> v){
	map<int,int> pam;
	int sz=v.size();
	for(int i=0;i<sz;i++){
		pam[v[i]]=0;
	}
	//新座標が1からほしいときはnc=1にする
	int nc=0;
	for(pair<int,int> i:pam){
		pam[i.first]=nc;
		nc++;
	}
	return pam;
}
//↑座標圧縮
int main(){
	int N,M;
	cin>>N;
	vector<int> tes,ket,xal;
	for(int i=0;i<N;i++){
		int a;
		cin>>a;
		tes.pb(a);
		xal.pb(a);
	}
	cin>>M;
	for(int i=0;i<M;i++){
		int a;
		cin>>a;
		ket.pb(a);
		xal.pb(a);
	}
	sort(tes.begin(),tes.end());
	sort(ket.begin(),ket.end());
	sort(xal.begin(),xal.end());
	map<int,int> pam=comp(xal);
	int A[SIZE]={},B[SIZE]={};
	for(int i:tes)
		A[pam[i]]++;
	for(int i:ket)
		B[pam[i]]++;
	for(int i=0;i<SIZE-1;i++){
		if(B[i]>A[i]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 14312
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> p(n);

    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }

    int ans = 0;

    for (int j = 1; j < n-1 ; ++j) {
        if ((p[j]<p[j-1])&&(p[j]>p[j+1])){
            ans++;
        } else if((p[j]>p[j-1])&&(p[j]<p[j+1])){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
	fact.resize(n+1);
	inv.resize(n+1);
	invfact.resize(n+1);
	fact[0]=inv[0]=invfact[0]=1;
	inv[1]=1;
	rep(i,n){
		fact[i+1]=fact[i]*(i+1)%mod;
		if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
		invfact[i+1]=invfact[i]*inv[i+1]%mod;
	}
}
ll perm(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
	if(n<0||k<0||k>n)return 0;
	return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
	k%=mod-1;
	if(k<0)k+=mod-1;
	ll ret=1;
	while(k){
		if(k&1)ret=ret*n%mod;
		n=n*n%mod;
		k>>=1;
	}
	return ret;
}
int main(){
	mod_build(202020);
	ll n,m,k;
	cin>>n>>m>>k;
	ll res1=(m*m*m-m)%mod*n%mod*n%mod*inv[6]%mod;
	ll res2=(n*n*n-n)%mod*m%mod*m%mod*inv[6]%mod;
	ll ans=(res1+res2)*powmod(comb(m*n,2),mod-2)%mod;
	ans*=comb(m*n,k)*comb(k,2)%mod;
	cout<<ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;

int main(){
    int N;
    cin>>N;
    int P[N];
    for (int i=0;i<N;i++){
        cin>>P[i];
    }
    int min=P[0],n=1;
    for (int j=1;j<N;j++){
        if (P[j]<=min) {
            min=P[j];
            n+=1;
        }
    }
    cout<<n<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	    static String a;
	    public static void main(String[] args) {
	        Scanner stdIn = new Scanner(System.in);
	        int n = stdIn.nextInt();
	        int count = 0;
	        IN:for(int i = 0; i < n; i++) {
	            int x = stdIn.nextInt();
	            for(int j = 2; j*j <= x; j++) {
	                if(x % j == 0) continue IN;
	            }
	            count++;
	        }
	        System.out.println(count);
	    }
	}


Measured memory_bytes: 40676
import sys

def generate_next_hexes(x, y):
    hexes = list()
    hexes.append((x, y - 1))
    hexes.append((x, y + 1))
    hexes.append((x - 1, y))
    hexes.append((x + 1, y))
    if y % 2:
        hexes.append((x - 1, y - 1))
        hexes.append((x - 1, y + 1))
    else:
        hexes.append((x + 1, y - 1))
        hexes.append((x + 1, y + 1))
    return hexes

def update_map(hex_map, hexes):
    num_updated_hexes = 0
    distance = 0
    while hexes:
        next_hexes = []
        for pos in hexes:
            x = pos[0]
            y = pos[1]
            if (1 <= x <= m and 1 <= y <= n
                    and (pos not in hex_map or distance < hex_map[pos])):
                hex_map[pos] = distance
                num_updated_hexes += 1
                next_hexes += generate_next_hexes(x, y)
        distance += 1
        hexes = next_hexes
    return num_updated_hexes

while True:
    (m, n) = [int(i) for i in sys.stdin.readline().split()]
    if m == n == 0:
        break

    s = int(sys.stdin.readline())
    stores = []
    for i in range(s):
        cord = [int(j) for j in sys.stdin.readline().split()]
        stores.append(tuple(cord))
    hex_map = {}
    update_map(hex_map, stores)

    t = int(sys.stdin.readline())
    candidates = []
    for i in range(t):
        cord = [int(j) for j in sys.stdin.readline().split()]
        candidates.append(tuple(cord))

    # search max num
    max_num_blocks = 0
    for candidate in candidates:
        new_hex_map = hex_map.copy()
        num_blocks = update_map(new_hex_map, [candidate])
        max_num_blocks = max(max_num_blocks, num_blocks)

    print(max_num_blocks)

Measured memory_bytes: 7044
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int MOD = 1e9 + 7;

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
		a[i] -= (i + 1);
	}
	sort(a.begin(), a.end());
	int x;
	if (n % 2 == 1) x = a[n / 2];
	else x = (a[(n / 2) - 1] + a[n / 2]) / 2;

	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sum += abs(b[i] - (x + (i + 1)));
	}
	cout << sum << endl;
}


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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    cout << (!a ? 1 : !b ? 2 : !c ? 3 : !d ? 4 : 5) << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, b;
	cin >> a >> b;
	cout << (a * b / 2) << endl;
	return 0;
}
 

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!(
    r: f64,
    );
    let pi = std::f64::consts::PI;
    let ans = 2.0 * r * pi;
    println!("{}", ans);
}


Measured memory_bytes: 2204
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    int r, g; cin >> r >> g;
    cout << 2 * g - r << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var S, T string
	fmt.Scan(&S, &T)
	S = Reverse(S)
	T = Reverse(T)
	for i := 0; i <= len(S)-len(T); i++ {
		b := true
		for j := 0; j < len(T); j++ {
			t := T[j : j+1]
			s := S[i+j : i+j+1]
			if t == s || s == "?" {
			} else {
				b = false
				break
			}
		}
		if b {
			w := S[:i] + T + S[i+len(T):]
			w = strings.Replace(w, "?", "a", -1)
			fmt.Println(Reverse(w))
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}
func Reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

Measured memory_bytes: 640
N = int(input())
Vlist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

value = 0
for i in range(N):
    if Vlist[i] - Clist[i] > 0:
        value += Vlist[i] - Clist[i]

print(value)


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

#define ENGZ ios::sync_with_stdio(0);cin.tie(0);ios_base::sync_with_stdio(0);
#define sfi(x) scanf("%d" , &x)
#define sfi2(x, y) scanf("%d%d" , &x,&y)
#define sfl2(x, y) scanf("%I64d%I64d" , &x,&y)
#define sfl(x) scanf("%I64d" , &x)
#define sfl3(x, y, z) scanf("%I64d%I64d%I64d", &x, &y, &z)
#define sfd(x) scanf("%lf", &x)
#define sfd2(x, y) scanf("%lf", &x, &y)
#define sfs(x) scanf("%s", &x)
#define testv(x) cerr << x << ' '
#define wtf(s) freopen((s), "w", stdout)
#define rff(s) freopen((s), "r", stdin)
#define test cerr << "here"
#define fst(x) cout << fixed << setprecision(x)
#define mod 1000000007
#define pi (2 * acos(0))
typedef long double ld;
typedef long long ll;

ll gcd(ll a , ll b)
{
    if(b == 0)
        return a;
    return gcd(b, a % b);
}

int main()
{
    ENGZ
    ll n, x, ans = 1e9, y;
    cin >> n >> x;
    for (int i = 0; i < n ; i++)
    {
        cin >> y;
        if (i == 0)
            ans = abs(y - x);
        else
            ans = gcd(ans, abs(y - x));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
#define pb push_back
typedef long long ll;
const int inf = 2e9;
using namespace std;
ll MOD = 1000000007;
typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;

int a,b,c,d,n,q,t,k,res,suma,minimo,maxi,indi;
vector<ii> PC;

bool ord(ii a, ii b){
  return a.first<b.first;
}

int main(){
    ll ans = 0;
    ll m;
    scanf("%d%lld",&n,&m);
    for(int i=0; i<n; i++){
      scanf("%d",&a);
      scanf("%d",&b);
      PC.pb({a,b});
    }
    sort(PC.begin(),PC.end(),ord);

    for(int i = 0; i<n; i++){
      if(m<=PC[i].second){

        ans+=ll(m*PC[i].first);
        break; 
      } else {
        ans+=ll(PC[i].second)*ll(PC[i].first);
        m-=PC[i].second;
      }
    }

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

Measured memory_bytes: 1400
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	a, b := getInt(), getInt()
	s := make([]bool, 3)

	s[a-1] = true
	s[b-1] = true

	for i, v := range s {
		if !v {
			fmt.Fprintln(wr, i+1)
		}
	}
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
 
int main(void){
    int a,b,c;
    cin>>a>>b>>c;

     if(a==b && b != c) {cout<<"Yes";}	
     else if(b==c && c != a) {cout<<"Yes";} 
     else if(c==a && a != b) {cout<<"Yes"; }
     else {cout<<"No";}
     
    return 0;
}

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

const int MAXN = 1e5;

int N, L;
int A[MAXN + 10];

int main() {
   scanf("%d%d", &N, &L);
   for(int i = 1; i <= N; i++) {
      scanf("%d", &A[i]);
   }
   int i = 1;
   while(i+1 <= N && A[i]+A[i+1] < L) i++;
   if(i == N) printf("Impossible\n");
   else {
      printf("Possible\n");
      
      int j = 1;
      while(j < i) {
         printf("%d\n", j);
         j++;
      }
      j = N-1;
      while(j > i) {
         printf("%d\n", j);
         j--;
      }
      printf("%d\n", i);
   }
}


Measured memory_bytes: 1152
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;



signed main() {
	int n; cin >> n;
	int ans = n / 11;
	ans = ans * 2;
	n = n % 11;
	if (n > 0)ans++;
	if (n > 6)ans++;
	cout << ans << endl;
}

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

int main()
{
    int age, fare;
    cin >> age >> fare;

    if (age >= 13) {
        cout << fare << endl;
    } else if (6 <= age && age <= 12) {
        cout << fare / 2 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf 10000000000000
#define mod 1000000007
#define maxn 100009
#define maxr 100009
void solve()
{
	ll arr[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll k;
	rl(k);
	cout<<arr[k-1]<<endl;
	return;
}
int main()
{
	
	ll t=1;
	//rl(t);

	//cin>>t;
	//scanf()
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;


int main() {
  ll n, k, s; cin >> n >> k >> s;
  if(s != 1e9){
    rep(i, 0, k) cout << s << " ";
    rep(i, 0, n-k){
      if(i) cout << " ";
      cout << s+1;
    }
    cout << endl;
  }else{
    rep(i, 0, k) cout << s << " ";
    rep(i, 0, n-k){
      if(i) cout << " ";
      cout << 1;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1280
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        int x = 0;
        if(S.equals("RRR")) x = 3;
        else if(S.equals("RRS")) x = 2;
        else if(S.equals("SRR")) x = 2;
        else if(S.equals("RSR")) x = 1;
        else if(S.equals("RSS")) x = 1;
        else if(S.equals("SSR")) x = 1;
        else if(S.equals("SRS")) x = 1;
        
        System.out.println(x);
    }
}


Measured memory_bytes: 35576
//#define DEB1 //output check function
//#define DEB2 //same output, input from input.txt

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <thread>
#include <mutex>
#include <iomanip>

#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define ALL(t) (t).begin(),(t).end()
#define FILL(a,c) fill(a, a+ sizeof(a)/sizeof(*a),c)
#define FILL2D(A,c) fill(A[0], A[0] +sizeof(A)/sizeof(**A),c)
#define FILL3D(A,c) fill(A[0][0], A[0][0] +sizeof(A)/sizeof(***A),c)
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define IN(a, x, b) (a<=x && x<b)
#define PB push_back

using namespace std;

using LL = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<LL,LL>;
using VI = vector<int>;
using VVI = vector<VI>;


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


#ifdef DEB1
#define DPRINT(x) cout<< #x << "=" << (x) << endl; // print at debug mode
#else
#define DPRINT(x) ;
#endif
#ifdef DEB1
#define DCHECK(x) cout<< "debug check" << #x << endl;
#else
#define DCHECK(x) ;
#endif
 


/*
constant values
*/

//const int dx[] = {1,0,-1,0};
//const int dy[] = {0,1,0,-1};
//const int MX = 31001;

//const ll INF= 1LL<<60 ;//INF = 1001001001001; //1e9
struct original
{
    int id, name, limit;
};

int INF = 20000;
int A[110];
int B[110];
int res[110];
original TMP[110];



bool HikakuFunction(const original& Hidari, const original& Migi){
    if(Hidari.limit == Migi.limit){
        return Hidari.name > Migi.name;
    }
    else{
        return Hidari.limit < Migi.limit;
    }
    }




// Main program
void solve(){
    bool flag = 0;
    int target_id;
    int N; cin >> N ;
    REP(i,N) cin >> A[i]; //id
    
    REP(i,N){
        B[i] = (i+1) - A[i]; //limit
        if(B[i] < 0) flag = 1;
    }

    if(!flag){
        REP(i,N){

            //copy A,B to original
            REP(j,N){
                TMP[j].id = j;
                TMP[j].name = A[j];
                TMP[j].limit = B[j];
            }

            sort(TMP,TMP+N,HikakuFunction);

            target_id = TMP[0].id;

            res[(N-1) -i] = TMP[0].name;
            
            //update limit
            B[target_id] = INF;
            REPN(j,N,target_id){
                --B[j];
                if(B[j]<0) flag = 1;
            }
        }
    }

    //output
    if(flag) cout << -1 << endl;
    else{
        REP(i,N){
            cout << res[i] << endl;
        }
    }

}



// ----------------------------------------------
int main() {

#ifdef DEB2
    cout << "DEBUG MODE"  << endl;
	ifstream in("input.txt"); //for debug
	cin.rdbuf(in.rdbuf()); //for debug
#endif

	int T=1; 

	for (int i = 0; i < T; ++i) {
		solve();
	}
}

Measured memory_bytes: 256
def main():
    n=int(input())
    a=list(map(int,input().split(' ')))
    color = [0]*8
    ans_max = 0
    for i in a:
        if 1<= i <= 399:
            color[0] = 1
        elif i <= 799:
            color[1]=1
        elif i <= 1199:
            color[2] = 1
        elif i <= 1599:
            color[3] = 1
        elif i <= 1999:
            color[4] = 1
        elif i <= 2399:
            color[5] = 1
        elif i <= 2799:
            color[6] = 1
        elif i <= 3199:
            color[7] = 1
        else:
            ans_max += 1
    print(max(1,sum(color)),ans_max+sum(color))
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 100001

typedef struct{
  char name[10];
  int time;
} qu;

int head,tail;

int main(){
  int i,n,x,mt,sum = 0;
  qu q[MAX];

  scanf("%d%d",&n,&mt);
  for(i = 1;i <= n;i++){
    scanf("%s%d",q[i].name,&q[i].time);
  }
  head = 1;
  tail = n+1;

  while(1){
    if(head == tail) break;
      if(q[head].time <= mt){
	sum += q[head].time;
	printf("%s %d\n",q[head].name,sum);
	head++;
	if(head == MAX) head = 0;
      }
      else{
	sum += mt;
	q[head].time -= mt;
	q[tail] = q[head];
	head++;
	tail++;
	if(tail == MAX) tail = 0;
	if(head == MAX) head = 0;
	}
  }

  return 0;
}



Measured memory_bytes: 3256
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

ans = 0


for i in range(N-1):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp += (X[i][k] - X[j][k])**2
        if tmp**0.5 %1 == 0:
            ans += 1

print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
N = int(input())
edge = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    edge[a].append((b, c % 2))
    edge[b].append((a, c % 2))

root = 1
dist = [-1] * (N + 1)
dist[root] = 0
node = [root]

while node:
    s = node.pop()
    d = dist[s]
    for t, c in edge[s]:
        if dist[t] != -1:
            continue
        dist[t] = (d + c) % 2
        node.append(t)

print(*dist[1:], sep="\n")


Measured memory_bytes: 37160
#include <iostream>
using namespace std;
int main()
{

    int a, b;
    cin >> a >> b;
    if (a < b)
    { //a is always bigger than b
        int c = a;
        a = b;
        b = c;
    }
    int c = a - b;

    int d = 16 - 2 * b;
    if (c <= d / 2)
    {
        cout << "Yay!";
    }
    else
    {
        cout << ":(";
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(void)
{
	int n;
	int i;
	long sum;
	
	sum = 1;
	
	scanf("%d", &n);
	
	for (i = 1; i <= n; i++){
		sum *= i;
	}
	
	printf("%ld\n", sum);
	
	return (0);
}

Measured memory_bytes: 1020
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define lld long long int

void next_permutation(int* a, int n){
    int tmp, x=-1, y=-1, z;
    for(int i=n-1; i>0; i--){
        if(*(a+i-1) < *(a+i)){
            x = i-1;
            break;
        }
    }
    if(x==-1){
        return;
    }
    for(int i=n-1; i>=0; i--){
        if(*(a+x) < *(a+i)){
            y = i;
            break;
        }
    }
    tmp = *(a+x);
    *(a+x) = *(a+y);
    *(a+y) = tmp;
    for(int i=x+1; i<n; i++){
        z = n-(i-x);
        if(i < z){
            tmp = *(a+z);
            *(a+z) = *(a+i);
            *(a+i) = tmp;
        }else{
            break;
        }
    }
    return;
}

int main(){
    int n;
    scanf("%d", &n);
    int p[n], q[n], r[n];
    rep(i, 0, n){
        scanf("%d", &p[i]);
        r[i] = i+1;
    }
    rep(i, 0, n){
        scanf("%d", &q[i]);
    }
    int x=1, a=-1, b=-1;
    while(a==-1 || b==-1){
        if(memcmp(p, r, sizeof(p))==0){
            a = x;
        }
        if(memcmp(q, r, sizeof(q))==0){
            b = x;
        }
        next_permutation(r, n);
        x++;
    }
    printf("%d", abs(a-b));

    return 0;
}

Measured memory_bytes: 128
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 210000
#define LL long long
using namespace std;
struct node{int y,nex;}a[2*N];
int fir[N],len,n,f[N],g[N],high[N],low[N];
bool in[N],out[N];
char s[N];
LL ans;
void dp1(int x,int fa)
{
	if(s[x]=='1') in[x]=1;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dp1(y,x);
		f[x]=max(f[x],f[y]+1);
		in[x]|=in[y];
	}
}
void dp2(int x,int fa)
{
	int mx1=0,mx2=0,cnt=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		if(f[y]+1>mx1) mx2=mx1,mx1=f[y]+1;
		else if(f[y]+1>mx2) mx2=f[y]+1;
		cnt+=in[y];
	}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		if(f[y]+1==mx1) g[y]=max(g[x]+1,mx2+1);
		else g[y]=max(g[x]+1,mx1+1);
		out[y]=out[x];
		if(cnt-in[y] || s[x]=='1') out[y]=1;
		dp2(y,x);
	}
}
void dfs(int x,int fa)
{
	int mx1=g[x],mx2=0;
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		if(f[y]+1>mx1) mx2=mx1,mx1=f[y]+1;
		else if(f[y]+1>mx2) mx2=f[y]+1;
	}
	high[x]=min(mx1-1,mx2+1);
	if(s[x]=='1') low[x]=0;
	else
	{
		low[x]=high[x]+1;
		if(out[x]) low[x]=min(low[x],g[x]);
		for(int k=fir[x];k;k=a[k].nex)
		{
			int y=a[k].y;
			if(y==fa) continue;
			if(in[y]) low[x]=min(low[x],f[y]+1);
		}
	}
	for(int k=fir[x];k;k=a[k].nex)
	{
		int y=a[k].y;
		if(y==fa) continue;
		dfs(y,x);
	}
}
void ins(int x,int y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	scanf("%s",s+1);
	dp1(1,0);dp2(1,0);
	dfs(1,0);
	for(int i=1;i<=n;i++) ans+=high[i]-low[i]+1;
	ans++;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 19968
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 100000000000000

int main(){
  int N,C;
  cin>>N>>C;
  vector<int> s(N),t(N),c(N);
  for(int i=0;i<N;i++){
    cin>>s.at(i)>>t.at(i)>>c.at(i);
    c.at(i)--;
  }

  vector<vector<int>> record(C,vector<int>(100005,0));
  for(int i=0;i<N;i++){
    record.at(c.at(i)).at(s.at(i))++;
    record.at(c.at(i)).at(t.at(i)+1)--;
  }
  int ans=0;
  for(int i=1;i<100005;i++){
    int count=0;
    for(int j=0;j<C;j++){
      record.at(j).at(i)+=record.at(j).at(i-1);
      if(record.at(j).at(i)>0){
        count++;
      }
    }
    ans=max(ans,count);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 13568
#include <stdio.h>
int main(void){
  int a,b,k;//下、上、倍数
  int i=0;
  int c=0;//7の倍数
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
for(i=1;c<a;++i){
  c=k*i;
}
  if(c<=b){
    printf("OK\n");
  }else{
    printf("NG\n");
  }
return 0;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 210000;

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

	int N;
	cin >> N;

	rep(i, 0, 9)
	{
		if (111 * i < N && N <= 111 * (i + 1))
		{
			cout << 111 * (i + 1) << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Text.RegularExpressions;

namespace Atcoder2
{
    class Program
    {

        public static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            int[] count = new int[num];

            for(int x = 1; x < 101; x++)
            {
                for (int y = 1; y < 101; y++)
                {
                    for (int z = 1; z < 101; z++)
                    {
                        int ans = x * x + y * y + z * z + x * y + y * z + z * x;
                        if(ans <= num)
                        {
                            count[ans - 1] += 1;
                        }
                    }
                }
            }
            
            for (int i = 0; i < num; i++)
            {
                Console.WriteLine(count[i]);
            }

        }
    }
}


Measured memory_bytes: 27388
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define fastio    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;


const int INF = 1e9;
const ll MOD = 1e9 + 7;
const int N = 1e6 + 3;
int ara[N];

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

    for(int i =1 ; i <=100 ; i++ )     {
        for(int j =1 ; j <= 100 ; j++ ) {
            for(int k =1 ; k <= 100; k++ ) {
                int tmp = i*i + j*j + k*k + i*j + i*k + j*k;
                ara[tmp]++;
            }
        }
    }
    for(int i =1 ; i <=n ; i++ ) cout<<ara[i]<<'\n';

    return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int A, B; cin >> A >> B;
    if (A <= 8 && B <= 8) cout << "Yay!" << endl;
    else                  cout << ":(" << endl;
}


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

bool match( char ch, const string& p ) {
	for( auto a: p ) {
		if( a == ch ) { return true; }
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio( false );

	string s;
	while( cin >> s ) {
		int n = (int)s.size();
		int result = 0;

		for( int i = n-1; i >= 0; --i ) {
			if( s[i] == 'I' ) {
				result += i < n-1 && s[i+1] != 'I' ? -1 : 1;
			}
			else if( s[i] == 'V' ) {
				result += i < n-1 && match( s[i+1], "XLCDM" ) ? -5 : 5;
			}
			else if( s[i] == 'X' ) {
				result += i < n-1 && match( s[i+1], "LCDM" ) ? -10 : 10;
			}
			else if( s[i] == 'L' ) {
				result += i < n-1 && match( s[i+1], "CDM" ) ? -50 : 50;
			}
			else if( s[i] == 'C' ) {
				result += i < n-1 && match( s[i+1], "DM" ) ? -100 : 100;
			}
			else if( s[i] == 'D' ) {
				result += i < n-1 && match( s[i+1], "M" ) ? -500 : 500;
			}
			else if( s[i] == 'M' ) {
				result += 1000;
			}
		}

		cout << result << endl;
	}

	return 0;
}



Measured memory_bytes: 3160
f = readline.split(" ")
M = f[0].to_i
N = f[1].to_i


i = 22
j = 4
ans = 0

while j < M+1 
  while i < N+1
    Z = i.to_s
    D = Z.split("")
    d_1 = D[0].to_i
    d_2 = D[1].to_i
    if   d_1 != 0 
      if d_2 != 0
        if d_1 != 1
          if d_2 != 1
            if j == d_1 * d_2
               ans += 1
    end
          end
        end
      end
    end
            
    i +=1
  end
  i = 22
  j += 1
end

puts ans

Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){a=(a+M)%M;b=(b+M)%M;a=(a+b)%M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

////////////////////////////////////////////////////////////////////
///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n,l;
signed main(){
  cin>>n>>l;
  int ans, sum = 0;
  rep(i,n)sum += l+i;
  ans = INF;
  rep(i,n){

    if(abs(ans) > abs(l+i)){
    ans = l+i;
  }
  }
  cout << sum - ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    for (int i = 0; i < N;i++){
        cin >> A[i] >> B[i];
    }
    vector<pair<int, int>> AB(N);
    for (int i = 0; i < N; i++){
        AB[i] = {A[i], B[i]};
    }
    sort(AB.begin(), AB.end());
    long long ans = 0;
    for (int i = 0; i < N;i++)
    {
        int l = min(M, AB[i].second);
        ans += (long long)AB[i].first * l;
        M -= l;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
while True:
    n, m = map(int, input().split())
    if not n:
        break

    dest = [0] * n
    for tray in range(3):
        itr = map(int, input().split())
        next(itr)
        for i in itr:
            dest[i - 1] = tray

    cnt = 0
    current_tray = 0
    for i, tray in enumerate(dest):
        move = abs(tray - current_tray)
        if move == 1:
            cnt += 3 ** (n - i - 1)
            current_tray = abs(current_tray - 2)
        elif move == 2:
            cnt += 2 * 3 ** (n - i - 1)

    ans = min(cnt, 3 ** n - cnt - 1)
    print(ans if ans <= m else -1)

Measured memory_bytes: 7564
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
   
    
    int n,m,c;
    cin>>n>>m>>c;
    int a[n][m];
    int b[m];
    rep(i,m){cin>>b[i];}
    rep(i,n){
        rep(j,m){
            cin>>a[i][j];
        }
    }
    int ans=0;
    rep(i,n){
        int sum=c;
        rep(j,m){
            sum+=a[i][j]*b[j];
        }
        if(sum>0){ans++;}
    }
    
    
    
    cout<<ans<<endl;
    
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dp[1000000];
int h[1000000];
int n,k,m;   
int cost(int n)
{
    if(dp[n]!=100000)
    return dp[n];
    else
    {
        for (long long int o=1; o<=k&&((n-o)>=0); o++)
        {
            if (o==1)
            dp[n]=(abs(h[n]-h[n-o])+cost(n-o));
            else if ((abs(h[n]-h[n-o])+cost(n-o))<dp[n])
            dp[n]=(abs(h[n]-h[n-o])+cost(n-o));
        }
        return dp[n];
    }
    
}
int main()
{
    
    cin>>n>>k;
    m=n;
    for(int i=0;i<n;i++)
    {
        cin>>h[i];dp[i]=100000;
        
    }
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    cout<<cost(n-1);
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N, A, B;

int main(){
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  
  std::cin >> N >> A >> B;

  int mx = std::min(A, B), mn = 0;

  if(A + B >= N){
      mn = A + B - N;
  }

  std::cout << mx << " " << mn << std::endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 19, mod = 1000000007;

vector <int> G[maxN], A, B, r[3];
int ile[3], p[maxN];

void dfs(int v, int fat, int d)
{
	d % 2 ? B.pb(v) : A.pb(v);
	for (int u : G[v])
		if (u != fat)
			dfs(u, v, d+1);
}

void mv(vector <int>& v, int k)
{
	r[k].pb(v.back());
	v.pop_back();
	ile[k]--;
}

void solve()
{
	int n;
	scanf ("%d", &n);
	FOR(i, 1, n)
	{
		int a, b;
		scanf ("%d%d", &a, &b);
		G[a].pb(b);
		G[b].pb(a);
	}
	
	dfs(1, 0, 0);
	
	ile[0] = n / 3;
	ile[1] = (n+2) / 3;
	ile[2] = n/3 + (n%3 == 2);
	
	if (A.size() > B.size())
		swap(A, B);
	
	while (!B.empty() and ile[2])
		mv(B, 2);
		
	vector <int>& C = A.size() > B.size() ? A : B;
	while (ile[1])
		mv(C, 1);
		
	while (ile[0])
	{
		if (A.empty())
			mv(B, 0);
		else
			mv(A, 0);
	}
	
	FOR(k, 1, 4)
	{
		int i = k;
		for (int v : r[k%3])
			p[v] = i, i+=3;
	}
	
	FOR(i, 1, n+1)
		printf("%d ", p[i]);
	printf("\n");	
} 

 
int main()
{
    int t;
    t=1;//scanf ("%d", &t);
    while (t--)
    	solve();
    return 0;    
}


Measured memory_bytes: 25076
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    int N;
    cin>>N;
    vector<int> arr(N);
    for(int i=0;i<N;++i){
        cin>>arr[i];
    }
    sort(arr.begin(), arr.end());
    int max = arr[N-1];
    int sum = 0;
    for(int i=0;i<N-1;++i){
        sum += arr[i];
    }
    if(max<sum) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
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<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N, K;
int h[110000];
int dp[110000];

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

  rep(i, N) cin >> h[i];

  rep(i, N) dp[i] = INF;
  dp[1] = 0;
  
  for (int i=1;i<N;++i) {
    rep(j, K) {
      if (i+j<=N) {
        chmin(dp[i+j], dp[i] + abs(h[i+j]-h[i]));
      }
    }
  }

  cout << dp[N] << "\n";
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
 
n = int(input())
a = list(map(int,input().split()))

d = dict()
for e in a:
    if e in d:
        d[e] += 1
    else:
        d[e] = 1

s = 0
for e in d:
    s += d[e]*(d[e]-1)//2

for e in a:
    if d[e] <= 1:
        print(s)
    else:
        k = d[e]
        res = s - k*(k-1)//2 + (k-1)*(k-2)//2
        print(res)

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

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

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x;
    ll a;
    cin>>x>>a;
    ll ans=0;
    if(x<a){
        ans = 0;
    }else{
        ans = 10;
    }
    
    cout<<ans<<endl;
    return  0;
}


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

using namespace std;

int main(){
    int a, b, c;
    string s = "NO";
    cin >> a >> b >> c;

    for(int i = 1; i < b; i++){
        if(a*i % b == c){
            s = "YES";
            break;
        }
    }

    cout << s << endl;
}

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

const int N_MAX = 100000;
const int M_SQRT_MAX = 40000;

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

  int s[2 * M_SQRT_MAX];
  int t = 0;
  for (int i = 1; i * i <= M; ++i) {
    if (!(M % i)) {
      s[t++] = i;
    }
  }
  for (int i = t - 1; i >= 0; --i) {
    if (s[i] * s[i] == M) {
      continue;
    }
    s[t++] = M / s[i];
  }
  int ans;
  for (int i = t - 1; i >= 0; --i) {
    if (s[i] <= M / N) {
      ans = s[i];
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)



void solve() 
{
    ll x,k,d;
    cin>>x>>k>>d;
    ll times = abs(x/d);
    if( times <= k)
    {
        times = k - times;
        if(times % 2 == 0)
        {
            cout<<abs(x)%d;
        }
        else
        {
            cout<<abs(min( (abs(x)%d) +d , (abs(x)%d) -d));
        }
        return;    
    }
    else
    {
        cout<<abs(min( (abs(x)) +d*k , (abs(x)) -d*k));
        return;
    }
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc = 1; 
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 3620
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  int M = N / 2 + N % 2;
  if (M >= K) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256