akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    int q;
    rep(i, n) cin >> p[i];
    int cnt=0;
    int flag=0;
    /*
    rep(i, n) {
        if (p[i] == 1) {
            cnt++;
            break;
        }
        if (q[0] < p[i]) q[0] = p[i];
        rep(j, i+1) {
            if (p[i] <= p[j]) flag++;
            else break;
            if (flag == i+1) {
                cnt++;
            }
        }
        flag = 0;
    }*/
    q = p[0];
    rep(i, n) {
        if (p[i] <= q) {
            cnt++;
            q = p[i];
        }
        if (q == 1) break;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;

ll Diff(int H, int W, int iW)
{
	int Wres = W - iW;
	int W2 = Wres / 2;
	int W3 = Wres - W2;
	int Wdiff = max(iW, max(W2, W3)) - min(iW, min(W2, W3));
	ll ret = static_cast<ll>(Wdiff) * H;

	int H1 = H / 2;
	int H2 = H - H1;
	ll s1 = static_cast<ll>(iW) * H;
	ll s2 = static_cast<ll>(Wres) * H1;
	ll s3 = static_cast<ll>(Wres) * H2;
	ll ret2 = max(s1, max(s2, s3)) - min(s1, min(s2, s3));
	return min(ret, ret2);
}

void ABC062C()
{
	int H, W;
	cin >> H >> W;

	ll minS = 10000000000;
	for (int i = 0; i < W; ++i)
	{
		minS = min(minS, Diff(H, W, i));
	}
	for (int i = 0; i < H; ++i)
	{
		minS = min(minS, Diff(W, H, i));
	}
	cout << minS << endl;
}

int main()
{
	ABC062C();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
struct Point
{
	Point(double _x, double _y) : x(_x), y(_y) {}
	double x;
	double y;
};
typedef Point Vector;
bool isConvex(Point& P1, Point& P2, Point& P3){
	Vector V1(P1.x - P2.x, P1.y - P2.y);
	Vector V2(P3.x - P2.x, P3.y - P2.y);
	return (V1.x * V2.y - V1.y * V2.x) > 0;
}
bool isConvexSquare(Point& P1, Point& P2, Point& P3, Point& P4){
	bool b1 = isConvex(P1, P2, P3);
	bool b2 = isConvex(P2, P3, P4);
	bool b3 = isConvex(P3, P4, P1);
	bool b4 = isConvex(P4, P1, P2);
	return (b1 == b2 && b2 == b3 && b3 == b4 && b4 == b1);
}
vector<double> Split(string& line){
	vector<double> vN(8, 0.0);
	string::size_type p1 = 0;
	string::size_type p2 = line.find(',');
	int i = 0;
	double v;
	while (p1 != string::npos){
		if (p1 == 0) v = atof(line.substr(0, p2).c_str());
		else if (p2 != string::npos)	v= atof(line.substr(p1 + 1, p2 - p1 - 1).c_str());
		else v = atof(line.substr(p1 + 1).c_str());
		vN[i] = v;
		p1 = p2;
		++i;
		if (p1 != string::npos)
			p2 = line.find(',', p1 + 1);
	}
	return vN;
}
void getValue(string& line, double* X, double* Y){
	vector<double> vN = Split(line);
	X[0] = vN[0];
	Y[0] = vN[1];
	X[1] = vN[2];
	Y[1] = vN[3];
	X[2] = vN[4];
	Y[2] = vN[5];
	X[3] = vN[6];
	Y[3] = vN[7];
}
int main()
{
	double X[4] = {}, Y[4] = {};
	string line;
	while (cin >> line){
		getValue(line, X, Y);
		Point P1(X[0], Y[0]);
		Point P2(X[1], Y[1]);
		Point P3(X[2], Y[2]);
		Point P4(X[3], Y[3]);
		if (isConvexSquare(P1, P2, P3, P4)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 1188
using System.Collections.Generic;
using System.Linq;
using System;

public class Team
{
    public string n { get; set; }
    public int w { get; set; }
    public int L { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var teams = new List<Team>();
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            for (int i = 0; i < n; i++)
            {
                string[] s = Console.ReadLine().Trim().Split(' ');
                var wc = 0; var Lc = 0;
                for (int j = 0; j < n - 1; j++)
                    if (s[j + 1] == "0") wc++;
                    else if (s[j + 1] == "1") Lc++;
                teams.Add(new Team { n = s[0], w = wc, L = Lc });
            }
            foreach (var x in teams.OrderByDescending(y => y.w).ThenBy(y => y.L))
                Console.WriteLine(x.n);
        }
    }
}

Measured memory_bytes: 9784
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 998'244'353;

int main() {
    std::ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    s[1] = 'B' + 'R' - s[1];
    cout << s;
}




Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
using ll = long long;
const int mod = 1000000007;
 
int main(){
  int n; ll k;
  cin >> n >> k;
  
  vector<int> a(n);
  rep(i, n){
    cin >> a[i];
    a[i]--;
  }
  
  int f = n; int s = 0;
  vector<int> to(n), old(n ,-1);
  to[0] = 0, old[0] =0;
  rep(i, n){
    if(i==0) continue;
    to[i] = a[to[i-1]];
    if(old[to[i]] != -1){
      f = i, s = old[to[i]];
      break;
    }
    old[to[i]] = i;
  }  

  int num;
  if(k < s) num = k;
  else num = s + (k - s) % (f - s);
  cout << to[num]+1 << endl;
    
  return 0;
}

Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  int n; cin >> n;
  set<string> s;
  for(int i = 0;i < n; ++i) {
    string x; cin >> x;
    s.insert(x);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 19256
from bisect import bisect_left

def main():
    n=int(input())
    L=list(map(int,input().split()))
    L.sort()
    ans=0
    for i in range(n-2):
        for j in range(i+1,n-1):
            ans+=bisect_left(L,L[i]+L[j])-j-1
    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 43228
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep(j,n) for(ll j=0;j<(ll)n;j++)
#define rep(k,n) for(ll k=0;k<(ll)n;k++)
using namespace std;

int main() {
	ll N = 0, counter = 0, min = 0;
	cin >> N; 
	vector<ll> P(N,0);
	rep(i, N) cin >> P[i];
	min = P[0];
	rep(j, N) {
		if (P[j] <= min) {
			min = P[j];
			counter++;
		}
		
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 1792
N=int(input())
import math
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
A=A+[math.inf]
B=B+[math.inf]
C=C+[math.inf]
d=[0 for i in range(N)]
ac=0
for i in range(N):
  while C[ac]<=B[i]:
    ac+=1
  if ac==N:
    break
  d[i]=N-ac
ab=0
ans=0
for i in range(1,N):
  d[i]+=d[i-1]
def f(x):
  if x!=0:
    return d[N-1]-d[x-1]
  else:
    return d[N-1]
for i in range(N):
  while B[ab]<=A[i]:
    ab+=1
    if ab==N:
      break
  ans+=f(ab)
print(ans)

Measured memory_bytes: 112388
#include <iostream>
#include <cmath>

long double int2real(uint64_t n)
{
  return static_cast<long double>(n);
}

uint64_t real2int(long double f)
{
  return static_cast<uint64_t>(::floor(f));
}

uint64_t digit(uint64_t x)
{
  return real2int(::log10l(int2real(x)) + 1);
}

uint64_t F(uint64_t A, uint64_t B)
{
  return std::max(digit(A), digit(B));
}

int main()
{
  uint64_t N;
  std::cin >> N;
  
  uint64_t M = real2int(::sqrtl(int2real(N)));
  
  uint64_t min = 1e+12;
  
  for (unsigned A = 1; A <= M; ++A) {
    if (N % A > 0) continue;
    
    unsigned B = N / A;
    min = std::min(min, F(A, B));
  }
  
  std::cout << min << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n:i32,
        y:i32,
    }
    let mut ans = (-1,-1,-1);
    'outer :for i in 0..n+1 {
        for j in 0..n+1 {
            let k = n - i - j;
            if k < 0 {continue;}
            if i*10000+j*5000+k*1000 == y {
                ans = (i, j, k);
                break 'outer;
            }
        }
    }
    println!("{} {} {}", ans.0, ans.1, ans.2);
}

Measured memory_bytes: 4352
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def resolve():
    n = int(input())
    p_list = list(map(int, input().split()))

    answer_count = 0
    min_num = 999999
    for i in range(n):
        if min_num > p_list[i]:
            min_num = p_list[i]
            answer_count += 1

    print(answer_count)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 75472
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <map>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)

typedef long long ll;
const int maxn = 100005;
const ll mod = 1e9+7;
const int INF = 0x3f3f3f3f;
const double eps = 1e-9;

int n,m;
int a[maxn];
char s[maxn];

int main()
{
    int ans=0;
    scanf("%d%d",&n,&m);
    int x;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        ans+=min(x,abs(m-x));
    }
    printf("%d\n",ans*2);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

ll x,y;

int main(){
	cin>>x>>y;
	
	int ans=0;
	for(ll i=x;i<=y;i*=2)
		ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=500500;
int n,m,k;
struct node
{
    string s;
    int sco,id;
}e[110];
bool cmp(node a,node b)
{
    if(a.s!=b.s)return a.s<b.s;
    return a.sco>b.sco;
}
int ans[110];
int main()
{
	scanf("%d",&n);
    for(int i=1;i<=n;i++)cin>>e[i].s>>e[i].sco,e[i].id=i;
    sort(e+1,e+1+n,cmp);
    for(int i=1;i<=n;i++)cout<<e[i].id<<endl;//ans[e[i].id]=i;
    //for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

bool sosu(int n)
{
    if (n == 1){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n == 3){
        return true;
    }
    else if (n%6 == 0 || n%6 == 2 || n%6 == 3 || n%6 == 4){
        return false;
    }
    else {
        for (int i = 2;i <= sqrt(n);i++){
            if (n%i == 0){
                return false;
            }
        }
        return true;
    }
}

int main()
{
    int x;
    cin >> x;
    int i = 0;
    while (!sosu(x+i)){
        i++;
    }
    cout << x+i << endl;
}


Measured memory_bytes: 384
#include <iostream>

int tetrahedral_number (int n)
{
    return (n * (n + 1) * (n + 2)) / 6;
}


const int MAX_NUM = 1000000;

int* solve_regular_problem ()
{
    int* solutions = new int[MAX_NUM + 1];

    std::fill (solutions, solutions + MAX_NUM + 1, MAX_NUM);

    solutions[0] = 0;

    int cnt = 0;

    int i = 1;

    for (int tetra_num = 1; tetra_num < MAX_NUM; tetra_num = tetrahedral_number (++i))
    {

        for (int j = tetra_num; j < MAX_NUM; j++)
        {
            solutions[j] = std::min (solutions[j], solutions[j - tetra_num] + 1);
        }

    }

    return solutions;
}

int* solve_odd_problem ()
{
    int* solutions = new int[MAX_NUM + 1];

    std::fill (solutions, solutions + MAX_NUM + 1, MAX_NUM);

    solutions[0] = 0;

    
    int i = 1;

    for (int tetra_num = 1; tetra_num < MAX_NUM; tetra_num = tetrahedral_number(++i))
    {
        if (tetra_num % 2 != 0)
        {
            for (int j = tetra_num; j < MAX_NUM; j++)
            {
                solutions[j] = std::min (solutions[j], solutions[j - tetra_num] + 1);
            }

        }

    }

    return solutions;
}

int main ()
{

    auto solutions = solve_regular_problem ();

    auto odd_solutions = solve_odd_problem ();

    int n = 0;
    while (std::cin >> n, n != 0)
    {

        std::cout << solutions[n] << " " << odd_solutions[n] << std::endl;

    }

    return 0;
}

Measured memory_bytes: 8992
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct Node{
  int key;
  struct  Node *next,*prev;
};

struct Node *nil;

struct Node* listSearch(int key){
  struct Node *cur=nil->next;
  while(cur!=nil && cur->key != key){
    cur=cur->next;
  }
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil) break;
    if(isf++>0) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
  deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0, nd=0;
  scanf("%d",&n);
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
    if(com[0]== 'i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
      if(com[6]=='F') deleteFirst();
      else if(com[6]=='L') deleteLast();
    } else{
      deleteKey(key);
      nd++;
    }
    size--;
  }
}

printList();

 return 0;
}



Measured memory_bytes: 33024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<pair<ll, ll>> robot(n);
    rep(i, n) cin >> robot[i].first >> robot[i].second;
    sort(ALL(robot));
    ll ans = 1;
    ll last = 0;
    rep(i, 1, n)
    {
        cerr << robot[i].first << " " << last << endl;
        ll a = robot[last].first + robot[last].second;
        ll b = robot[i].first - robot[i].second;
        if (a > b)
        {
            b = robot[i].first + robot[i].second;
            if (b < a)
            {
                last = i;
            }
        }
        else
        {
            ans++;
            b = robot[i].first + robot[i].second;
            if (b > a)
            {
                last = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  ll A, B, N;
  cin >> N >> A >> B;
  ll diff = B - A;
  if (diff == 0) {
    cout << 0 << endl;
    return 0;
  }

  if (A % 2 == B % 2) {
    cout << (B - A) / 2 << endl;
  } else {
    cout << min(A - 1, N - B) + 1 + (B - A - 1) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;
int main(){
  ll N;
  cin >>N;
  if(N%2==1){
    cout<<0;
    return 0;
  }
  ll div=5;
  ll cnt=0;
  while(N>=div){
    cnt+=(N/(2*div));
    div*=5;
  }
  cout<<cnt;
  return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<map>
#include<string>
#include<algorithm>
#define repb(i,n) for(int i=n;i--;)
using namespace std;
int main(){
	int n,s,w,W; string f;
	while(cin>>n,n){
		vector<pair<int,pair<int, string> > > t; W=0;
		repb(i,n){
			cin>>f>>w>>s;
			t.push_back(make_pair(w,make_pair(s,f)));
			W+=w;
		}
		sort(t.begin(),t.end());
		vector<string> fukuro;
		while(!t.empty()){
			repb(i,t.size())if(W-t[i].first<=t[i].second.first){
				fukuro.push_back(t[i].second.second);cout<<t[i].second.second<<endl;
				W-=t[i].first;
				t.erase(t.begin()+i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	ll N;
	cin >> N;
	ll A[200001];
	ll B[200001];
	for(int i = 0; i < N; i++){
		cin >> A[i] >> B[i];
	}
	sort(A, A+N);
	sort(B, B+N);
	
	if(N % 2 == 1){
		ll min = A[(N+1)/2-1];
		ll max = B[(N+1)/2-1];
		cout << (max-min)+1 << endl;
	}else{
		ll min = (A[N/2-1] + A[N/2+1-1]);
		ll max = (B[N/2-1] + B[N/2+1-1]);
		cout << (max-min)+1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 6692
#include <stdio.h>
 
int main() 
{
    int i;
    char b, l[26] = {0};
     
    while(scanf("%c", &b) != EOF){
        if(b >= 'A' && b <= 'z')
            {
            if(b >= 'a')
            {
                 l[b - 'a']++;
            }
            
            else 
            {
                l[b-'A']++;
            }
        }
    }
    
    for(i = 0; 26 > i; i++)
    {
        printf("%c : %d\n",'a'+ i, l[i]);
    }
    return 0;
}



Measured memory_bytes: 2056
N=int(input())

A=[[0 for i in range(9)] for j in range(9)]
keta=1
for i in range(N+1):
  a=i%10
  if i>=keta*10:
    keta=keta*10
  b=i//(keta)
  #print(a,b)
  if a!=0 and b!=0:
    A[a-1][b-1]+=1

x=0
for i in range(9):
  for j in range(9):
    k=A[i][j]*A[j][i]
    #print(i,j,A[i][j],A[j][i])
    x+=k
print(x)
  

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

using namespace std;

int n;
int a[3005];
vector<int> G[3005];
int dp[3005];

vector<int> topo;
bool used[3005];

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]) tpsort(G[v][i]);
	}
	topo.push_back(v);
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int u, v;
	for(int i = 1; i <= n-1; i++){
		cin >> u >> v;
		if(a[u] > a[v]) G[v].push_back(u);
		if(a[u] < a[v]) G[u].push_back(v);
	}
	
	for(int i = 1; i <= n; i++) if(!used[i]) tpsort(i);
	reverse(topo.begin(), topo.end());
	
	for(int i = 0; i < topo.size(); i++){
		int v = topo[i];
		if(dp[v] == 0){
			for(int j = 0; j < G[v].size(); j++) dp[G[v][j]] = 1;
		}
	}
	
	for(int i = 1; i <= n; i++){
		if(dp[i]) cout << i << " ";
	}
	cout << endl;
	
	return 0;
}

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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int K; cin >> K;
	--K;
	int n = (int)s.length();

	set<string> words; words.clear();
	for (int len = 1; len <= min(5,n); ++len){
		for (int i = 0; i < n; ++i){
			string sub = s.substr(i, len);
			words.insert(sub);
		} // end for
	} // end for

	set<string>::iterator it = words.begin();
	for (int i = 0; it != words.end(); ++it, ++i){
		string t = (*it);
		if (i == K){
			cout << t << endl;
			break;
		} // end if
	} // end for

	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>
#include <cassert>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n,d;
    cin >> n >> d;
    int ans = 0;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        if(x*x + y*y <= d*d)ans++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i=0; i < n; i++)
int main(void) {
    int n , k, q;
    cin >> n >> k >> q;
    vector<int> data(n,k-q);
    rep(i,q){
      int x;
      cin >> x;
      data.at(x-1)++;
    }
    rep(i,n){
      if(data.at(i) > 0){
        cout << "Yes" << endl;
      }else {
        cout << "No" << endl;
      }
    }
    return 0;
}


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

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

  int n;cin>>n;

  int p=111;
  for(int i=1;i<20;i++){
    if(n<=p){
      cout<<p<<endl;
      break;
    }
    p=111*i;
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

char ca[10005];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	cin>>ca;
	for(i=n;i<n*2;i++){
		ca[i]=ca[2*n-i-1];
	}
	ca[2*n]='\0';
	a=0;
	for(i=0;i<=n;i++){
		for(j=0;j<n;j++){
			if(ca[a+j]>ca[i+j]){a=i;break;}
			if(ca[a+j]<ca[i+j])break;
		}
	}
	if(m==1){
		for(i=0;i<n;i++){
			cout<<ca[a+i];
		}
		cout<<endl;
		return 0;
	}
	m--;
	b=0;
	for(i=0;i<n;i++){
		if(ca[a]==ca[a+i])b++;
		else break;
	}
	c=b;
	for(i=0;i<m;i++){
		b*=2;
		if(b>=n)break;
	}
	j=0;
	for(i=0;i<n;i++){
		if(i==b)j=c;
		if(i>b)j++;
		cout<<ca[a+j];
	}
	cout<<endl;
			
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,m,ans;
signed main(){
	scanf("%lld",&n);
	m=n-1;
	if (m>=2)
	{
		for (register int i=2; i*i<=m; ++i)
		if (m%i==0)
		{
			ans++;
			if (m/i!=i) ans++;
		}
		ans++;
	}
	if (n>=2)
	{
		for (register int i=2; i*i<=n; ++i)
		if (n%i==0)
		{
			int now=n;
			while (now%i==0) now/=i;
			if (now%i==1) ans++;
		}
		ans++;
	}
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        while (sc.hasNextLine()) {
                                int c1, c2, c3;
                                try {
                                        c1 = sc.nextInt();
                                        c2 = sc.nextInt();
                                        c3 = sc.nextInt();
                                } catch (Exception e) {
                                        break;
                                }
                                int A = 0, B = 0;
                                for (int i = 1; i <= 10; i++) {
                                        if (i != c1 && i != c2 && i != c3) {
                                                if (i + c1 + c2 <= 20) {
                                                        A++;
                                                } else {
                                                        B++;
                                                }
                                        }
                                }
                                if (A >= B) {
                                        System.out.println("YES");
                                } else {
                                        System.out.println("NO");
                                }
                        }
                }
        }
}

Measured memory_bytes: 25972
n = int(input())
a = map(int, input().split())
ans = 0
c = 0
m = 10 ** 9

for i in a:
    if i > 0:
        ans += i
        if m > i:
            m = i
    else:
        ans -= i
        c += 1
        if m > -i:
            m = -i

if c % 2 == 1:
    ans -= 2 * m

print(ans)

Measured memory_bytes: 11212
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	string s ; cin >> s ;
	ll ans = 0 ;
	ll cnt = 0 ;
	for(int i=0;i<s.size();i++){
		if(s.at(i)=='T'){
			if(cnt==0) ans++ ;
			else cnt-- ;
		}else cnt++ ;
	}
	cnt = 0 ;
	reverse(all(s)) ;
	for(int i=0;i<s.size();i++){
		if(s.at(i)=='S'){
			if(cnt==0) ans++ ;
			else cnt-- ;
		}else cnt++ ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 3732
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	printf("%d\n",!!(a%b));
}


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

int64_t modPow(int64_t a, int64_t n, int64_t p) {
    int64_t ret = 1;
    while(n > 0){
        if(n & 1){
            ret = (ret * a) % p;
        }
        a = (a * a) % p;
        n >>= 1;
    }
    return ret % p;
}

void solve(){
    int64_t n, k;
    cin >> n >> k;

    int64_t gcd[k+1];
    for(int64_t i = 0; i <= k; i++){
        gcd[i] = 0;
    }

    int64_t g, ans = 0;
    for(int64_t i = k; i >= 1; i--){
        g = k / i;
        gcd[i] = modPow(g, n, MOD);
        for(int64_t j = i * g; j > i; j -= i){
            gcd[i] -= gcd[j];
        }
        ans += gcd[i] * i;
        ans %= MOD;
    }
    while(ans < 0){
        ans += MOD;
    }
    cout << ans << endl;
}

int main(){
    solve();
}

Measured memory_bytes: 4412
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Rishabhdeep Singh
 */

// doot diddly donger cuckerino Hahahahahah
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

// @formatter:off
#define PB              push_back
#define EB              emplace_back
#define F               first
#define S               second
#define all(x)          (x).begin(), (x).end()
#define rall(x)         rbegin(x), rend(x)
#define sz(x)           (long long) (x).size()
#define NL              << '\n'
#define IOS             ios::sync_with_stdio(false);cin.tie(NULL); cout << fixed << setprecision(12);
#define IN_REP          int tt; cin >> tt; while(tt--)
#define sim             template<typename T
#define ris             return *this
#define dor             > debug & operator <<
#define eni(x)          sim > typename enable_if<sizeof dud<T>(0) x 1, debug&>::type operator<<(T i)
sim> struct rge { T b, e; };
sim> rge<T> range(T i, T j) { return rge<T>{i, j}; }
sim> auto dud(T *x) -> decltype(cerr << *x, 0);
sim> char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) { cerr << boolalpha << i; ris; }
  eni(==) { ris << range(all(i)); }
  sim, typename U dor(pair<U, T> d) { ris << "(" << d.first << ", " << d.second << ")"; }
  sim dor(rge<T> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
  sim dor(const T&) { ris; }
#endif
};
#define pr(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vb = vector<bool>;

using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template<typename T> T gcd(T x, T y) { return (y == 0) ? x : gcd(y, x % y); }
template<typename T> void mini(T& x, T y) { x = min(x, y); }
template<typename T> void maxi(T& x, T y) { x = max(x, y); }
template<typename T, typename U> string to_string(pair<T, U> p) { return to_string(p.F) + " " + to_string(p.S); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
// @formatter:on


class BFizzBuzzSum {
 public:

  auto solveOne(istream &cin, ostream &cout) {

  }

  void solve(std::istream& cin, std::ostream& cout) {
	int n;
	cin >> n;
	ll res = 0;
    for (int i = 0; i <= n; ++i) {
      if(i % 15 == 0){
        continue;
      }
      if(i % 3 == 0 || i % 5 == 0) continue;
      res += i;
    }
    cout << res <<'\n';
  }
};

int main() {
    IOS;
	BFizzBuzzSum solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

ll f(int x) {
   ll res = 1;
   rep(i, 0, 5) res *= x;
   return res;
}

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

   int x;
   cin >> x;
   rep(i, 0, 1005) {
      rep(j, -1005, 1000) {
         if (f(i) - f(j) == x) {
            printf("%d %d\n", i, j);
            return 0;
         }
      }
   }
   return 0;
}

Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	var tmp = ReadIntArray();
	int a = tmp[0], b = tmp[1], c = tmp[2];
	int ans = Math.Max(0, c - (a - b));
	WriteLine(ans);
    }
}


Measured memory_bytes: 13396
m_num = gets.to_i
m_hps = gets.split(" ").map{|d|d.to_i}

def gcd n,m
  if (m == 0)
    return n;
  end
  return gcd(m, n % m)
end

# 0/1で求める その結果と2で計算 その結果と3で計算 その結果と4で計算
# 終了条件：次のインデックス==m_num
tmp_gcd = gcd(m_hps[0],m_hps[1])
next_index = 2
while(next_index < m_num)
  tmp_gcd = gcd(tmp_gcd, m_hps[next_index])
  next_index += 1
end

puts tmp_gcd.to_s

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int>black(N+1,0);
    vector<int>white(N+1,0);
    for (int i = 1; i <= N; ++i) {
        if(S[i-1] == '#'){
            black[i] = black[i-1] + 1;
            white[i] = white[i-1];
        }else{
            white[i] = white[i-1] + 1;
            black[i] = black[i-1];
        }
    }
    int ans = mod;
    for (int i = 0; i <= N; ++i) {
        int sum = black[i] + white[N] - white[i];
        if(sum < ans){
            ans = sum;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 2180
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N; readf("%d\n", &N);
    auto A = readln.chomp.split(" ").map!(to!int).array;
    int l = A.reduce!min;
    int u = A.reduce!max;
    writeln(u - l);
}


Measured memory_bytes: 256
s = input()
t = input()

ans = ['?' for i in range(len(s))]
start_pos = 0
cond = False
count = 0

if len(s) < len(t):
    print('UNRESTORABLE')
else:
    for i in range(len(s) - len(t) + 1):
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == "?":
                count += 1
        if count == len(t):
            start_pos = i
            cond = True
        count = 0
    if cond:
        ans = list(s)
        for k in range(len(t)):
            ans[start_pos+k] = t[k]
        ans = "".join(ans)
        ans = ans.replace("?", "a")
        print(ans)
    else:
        print('UNRESTORABLE')




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

ll n,s;

bool ok(int b)
{
    ll res=0;
    ll t=n;
    while(t)
    {
        res+=t%b;
        t/=b;
    }
    return (res==s);
}

int main()
{
    cin>>n>>s;
    for(int i=2;i<=1e6;i++)
    {
        if(ok(i))
        {
            cout<<i; return 0;
        }
    }
    ll res=1e18;
    if(n==s) res=s+1;
    for(int i=1;i<=1e6;i++)
    {
        ll ones=s-i;
        ll t=n;
        t-=ones;
        if(t%i==0)
        {
            ll base=t/i;
            if(base>ones && i<base && ones>=0)
            {
                res=min(res,base);
            }
        }
    }
    if(res==1e18) cout<<-1;
    else cout<<res;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename Monoid>
class SegmentTree {
	std::vector<Monoid> data;
	size_t sz;
	
	using F = std::function<Monoid(Monoid, Monoid)>;
	
	const F f;
	const Monoid E;
	
	public:
	SegmentTree(const size_t n, const F f, const Monoid E) : f(f), E(E) {
		sz = 1;
		while(sz < n) sz <<= 1;
		data.assign(sz << 1, E);
	}
	void set(int k, const Monoid x) {
		data[k + sz] = x;
	}
	void build() {
		for(int k = sz - 1; k > 0; k--) data[k] = f(data[2 * k + 0], data[2 * k + 1]);
	}
	void update(int k, const Monoid x) {
		k += sz;
		data[k] = f(data[k], x);
		
		while(k >>= 1) data[k] = f(data[k << 1 ^ 0], data[k << 1 ^ 1]);
	}
	Monoid query(int a, int b) {
		Monoid L = E, R = E;
		for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if(a & 1) L = f(L, data[a++]);
			if(b & 1) R = f(data[--b], R);
		}
		return f(L, R);
	}
	const Monoid operator[](const int k) const {
		return data[k + sz];
	}
};

int main() {
	int n; scanf("%d", &n); std::vector<int> a(n), vec;
	for(int i = 0; i < n; i++) scanf("%d", &a[i]); vec = a;
	sort(begin(vec), end(vec)); vec.erase(unique(begin(vec), end(vec)), end(vec));
	
	SegmentTree<int> seg(n, [](int a, int b) { return a + b; }, 0);
	auto getIndex = [&seg, n](int p) {
		if(!seg.query(0, p)) return -1;
		int ok = 0, ng = p;
		while(std::abs(ok - ng) > 1) {
			int mid = (ok + ng) >> 1;
			
			if(seg.query(mid, p)) ok = mid;
			else ng = mid;
		}
		return ok;
	};
	
	int ans = 0;
	for(int i = 0; i < n; i++) {
		int k = lower_bound(begin(vec), end(vec), a[i]) - begin(vec);
		int ret = getIndex(k);
		
		if(ret == -1) {
			seg.update(k, 1);
			ans++;
		} else {
			seg.update(ret, -1);
			seg.update(k, 1);
		}
		
	//	for(int i = 0; i < n; i++) cout << seg[i] << " "; cout << endl;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};
int main(void) {
	int n; cin >> n;
	vi num(n,0);
	Sieve sv(1005);
	for(int i=1; i<=n; i++){
		vector<P> f = sv.factor(i);
		for(auto p: f) num[p.fi-1] += p.se;
	}
	mint ans = 1;
	rep(i,n) ans = ans*(num[i]+1);
	cout << ans << endl;
}


Measured memory_bytes: 256
# 何回目のアタックだよこれ（前回までのは当然読んですら無い）
# 単純にa<bのとき貯めれるだけためて残りをbにぶっこむのじゃ駄目なの?
k, a, b = map(int, input().split())
if a >= b or b - a <= 2:
    # 貯めるだけムダなので全振り
    print(1 + k)
    exit()
x = a  # はじめてa枚貯まってから1円に交換したターン
d = k - x  # x時点での残りターン

if d == 0:
    # 変えないほうがよかったね
    print(1 + k)
    exit()
if d % 2 == 0:
    # 直前で止めて+1したほうがいい
    print(a + (b - a) * (d // 2) + 1)
else:
    # そのまま交換したほうがいい
    print(b + (b - a) * (d // 2))


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

int main(){
  int n,m;
  cin >> n >> m;
  int a;
  for(int i=0; i!=m; i++){
    cin >> a;
    n = n - a;
  }
  if(n < 0){
    cout << -1 << '\n';
  }else{
    cout << n << '\n';
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
void print_line(vector<ll> &line) {
    for (int i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

int main() {

    string s;
    getline(cin, s);

    char diff = 'a' - 'A';
    for (int i = 0; i < s.size(); i++) {
        char c = s[i];
        if ('a' <= c && c <= 'z') {
            char n = c - diff;
            cout << n;
        } else if ('A' <= c && c <= 'Z') {
            char n = c + diff;
            cout << n;
        } else {
            cout << c;
        }
    }
    cout << endl;

}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define f first
#define s second
#define N 1001
#define INF (1e9)
using namespace std;
typedef complex<double> P; //Point
typedef pair<P,P> L; //Line, Segment
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);

double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }
int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  return ( ccw(s1.f,s1.s,s2.f) * ccw(s1.f,s1.s,s2.s) <= 0 &&
           ccw(s2.f,s2.s,s1.f) * ccw(s2.f,s2.s,s1.s) <= 0 );
}

typedef pair<double,int> Pi;
double dijkstra(vector<P>A,vector<P>B){
  vector<double>D(N,INF);
  priority_queue<Pi,vector<Pi>,greater<Pi> >Q;
  Q.push(Pi(0,0));
  D[0]=0;
  while(!Q.empty()){
    Pi t=Q.top();Q.pop();
    int pos=t.s;
    double cost=t.f;
    if(D[pos]<cost)continue;
    if(pos==1)return cost+abs(A[0]-A[1]);    

    for(int i=0;i<B.size();i++){
      double ncost=cost+abs(B[pos]-B[i]);
      if(isIntersect(L(A[0],A[1]),L(B[pos],B[i]))||D[i]<=ncost)continue;
      D[i]=ncost;
      Q.push(Pi(ncost,i));
    }
  }
  return INF;
}

int main(){
  int n,m;
  cin>>n>>m;
  vector<P> A(n),B(m); 
  for(int i=0,x,y;i<n;i++)cin>>x>>y,A[i]=P(x,y);
  for(int i=0,x,y;i<m;i++)cin>>x>>y,B[i]=P(x,y);
  double ans=min(dijkstra(A,B),dijkstra(B,A));
  printf("%.10f\n",ans<INF? ans:-1);
  return 0;
}

Measured memory_bytes: 3388
N = int(input())
S = input()
S = S[::-1]

cnt = S.count('B')*S.count('G')*S.count('R')

for i in range(N-2):
    for j in range(i,N-1):
        k = 2*j-i
        if  k<=N-1:
            if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k] :
                cnt -= 1


print(cnt)

Measured memory_bytes: 9200
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int n;
vector<vector<int> > graph(200001);

pair<int, int> getMaxDistNode(int now)
{
	vector<int> dist(200001, -1);
	dist[now] = 1;
	queue<int> qu;
	qu.push(now);
	while(!qu.empty()){
		int tmp = qu.front();
		qu.pop();
		for(int i = 0; i < graph[tmp].size(); i++){
			int next = graph[tmp][i];
			if(dist[next] >= 0) continue;
			dist[next] = dist[tmp] + 1;
			qu.push(next);
		}
	}
	int ans = 0;
	for(int i = 1; i < n; i++){
		if(dist[i] > dist[ans]) ans = i;
	}
	return make_pair(ans, dist[ans]);
}

int main()
{
	cin >> n;
	for(int i = 0; i < n - 1; i++){
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	int node1 = getMaxDistNode(0).first;
	int diameter = getMaxDistNode(node1).second;

	bool canWin[200001];
	canWin[0] = false;
	canWin[1] = true;
	canWin[2] = false;
	for(int i = 3; i <= diameter; i++){
		canWin[i] = !canWin[i - 1] || !canWin[i - 2];
	}
	if(canWin[diameter]) cout << "First" << endl;
	else cout << "Second" << endl;

}

Measured memory_bytes: 13556