akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <numeric>

int const MAXN = 200000;
int const MAXNN = 1<<18;
int64_t const INF = (int64_t)1<<59;

int N, NN;
int64_t C, h[MAXN];

// 0: l_inf
int64_t ic[MAXN], sl[MAXN];
int64_t dp[MAXN];

int f[MAXNN*2-1], hi[MAXN], rev_hi[MAXN];

void init() {
  ic[0] = INF;
  sl[0] = 0;
  NN = 1;
  while(NN < N+1) NN <<= 1;
  std::fill(f, f+NN*2-1, 0);
  std::iota(hi, hi+N, 0);
  std::sort(hi, hi+N, [](int l, int r){ return h[l]<h[r]; });
  for(int i = 0; i < N; ++i) rev_hi[hi[i]] = i;
}

// calc value of line-i at h[hi[j]]
inline int64_t calc_f(int i, int j) {
  int64_t x = h[hi[j]];
  return sl[i]*x + ic[i];
}

// update by line-i
void update(int i) {
  int k = 0, l = 0, r = N;
  for(;;) {
    int v = f[k];
    int64_t dL = calc_f(v, l) - calc_f(i, l);
    if(l == r-1) {
      if(dL > 0) f[k] = i;
      return;
    }
    int64_t dR = calc_f(v, r-1) - calc_f(i, r-1);
    if(dL <= 0 && dR <= 0) return;
    if(dL >= 0 && dR >= 0) {
      f[k] = i;
      return;
    }
    int m = (l+r)/2;
    if(calc_f(v, m-1) - calc_f(i, m-1) > 0) {
      dL = -dL;
      v = i; i = f[k]; f[k] = v;
    }
    if(dL >= 0) {
      r = m;
      k = 2*k+1;
    } else {
      l = m;
      k = 2*k+2;
    }
  }
}

// get min at h[i];
int64_t get_min(int i) {
  i = rev_hi[i];
  int k = 0, l = 0, r = N;
  int v = f[k];
  int64_t ans = calc_f(v, i);
  while(r - l > 1) {
    int m = (l+r)/2;
    if(i < m) {
      r = m;
      k = 2*k + 1;
    } else {
      l = m;
      k = 2*k + 2;
    }
    if(f[k] == 0) break;
    v = f[k];
    ans = std::min(ans, calc_f(v, i));
  }
  return ans;
}


int main() {
  std::cin >> N >> C;
  for(int i = 0; i < N; ++i) std::cin >> h[i];

  init();
  dp[0] = 0;
  for(int i = 1; i < N; ++i) {
    sl[i] = -h[i-1]*2;
    ic[i] = dp[i-1] + h[i-1]*h[i-1];
    update(i);
    dp[i] = get_min(i) + h[i]*h[i] + C;
  }
  std::cout << dp[N-1] << std::endl;
  return 0;
}


Measured memory_bytes: 10112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();

        sc.close();

        StringBuilder sb = new StringBuilder(b);
        b = sb.reverse().toString();

        if (a.equals(b)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }

}


Measured memory_bytes: 21844
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
 *
 * @author acesine
 */
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);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt(), B = in.nextInt(), C = in.nextInt();
            if (C >= A && C <= B) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 22612
import java.util.Scanner;

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



		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		
		int a = sc.nextInt();
		int n = h/a;
		if(n*a==h) {
			System.out.println(n);
		}else {
			System.out.println(n+1);
			
		}
	}

}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


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

#define QUE_MAX (100000)

int w, h, n;
int x1[1001], x2[1001], y1[1001], y2[1001];

typedef struct {
    int x, y;
} POINT;

POINT queue[QUE_MAX];
int u[2][1024];
int head, tail;

void enq(POINT t)
{
    queue[tail++ % QUE_MAX] = t;
}

POINT deq(void)
{
    return (queue[head++ % QUE_MAX]);
}

int comp(const void *a, const void *b)
{
    int x, y;
    x = *(int *)a;
    y = *(int *)b;
    
    return (x - y);
}

int compress(int *x1, int *x2)
{
    int i, j;
    int merge[2048];
    int idx;
    int unq;
    
    for (i = 0; i < n; i++){
        merge[i] = x1[i];
        merge[n + i] = x2[i];
    }
    
    qsort(merge, 2 * n, sizeof(int), comp);
    memset(u, 0, sizeof(u));
    unq = 0;
    for (i = 0; i < 2 * n; i++){
        for (j = 0; j < n; j++){
            if (x1[j] == merge[i] && !u[0][j]){
                x1[j] = unq = i;
                u[0][j] = 1;
            }
            if (x2[j] == merge[i] && !u[1][j]){
                x2[j] = unq = i;
                u[1][j] = 1;
            }
        }
    }
    return (unq);
}

int main(void)
{
    int i;
    int x, y;
    int ans;
    static char field[2048][2048];
    POINT temp, add;
    int dx[] = {1, 0, -1, 0};
    int dy[] = {0, 1, 0, -1};
    
    while (1){
        scanf("%d%d", &w, &h);
        
        if (w + h == 0){
            break;
        
        }
        
        scanf("%d", &n);
        
        for (i = 0; i < n; i++){
            scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
        }
        x1[i] = 0, x2[i] = w, y1[i] = 0, y2[i] = h;
        n++;
        
        w = compress(x1, x2);
        h = compress(y1, y2);
        
        memset(field, 0, sizeof(field));
        for (i = 0; i < n - 1; i++){
            for (y = y1[i]; y < y2[i]; y++){
                for (x = x1[i]; x < x2[i]; x++){
                    field[y][x] = 1;
                }
            }
        }
        
        ans = 0;
        for (y = 0; y < h; y++){
            for (x = 0; x < w; x++){
                if (field[y][x]){
                    continue;
                }
                ans++;
                
                head = tail = 0;
                temp.y = y;
                temp.x = x;
                field[temp.y][temp.x] = 1;
                enq(temp);
                
                while (head != tail){
                    temp = deq();
                    for (i = 0; i < 4; i++){
                        add.x = temp.x + dx[i];
                        add.y = temp.y + dy[i];
                        if (0 <= add.x && add.x < w && 0 <= add.y && add.y < h && !field[add.y][add.x]){
                            field[add.y][add.x] = 1;
                            enq(add);
                        }
                    }
                }
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 0
import sys
import math
X = int(input())

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

for x in range(X, X * 2):
    if is_prime(x):
        print(x)
        sys.exit(0)


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

#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define ALL( a )        (a).begin(), (a).end()             

int gcd( int a, int b );

int main(void){
    int w, h, c; cin >> w >> h >> c;
    
    if( w < h ) swap( w, h );
    
    cout << w / gcd( w, h ) * h / gcd( w, h ) * c <<endl;
}

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


Measured memory_bytes: 3104
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cassert>

using namespace std;

const long long MM = 1e9+7;

long long gcd(long long a, long long b, long long & x, long long & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long x1, y1;
    long long d = gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}


long long inverse(long long a) {
  long long x,y;

  gcd(a, MM, x, y);
  return (x+MM)%MM;
}

int main() {

  assert(inverse(1)==1);
  int N, W, H;

  scanf("%d %d %d\n", &H, &W, &N);

  vector<pair<int, int>> wall(N+1);
  for(auto i=0; i<N; i++) {
    int r, c;
    scanf("%d %d", &r, &c);
    wall[i].first = r;
    wall[i].second = c;
  }

  wall[N].first = H;
  wall[N].second = W;
  
  N++;

  sort(wall.begin(), wall.end());

  vector<long long> fac(3e5+1, 1);
  vector<long long> facinv(3e5+1, 1);
  for(auto i=1;i<3e5+1;i++) {
    fac[i] = (fac[i-1]*i) % MM;
    facinv[i] = inverse(fac[i]); 
  }

  // for(auto i =0; i<N; i++) printf("%d %d\n", wall[i].first, wall[i].second);

  vector<long long> F_on(N+1, 0), F_off(N+1, 0);

  for (auto i=0; i < N; i++) {
    for (auto j=0; j< i; j++) {
      long long dx = wall[i].first - wall[j].first;
      long long dy = wall[i].second - wall[j].second;
      if (dx >= 0 && dy >=0){
        long long s = dx + dy; 
        long long scdx = (fac[s] * facinv[dx]) % MM ;// s choose dx
        scdx = ( scdx * facinv[dy]) % MM ;// s choose dx

        F_on[i] += (F_off[j] * scdx) % MM;
        F_on[i] %= MM;
      }

    }
    long long ttt = wall[i].first-1 + wall[i].second-1;
    long long cc = (fac[ttt] * facinv[ wall[i].first-1]) % MM;
    cc = (cc * facinv[ wall[i].second-1]) % MM;

    F_off[i] = cc - F_on[i];
    F_off[i] += MM;
    F_off[i] %= MM;
    // printf("i %d cc %lld fon %lld  foff %lld\n ", i, cc, F_on[i], F_off[i]);
  }

  cout << F_off[N-1] << endl;

  return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
	int n;
	cin >> n;
	ll a[n];
	rep(i, n) cin >> a[i];
	ll m = 1, ans = a[0] - 1;
	repl(i, 1, n) {
		if (a[i] == m + 1)
			m++;
		else
			ans += (a[i] - 1) / (m + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import Counter
from itertools import product

n,m,q  = map(int,input().split())
rails=[tuple(map(int,input().split())) for i in range(m)]
qs=[tuple(map(int,input().split())) for i in range(q)]

xlist = [[0 for j in range(n)] for i in range(n)]
sumlist = [[0 for j in range(n+1)] for i in range(n)]
sumsumlist = [[0 for j in range(n+1)] for i in range(n+1)]
for (l,r),i in Counter(rails).items():
    xlist[l-1][r-1]=i


for (i,j) in product(range(n),range(n)):
    sumlist[i][j+1]=sum(xlist[i][0:j+1])

for (i,j) in product(range(n),range(n)):
    sumsumlist[i+1][j+1] = sum(map(lambda x:x[j+1],sumlist[0:i+1]))



for (p,q) in qs:
    ans = sumsumlist[q][q]- sumsumlist[q][p-1] -sumsumlist[p-1][q] + sumsumlist[p-1][p-1]
    print(ans)



Measured memory_bytes: 125400
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <stack>
#include <cstring>
#include<complex>
using namespace std;

#define loop(i,a,b) for(int i = a; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()
typedef complex<double> P;
int main(void){
  int n;
  while(cin>>n,n!=-1){
    P out(1,0);
    rep(i,n-1){
      P a(0,1);
      P t=out*a;
      t/=abs(t);
      out+=t;
    }
    printf("%.9f %.9f\n",real(out),imag(out));
  }
}

Measured memory_bytes: 1216
from collections import deque

n = int(input())
dll = deque()
for i in range(n):
    command = input().split()
    if command[0] == 'insert':
        dll.appendleft(command[1])
    elif command[0] == 'delete':
        try:
            dll.remove(command[1])
        except:
            pass
    elif command[0] == 'deleteFirst':
        dll.popleft()
    else:
        dll.pop()
print(*dll)

Measured memory_bytes: 71820
#include<bits/stdc++.h>
using namespace std;
int h,w;
int arr[205][205];
int cost[12][12];
int f(int num){
	if(num==-1) return 0;
	return cost[num][1];
}
int main(){
	cin>>h>>w;
	
	for(int i=0; i<=9; i++){
		for(int j=0; j<=9; j++) cin>>cost[i][j];
	}
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++) cin>>arr[i][j];
	}
	for(int k=0; k<=9; k++){
		for(int i=0; i<=9; i++){
			for(int j=0; j<=9; j++){
				cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
			}
		}
	}
	long long ret = 0;
	for(int i=1; i<=h; i++){
		for(int j=1; j<=w; j++){
			ret+=f(arr[i][j]);
		}
	}
	cout<<ret;
}

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

int main()
{

  for(;;)
    {
      char n[200];
      cin.getline(n,sizeof(n));
      if(n[0]=='.')
	break;
      bool check=true;
      int cnt1=0;
      int cnt2=0;
      string buf;
      int in=0;
      for(int i=0;n[i]!='.';i++)
	{
	  if(n[i]=='(')
	    {
	      cnt1++;
	      buf[in]=n[i];
	      in++;
	    }
	  if(n[i]=='[')
	    {
	      cnt2++;
	      buf[in]=n[i];
	      in++;
	    }
	  if(n[i]==')')
	    {
	      cnt1--;
	      in--;
	      if(in<0||buf[in]!='(')
		check=false;
	    }
	  if(n[i]==']')
	    {
	      cnt2--;
	      in--;
	      if(in<0||buf[in]!='[')
		check=false;
	    }
	  
	  if(cnt1<0||cnt2<0)
	    check=false;
	}

      if(cnt1!=0||cnt2!=0)
	check=false;
      
      if(check)
	cout<<"yes"<<endl;
      else
	cout<<"no"<<endl;
    }
}

Measured memory_bytes: 1128
use proconio::input;
use rand::Rng;

pub fn get_time() -> f64 {
    static mut STIME: f64 = -1.0;
    let t = std::time::SystemTime::now()
        .duration_since(std::time::UNIX_EPOCH)
        .unwrap();
    let ms = t.as_secs() as f64 + t.subsec_nanos() as f64 * 1e-9;
    unsafe {
        if STIME < 0.0 {
            STIME = ms;
        }
        ms - STIME
    }
}

pub struct State {
    max_day: usize,
    sat: isize,
    out: Vec<usize>,
    last: Vec<usize>,
    c: Vec<isize>,
    s: Vec<Vec<isize>>,
}

impl State {
    fn calclate_score(&mut self) -> isize {
        self.sat = 0;
        self.last = vec![0; 26];
        let mut s: isize = 0;
        for i in 0..26 {
            s += self.c[i];
        }
        let mut temp_minus = 0;
        for d in 0..self.max_day {
            temp_minus += s;
            assert!(0 <= self.out[d] && self.out[d] <= 25);
            let j = self.out[d as usize] as usize;
            temp_minus -= self.c[j] * (d + 1 - self.last[j]) as isize;
            self.sat -= temp_minus;
            self.last[j] = d + 1;
            self.sat += self.s[d][j];
        }
        self.sat
    }
    fn initialize_output(&mut self) {
        for i in 0..self.max_day {
            let mut max = 0;
            for j in 0..26 {
                max = if self.s[i][max] < self.s[i][j] {
                    j
                } else {
                    max
                };
            }
            self.out[i] = max;
        }
        for i in 0..self.max_day {
            let mut max = 0;
            let mut max_score = -1000000000;
            for j in 0..26 {
                self.out[i] = j;
                let temp = self.calclate_score();
                if max_score < temp {
                    max = j;
                    max_score = temp;
                }
            }
            self.out[i] = max;
        }
        eprintln!("{}", self.calclate_score());
    }
}

fn main() {
    input! {
        max_day: usize,
        c: [isize; 26],
        s: [[isize; 26]; max_day],
    }
    let mut plan = State {
        max_day: max_day,
        sat: 0,
        out: vec![0; max_day],
        last: vec![0; 26],
        c,
        s,
    };
    plan.initialize_output();
    let mut rng = rand::thread_rng();
    let mut max_score = plan.calclate_score();
    let mut loop_cnt = 0;
    while get_time() < 1.9 {
        // eprintln!("{}", max_score);
        let d: usize = rng.gen_range(0, max_day);
        let q: usize = rng.gen_range(0, 26);
        let old = plan.out[d];
        plan.out[d] = q;
        let score = plan.calclate_score();
        if max_score < score {
            max_score = score;
        } else {
            plan.out[d] = old;
        }
        loop_cnt += 1;
    }
    for x in plan.out {
        println!("{}", x + 1);
    }
    eprintln!("score:{}, loop:{}", max_score, loop_cnt);
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  scanf("%d",&n);
  static long long A[100000];
  for(int i=0;i<n;i++){
    scanf("%lld",A+i);
  }
  sort(A,A+n);
  long long S=A[0];
  int x=0;
  for(int i=1;i<n;i++){
    if(2*S<A[i]){
      x=i;
    }
    S+=A[i];
  }
  printf("%d\n",n-x);
  return 0;
}

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

using namespace std;

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

vector<pll> graph[100100];
ll dist[100100];
int v,e;

#define INF (1ll << 60)

void dijkstra(int s){
	int from,i,to;
	ll d,l;
	pll tmp;
	priority_queue<pll, vector<pll>, greater<pll> > pq;
	fill(dist,dist+v,INF);
	dist[s]=0;
	pq.push(pll(dist[s],s));
	while(!pq.empty()){
		tmp = pq.top();
		pq.pop();
		from = tmp.second;
		d = tmp.first;
		for(i=(graph[from].size()-1); i>=0; i--){
			to = graph[from][i].second;
			l = graph[from][i].first;
			if(dist[to] > d+l){
				dist[to] = d+l;
				pq.push(pll(dist[to],to));
			}
		}
	}
}

int main(void){
	int i,s,t,r;
	ll d;
	cin >> v >> e >> r;
	for(i=0; i<e; i++){
		cin >> s >> t >> d;
		graph[s].push_back(pll(d,t));
	}
	dijkstra(r);
	for(i=0; i<v; i++){
		if(dist[i] == INF){
			cout << "INF" << endl;
		}else{
			cout << dist[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 17708
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int main()
{
ll h,n;
cin>>h>>n;
ll a[n],b[n];
ll mn=100000;
for(ll i=0;i<n;i++)
{
cin>>a[i]>>b[i];
mn=min(mn,b[i]);
}
ll dp[h+1];
dp[0]=0;
dp[1]=mn;
for(ll i=2;i<=h;i++)
{
mn=-1;
for(ll o=0;o<n;o++)
{
ll u=i-a[o];
if(u<=0)
{
if(-1==mn)
{
mn=b[o];
}
mn=min(mn,b[o]);
}
else
{
if(mn==-1)
{
mn=b[o]+dp[u];
}
mn=min(mn,b[o]+dp[u]);
}
}
dp[i]=mn;
}
cout<<dp[h];
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define inf LLONG_MAX>>2
#define MAX 1000000
#define mod 1000000007
#define pb push_back
#define f(i,a,n,x) for ((i)=(a);(i)<(n);(i)+=(x))
#define fd(i,a,n,x) for ((i)=(a);(i)>=(n);(i)-=(x))
#define fi first
#define se second
#define mk make_pair
#define pi pair
#define vt vector
#define ms multiset
#define is insert
using namespace std;
void read(vt<ll> &a,ll n){ll i,temp;f(i,0,n,1){cin>>temp;a.pb(temp);}}
ll fa[MAX];
ll power(ll p,ll q){
    ll res=1;
    p%=mod;
    while(q){
        if (q&1)
            res=(res*p)%mod;
        q>>=1;
        p=(p*p)%mod;
    }
    return res;
}
ll fact(ll n){
    if (n<=1)
        return fa[n]=1;
    if (fa[n])
        return fa[n];
    return fa[n]=(n*fact(n-1))%mod;
}
ll ncr(ll n,ll r){
    if (!r)
        return 1;
    return (((fact(n)*power(fact(n-r),mod-2))%mod)*power(fact(r),mod-2))%mod;
}
void solve(){
    string s;
    ll i,count=0,ans=-inf;
    cin>>s;
    f(i,0,s.length(),1)
        if (s[i]=='R')
            count++;
        else{
            ans=max(ans,count);
            count=0;
        }
    ans=max(ans,count);
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

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

    int n,d,x;
    cin >> n >> d >> x;
    vector<int> vi(n);
    REP(i,n) cin >> vi[i];
    int day;
    REP(i,n){
        day=1;
        while(d>=day){
            ++x;
            day=day+vi[i];
        }
    }
    cout <<x << endl;
    return 0;
}


Measured memory_bytes: 256
n,d =  map(int,input().split())
Xnd = [list(map(int,input().split())) for _ in range(n)]
def cal(a,b):
  len2 = 0
  for i in range(d):
    len2 += (Xnd[a][i]-Xnd[b][i])**2 
  leng = len2 ** (0.5)
  return leng

cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    if cal(i,j).is_integer():
      cnt+=1
print(cnt)    



Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
  int a,b,c=0;
  int i,j,l;

  scanf("%d %d",&a,&b);

  for(i=0;i<=a;i++){
    for(j=0;j<=a;j++){
      l=b-i-j;
      if(l<=a &&l>=0)
        c++;
    }
  }

  printf("%d\n",c);

  return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using  namespace std;
int main(){
    long long n, k, a, check, ans = 0, typenum = 0;
    cin >> n >> k;
    map<long long, long long> A;
    for(int i=0;i<n;i++){
        cin >> a;
        A[a]++;
    }
    vector<long long> A2;
    for(auto itr = A.begin(); itr != A.end(); itr++){
        A2.push_back(itr->second);
        typenum++;
    }
    sort(A2.begin(),A2.end());
    for(int i=0;i<(typenum-k);i++){
        ans += A2[i];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 14964
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a,b,c;
	cin>>a>>b>>c;
	int n=a;
	if(c>a) {
		a=c;
	}
	if(b>a) {
		a=b;
	}
	if(c<b) {
		b=c;
	}
	if(n<b) {
		b=n;
	}
	cout<<a-b;
	return 0;
}

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

int main(void){
    ll N;cin>>N;
    string s(N,'a');
    string ms(N,'a');
  
  if(N==1){
    cout<<s<<endl;
    return 0;
  }

    ll itr = 0;
    bool back=false;
    while(true){
        if(back){
            if(itr==0){
                break;
            }
            s[itr]++;

            char maxc='a';
            for(int i=0;i<itr;i++){
                maxc = max(maxc,s[i]);
            }

            if(s[itr]>=maxc+2){
                s[itr]='a';
                back=true;
                itr--;
                continue;
            }
            back=false;
            itr++;
        }
      
      ll itr2=itr+1;

        if(itr2>=N){

            cout<<s<<endl;
            s[itr]++;

            
            char maxc='a';
            for(int i=0;i<itr;i++){
                maxc = max(maxc,s[i]);
            }

            if(s[itr]>=maxc+2){
                s[itr]='a';
                back=true;
                itr--;
                continue;
            }
            continue;
        }

        itr++;
    }
}

Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    
    int mx = 0, mn = n;
    REP(i, n) {
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    if (mx - mn > 1) {
        cout << "No\n";
    } else if (mx - mn == 1) {
        int cnt = 0;
        REP(i, n) {
            if (a[i] == mx) ++cnt;
        }
        if (cnt == 1) {
            cout << "No\n";
        } else {
            int d = n - cnt + 1;
            int u = n - cnt + cnt / 2;
            if (mx >= d && mx <= u) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    } else {
        int d = 1;
        int u = n / 2;
        if (mx >= d && mx <= u) {
            cout << "Yes\n";
        } else {
            if (mx == n - 1) {
                cout << "Yes\n";
            } else {
                cout << "No\n";
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3744
// C - 4/N

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	for (ll h=1; h<=3500; h++) {
		for (ll n=h; n<=3500; n++) {
			if (4*h*n - N*n - N*h <= 0) continue;

			if (N*h*n % (4*h*n - N*n - N*h) == 0) {
				ll w = N*h*n / (4*h*n - N*n - N*h);
				cout << h << " " << n << " " << w << endl;
				return 0;
			}
		}
	}

	return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

int main() {
  vector<int> n(3);
  rep(i, 0, 3) {
    cin >> n[i];
  }
  sort(All(n));
  reverse(All(n));
  cout << n[0]*10 + n[1] + n[2] << endl;
};


Measured memory_bytes: 256
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    string s = input<string>();

    vector<int> cnt(26);

    for (char ch: s) {
        cnt[ch - 'a'] += 1;
    }

    int ans = 1;
    const int mod = 1000 * 1000 * 1000 + 7;

    for (int el: cnt)
        ans = ((int64_t(ans))* (el + 1)) % mod;

    cout << (ans + mod - 1) % mod << "\n";
    
    return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans=0
memo=1000
for i in a:
    ans += b[i-1]
    if (i - memo) == 1:
        ans+=c[memo-1]
    memo=i
print(ans)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(ll i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define NG cout <<"UNRESTORABLE" << endl;

#define INF 10101010

int main()
{
    string s;
    string t;
    cin >> s;
    cin >> t;

    bool result=false;
    int i=0;
    int j=0;
    reverse(s.begin(),s.end());
    reverse(t.begin(),t.end());
    while(s[i]!='\0'){
        j=0;
        if(s[i]==t[j]||s[i]=='?'){
            while(t[j]!='\0'){
                if(s[i+j]==t[j]||s[i+j]=='?'){
                    ++j;
                }else{
                    break;
                }
            }
            if(t[j]=='\0'){
                rep(k,j){
                    s[i+k]=t[k];
                }
                result=true;
                break;
            }
        }
        ++i;
    }
    i=0;
    while(s[i]!='\0'){
        if(s[i]=='?'){
            s[i]='a';
        }
        ++i;
    }
    reverse(s.begin(),s.end());
    if(result){
        cout << s << endl;
    }else{
        NG;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define f(a) (a%2?3*a+1:a/2)
int main(){
  int s;
  cin>>s;
  map<int,bool> m;
  for(int i=1;;m[s]=true,s=f(s),i++)if(m[s]){cout<<i;return 0;}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF = 1001001001;

struct P
{
	int x, y;
	P(int x=0, int y=0) : x(x), y(y) {}
};

int main() {
	int h, w;
	cin >> h >> w;
	int Ch, Cw, Dh, Dw;
	cin >> Ch >> Cw >> Dh >> Dw;
	Ch--; Cw--; Dh--; Dw--;
	P c, d;
	c.x = Ch, c.y = Cw, d.x = Dh, d.y = Dw;
	vector<string> s(h);
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	deque<P> q;
	vector<vector<int>> dist(h, vector<int>(w, INF));
	q.push_back(c);
	dist[c.x][c.y] = 0;
	while (!q.empty()) {
		P p = q.front(); q.pop_front();
		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				int nx = p.x + i;
				int ny = p.y + j;
				if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
				if (s[nx][ny] == '#') continue;
				int cost = (abs(i)+abs(j) <= 1) ? 0 : 1;
				if (dist[nx][ny] > dist[p.x][p.y] + cost) {
					dist[nx][ny] = dist[p.x][p.y] + cost;
					if (cost == 1) q.push_back({nx, ny});
					else q.push_front({nx, ny});
				}
			}
		}
	}
	int ans = dist[d.x][d.y];
	if (ans >= INF) ans = -1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8636
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000000
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
ll a[N],b[N];
int main()
{	int n,x; ll ans=0; cin>>n;
	for(rint i=1;i<=n;i++) scanf("%d",&x),a[i]=a[i-1]+x,b[i]=b[i-1]^x;
	for(rint i=1;i<=n;i++)
	{	int l=i,r=n,A=-1;
		while(l<=r)
		{	int mid=(l+r)>>1;
			if(a[mid]-a[i-1]==(b[mid]^b[i-1])) A=mid,l=mid+1;
			else r=mid-1;
		}
		ans+=(A-i+1);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6016
//https://atcoder.jp/contests/abc157/tasks/abc157_d
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359;
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 vi vis2(MX);
vi adj[MX];
 vi vis(MX);
 vi siz(MX);
 vi ans(MX);
vi cnt(MX);
 void dfs2(int S,int index)
 {
 	ans[S]=siz[index]-sz(adj[S])-1;
 	vis2[S]=1;
 	F0R(x,sz(adj[S]))
 	{
 		int val=adj[S][x];
 		if(!vis2[val])
 		{
 			dfs2(val,index);
 		}
 	}
 }
 void dfs(int S,int fill)
 {
 	siz[S]=1;
 	vis[S]=fill;
 	F0R(x,sz(adj[S]))
 	{
 		int val=adj[S][x];
 		if(!vis[val])
 		{
 			dfs(val,fill);
 			siz[S]+=siz[val];
 		}
 	}
 }
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N,M,K;
	cin>>N>>M>>K;
	F0R(x,M)
	{
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	FOR(x,1,N+1)
	{
		if(!vis[x])
		{
			dfs(x,x);
			dfs2(x,x);
		}
	}
	F0R(x,K)
	{
		int a,b;
		cin>>a>>b;
		if(vis[a]==vis[b])
			cnt[a]++,cnt[b]++;
	}
	FOR(x,1,N+1)
	{
		cout<<ans[x]-cnt[x]<<' ';
	}
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343
 



Measured memory_bytes: 8832
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll unsigned long long
#define md 1000000007
#define pb push_back
#define ff first
#define ss second
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,start,end) for(ll i=start;i<end;i++) 
using namespace std;
using namespace __gnu_pbds;
typedef priority_queue<int, vector<int>, greater<int> > min_pq;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OST;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }


int main(){
    fio();
    int a,b;
    cin>>a>>b;
    const float t1 = 0.08, t2 = 0.1;
    int a1 = a/t1;
    for(int i=a1;i<=a1+20;++i){
        if(int(t1*i)==a and int(t2*i)==b){
            cout<<i;
            exit(0);
        
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
cnt=0

for i in range(n):
  for j in range(i+1,n):
    distance = 0
    for k in range(d):
      distance+=(l[i][k]-l[j][k])**2
    
    if (distance**0.5).is_integer():
      cnt+=1
      
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int ,int>;
int compress(vector<ll> &x1, vector<ll> &x2, vector<ll> &x3, vector<ll> &xs)
{
    int n = x1.size();
    for(int i = 0; i < n; i++) xs.push_back(x1[i]); 
    n = x2.size();
    for(int i = 0; i < n; i++) xs.push_back(x2[i]); 
    n = x3.size();
    for(int i = 0; i < n; i++) xs.push_back(x3[i]); 
    xs.push_back(-1e10);
    xs.push_back(-1e10);
    xs.push_back(0);
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    n = x1.size();
    for(int i = 0; i < n; i++) x1[i] = lower_bound(xs.begin(), xs.end(), x1[i]) - xs.begin();
    n = x2.size();
    for(int i = 0; i < n; i++) x2[i] = lower_bound(xs.begin(), xs.end(), x2[i]) - xs.begin();
    n = x3.size();
    for(int i = 0; i < n; i++) x3[i] = lower_bound(xs.begin(), xs.end(), x3[i]) - xs.begin();
    return xs.size();
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    vector<ll> d(m);
    vector<ll> e(m);
    vector<ll> f(m);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    for(int i = 0; i < m; i++) cin >> d[i] >> e[i] >> f[i];
    vector<ll> xc;
    vector<ll> yc;
    int h = compress(a, b, d, xc);
    int w = compress(c, e, f, yc);

    vector<vector<bool>> wallx(h, vector<bool>(w, false));
    vector<vector<bool>> wally(h, vector<bool>(w, false));
    for(int i = 0; i < n; i++)
    {
        for(int x = a[i]; x < b[i]; x++)
        {
            wallx[x][c[i]] = true;
        }
    }
    for(int i = 0; i < m; i++)
    {
        for(int y = e[i]; y < f[i]; y++)
        {
            wally[d[i]][y] = true;
        }
    }
    vector<vector<bool>> field(h, vector<bool>(w, false));
    queue<P> que;
    int posx = lower_bound(xc.begin(), xc.end(), 0) - xc.begin();
    int posy = lower_bound(yc.begin(), yc.end(), 0) - yc.begin();
    que.push(P(posx, posy));
    while(!que.empty())
    {
        int x = que.front().first;
        int y = que.front().second;
        que.pop();
        if(x == 0 || x == h-1 || y == 0 || y == w-1)
        {
            cout << "INF" << endl;
            return 0;
        }
        if(field[x][y]) continue;
        field[x][y] = true;
        if(!wallx[x][y+1]) que.push(P(x, y+1)); // r
        if(!wallx[x][y]) que.push(P(x, y-1));   // l
        if(!wally[x+1][y]) que.push(P(x+1, y)); // d
        if(!wally[x][y]) que.push(P(x-1, y));   // u
    }
    ll ans = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(field[i][j])
            {
                ans += (ll)(xc[i+1] - xc[i]) * (yc[j+1] - yc[j]);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7480
'use strict'

function main(input) {
  input = input
    .trim()
    .split(' ')
    .map(Number)

  if (input[1] % input[0] == 0) {
    console.log(input[0] + input[1])
  } else {
    console.log(input[1] - input[0])
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

using namespace std;
#define ll long long
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n;
	cin>>n;
	ll A[n];
	ll B[n];
	ll C[n];
	for (int i=0; i<n; i++){
		cin>>A[i]>>B[i]>>C[i];
	}
	ll dp[n][3];
	dp[0][0] = A[0];
	dp[0][1] = B[0];
	dp[0][2] = C[0];
	for (int i=1; i<n; i++){
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + B[i];
		dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + C[i];
	}
	ll ans = 0;
	for (int i=0; i<=2; i++){
		ans = max(dp[n - 1][i], ans);
	}
	cout<<ans;
}

Measured memory_bytes: 8312
from collections import deque
H, W = map(int, input().split())
ch, cw = [int(i) - 1 for i in  input().split()]
dh, dw = [int(i) - 1 for i in  input().split()]
maze = []
for _ in range(H):
    a = input()
    maze.append(a)
d = deque([(ch, cw, 0)])
value = [[-1 for _ in range(W)] for _ in range(H)]
while d:
    h, w, v = d.popleft()
    if value[h][w] == -1:
        value[h][w] = v
        for hi in range(-2, 3):
            for wi in range(-2, 3):
                next_h = h + hi
                next_w = w + wi
                if (0 <= next_h < H) & (0 <= next_w < W):                
                    if (maze[next_h][next_w] == '.'):
                        if (abs(hi) + abs(wi) == 1) & (value[next_h][next_w] == -1):
                            d.appendleft((next_h, next_w, v))
                        elif (abs(hi) + abs(wi) > 1) & (value[next_h][next_w] == -1):
                            d.append((next_h, next_w, v + 1))
    else:
        continue
print(value[dh][dw])

Measured memory_bytes: 201908
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;


int main(){
    ll K;
    cin >> K;
    string S;
    cin >> S;
    if(S.size()<=K) cout << S << endl;
    else{
        for(int i=0; i<K; i++){
            cout << S[i];
        }
        cout << "..." << endl;
    }
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double x = h * 30 + 0.5 * m;
  double y = m * 6;
  double deg = min(abs(x - y), 360 - abs(x - y));
  double c2 = a * a + b * b - 2 * a * b * cos(deg * M_PI / 180);
  cout << fixed << setprecision(10) << sqrt(c2) << endl;
  return 0;
}

Measured memory_bytes: 4220
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int a,b,c,d;
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    if(a+b+c+d==7){
        printf("%d+%d+%d+%d=7\n",a,b,c,d);
        return 0;
    }
    if(a+b+c-d==7){
        printf("%d+%d+%d-%d=7\n",a,b,c,d);
        return 0;
    }
    if(a+b-c+d==7){
        printf("%d+%d-%d+%d=7\n",a,b,c,d);
        return 0;
    }
    if(a+b-c-d==7){
        printf("%d+%d-%d-%d=7\n",a,b,c,d);
        return 0;
    }
    if(a-b+c+d==7){
        printf("%d-%d+%d+%d=7\n",a,b,c,d);
        return 0;
    }
    if(a-b+c-d==7){
        printf("%d-%d+%d-%d=7\n",a,b,c,d);
        return 0;
    }
    if(a-b-c+d==7){
        printf("%d-%d-%d+%d=7\n",a,b,c,d);
        return 0;
    }
    if(a-b-c-d==7){
        printf("%d-%d-%d-%d=7\n",a,b,c,d);
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 100000
using namespace std;

int gcd(int a, int b){
  int large = max(a, b);
  int small = min(a, b);
  int r = large%small;
  if(r != 0){
    return gcd(small, r);
  }
  else{
    return small;
  }
}

int main(){
  int n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  int nmgcd = gcd(n, m);
  rep(i, 0, nmgcd){
    int x = n/nmgcd;
    int y = m/nmgcd;

    if(s[i*x]!=t[i*y]){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (long long) n*m/nmgcd << endl;
  return 0;
}


Measured memory_bytes: 512
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n;in(n);
  vector<ll> A(n);
  loop(i,0,n) in(A[i]);
  map<ll, int> M;
  loop(i,0,n) {
    M[A[i]]++;
  }
  
  ll ans = 0;
  ll max_ = 0;
  for (auto&&m: M) {
    if (m.second >= 4) ans = max(ans, m.first*m.first);
    else if (m.second >= 2) {
      ans = max(ans, m.first*max_);
    }
    if (m.second >= 2) max_ = max(max_, m.first);
  }
  print(ans);
  return 0;
}


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

int main(){
    vector<vector<int>> a(3, vector<int>(3));
    for(int i=0; i<3; i++) 
        for(int j=0; j<3; j++) cin >> a.at(i).at(j);
    
    int n;
    cin >> n;

    vector<int> b(n);
    for(int i=0; i<n; i++) cin >> b.at(i);

    vector<vector<bool>> hit(3, vector<bool>(3));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(b.at(i) == a.at(j).at(k)) hit.at(j).at(k) = true;
            }
        }
    }


    for(int j=0; j<3; j++){
        if(hit.at(j).at(0) && hit.at(j).at(1) && hit.at(j).at(2)) {
            cout << "Yes"; return 0;}
    }
    for(int j=0; j<3; j++){
        if(hit.at(0).at(j) && hit.at(1).at(j) && hit.at(2).at(j)){cout << "Yes"; return 0;}
    }
    if(hit.at(0).at(0) && hit.at(1).at(1) && hit.at(2).at(2) ||
        hit.at(0).at(2) && hit.at(1).at(1) && hit.at(2).at(0)) {cout << "Yes"; return 0;}

    cout << "No";
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N; std::cin >> N;
  int index = 1;
  int num_break = 0;
  for (int i = 0; i < N; ++i) {
    int a; std::cin >> a;
    if (a == index) {
      ++index;
    } else {
      ++num_break;
    }
  }

  if (num_break == N) std::cout << -1 << std::endl;
  else                std::cout << num_break << std::endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[n];
    for(int i=1; i<=n; i++)
        cin>>a[i];
    int sum=0;
    for(int i=1; i<=n; i++)
        sum=sum+a[i];
    float div=sum*1.0/(4*m);
    int c=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i]>=div)
            c++;
    }
    if(c>=m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm> 

#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
#define def2D(T,name,row,column,d) vector<vector<T>> name(row,vector<T>(column,d));

using namespace std;

const long long int inf = 1 << 20;

bool dfs(int n, vector<vector<int>>& edge, vector<int>& a, vector<int>& b) {
  vector<bool> check(n,false);

	stack<int> st;
	st.push(0);
	while (!st.empty()) {
	  int s = st.top();
		st.pop();

		rep(i, n) 
			if (edge[s][i] == 1 && !check[i]) {
			  st.push(i);
				check[i] = true;
			}

	}
	bool connected = true;
	for (bool b : check) connected = connected && b; 
	return connected;
}

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

	vector<int> a(m), b(m);
	def2D(int,edge,n,n,0);

	rep(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
		edge[a[i]][b[i]] = 1;
		edge[b[i]][a[i]] = 1;
	}

	int ans = 0;
	rep(e, m) {
		edge[a[e]][b[e]] = 0;
		edge[b[e]][a[e]] = 0;
		if (!dfs(n,edge, a, b)) ans++;
		edge[a[e]][b[e]] = 1;
		edge[b[e]][a[e]] = 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#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>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#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 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

#define MAX 1000005

long long fac[MAX], finv[MAX], inv[MAX];

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long ncr(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main(void) {
    init();
    int x,y;
    cin >> x >> y;
    //(1,2)または(2,1)
    int ans = 0;
    rep(i,x+1){
        int tx = x - i;
        int ty = y - 2*i;
        //(1,2)をi回したとき、(2,1)は何回できるか？
        //cout << "?" << i << " " <<tx << " " << ty << endl;
        if(tx%2 || tx/2 != ty)continue;
        //(1,2)をi回、(2,1)をty回する移動の通り数
        //cout << i << " " << ty << endl;
        ans += ncr(i+ty,i);
        ans %= MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 23680
ans = ''
while True:
    s = input()
    if s == '-':
        break
    n = int(input())
    L = []
    i = 0
    while i < n:
        j = int(input())
        s = s[j:] + s[:j]
        i += 1
    ans += s + '\n'
if ans != '':
    print(ans[:-1])


Measured memory_bytes: 5604