akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

class Point{
	int x;
	int y;
	int z;
	int w;
	int count;
	Point(int a,int b,int c,int d,int e){
		this.x = a;
		this.y = b;
		this.z = c;
		this.w = d;
		this.count = e;
	}
}

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		int[] L = new int[N];

		for(int i = 0 ; i < N ; i++){
			L[i] = sc.nextInt();
		}
		sc.close();

		int[] dx = {1,0,0};
		int[] dy = {0,1,0};
		int[] dz = {0,0,1};
		int[] dw = {0,0,0};

		Deque<Point> stack = new ArrayDeque<Point>();
		stack.push(new Point(0,0,0,0,0));

		int ans = 100000000;
		int tmp = 0;
		while(!stack.isEmpty()){
			Point p = stack.poll();

			int nx = p.x;
			int ny = p.y;
			int nz = p.z;
			int nw = p.w;
				for(int i = 0 ; i < 3 ; i++){
					int x = nx + (dx[i] * L[p.count]);
					int y = ny + (dy[i] * L[p.count]);
					int z = nz + (dz[i] * L[p.count]);
					int w = nw + 10;
					int count = p.count + 1;
					if(count < N){
						stack.push(new Point(nx,ny,nz,nw,count));
						stack.push(new Point(x,y,z,w,count));
					}

					if(x!=0 && y!=0 && z !=0){
						tmp = Math.abs(A-x) + Math.abs(B-y) + Math.abs(C-z) + w - 30;
//						System.out.println(x + " " + y + " " + z + " " + w + " " + tmp);
						if(ans > tmp){
							ans = tmp;
						}
					}
				}
		}

		System.out.println(ans);

	}
}


Measured memory_bytes: 33800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

map<ll, int> prime_factor(ll n) {
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; i++) {
        while (n % i == 0) {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

void solve() {
    ll n;
    cin >> n;
    auto mp = prime_factor(n);
    int ans = 0;
    for(auto p : mp) {
        int m = 1;
        while(p.se >= m) {
            ans++;
            p.se -= m;
            m++;
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 3616
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}
func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0
	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	m := getNextInt(scanner)
	k := getNextInt(scanner)
	if k >= 1<<uint(m) {
		fmt.Fprintln(writer, -1)
		return
	}
	if k == 0 {
		for i := 0; i < 1<<uint(m); i++ {
			fmt.Fprintln(writer, i)
			fmt.Fprintln(writer, i)
		}
		return
	}
	if m == 1 {
		fmt.Fprintln(writer, -1)
		return
	}
	fmt.Fprintln(writer, k)
	for i := 0; i < 1<<uint(m); i++ {
		if i == k {
			continue
		}
		fmt.Fprintln(writer, i)
	}
	fmt.Fprintln(writer, k)
	for i := 0; i < 1<<uint(m); i++ {
		if 1<<uint(m)-1-i == k {
			continue
		}
		fmt.Fprintln(writer, 1<<uint(m)-1-i)
	}
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<stack>
static const int MAX=100000;
static const int NIL=-1;

int n;
std::vector<int> G[MAX];
int color[MAX];
void DFS(int,int);
void assignColor(void);

int main(){
  int s, t, m, q;
  std::cin >> n >> m;
  for(int i=0; i<m; i++){
    std::cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  assignColor();
  std::cin >> q;
  for(int i=0; i<q; i++){
    std::cin >> s >> t;
    if(color[s] == color[t]) std::cout << "yes\n";
    else std::cout << "no\n";
  }
  return 0;
}
void assignColor(void){
  int id=1;
  for(int i=0; i<n; i++) color[i] = NIL;
  for(int u=0; u<n; u++) if(color[u] == NIL) DFS(u, id++);
}
void DFS(int r, int c){
  std::stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty()){
    int u=S.top(); S.pop();
    for(int i=0; i<G[u].size(); i++){
      int v=G[u][i];
      if(color[v] == NIL){
        color[v] = c;
        S.push(v);
      }
    }
  }
}

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

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

using namespace std;

typedef pair<int,int> ii;
const int IINF = INT_MAX;

vector<ii> G[100010];
int mincost[100010];
int V,E,r;

struct Data{
  int cur,cost;
  bool operator < (const Data& data) const{ return cost > data.cost; }
};

int main(){
  scanf("%d %d %d",&V,&E,&r);

  int s,t,d;
  rep(i,E){
    scanf("%d %d %d",&s,&t,&d);
    G[s].push_back(ii(t,d));
  }

  // Shortest Path Faster Algorithm 
  // O(kE)

  rep(i,V) mincost[i] = IINF;
  mincost[r] = 0;
  deque<int> deq; deq.push_back(r);
  vector<int> in_queue(V,0); in_queue[r] = 1;
  vector<int> time_stamp(V,0); time_stamp[r] = 1;

  bool found = false;

  while(!deq.empty()){
    int u = deq.front(); deq.pop_front(); in_queue[u] = 0;
    
    rep(i,(int)G[u].size()){
      int v = G[u][i].first, c = G[u][i].second;
      if( mincost[v] > mincost[u] + c ) {
        mincost[v] = mincost[u] + c;
        if( !in_queue[v] ) {
          deq.push_back(v);
          in_queue[v] = 1;
          time_stamp[v]++;
          if( time_stamp[v] >= V-1 ) {
            found = true;
            goto Skip;
          }
        }
      }
    }
  }
 Skip:;
  if( found ){
    puts("NEGATIVE CYCLE");
    return 0;
  }
  rep(i,V) {
    if( mincost[i] == IINF ) puts("INF");
    else printf("%d\n",mincost[i]);
  }

  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<queue>
#include <string.h>
#include <algorithm>

using namespace std;

int main(){
  int D;cin>>D;
  int C;cin>>C;
  int data[D][2];
  int ans=10000;
  for (int i = 0; i < D; i++) cin>>data[i][0]>>data[i][1];

  for (int bit = 0; bit < (1<<D); bit++) {
    int tmp_ans=0;
    int sum=0;
    for (int i = 0; i < D; i++) {
      if(bit&(1<<i)){
        sum+=(D-i)*100*data[D-i-1][0]+data[D-i-1][1];
        tmp_ans+=data[D-i-1][0];
      }
    }
    if(C<=sum){
      ans=min(ans,tmp_ans);
    }
    else if (sum<C){
      int search_i=0;
      while(true){
        if(!(bit&(1<<search_i))) break;
        search_i++;
      }
      for (int j = 0; j <data[D-search_i-1][0]; j++) {
        sum+=100*(D-search_i);
        tmp_ans++;
        if(C<=sum){
          ans=min(ans,tmp_ans);
          break;
        }
      }
    }
  }
  cout<< ans  << "\n";
}

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

int main() {
   int n, a[100005], ans;
   cin >> n;
    for(int i=0; i<n; i++) cin >> a[i];
    ans=a[0];
    for(int i=1; i<n; i++) {
        ans=__gcd(ans, a[i]);
    }
    cout << ans;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
double l;
int main(void){
	cin>>l;
	double k=(double)l/3;
	cout<<fixed<<setprecision(10)<<(double)k*k*k;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  long A = input();
  long B = input();
  long K = input();

  if(A <= K){
    K -= A;
    A = 0;
    B -= K;
    B = max((long)0,B);
  }
  else{
    A -= K;
  }

  cout << A << " " << B << endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < static_cast<int>(n); ++i)
#define per(i, n) for(int i = static_cast<int>(n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

constexpr char sp = ' ';
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n, ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}

int dp[10101];

int main(){

    int h, n;
    cin >> h >> n;
    vector<int> a(n), b(n);

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

    fill_n(dp, 10101, INF);
    dp[0] = 0;

    for(int i = 0; i < n; ++i){
        for(int j = 0; j <= h; ++j){
            int x = 0;
            if(j-a[i] >= 0) x = dp[j-a[i]];
            dp[j] = min(dp[j], x+b[i]);
        }
    }
    cout << dp[h] << '\n';
    return 0;
}


Measured memory_bytes: 256
N = int(input())
p_numbers = [2]
p_dict = {}
for num in range(3, N+1):
  is_prime = True
  for p_num in p_numbers:
    if num%p_num == 0:
      is_prime = False
      break
  if is_prime:
    p_numbers.append(num)
for num in range(1, N+1):
  for prime in p_numbers:
    div = num
    while True:
      if div%prime == 0:
        if prime in p_dict:
          p_dict[prime] += 1
        else:
          p_dict[prime] = 1
      else:
        break
      div = div//prime
ans = 1
for value in p_dict.values():
  ans *= (value+1)
print(ans%(10**9+7))


Measured memory_bytes: 3064
#include <stdio.h>
 
int main()
{
   int N,L,f[10000],i=0 ,min=100000,sum=0,t;
   scanf("%d %d",&N,&L);
   for(i=1;i<=N;i++)
   {
       f[i]=L+i-1;
       t=f[i];
       if(t<0)
       {t=-t;}
       if(min<0)
       {min=-min;}
       if(t<min)
       {
           min=f[i];
       }
       sum=sum+f[i];
   }
   sum=sum-min;
   printf("%d",sum);
   
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define rep(i,n,b) for(int i=0;i<n;i=i+b)
#define ld long double 
using namespace std;
int main() 
{
 int x;
 cin >> x;
 if(x>=30)
 {
 cout << "Yes";
 }
 else
  {
    cout << "No";
  }
}


Measured memory_bytes: 3588
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int a, b; cin >> a >> b;
	for (int i = a - 1;i >= 0;--i) {
		cout << b - i << " ";
	}
	REP(i, 1, a)cout << b + i << (i == a - 1 ? "\n" : " ");

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int n,x,ans=0;
  for(int l=0; l<100; l++) {
      cin >> n >> x;
      if(n==0&&x==0) {
          return 0;
      }
      ans=0;
      for(int i=1; i<=n-2; i++) {
          for(int j=i+1; j<=n-1; j++) {
              for(int k=j+1; k<=n; k++) {
                  if(i+j+k==x) {
                      ans++;
                  }
              }
          }
      }
      cout << ans << endl;
  }
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
#define pb push_back
#define mp make_pair
#define x first
#define y second
typedef long long int ll;
// typedef tree< ll, null_type, less_equal< ll >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define pii pair<ll,ll>
const ll N = 3e5 +9;
// const ll m = 1e9 + 7;
const ll inf= 1e16;
const ll mod = 1e9 + 7;
ll dp[3005][3005][2];
ll a[3005];
ll rec(ll i,ll j,ll p){
	if(i==j){
		if(p==0){
			dp[i][j][p] = -a[i];
			return -a[i];		
		}
		dp[i][j][p] = a[i];
		return a[i];
	}
	if(dp[i][j][p]!=-1){
		return dp[i][j][p];
	}
	else{
		if(p==1){
			return dp[i][j][p] = max(rec(i+1,j,0)+a[i],rec(i,j-1,0)+a[j]);
		}
		else{
			return dp[i][j][p] = min(rec(i+1,j,1)-a[i],rec(i,j-1,1)-a[j]);
		

		}
	}
}

int main() {   
     ios::sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
    
     ll t=1;
     // cin>>t;
     while(t--){
     	ll n;cin>>n;
     	for(int i = 0;i<n;i++){
     		cin>>a[i];
     	}
     	memset(dp,-1,sizeof(dp));
     	cout<<rec(0,n-1,1);
     }     
}

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

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

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

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

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

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

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

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

fn main() {
    input!{
        h: usize,
        w: usize,
        n: usize,
        v: [[usize; 2]; n]
    }
    let d = 1000000007;
    let mut ws = v;
    ws.sort_by(|x, y| if x[0] == y[0] {x[1].cmp(&y[1])} else {x[0].cmp(&y[0])});
    let mut tab: Vec<usize> = vec![0; n];
    let mut ss: Vec<usize> = vec![1; h + w];
    for i in 1..h + w {
        ss[i] = ss[i - 1] * i % d;
    }
    let sis: Vec<usize> = ss.iter().clone().map(|&x| inv_m(x, d)).collect();
    for i in 0..n {
        tab[i] = comb_mem(&ss, &sis, ws[i][0] + ws[i][1] - 2, ws[i][0] - 1, d);
        for j in 0..i {
            if ws[i][1] < ws[j][1] {
                continue;
            }
            tab[i] = (tab[i] + d - tab[j] * comb_mem(&ss, &sis, ws[i][0] + ws[i][1] - ws[j][0] - ws[j][1], ws[i][0] - ws[j][0], d) % d) % d;
        }
    }
    let mut ans = comb_mem(&ss, &sis, h + w - 2, h - 1, d);
    for i in 0..n {
        ans = (ans + d - tab[i] * comb_mem(&ss, &sis, h + w - ws[i][0] - ws[i][1], h - ws[i][0], d) % d) % d;
    }
    println!("{}", ans);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

// only when d is prime
fn inv_m(n: usize, d: usize) -> usize {
    pow_m(n, d - 2, d)
}

fn comb_mem(ss: &Vec<usize>, sis: &Vec<usize>, n: usize, r: usize, d: usize) -> usize {
    ss[n] * sis[n - r] % d * sis[r] % d
}


Measured memory_bytes: 8444
#include<iostream>
using namespace std;
int main(){
	long long int n,ans=1;
  	cin >>n;
    const int dev = 1e9 + 7;
    for (int i = 1; i <= n; i++)
    {
        ans = ans % dev;
        ans *= i;
    }
    ans %= dev;
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int maxa = 1e5 + 5;
    vi cnt(maxa, 0);
    int n, i;
    cin >> n;
    vi a(n);
    ll sm = 0;
    for(i=0;i<n;i++){
        cin >> a[i];
        sm += a[i];
        cnt[a[i]]++;
    }
    int q;
    cin >> q;
    while(q--){
        int b,c;
        cin >> b >> c;
        sm += cnt[b]*ll(c - b);
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sm << "\n";
    }

    return 0;
}

Measured memory_bytes: 3988
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	int a,b;
	scanf("%d %d",&a,&b);
	if(a>8||b>8)puts(":(");
	else puts("Yay!");
	return 0;
}

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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int n;cin>>n;
	cout << n+(n*n)+(n*n*n);
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 3632
#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)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

ll comb2(ll n) // comb(n,2)
{
  if (n == 0) return 0;
  return n * (n - 1) / 2;
}

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i,0,N) cin >> A[i];

  // S[i+1] = S[0]...S[i]の和
  vector<ll> S(N+1);
  S[0] = 0;
  REP(i,0,N) S[i+1] = S[i] + A[i];

  // Sの各要素の出現回数
  // (S[0]=0も含むことに注意)
  map<ll,int> mp;
  for(auto const& s : S) {
    if (mp.count(s) > 0) mp[s]++;
    else mp[s] = 1;
  }

  ll ans = 0;
  // S[i]=S[j]なる(i,j)
  for(auto it = mp.begin(); it != mp.end(); ++it) {
    ans += comb2(it->second);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 15104
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N, T;
    cin >> N >> T;

    int c_min = inf;

    REP(i, N) {
        int c, t;
        cin >> c >> t;

        if(t > T) continue;

        c_min = min(c_min, c);
    }
    
    if (c_min == inf) cout << "TLE" << endl;
    else cout << c_min << endl;


}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define quickIO()	{cin.tie(0);	cout.sync_with_stdio(false);}
#define reach(i,a)	for(auto i:a)
#define rep(i,n)	for(int i=0;i<(int)n;i++)
#define REP(i,n)	for(int i=0;i<=(int)n;i++)
#define srep(i,a,n)	for(int i=a;i<(int)n;i++)
#define SREP(i,a,n)	for(int i=a;i<=(int)n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
int bitcnt(ll x) {
	x = ((x & 0xAAAAAAAAAAAAAAAA) >> 1) + (x & 0x5555555555555555);
	x = ((x & 0xCCCCCCCCCCCCCCCC) >> 2) + (x & 0x3333333333333333);
	x = ((x & 0xF0F0F0F0F0F0F0F0) >> 4) + (x & 0x0F0F0F0F0F0F0F0F);
	x = ((x & 0xFF00FF00FF00FF00) >> 8) + (x & 0x00FF00FF00FF00FF);
	x = ((x & 0xFFFF0000FFFF0000) >> 16) + (x & 0x0000FFFF0000FFFF);
	x = ((x & 0xFFFFFFFF00000000) >> 32) + (x & 0x00000000FFFFFFFF);
	return x;
}
int bitcnt(int x) {
	x = ((x & 0xAAAAAAAA) >> 1) + (x & 0x55555555);
	x = ((x & 0xCCCCCCCC) >> 2) + (x & 0x33333333);
	x = ((x & 0xF0F0F0F0) >> 4) + (x & 0x0F0F0F0F);
	x = ((x & 0xFF00FF00) >> 8) + (x & 0x00FF00FF);
	x = ((x & 0xFFFF0000) >> 16) + (x & 0x0000FFFF);
	return x;
}
ll sqrt(ll x) {
	ll left = 0, right = x;
	rep(i, 100) {
		ll mid = (left + right) >> 1;
		if (mid*mid <= x)	left = mid;
		else	right = mid;
	}
	return left;
}
ll gcd(ll a, ll b) {
	return a%b == 0 ? b : gcd(b, a%b);
}
#define debug(x)	printf("Case #%d: ", x)
#define DEBUG 0
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ld eps = 1e-15;
const int dx[] = { 1,0,-1,0,0 };
const int dy[] = { 0,1,0,-1,0 };

// 別解（というかこっちが想定解らしい）
// AとCをソートして、Bを順番に見ます。
// そのなかで、a[i]<b[j]となるiの個数もb[j]<c[k]となるkの個数もlower_boundやupper_boundで出来ます。
// これかければb[j]を使う通り数が求まるので、ループで求めましょう。

int main() {
	int n;	cin >> n;
	vint a(n), b(n), c(n);
	rep(i, n)	cin >> a[i];
	rep(i, n)	cin >> b[i];
	rep(i, n)	cin >> c[i];
	sort(all(a));	sort(all(c));

	ll ret = 0;
	rep(i, n) {
		ll numA = distance(a.begin(), lower_bound(all(a), b[i]));
		ll numB = c.size() - distance(c.begin(), upper_bound(all(c), b[i]));
		ret += numA*numB;
	}
	cout << ret << endl;
	return 0;
}

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

int main(){
long long d,n;
cin>>d>>n;
if(d==0){
cout<<((n!=100)?n:101);
}
else if(d==1){
cout<<((n!=100)?n*100:10100);
}
else {
cout<<((n!=100)?n*10000:1010000);
}
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

		boolean exit=true;
		int c = 0;
		while(exit==true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if(a==0 && b==0)exit=false;
			if(exit==true){
				if(c!=0)System.out.println();
				c++;
				int count=0;
				for(int i=a;i<=b;i++){
					if(i%400==0 || (i%4==0 && i%100!=0)){
						System.out.println(i);
						count++;
					}
				}
				if(count==0)System.out.println("NA");	
			}
		}

	}
}

Measured memory_bytes: 20728
// https://atcoder.jp/contests/abc134/tasks/abc134_d

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    vector<int> a(n + 1, 0);
    vector<bool> b(n + 1, false);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; i--) {
        int sum = 0;
        for (int j = i << 1; j <= n; j += i) {
            sum += b[j];
        }
        if ((sum & 1) != a[i]) {
            b[i] = true;
            ans++;
        }
    }
    cout << ans << endl;
    for (int i = 1; i <= n; i++) {
        if (b[i]) {
            cout << i << endl;
        }
    }

    return 0;
}


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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    double pi = 3.14159265359;

    double a, b, x;
    std::cin >> a >> b >> x;

    auto init_h = x / (a * a);
    auto r      = 0.0;
    auto l      = 90.0;
    if(b <= init_h * 2) {
        while(0.0000001 <=  abs(r - l)) {
            auto med = (r + l) / 2;
            auto h   = init_h + (a * tan((med / 180) * pi)) / 2;
            if(b < h) {
                l = med;
            }
            else {
                r = med;
            }
        }
        std::cout << setprecision(10) << r << std::endl;
    }
    else {
        std::cout << setprecision(10) << atan2(b * b * a, x * 2) * 180 / pi  << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
char str[10];
int i;
int main(void){
    for(i = 0;i < 10;i++){
        scanf("%s",&str[i]);
    }
    if(str[5] == '1'){
        printf("TBD");
    }else{
        if(str[6]<= '4'){
            printf("Heisei");
        }else{
            printf("TBD");
        }
    }
    return 0;
}


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

using namespace std;

int main()
{
  string a, b;
  int i;
  
  cin >> a >> b;
  
  if(a.size() > b.size()){
    cout <<  "GREATER" << endl;
  }
  else if(a.size() < b.size()){
    cout << "LESS" << endl;
  }
  else{
	for(i = 0; i < a.size(); i++){
      if(a[i] > b[i]){
        cout <<  "GREATER" << endl;
        return 0;
      }
      if(a[i] < b[i]){
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define pp pair<int,int>
#define ppn pair<int,pp>
#define F first
#define S second
#define N 300005
#define mod 1000000007
#define pi 3.14159265358979323846

using namespace std;

int n, m, a, b, xxx, yyy, ans;

char s[1005][1005];
int dp[1005][1005];
int xx[]={-1,0,0,1},yy[]={0,-1,1,0};
 priority_queue<ppn,vector<ppn>,greater<ppn> > q;


bool check()
{

    q.push({0,{a-1,b-1}});
    while(!q.empty()){
        ppn t = q.top();
        q.pop();


        int u = t.S.F;
        int v = t.S.S;
        int c = t.F;
        if(dp[u][v])continue;
        dp[u][v]=1;

        //cout<<t.F<<" "<<t.S.F<<" "<<t.S.S<<endl;
        if(u==xxx-1&&v==yyy-1){
            ans = c;
            return true;
        }
        for(int i=-2;i<=2; i++){
            for(int j=-2;j<=2; j++){
                //if(!i&&!j)continue;
                int x = u+i;
                int y = v+j;
                 if(x<0||x>=n||y<0||y>=m)
                    continue;
                if(dp[x][y]||s[x][y]=='#')continue;
                q.push({t.F+1,{x,y}});
            }
         }


       for(int i=0; i<4; i++){
          int x =u+xx[i];
          int y = v+yy[i];
           if(x<0||x>=n||y<0||y>=m)
                    continue;
          if(dp[x][y]||s[x][y]=='#')continue;
                q.push({t.F,{x,y}});
       }
    }
   return false;

}
int main()
{


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




    // memset(dp,-1,sizeof dp);
     cin>>n>>m;
     cin>>a>>b>>xxx>>yyy;
     for(int i=0; i<n; i++)for(int j=0; j<m; j++)cin>>s[i][j];


     if(check())cout<<ans<<endl;
     else cout<<-1<<endl;



}


Measured memory_bytes: 9728
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

// enum_div 約数列挙O(√N)
// 順番はバラバラ
template<typename T>
vector<T> enum_div(T n) {
    vector<T> ret;
    for (T i = 1; i * i <= n; ++i)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    int sum = 0;
    REP(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    auto e = enum_div(sum);
    sort(e.rbegin(), e.rend());
    vector<int> b(n);
    REP(i, e.size()) {
        int total = 0;
        REP(j, n) {
            b[j] = a[j] % e[i];
            total += b[j];
        }
        sort(b.rbegin(), b.rend());
        int num = total / e[i];
        REP(j, num) {
            total -= b[j];
        }
        if (k >= total) {
            cout << e[i] << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
#define pii pair<int, int>
/* * * *   * * *   	* * * */
/* *
 *
 * Author: Hamkor
 *
 * */
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n; cin>>n;
    int a[n+1], b[n+1], c[n+1];
    for (int i=1; i<=n;++i) cin>>a[i];       
    for (int i=1; i<=n;++i) cin>>b[i];       
    for (int i=2; i<=n;++i) cin>>c[i];
    int ans=b[a[1]];
    for (int i=2; i<=n; ++i){
		ans+= a[i-1]+1 == a[i] ? b[a[i]] + c[a[i]] : b[a[i]];
	}
	cout<<ans<<endl;        
	return 0;
}


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

using namespace std;

void yes() {
  printf("Yes");
  exit(0);
}
void no() {
  printf("No");
  exit(0);
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= 9; i++)
    for (int j = 1; j <= 9; j++)
      if (i * j == n) yes();
  no();
  return 0;
}


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


int main() {
	int a, b, c,p;
	p = 0;
	cin >> a >> b >> c;
	for (int n = a; n <b+1; n++) {;
		if (c%n==0) {
			p = p + 1;
		}
	}
	cout << p << endl;
	return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    int N;
    cin >> N;
    
    if (N == 1) cout << "Hello World" << endl;
    else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    
    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());  // sの並べ替えで最も小さい = 昇順
  sort(t.begin(), t.end(), greater<char>());  // tの並べ替えで最も大きい = 降順
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100001)

def gcd(b, s):
    return s if b % s == 0 else gcd(s, b % s)

# 一人消してgcd
n = int(input())
nl = sorted(list(map(int, input().split(' '))))
rl = nl[::-1]
sumnl = [nl[0]]
sumrl = [rl[0]]
for i in range(1, len(nl)):
    sumnl.append(gcd(sumnl[-1], nl[i]))
    sumrl.append(gcd(sumrl[-1], rl[i]))
sumrl = sumrl[::-1]
if len(sumnl) == 1:
    print(sumnl[0])
else:
    print(max([sumnl[-2]] + [gcd(sumnl[i],sumrl[i+2]) for i in range(len(sumrl) - 2)] + [sumrl[1]]))


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

 int main(){
  while(1){
     int n,m;
    int mn[1001],cnt[101]={},ans[1001]={},ansm=0;
    string str[101],str2[1001];
    cin>>n>>m;
    if(n+m==0) break;
    for(int i=0;i<n;i++)cin>>str[i]>>mn[i];
    for(int i=0;i<n;i++)
      for(int j=0;j<8;j++)if(str[i][j]>='0' && str[i][j]<='9') cnt[i]++;
    for(int i=0;i<m;i++) cin>>str2[i];
    for(int i=0;i<n;i++)
      for(int k=0;k<m;k++){
	ans[k]=0;
	for(int j=7;j>=0;j--)if(str2[k][j]==str[i][j])ans[k]++;
	if(ans[k]==cnt[i])  ansm+=mn[i];
      }
    cout<<ansm<<endl;
  }
  return 0;
}

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

const int N=2100,K=1e4+100;
char ch[N][K];
int n,k,len[N];
bitset<K> f[N];
pair<int,int> v[2][K];

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",ch[i]+1);
		len[i]=strlen(ch[i]+1);
	}
	f[n+1][0]=1;
	for(int i=n;i>=1;--i)
		f[i]=f[i+1]|(f[i+1]<<len[i]);
	int cnt=0;
	for(int i=1;i<=n;++i)
		if(f[i+1][k-len[i]]) v[0][++cnt]=make_pair(i,1);
	for(int i=1;i<=k;++i)
	{
		char Ans='z'; int ncnt=0,ID=n+1;
		for(int j=1;j<=cnt;++j)
			Ans=min(Ans,ch[v[i-1&1][j].first][v[i-1&1][j].second]);
		putchar(Ans);
		for(int j=1;j<=cnt;++j)
		{
			int id=v[i-1&1][j].first,pos=v[i-1&1][j].second;
			if(ch[id][pos] != Ans) continue;
			if(pos<len[id]) v[i&1][++ncnt]=make_pair(id,pos+1);
			else ID=min(ID,id);
		}
		for(int j=ID+1;j<=n;++j)
			if(k-i-len[j]>=0 && f[j+1][k-i-len[j]]) v[i&1][++ncnt]=make_pair(j,1);
		cnt=ncnt;
	}
	return 0;
}


Measured memory_bytes: 22784
///...................SUBHASHIS MOLLICK...................///
///.....DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING....///
///.............ISLAMIC UNIVERSITY,BANGLADESH.............///
///....................SESSION-(14-15)....................///
#include<bits/stdc++.h>
using namespace std;
#define sf(a) scanf("%lld",&a)
#define sf2(a,b) scanf("%lld %lld",&a,&b)
#define sf3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define pf(a) printf("%lld",a)
#define pf2(a,b) printf("%lld %lld",a,b)
#define pf3(a,b,c) printf("%lld %lld %lld",a,b,c)
#define nl printf("\n")
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define MPI map<int,int>mp;
#define fr(i,n) for(i=0;i<n;i++)
#define fr1(i,n) for(i=1;i<=n;i++)
#define frl(i,a,b) for(i=a;i<=b;i++)
/*primes in range 1 - n
1 - 100(1e2) -> 25 pimes
1 - 1000(1e3) -> 168 primes
1 - 10000(1e4) -> 1229 primes
1 - 100000(1e5) -> 9592 primes
1 - 1000000(1e6) -> 78498 primes
1 - 10000000(1e7) -> 664579 primes
large primes ->
104729 1299709 15485863 179424673 2147483647 32416190071 112272535095293 48112959837082048697
*/
//freopen("Input.txt","r",stdin);
//freopen("Output.txt","w",stdout);
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
main()
{
    timesave;
    long a;
    string s;
    while(cin>>a>>s)
    {
        if(a<3200)
            cout<<"red"<<endl;
        else
            cout<<s<<endl;
    }
}



Measured memory_bytes: 256
i = int(input())
a = [int(x) for x in input().split()]

color = [False]*8
top = 0

for i in a:
    if i <= 399:
        color[0] = True
    elif i <= 799:
        color[1] = True
    elif i <= 1199:
        color[2] = True
    elif i <= 1599:
        color[3] = True
    elif i <= 1999:
        color[4] = True
    elif i <= 2399:
        color[5] = True
    elif i <= 2799:
        color[6] = True
    elif i <= 3199:
        color[7] = True
    else:
        top += 1

mx = color.count(True) + top
mi = color.count(True)
if mi == 0 and top > 0:
    mi = 1
print('{} {}'.format(mi, mx))

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace id_0277cs
{
    class Program
    {
        static void Main(string[] args)
        {
            foreach( var i in Enumerable.Range(0, 4))
            {
                var vs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                var t = vs[0];
                var n = vs[1];
                if(t == 1) {
                    Console.WriteLine(n * 6000);
                }
                if(t == 2)
                {
                    Console.WriteLine(n * 4000);
                }
                if(t == 3)
                {
                    Console.WriteLine(n * 3000);
                }
                if(t == 4)
                {
                    Console.WriteLine(n * 2000);
                }
            }
        }
    }
}



Measured memory_bytes: 9540
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

static int64_t n;
static int64_t m;
static std::vector<int64_t> as;
static std::vector<std::pair<int64_t, int64_t>> items;
static int64_t sum;

void solve() {
  int j = 0;
  for (int i = 0; i < m; i++) {
    auto const item = items[i];
    auto const c = item.second;
    if (c <= as.front()) {
      return;
    }
    auto const b = item.first;
    auto const jEnd = std::min(j + b, n);
    for (; j < jEnd; ++j) {
      if (as[j] >= c) {
        break;
      }
      sum += (c - as[j]);
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n;
  std::cin >> m;
  as.resize(n);
  sum = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> as[i];
    sum += as[i];
  }
  std::sort(as.begin(), as.end());
  items.resize(m);
  for (int i = 0; i < m; i++) {
    std::cin >> items[i].first;
    std::cin >> items[i].second;
  }
  std::sort(items.begin(), items.end(), [](const auto& lhs, const auto& rhs) {
    return lhs.second > rhs.second;
  });
  solve();
  std::cout << sum << std::endl;
  return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
using namespace std;
const int N=100010;
struct tyc{
	int to,next;
}e[4*N];
int head[N],n,m,size=0;
int x,y;
int oh,si,oth;
long long ans;
bool p=0;
bool vis[N],color[N];
void add(int x,int y)
{
	size++;
	e[size].to=y;
	e[size].next=head[x];
	head[x]=size;
}
void dfs(int x,int fa)
{
	//cout<<x<<endl;
	vis[x]=1;
	color[x]=color[fa]^1;
	for (int i=head[x];i;i=e[i].next)
	{
		int y=e[i].to;
		if (y!=fa)
		{
			if (vis[y])
			{
				if (color[x]==color[y]) p=1;
				continue;
			}
			else dfs(y,x);
		}
	}
	return;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
		scanf("%d%d",&x,&y),add(x,y),add(y,x);
	for (int i=1;i<=n;i++)
	{

		if (!vis[i])
		{
			if (head[i]==0) {si++,vis[i]=1;continue;}
			p=0;
			dfs(i,0);
			if (p) oh++;
			else oth++;
		}
	}
	//cout<<si<<" "<<oh<<" "<<oth<<endl;
//	cout<<2ll*si*n-1ll*si*si+((oth==1)?2:2ll*oth*(oth-1))+((oh==1)?1:1ll*oh*(oh-1))+2ll*oh*oth<<endl;
	ans=2ll*si*n-1ll*si*si+2ll*oth*oth+1ll*oh*oh+2ll*oh*oth;
	printf("%lld",ans);
}

Measured memory_bytes: 6784
n,k=map(int,input().split())
a=list(map(int,input().split()))
check=[-1]*n
check[0]=1
ans=[0]
p=0
p=a[p]-1
while check[p]==-1:
  ans.append(p)
  check[p]=1
  p=a[p]-1
ans.append(p)
for i in range(len(ans)-1):
  if ans[i]==ans[-1]:
    x=i
    break
if k<=len(ans):
  print(ans[k]+1)
else:
  print(ans[(k-x)%(len(ans)-1-x)+x]+1)

Measured memory_bytes: 95012
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, a, b;
    cin >> n >> a >> b;
    int MAX, MIN;
    MAX = min(a, b);
    MIN = a + b - n;
    if (MIN < 0) {
        MIN = 0;
    }
    cout << MAX << " " << MIN << endl;
}


Measured memory_bytes: 256
n, x, m = gets.split.map(&:to_i)

r = x
res = x
r_arr = [r]
r_hash = {r => 0}

(n-1).times do |i|
  r = r ** 2 % m
  break unless r_hash[r].nil?

  res += r
  r_arr << r
  r_hash[r] = i + 1
end

ind = r_hash[r]
sub_arr = r_arr[ind..-1]
sum = sub_arr.sum
count = sub_arr.length
res += ((n - r_arr.length) / count) * sum

de = (n - r_arr.length) % count
de.times do
  res += r
  r = r ** 2 % m
end
puts res


Measured memory_bytes: 16664
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int N = Integer.parseInt(in.next());
            final int K = Integer.parseInt(in.next());
            final int R = Integer.parseInt(in.next());
            final int S = Integer.parseInt(in.next());
            final int P = Integer.parseInt(in.next());
            final char[] T = in.next().toCharArray();

            int ret = 0;
            for (int i = 0; i < N; i++) {
                int next = i + K;
                if (next < N && T[i] == T[next]) {
                    T[next] = ' ';
                }

                switch (T[i]) {
                    case 'r':
                        ret += P;
                        break;
                    case 's':
                        ret += R;
                        break;
                    case 'p':
                        ret += S;
                        break;
                    default:
                        break;
                }
            }
            out.println(ret);

        }

    }
}



Measured memory_bytes: 26280
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

int main()
{
    using P = std::pair<int, int>;

    int H, W;
    scanf(" %d %d", &H, &W);
    std::vector<std::vector<char> > A(H, std::vector<char>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++) scanf(" %c", &A[i][j]);
    }

    std::priority_queue<P, std::vector<P>, std::greater<P> > q; // (time, index)
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j] == '#') q.push(P(0, i*W+j));
        }
    }

    int time = 0;
    while(!q.empty()){
        time = q.top().first;
        int u = q.top().second / W;
        int v = q.top().second % W;
        q.pop();
        if(u != 0   && A[u-1][v] == '.'){A[u-1][v] = '#'; q.push(P(time+1, (u-1)*W+v));}
        if(u != H-1 && A[u+1][v] == '.'){A[u+1][v] = '#'; q.push(P(time+1, (u+1)*W+v));}
        if(v != 0   && A[u][v-1] == '.'){A[u][v-1] = '#'; q.push(P(time+1, u*W+v-1));}
        if(v != W-1 && A[u][v+1] == '.'){A[u][v+1] = '#'; q.push(P(time+1, u*W+v+1));}
    }
    std::cout << time << std::endl;
}

Measured memory_bytes: 11372
n = int(input())
aa = input()
l = aa.split()
for i in range(0,n):
    l[i] = int(l[i])
l.sort()
count = 0
for i in range(0,n-1):
    if l[i] == l[i+1]:
        count = count+1
if count == 0:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 19928