akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    ll N;
    cin >> N;
    ll ans = (N * (N - 1)) / 2;
    cout << ans << endl;
    return (0);
}

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

int m,n,k;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>m>>k;
    n=1;
    for(int i=1;i<=m;i++){
        n*=2;
    }
    if(k>=n){
        cout<<-1<<endl;
        return 0;
    }
    if(k==0){
        for(int i=0;i<n;i++){
            cout<<i<<' '<<i<<' ';
        }
        cout<<endl;
        return 0;
    }
    if(n==2){
        cout<<-1<<endl;
        return 0;
    }
    cout<<k<<' ';
    for(int i=0;i<n;i++){
        if(i==k)continue;
        cout<<i<<' ';
    }
    cout<<k<<' ';
    for(int i=n-1;i>=0;i--){
        if(i==k)continue;
        cout<<i<<' ';
    }
    cout<<endl;

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

string suit = "SHCD";

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

    int n;
    cin >> n;
    set<string> st;
    for (int i = 0; i < n; i++)
    {
        string s, t;
        cin >> s >> t;
        st.insert(s + t);
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 1; j <= 13; j++)
        {
            string k = suit[i] + to_string(j);
            if (st.find(k) == st.end())
                cout << suit[i] << " " << j << endl;
        }
    }
}



Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define lli long long
using namespace std ;
int main(){
    lli a = 0 , b = 0 , i , j , x ;
    cin >> x ;
    for(i=1;i<=1000;++i){
        for(j=-1000;j<i;++j){
            if(pow(i,5)-pow(j,5)==x) a = i , b = j ;
        }
    }    
    cout << a << " " << b << "\n" ;
    return 0 ;
}

Measured memory_bytes: 3980
from collections import deque
que = deque()
for _ in range(int(input())):
    op, v = (input().split() + ["1"])[:2]
    if op == "insert":
        que.appendleft(v)
    elif op == "delete":
        try:
            que.remove(v)
        except:
            pass
    elif op == "deleteFirst":
        que.popleft()
    elif op == "deleteLast":
        que.pop()
print(' '.join(que))     


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

int main(){
  long long int n,count;
  cin>>n;
  count=0;
  vector<long long int> v;
  vector<long long int> w;
  for(int i=0; i<n+1; i++){
    long long int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  for(long long int i=0; i<n; i++){
    long long int tmp;
    cin>>tmp;
    w.push_back(tmp);
  }
  for(long long int i=0;i<n; i++){
    if(v[i]+v[i+1]<=w[i]){
      count+=v[i]+v[i+1];
      v[i]=0;
      v[i+1]=0;
    }else{
      if(v[i]>=w[i]){
        count+=w[i];
        v[i]-=w[i];
      }else{
        count+=w[i];
        v[i+1]-=(w[i]-v[i]);
        v[i]=0;
      }
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 2548
import java.io.*;
import java.util.*;


public class Main {

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

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

		int[] x = new int[n];
		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}
		Arrays.sort(x);

		long[][][] dp = new long[n + 1][n + 1][a * n + 1];
//		for (int i = 0; i <= n; i++) {
//			Arrays.fill(dp[i], -1);
//		}
		dp[0][0][0] = 1;

		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				for (int k = 0; k <= j * a; k++) {
					dp[i][j][k] = dp[i - 1][j][k];
					if (k - x[i - 1] < 0 || j == 0) {
						continue;
					}
					dp[i][j][k] += dp[i - 1][j - 1][k - x[i - 1]];
				}
			}
		}

		long ret = 0;
		for (int i = 1; i <= n; i++) {
			ret += dp[n][i][i * a];
		}

		pr.println(ret);

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


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

int main() {
  int w, a, b;
  cin >> w >> a >> b;
  int r = 0;
  if (a <= b && b <= (a + w))
    cout << r << endl;
  else if ((a + w) < b)
    cout << b - (a + w) << endl;
  else
    cout << a - (b + w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int num[1000000];
int main(){
  int n,a,b;
  while(cin >> n >> a >> b,n + a + b){
    n++;
    fill(num,num + n,1);
    int j = 0;
    for(int i = 0 ; a*i + b*j < n ; i++ ){
      if(num[a*i + b*j] == 0)continue;
      for(j = 0 ; a*i + b*j < n ; j++ ){
	num[a*i + b*j] = 0;
      }
      j = 0;
    }
    int cnt = 0;
    for(int i = 0 ; i < n ; i++ )if(num[i])cnt++;
    cout << cnt << endl;
  }
}

Measured memory_bytes: 5064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = (a + b) * 2;
        System.out.println(area + " " + length);
        sc.close();
    }
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,n;
	bool q=false;
	char a;
	cin>>n;
	for (i=0;i<n;i++){
		cin>>a;
		if (a=='Y'){
			q=true;
		}
	}
	if (q==true){
		cout<<"Four";
	}
	else {
		cout<<"Three";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int main()
{
    string s;
    int a, b, c;
    while (cin >> s)
    {
        if (s != "HEISEI")
            return 0;
        cin >> a >> b >> c;
        if (a >= 32 || (a == 31 && b >= 5))
        {
            printf("? %d %d %d\n", a - 30, b, c);
        }
        else
        {
            printf("HEISEI %d %d %d\n", a, b, c);
        }
    }
}


Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int A = (S.at(0) - '0') * 10 + (S.at(1) - '0');
  int B = (S.at(2) - '0') * 10 + (S.at(3) - '0');
  if(A >= 1 && A <= 12 && B >= 1 && B <= 12){
    cout << "AMBIGUOUS" << endl;
  } else if (A >= 1 && A <= 12 && B >= 0 && B <= 99) {
    cout << "MMYY" << endl;
  } else if (B >= 1 && B <= 12 && A >= 0 && A <= 99) {
    cout << "YYMM" << endl;
  } else {
    cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  xs <- inp $ split toInt
  putStrLn . unwords . map show $ sortBy (\x y -> compare y x) xs

toInt :: String -> Int
toInt s = read s

split :: (String -> a) -> String -> [a]
split f = map f . words

inp :: (String -> a) -> IO a
inp f = f <$> getLine

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
char s[4];
int main() {
    cin >> s;
    if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    d1 = []
    d2 = []
    for _ in range(n):
        x, y = map(int, input().split())
        d1.append(x + y)
        d2.append(x - y)
    d1.sort()
    d2.sort()
    print(max(d1[-1] - d1[0], d2[-1] - d2[0]))


if __name__ == '__main__':
    main()


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  int n; cin >> n;
  int m = n / 100;
  n %= 100;
  
  if(m > 0 and m <= 12 and 1 <= n and n <= 12){
    cout << "AMBIGUOUS\n";
  }else if(m > 0 and m <= 12){
    cout << "MMYY\n";
  }else if(1 <= n and n <= 12){
    cout << "YYMM\n";
  }else{
    cout << "NA\n";
  }
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int[] p1;
	int[] p2;
	int ans;
	String[] S;

	Main(){
		// 整数の入力
		n = sc.nextInt();
		p1 = new int[n];
		p2 = new int[n];

		for(int i=0;i<n;i++){
			p1[i]=sc.nextInt();
			p2[i]=p1[i];
		}

		Arrays.sort(p2);

		for(int i=0;i<n;i++){
			ans += p1[i]==p2[i]?0:1;
		}

		// 出力
		System.out.println(ans>2?"NO":"YES");
	}

	public static void main(String[] args){
		new Main();
	}
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = "RGB";
    int K = (int) t.size();
    vector<int> xs(K * n);
    for (int i = 0; i < K * n; ++i) {
        for (int j = 0; j < K; ++j) {
            if (s[i] == t[j]) {
                xs[i] = j;
            }
        }
    }
    vector<vector<int>> colors(K);
    for (int i = 0; i < K * n; ++i) {
        colors[xs[i]].push_back(i);
    }
    vector<int> order(K * n, 0);
    for (int i = 0; i < n; ++i) {
        vector<int> run(K);
        for (int j = 0; j < K; ++j) {
            run[j] = colors[j][i];
        }
        sort(run.begin(), run.end());
        for (int j = 0; j < K; ++j) {
            order[run[j]] = j;
        }
    }
    long long prime = 998244353;
    vector<int> counters(K + 1, 0);
    counters[0] = n;
    long long answer = 1;
    for (int i = 0; i < K * n; ++i) {
        int multiplier = counters[order[i]] - counters[order[i]+1];
        answer = (answer * multiplier) % prime;
        ++counters[order[i]+1];
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 4492
N = int(input())
i = list(map(int, input().split()))
i_sum = sum(i)

n_bal = int(i_sum/2)

for num in range(1, N+1):
    if sum(i[:num]) >= n_bal :
        count = num
        break
rs1 = abs((sum(i[:count]) - (i_sum - sum(i[:count]))))
rs2 = abs((sum(i[:count-1]) - (i_sum - sum(i[:count-1]))))

if rs1 > rs2 :
    print(rs2)
elif rs1 <= rs2 :
    print(rs1)


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

int main(){
    vector<vector<int>> c(3, vector<int>(3, 0));
    int tate[3][2] = {0};
    int yoko[3][2] = {0};
    bool ans = 1;
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            cin >> c.at(i).at(j);
        }
    }

    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 2;j++){
            tate[i][j] = c.at(i).at(j + 1) - c.at(i).at(j);
            
        }
    }

    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 2;j++){
            yoko[i][j] = c.at(i).at(j + 1) - c.at(i).at(j);
            
        }
    }


    for(int i = 1;i < 3;i++){
        for(int j = 0;j < 2;j++){
            if(tate[i][j] != yoko[i - 1][j]) {
                ans = 0;
            } 
            if(yoko[i][j] != yoko[i - 1][j]) {
                ans = 0;
            } 
        }
    }
    
    if(ans){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()

using namespace std;

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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

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

int main() {
    int N,M=0;
    cin >> N;
    Vi a(N),b(N,0),ans;
    REP(i,N) cin >> a[N-1-i];

    REP(i,N) {
        // cout << N-i << ' ' << a[i] << ' ' << b[i] << endl;
        if (b[i]%2 != a[i]) {
            M++;
            ans.push_back(N-i);
            for (auto j:divisor(N-i)) {
                // cout << j << endl;
                b[N-j] += 1;
                }
        }
    }
    cout << M << endl;
    for (auto i:ans) cout << i << ' ';
    cout << endl;    
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//#include "testlib.h"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define int long long
#define ll long long
#define M 1000000007
#define MM 998244353
#define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define mii  map<ll ,ll >
#define sz(a) (int)a.size()
#define msi  map<string,ll >
#define rep(a,b)    for(ll i=a;i<b;i++)
#define rep0(n)    for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define ppb pop_back
#define endl '\n'
#define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define r0 return 0;
#define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
#define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define Set(a, s) (a, s, sizeof (a))
#define FOR repi
#define pii pair<int,int>
#define REVERSE(v) reverse(all(v))
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define debug cerr<<"bhau"<<endl
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
template<typename T, typename U> static inline void amin(T &x, U y) 
{ 
    if (y < x) 
        x = y; 
}
template<typename T, typename U> static inline void amax(T &x, U y) 
{ 
    if (x < y) 
        x = y; 
}
 
ll max(ll a, ll b) { return (a > b)? a : b;}
int min(int a, int b) { return (a < b)? a : b;} 


int solve(){


	int n;cin>>n;
	mii m;
	int a[n];
	for(int i=0;i<n;i++) {
		int x;cin>>x;
		a[i]=x;
		m[x]++;
	}
	int ans=0;
	for(auto i:m) ans+=(i.ss)*(i.ss-1)/2;
	for(int i=0;i<n;i++){
		int z=m[a[i]];
		int res=ans-(z-1);
		cout<<res<<endl;
	}

    return 0;
}
signed main(){
    asdf
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 11136
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let _n: usize = read();
    let input = read_vec::<i64>();
    let mut value = i64::max_value();

    for p in 1..101 {
        let temp = input.iter().map(|x| (x-p).pow(2)).sum();
        if value > temp {
            value = temp;
        }
    }

    println!("{}", value);

}

Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	int k=0;
	for (int i = 0;i < n;i++) {
		int a;
		cin >> a;
		if (a % 2 == 1)k++;
	}
	if (k % 2 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 764
K = int(input())
N = 50
if K <= 50:
    print(N)
    ans = [50]*K + [0]*(N-K)
    print(*ans)
    exit()

d,m = divmod(K,50)
ans = [d+49] * N
for i in range(N):
    if i < m:
        ans[i] += N-m+1
    else:
        ans[i] -= m
print(N)
print(*ans)

Measured memory_bytes: 9088
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n, m;
		HashMap<Integer, List<Integer>> islands = new HashMap<>();
		boolean result;

		n = sc.nextInt();
		for(int i = 1; i <= n; i++) {
			islands.put(i, new ArrayList<>());
		}
		m = sc.nextInt();
		for(int i = 0; i < m; i++) {
			islands.get(sc.nextInt()).add(sc.nextInt());
		}

		result = islands.get(1).stream().anyMatch(i -> islands.get(i).contains(n));
		if( result ) {
			System.out.println("POSSIBLE");
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}


Measured memory_bytes: 144760
#include <bits/stdc++.h>
using namespace std;
#define N (50500)

bool prime[N + 1];

int main()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	
	for (int i = 2; i * i <= N; i++){
		for (int j = i * i; j <= N; j += i){
			prime[j] = false;
		}
	}
	
	int n;
	while (~scanf("%d", &n)){
		int l = n - 1;
		while (!prime[l]) l--;
		int r = n + 1;
		while (!prime[r]) r++;
		printf("%d %d\n", l, r);
	}
	
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int x;
    cin >> x;
    YORN(x == 7 || x == 5 || x == 3)
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#define int long long

using namespace std;

class Solver {};
signed main()
{
	while (true)
	{
		int n;
		cin >> n;
		if (n == 0)
		{
			break;
		}

		string s;
		cin >> s;

		vector<int> cnts(n, 0);
		int field = 0;
		int now = 0;
		for (int i = 0; i < s.size(); i++)
		{
			if (s[i] == 'M')
			{
				cnts[now]++;
			}
			if (s[i] == 'L')
			{
				cnts[now] += field + 1;
				field = 0;
			}
			if (s[i] == 'S')
			{
				field += cnts[now] + 1;
				cnts[now] = 0;
			}
			now++;
			now %= n;
		}

		sort(cnts.begin(), cnts.end());
		for (int i = 0; i < n; i++)
		{
			cout << cnts[i] << " ";
		}
		cout << field << endl;
	}
}


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

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

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

    bool b=true;
    int hm=h[n-1];
    for(int i=n-2; i>=0; i--){
        if(h[i]>hm){
            if(h[i]-1<=hm){
                hm=h[i]-1;
            }else{
                b=false;
                break;
            }
        }else{
            hm=h[i];
        }
    }

    if(b) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 640
N = int(input())
S = input()

r=0
ListR = []
g=0
ListG = []
b=0
ListB = []
for i in range(N):
    if S[i] == 'R':
        r = r+1
        ListR.append(i)
    elif S[i] == 'G':
        g = g+1
        ListG.append(i)
    else:
        b = b+1
        ListB.append(i)
        
n = (N+1)//2
  
remove = 0
for i in range(1,n+1):
    for j in range(N-2*i):
        if S[j] != S[j+i] and S[j+i] != S[j+2*i] and S[j] != S[j+2*i]:
            remove = remove+1
            
print(r*g*b-remove)

Measured memory_bytes: 9240
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int N;
vector<int> D, T;
int M;

int main(void)
{
	int t;
	
	cin >> N;
	for(int i = 0; i < N; i++){
		cin >> t;
		D.push_back(t);
	}
	cin >> M;
	for(int i = 0; i < M; i++){
		cin >> t;
		T.push_back(t);
	}
	
	sort(D.begin(), D.end());
	sort(T.begin(), T.end());
	
	
	vector<int>::iterator p = D.begin()-1;
	bool ans = true;
	for(int i = 0; i < T.size(); i++){
		p = lower_bound(p+1, D.end(), T[i]);
		if(p == D.end() || p < D.begin()){
			ans = false;
			break;
		}
		if(*p != T[i]){
			ans = false;
			break;
		}
	}
	
	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 2548
from collections import defaultdict


ball_num = int(input().rstrip())
points = [int(n) for n in input().rstrip().split()]
point_dict=defaultdict(int)
total_pattern=0

for i in range(ball_num):
    point_dict[points[i]]+=1
for j in point_dict:
    total_pattern += point_dict[j]*(point_dict[j]-1)//2
    
total_pattern0=total_pattern
for ban_i in range(ball_num):
    total_pattern0 -= point_dict[points[ban_i]]*(point_dict[points[ban_i]]-1)//2         
    total_pattern0 += (point_dict[points[ban_i]]-1)*(point_dict[points[ban_i]]-2)//2
        
    print(total_pattern0)
    total_pattern0=total_pattern

Measured memory_bytes: 26780
inputs = STDIN.gets.chomp.split(' ').map(&:to_i)

N = inputs[0]
K = inputs[1]

COIN_PROBABILITY = 0.5

answer = 0

(1..N).each do |i|
  if i >= K
    answer += 1.0/N
    next
  end
  base_probability = 1.0/N
  time = 0
  while true do
    #puts "#{i}, #{time}: #{i *(2**time)}, #{K}"
    break if K <=(i * (2**time))
    time += 1
  end
  answer += base_probability * (COIN_PROBABILITY**time)
end

puts answer

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vector<pll> p(n);
  rep(i,n){
    cin>>p[i].F>>p[i].S;
  }
  PQ que;
  sort(all(p));
  ll ans=0;
  ll now=0;
  rep(i,m+1){
    if(i==0) continue;
    while(p[now].F<=i&&now<n){
      que.pu(p[now].S);
      now++;
    }
    if(sz(que)==0) continue;
    ans+=que.top();
    que.pop();
  }
  COUT(ans);
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll h,w,d;
  cin >> h >> w >> d;
  vector<vl> vec(h*w,vl(3));
  REP(i,h){
    REP(j,w){
      cin >> vec[i*w+j][0];
      vec[i*w+j][1] = i;
      vec[i*w+j][2] = j;
    }
  }
  sort(vec.begin(),vec.end(),[](vl a,vl b){return a[0]<b[0];});
  vector<vl> ans(d);
  REP(i,d){
    ll tmp = i;
    while(tmp<h*w){
      if(tmp==i){
        ans[i].push_back(0);
        tmp += d;
        continue;
      }
      ll diff = abs(vec[tmp-d][1]-vec[tmp][1])+abs(vec[tmp-d][2]-vec[tmp][2]);
      ans[i].push_back(ans[i][ans[i].size()-1]+diff);
      tmp += d;
    }
  }
  
  ll q;
  cin >> q;
  REP(i,q){
    ll l,r;
    cin >> l >> r;
    l--;
    r--;
    if(l==r){
      cout << 0 << endl;
      continue;
    }
    cout << ans[r%d][r/d] - ans[l%d][l/d] << endl;
  }
  return 0;
}


Measured memory_bytes: 10240
//created by Whiplash99
import java.io.*;
import java.util.*;
public class Main
{
    private static int dist[];
    private static ArrayDeque<Integer> edge[];

    private static void BFS(int i)
    {
        ArrayDeque<Integer> Q=new ArrayDeque<>();
        Q.add(i);

        while (!Q.isEmpty())
        {
            int u=Q.poll();
            for(int v:edge[u])
            {
                if(dist[v]!=-1) continue;
                dist[v]=dist[u]+1;
                Q.add(v);
            }
        }
    }
    public static void main(String[] args) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

        int i,N;

        String s[]=br.readLine().trim().split(" ");
        N=Integer.parseInt(s[0]);
        int X=Integer.parseInt(s[1])-1;
        int Y=Integer.parseInt(s[2])-1;

        dist=new int[N];
        edge=new ArrayDeque[N];
        for(i=0;i<N;i++) edge[i]=new ArrayDeque<>();

        for(i=0;i<N-1;i++)
        {
            edge[i].add(i+1);
            edge[i+1].add(i);
        }

        edge[X].add(Y);
        edge[Y].add(X);

        int count[]=new int[N];

        for(i=0;i<N;i++)
        {
            Arrays.fill(dist,-1);
            dist[i]=0;
            BFS(i);
            for(int j=0;j<N;j++) count[dist[j]]++;
        }


        StringBuilder sb=new StringBuilder();
        for(i=1;i<N;i++) sb.append(count[i]/2).append("\n");

        System.out.println(sb);
    }
}

Measured memory_bytes: 59560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	FOR(i,1,4){
		if(i==a || i==b) continue;
		cout<<i<<endl;
		return 0;
	}
}

Measured memory_bytes: 256
def solve():
    K = int(input())
    if K % 10 not in [1, 3, 7, 9]:
        print(-1)
        return

    a = 7 % K
    for i in range(K+1):
        if a == 0:
            print(i+1)
            return
        a = (a * 10 + 7) % K

    print(-1)

solve()

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

int n;
const int maxn = 505;
int log2[maxn];
 int lowbit(int x) {return x&(-x);}
signed main(){
    scanf("%d", &n);
    log2[1] = 0; log2[2] = 1;
    for(int i = 4; i <= 500; i++) {
        log2[i] = log2[i/2] + 1;
    }
    for(int i = 1; i < n; i++) {
        for(int j = i+1; j <= n; j++) {
            printf("%d ", log2[lowbit(i ^ j)] + 1);
        }
        puts("");
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main(void){
    
    int N,i,j,tmp,flag,count=0;
    int A[100];
    
    scanf("%d",&N);
    
    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    
    i=0;
    flag=1;
    
    while(flag){
        flag=0;
        for(j=N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                tmp=A[j];
                A[j]=A[j-1];
                A[j-1]=tmp;
                flag=1;
                count++;
            }
        }
        i++;
    }
    for(i=0;i<N;i++){
        printf("%d",A[i]);
        if(i!=N-1){
    		printf(" ");
    	}
    }
    printf("\n");
    
    printf("%d\n",count);
    
    return 0;
}


Measured memory_bytes: 2040
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>s;
	if(s=="ARC")
	cout<<"ABC";
	else
	cout<<"ARC";
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int MAX_N=10050;
int n;
vvin edge(MAX_N);
vin indegree(MAX_N);

//頂点番号0,1,...,n-1
vin topological_sort(){
    vin sorted;
    queue<int> q;
    rep(i,n)if(!indegree[i])q.push(i);
    while(q.size()){
        auto p=q.front();q.pop();
        sorted.push_back(p);
        for(auto e:edge[p]){
            indegree[e]--;
            if(!indegree[e])q.push(e);
        }
    }
    return sorted;
}

int main(){
    int m;cin>>n>>m;
    int s,t;
    rep(i,m){
        cin>>s>>t;
        edge[s].push_back(t);
        indegree[t]++;
    }
    vin ans=topological_sort();
    rep(i,n)cout<<ans[i]<<endl;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n, m;
    cin >> n >> m;
    ll a[m];
    ll sum = 0;
    rep(i, m) {
        cin >> a[i];
        sum += a[i];
    }

    ll ans = n-sum;
    if ( ans < 0 ) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
n, m, k = map(int, input().split())
friend = []
for _ in range(m):
    a, b = map(int, input().split())
    friend.append((a - 1, b - 1))
block = []
for _ in range(k):
    c, d = map(int, input().split())
    block.append((c - 1, d - 1))

# fri: 各人の友達の人数
fri = [0] * n
for a, b in friend:
    fri[a] += 1
    fri[b] += 1

# 友達の友達の数
class UnionFindTree:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0] * n

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        else:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
            else:
                self.parent[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

fri_fri = [0] * n
uft = UnionFindTree(n)
for a, b in friend:
    if uft.root(a) == uft.root(b):
        continue
    count = fri_fri[uft.root(a)] + fri_fri[uft.root(b)] + 1
    uft.unite(a, b)
    fri_fri[uft.root(a)] = count

# ブロック関係かつ友達の友達の人数
for c, d in block:
    if uft.root(c) == uft.root(d):
        fri[c] += 1
        fri[d] += 1

# 数え上げ
ans = []
for i in range(n):
    ans.append(str(fri_fri[uft.root(i)] - fri[i]))

print(' '.join(ans))

Measured memory_bytes: 125144
//41
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n,m;cin>>n>>m,n|m;){
    int t[100],h[100];
    int ts=0,hs=0;
    for(int i=0;i<n;i++){
      cin>>t[i];
      ts+=t[i];
    }
    for(int i=0;i<m;i++){
      cin>>h[i];
      hs+=h[i];
    }
    int tt,hh;
    tt=hh=101;
    for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
	if(ts-t[i]+h[j]==hs-h[j]+t[i]&&t[i]+h[j]<tt+hh){
	  tt=t[i];
	  hh=h[j];
	}
      }
    }
    if(tt==101){
      cout<<-1<<endl;
    }else{
      cout<<tt<<' '<<hh<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

long long sum[300000];

int main ()
{
	int n;
	long long ans,a;
	scanf ("%d",&n);
	sum[0]=0;
	for (int i=1;i<=n;i++)
	{
		scanf ("%lld",&a);
		sum[i]=sum[i-1]+a;
	}
	ans=abs(sum[1]*2-sum[n]);
	for (int i=2;i<n;i++)
		ans=min(ans,abs(sum[i]*2-sum[n]));
	printf ("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int N;
	cin>>N;
	printf("%s\n", N >= 30 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll n,i;
  cin>>n>>i;

  cout<<n-i+1<<endl;
  return 0;
}


Measured memory_bytes: 3628
from bisect import bisect_left, bisect_right; from collections import Counter, defaultdict, deque, OrderedDict; from copy import deepcopy; from fractions import gcd; from functools import lru_cache, reduce; from math import ceil, floor; from sys import stdin, setrecursionlimit
import heapq as hq; import itertools as its; import operator as op


# globals
inf = float('inf')
input = stdin.readline


def main():
    n = get_int()
    P = get_li()
    ans = 0
    for a, b, c in zip(P, P[1:], P[2:]):
        if a < b < c or a > b > c:
            ans += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def gets(n, types, sep=None):
    if len(types) == 1:
        return [types[0](input().strip()) for _ in range(n)]
    return list(zip(*(
        [t(x) for t, x in zip(types, input().strip().split(sep=sep))]
        for _ in range(n)
    )))


if __name__ == '__main__':
    setrecursionlimit(4100000)
    main()


Measured memory_bytes: 65516
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d;cin>>n>>d;
    auto x=make_v<int>(n,d);
    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }
    vector<int> ok(100000);
    for(int i=1;i<=1000;i++){
        if(i*i>=100000){
            break;
        }
        ok[i*i]=1;
    }
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int s=0;
            for(int k=0;k<d;k++){
                s+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            ans+=ok[s];
        }
    }
    cout<<ans<<endl;
}


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

int main(){
  int N, l[110000], r[110000];
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> l[i] >> r[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    ans += r[i] - l[i] + 1;
  }
  cout << ans << endl;
}

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;
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
// find_by_order(), order_of_key()
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string>) {}
template<typename T1,typename T2> ostream& operator<<(ostream& os, pair<T1,T2> buf) {
  return os << "(" << buf.first << ": " << buf.second << ")"; }
#define DefOut(Con) template<typename T>ostream&operator<<(ostream&os,Con<T>&A){ bool f = false; os << "{"; \
  for (const auto e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
#define DefOut2(Con) template<typename K,typename V>ostream&operator<<(ostream&os,Con<K,V>&A) \
{ bool f = false; os << "{"; for (auto &e: A) { if (f) os << ", "; os << e; f = true; } return os << "}"; }
template<typename T>ostream &operator << (ostream &os,vector<vector<T>>& A) {
  for (auto &B: A) os << '\n' << B; return os; }
DefOut(vector) DefOut(set) DefOut(multiset) DefOut2(map) 
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << a << endl; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18;
/***********************************************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int l, r;
  cin >> l >> r;
  if (r - l > 2050) kek(0);
  int ans = 2019;
  for (int i = l; i <= r; ++i) {
    for (int j = i + 1; j <= r; ++j) {
      uin(ans, i % 2019 * (j % 2019) % 2019);
    }
  }
  kek(ans);
  
  return 0;
} 


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

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

int main(){

  int A;
  cin>>A;
  int a=A/100,b=(A-a*100)/10;
  if(a==7)
    cout<<"Yes";
  else if(b==7)
    cout<<"Yes";
    else if(A-a*100-b*10==7)
      cout<<"Yes";
    else
      cout<<"No";
  //cout<<a<<b;
      
    

  return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
using namespace std;

int main(){

    int A,B;
    cin >> A >> B;
    if(A < 10 && B < 10){
        cout << A * B << endl;
    }else{
        cout << -1 << endl;
    }

}

Measured memory_bytes: 256
n = gets.to_i
dp = Array.new(n) { Array.new n }
n.times do |i|
  r, _, *ts = gets.split.map(&:to_i)
  ts.each {|j| dp[r-1][j-1] = 1 }
  dp[i][i] = 0
end
n.times do |k|
  n.times do |i|
    n.times do |j|
      dp[i][j] = dp[i][k] + dp[k][j] if dp[i][k] && dp[k][j] && (!dp[i][j] || dp[i][k] + dp[k][j] < dp[i][j])
    end
  end
end
gets.to_i.times do
  s, d, v = gets.split.map(&:to_i)
  puts dp[s-1][d-1] && dp[s-1][d-1] + 1 <= v ? dp[s-1][d-1] + 1 : 'NA'
end

Measured memory_bytes: 8916
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;

struct edge {
    int to, cost;
};
typedef vector<vector<edge> > AdjList;

AdjList graph;

const int INF = 10000000;
vector<int> dist;

void dijkstra(int n, int s){
    dist = vector<int>(n,INF);
    dist[s] = 0;
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first){
            continue;
        }
        for(int i=0;i < graph[v].size();i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}


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

    graph = AdjList(200005);

    for(int i=0;i<m;i++){
        int from, to;
        cin >> from >> to;
        from--;
        to--;
        graph[from].push_back((edge){to,1});
        graph[to].push_back((edge){from,1});
    }
    dijkstra(n,0);

    if(dist[n-1] == 2){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 15080
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

typedef double P_type;
typedef complex<P_type> P;
const P_type P_eps = 1e-8; //整数の時はゼロ

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return abs(a.real() - b.real()) < P_eps ? a.imag() + P_eps*2 < b.imag() : a.real() + P_eps*2 < b.real();
  }
};

int main(){
  int n, k;
  vector<P> vec;
  
  scanf("%d%d", &n, &k);

  for(int i=0;i<n;i++){
    int x, y;
    scanf("%d%d", &x, &y);
    vec.push_back(P(x, y));
  }

  int ans = 0;
  
  for(int i=0;i<n;i++){
    map<P, int> dic;
    for(int j=0;j<n;j++){
      if(i == j) continue;

      P r = (vec[i] - vec[j]) / abs(vec[i] - vec[j]);

      if(r.real() < 0) r *= -1;
      if(abs(r.real()) < P_eps && r.imag() < 0) r *= -1;
      dic[r]++;
    }

    for(auto it : dic){
      ans = max(ans, it.second);
    }
  }

  printf("%d\n", ans >= k-1);
  
  return 0;
}



Measured memory_bytes: 3400
#include<bits/stdc++.h>
#include <cstdio>   
#define pb          push_back 
#define endl        "\n"
#define mostrar(x,y) cout<<x<<" "<<y<<endl;
#define f           first
#define s           second
#define mod         1000000007
#define EPS         1e-9
using namespace std;
typedef pair<int,int> ii;
typedef pair<pair<int,int>,int> iii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;

 
int main(){
    ofstream out("output.txt");


    int x,a;
    cin>>x>>a;
    if(x<a) cout<<0;
    else if(!(x<a)) cout<<10;
    
    return 0;
}


Measured memory_bytes: 256
S = input()
ans_list = [0] * (len(S) + 1)
for i in range(len(S)):
    if S[i] == '<':
        ans_list[i + 1] = ans_list[i] + 1

for i in range(len(S) - 1,-1,-1):
    if S[i] == '>':
        ans_list[i] = max(ans_list[i + 1] + 1, ans_list[i])

print(sum(ans_list))

Measured memory_bytes: 23336
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double ma = -1;
	int mws = -1, msu = -1;
	rep(i, 31) {
		rep(j, 31) {
			int wa = a * i + b * j;
			if (wa * 100 > f) break;
			if (wa == 0) continue;
			rep(k, 3001) {
				rep(l, 3001) {
					int su = c * k + d * l;
					if (wa * 100 + su > f) break;
					if (e * wa < su) continue;
					double ans = (double)su / ((double)wa * 100 + (double)su);
					if (ans > ma) {
						ma = ans;
						mws = wa * 100 + su;
						msu = su;
					}
				}
			}
		}
	}
	cout << mws << " " << msu << endl;

	return 0;
}


Measured memory_bytes: 256