akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
const int NMAX = 3e5 + 5;
int x[NMAX], y[NMAX], n, m, k, freqx[NMAX], freqy[NMAX], maxx, maxy, sol, cntx[NMAX], cnty[NMAX], mx, my;
bool posx[NMAX], posy[NMAX];

int main() {
    cin >> n >> m >> k;
    for(int i = 1; i <= k; i++) {
        cin >> x[i] >> y[i];
        freqx[x[i]]++;
        freqy[y[i]]++;
        if(freqx[maxx] < freqx[x[i]]) {
            maxx = x[i];
        }
        if(freqy[maxy] < freqy[y[i]]) {
            maxy = y[i];
        }
    }
    for(int i = 1; i <= k; i++) {
        if(x[i] == maxx) {
            posy[i] = 1;
        }
        if(y[i] == maxy) {
            posx[i] = 1;
        }
    }
    for(int i = 1; i <= k; i++) {
        if(posx[i] == 0) {
            cntx[x[i]]++;
            if(cntx[x[i]] > cntx[mx]) {
                mx = x[i];
            }
        }
        if(posy[i] == 0) {
            cnty[y[i]]++;
            if(cnty[y[i]] > cnty[my]) {
                my = y[i];
            }
        }
    }
    cout << max(freqx[maxx] + cnty[my], freqy[maxy] + cntx[mx]);
    return 0;
}

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

int main(){
    int ans=0;
    int n,m;
    cin >> n >> m;
    vector<pair<int,bool>> v;
    rep(i,n){
        int a;
        cin >> a;
        v.push_back({a,true});
    }
    rep(i,m){
        int a,b;
        cin >> a >> b;
        if(v[a-1].first>=v[b-1].first){
            v[b-1].second = false;
        }if(v[a-1].first<=v[b-1].first){
            v[a-1].second = false;
        }
    }
    for(auto x:v){
        if(x.second){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3952
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		if (N >= M) {
			System.out.println(0);
			return;
		}
		
		int[] map = new int[M];
		for (int i = 0; i < M; i++) {
			map[i] = sc.nextInt();
		}
		
		Arrays.sort(map);
		
		int sum = 0;
		int[] ruiseki = new int[M-1];
		for (int i = 0; i < M-1; i++) {
			ruiseki[i] = map[i+1] - map[i];
			sum += ruiseki[i];
		}
		
		Arrays.sort(ruiseki);
		
		for (int i = ruiseki.length-1; ruiseki.length-N < i; i--) {
			sum -= ruiseki[i];
		}
		
		
		System.out.println(sum);
		
		
	}
}


Measured memory_bytes: 48312
#include <stdio.h>
#include <algorithm>
using namespace std;

int main()
{
	int n, m[101]={0}, x, i, tot=0, k=0, c=0;
	
	scanf("%d %d" ,&n, &x);
	for(i=1; i<=n; i++)
	{
		scanf("%d" ,&m[i]);
		tot+=m[i];
	}
	
	sort(m+1, m+n+1);
	
	printf("%d\n" ,n+(x-tot)/m[1]);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;

int main(){
  int a,b,c;
  cin >> a>> b >> c;
  int d=(a+b+c)/2;
  double e=d*(d-a)*(d-b)*(d-c);
  cout << sqrt(e) << endl;
}

  

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

string shuffle(int h, string s){
	string newString = s;
	for (int i = 0; i < s.length(); i++){
		newString[(s.length() + i - h) % s.length()] = s[i];
	}
	return newString;
}


int main()
{
	string s;
	int m, h;
	while (cin >> s, s!="-"){
		cin >> m;
		for (int i = 0; i < m; i++){
			cin >> h;
			s = shuffle(h, s);
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
def main():
  s=str(input())
  l=len(s)
  ans=0
  
  for i in range(2**(l-1)):
    j=bin(i)[::-1]
    tmp=[]
    t=s
    c=1
    for k in j:
      if k=="1":
        tmp.append(t[-c:])
        t=t[:-c]
        c=1
      else:
        c+=1
    else:
      tmp.append(t)
    ans+=sum(map(int,tmp))
    
  print(ans)
  
  
if __name__=="__main__":
  main()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string a, b, c;
  cin >> a >> b >> c;

  cout << 'A' << b[0] << 'C' << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Ti4 tuple<int, int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

int main() {
    int n, m;
    cin >> n;
    string u[n];
    for (int i = 0; i < n; i++) cin >> u[i];
    
    bool key = 0;
    cin >> m;
    for (int i = 0; i < m; i++) {
        string t;
        cin >> t;
        string pf = "Unknown";
        for (int j = 0; j < n; j++) {
            if (t == u[j]) {
                if (key) pf = "Closed by";
                else pf = "Opened by";
                key ^= 1;
                break;
            }
        }
        cout << pf _ t << endl;
    }
}



Measured memory_bytes: 3228
n=int(input())
l=[]
ans1=0
for i in range(1,n+1):
    if i%2!=0:
        l.append(i)
for j in range(len(l)):
    ans=0
    for k in range(1,l[j]+1):
        if l[j]%k==0:
            ans+=1
    if ans==8:
        ans1+=1
print(ans1)

Measured memory_bytes: 3060
import math

def S(a,b,C):
    s=(a*b*math.sin(math.radians(C)))/2
    return s

def L(a,b,C):
    l=a+b+(a**2+b**2-2*a*b*math.cos(math.radians(C)))**0.5
    return l

def H(a,b,C):
    h=b*math.sin(math.radians(C))
    return h

a,b,C=map(float,input().split())
print(S(a,b,C))
print(L(a,b,C))
print(H(a,b,C))


Measured memory_bytes: 5708
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<map>
#include<vector>
#include<ctime>
#include<stack>
#define mp make_pair
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ull unsigned long long

using namespace std;

inline ll read()
{
    long long f=1,sum=0;
    char c=getchar();
    while (c<'0' || c>'9')
    {
        if (c=='-') f=-1;
        c=getchar();
    }
    while (c>='0' && c<='9')
    {
        sum=sum*10+c-'0';
        c=getchar();
    }
    return sum*f;
}
const int MAXN=200010;
const int Mod=998244353;
char s[MAXN];
int f[MAXN][3][3][2];
int main()
{
    scanf("%s",s+1);
    int n=strlen(s+1);
    if (n<=3)
    {
        if (n==1)
            cout<<1;
        else if (n==2)
        {
            if (s[1]==s[2])
                cout<<1;
            else
                cout<<2;
        }
        else
        {
            if (s[1]==s[2] || s[2]==s[3])
            {
                if (s[1]==s[2] && s[2]==s[3])
                    cout<<1;
                else 
                    cout<<6;
            }
            else
            {
                if (s[1]==s[3])
                    cout<<7;
                else
                    cout<<3;
            } 
        }
        return 0;
    }
    int sum=0,tot=0;
    for (int i=2;i<=n;i++)
        sum+=(s[i]==s[i-1]),tot+=s[i]-'a';
    tot+=s[1]-'a';
    tot%=3;
    if (sum==n-1)
    {
        cout<<1;
        return 0;
    }
    int ans=!sum;
    f[1][1][1][0]=f[1][2][2][0]=f[1][0][0][0]=1;
    for (int i=2;i<=n;i++)
        for (int j=0;j<=2;j++)
            for (int k=0;k<=2;k++)
                for (int p=0;p<=2;p++)
                {
                    int last=(j-k+3)%3;
                    f[i][j][k][1]+=f[i-1][last][p][1];
                    f[i][j][k][1]%=Mod;
                    if (k==p)
                        f[i][j][k][1]+=f[i-1][last][p][0];
                    else
                        f[i][j][k][0]+=f[i-1][last][p][0];
                    f[i][j][k][1]%=Mod,f[i][j][k][0]%=Mod;
                }
    for (int i=0;i<=2;i++)
        ans+=f[n][tot][i][1],ans%=Mod;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 14464
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N; cin >> N;
	vector<ll> v(3 * N), h(3 * N+1);
	ll vsum = 0;
	rep(i, 3 * N){
		ll a; cin >> a;
		v[i] = a;
		h[i+1] = h[i] + v[i];
		vsum += a;
	}

	ll micost[MAX];
	ll macost[MAX];
	memr(micost, 0);
	memr(macost, 0);

	priority_queue<ll, vector<ll>, greater<ll> > q;
	rep(i, N){
		q.push(v[i]);
	}
	rep(i, N){
		int a = i + N;
		q.push(v[a]);
		micost[i+1] = micost[i] + q.top();
		q.pop();
	}
	priority_queue<ll> q2;
	reverse(ALL(v));
	rep(i, N){
		q2.push(v[i]);
	}
	rep(i, N){
		int a = i + N;
		q2.push(v[a]);
		macost[i+1] = macost[i] + q2.top();
		q2.pop();
	}
	reverse(ALL(v));
	// rep(i, N+1){
		// if(i) cout << " ";
		// cout << micost[i];
	// }
	// cout << endl;
	// rep(i, N+1){
		// if(i) cout << " ";
		// cout << macost[i];
	// }
	// cout << endl;
	ll sum = 0;
	rep(i, N){
		sum += v[i];
	}
	ll ans = -LLINF;
	// cout <<  endl;
	rep(i, N + 1){
		ll tmp = sum - micost[i];
		int b = N - i;
		ll tmp2 = vsum - sum  - macost[b];
		// cout << tmp << " " << tmp2 << endl;
		chmax(ans, tmp - tmp2);
		if(i == N) break;
		sum += v[i + N];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8820
#![allow(dead_code)]
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};
#[fastout]
fn main() {
    input!(n: usize, x: usize, m: usize);

    let mut ans = vec![x; 1];

    for i in 1..n {
        let buff = ans[i - 1].pow(2) % m;
        if ans.contains(&buff) {
            let pos = ans.iter().position(|x| *x == buff).unwrap();
            let ans_len = ans.len();
            let wa = ans_len - pos;

            let count = (n - ans_len) / wa;
            let count_m = (n - ans_len) % wa;

            let mut sum = ans.iter().take(ans_len - wa + count_m).sum::<usize>();

            sum += ans.iter().skip(ans_len - wa).sum::<usize>() * (count + 1);
            println!("{}", sum);
            return;
        }

        ans.push(buff);
    }

    println!("{}", ans.iter().sum::<usize>());
}


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

using namespace std;

int main(void){
    int N;
    double s;
    vector<double> v;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> s;
        v.push_back(s);
    }
    sort(v.begin(), v.end());
    double ans = v[0];
    for(int i= 1; i < N; i++){
        ans = (ans + v[i])/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
m,p,q,r,b,*c;C[3][101][101];main(n){for(;~scanf("%d%d",&n,&m);){for(memset(C,9,9e4);n--;C[0][p][q]=C[0][q][p]=r,C[1][p][q]=C[1][q][p]=b)scanf("%d%d%d%d",&p,&q,&r,&b);for(n=m;n;n--)for(p=m;p;p--)for(q=m;q;q--)for(r=2;r--;*c=*c<b?*c:b)b=C[r][p][n]+C[r][n][q],c=C[r][p]+q;for(scanf("%d",&m);m--;printf("%d\n",C[r][p][q]))scanf("%d%d%d",&p,&q,&r);}}

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

using namespace std;
typedef long long li;

const li mod = 998244353;

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

    li n,m;
    cin>>n>>m;
    int r = n*m;
    if(r%2==0){cout<<"Even"<<"\n";}
    else {cout<<"Odd"<<"\n";}

    return 0;

}



Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]

dic=defaultdict(list)
for i in range(m):
    a,b=ab[i]
    dic[a-1].append(b-1)
    dic[b-1].append(a-1)
# print(dic)

d=deque([[0,0]])

ans=0
while d:
    now,itta=d.popleft()
    ikeru=dic[now]
    itta+=pow(2,now)
    # print(ans,now,itta)
    if itta==pow(2,n)-1:
        ans+=1
    for i in ikeru:
        if itta&pow(2,i)==0:
            d.append([i,itta])
            # print(d)
print(ans)

Measured memory_bytes: 67436
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
        String b[] = a.split("");
        int c[] = new int[4];
        for(int i = 0;i < 4; i++){
          c[i] =Integer.parseInt(b[i]);
        }
        if(c[0] + c[1] + c[2] + c[3] == 7){
          System.out.println(c[0] + "+" + c[1] + "+" + c[2] + "+" + c[3] + "=7");
        }else if(c[0] + c[1] + c[2] - c[3] == 7){
          System.out.println(c[0] + "+" + c[1] + "+" + c[2] + "-" + c[3] + "=7");
        }else if(c[0] + c[1] - c[2] + c[3] == 7){
          System.out.println(c[0] + "+" + c[1] + "-" + c[2] + "+" + c[3] + "=7");
        }else if(c[0] + c[1] - c[2] - c[3] == 7){
          System.out.println(c[0] + "+" + c[1] + "-" + c[2] + "-" + c[3] + "=7");
        }else if(c[0] - c[1] + c[2] + c[3] == 7){
          System.out.println(c[0] + "-" + c[1] + "+" + c[2] + "+" + c[3] + "=7");
        }else if(c[0] - c[1] + c[2] - c[3] == 7){
          System.out.println(c[0] + "-" + c[1] + "+" + c[2] + "-" + c[3] + "=7");
        }else if(c[0] - c[1] - c[2] + c[3] == 7){
          System.out.println(c[0] + "-" + c[1] + "-" + c[2] + "+" + c[3] + "=7");
        }else if(c[0] - c[1] - c[2] - c[3] == 7){
          System.out.println(c[0] + "-" + c[1] + "-" + c[2] + "-" + c[3] + "=7");
        }
    }
}

Measured memory_bytes: 39436
S = input()
# Q = int(input())
length = len(S)
ans = "Yes"
for i in range(length):
    if (i % 2 == 0):
        if (S[i] != "h"):
            ans = "No"
    else:
        if (S[i] != "i"):
            ans = "No"
if (length % 2 != 0):
    ans = "No"

print(ans)


Measured memory_bytes: 2940
n,k = map(int, input().split())
V = list(map(int, input().split()))

maxsum = -10**13
for i in range(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        su = (V[:i] + V[:n-j-1:-1])
        su.sort()
        sumsu = sum(su)
        #print("i,j:",i,j,su)
        if k-i-j > 0:
            for l in range(k-i-j):
                if len(su) > l and su[l] < 0: sumsu -= su[l]
        maxsum = sumsu if maxsum < sumsu else maxsum
print(maxsum)

Measured memory_bytes: 3064
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int kotae=0;int Ancer=0;
        int num = scan.nextInt();
        kotae=num/2;
        if(num%2==0){
            Ancer=kotae;
        }
        if(num%2==1){
            Ancer=kotae+1;
        }
    System.out.println(Ancer);
    }

}


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

int main() {
	int N,A,B;
    cin >> N >> A >> B;
    int count = 0;
    for(int i=1;i<=N;i++){
      int a = i/10000;
      int b = i/1000-a*10;
      int c = i/100-a*100-b*10;
      int d = i/10-a*1000-b*100-c*10;
      int e = i%10;
      int sum = a+b+c+d+e;
      if(A<=sum && sum<=B){
        count = count+i;
      }
    }
    cout << count << endl;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int X, A, B;
  cin >> X >> A >> B;
  cout << (X - A) % B << endl;

  return 0;
}

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

int main(){
  double r;
  double V, L;

  std::cin >> r;

  if(!(0 < r && r < 10000)) return 0;


   std::cout << std::fixed;

   std::cout << M_PI * r * r << " " << M_PI * 2 * r<< std::endl;
   
   return 0;
   
}


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

int gcd (int x, int y) {
    if (y == 0) {
        return x;
    }
    if (x % y == 0) {
        return y;
    }
    else {
        return gcd(y, x % y);
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<int> l(n);
    vector<int> r(n);
    l[0] = 0;
    r[n - 1] = 0;
    for (int i = 0; i < n - 1; i++) {
        l[i + 1] = gcd(l[i], a[i]);
    }
    for (int i = n - 1; i > 0; i--) {
        r[i - 1] = gcd(r[i], a[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, gcd(l[i], r[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
int x,y;
int main () {
cin >> x >> y;
if (x== 1||x== 3||x== 5||x== 7||x== 8||x== 10||x== 12)
	if (y==1 ||y==3||y==5||y==7||y==8||y==10||y==12){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
 else if 
(x== 4||x== 6||x== 9||x== 11)
	if (y== 4|| y== 6|| y==9|| y==11)

{cout << "Yes" << endl;}
else{
	cout << "No" << endl;
}

else if (x==2)
if (y==2)
{cout << "Yes" << endl;
}else
{cout << "No" << endl;
}
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int l;
int a[202020];
LL dp[6][202020];

LL calc(int k, int j){
    if(k == 1 || k == 5)return a[j];
    if(k%2 == 0){
        if(a[j] == 0)return 2LL;
        return a[j]%2;
    }
    return (a[j] + 1)%2;
}

int main(){
    INIT;
    cin >> l;
    REP(i, l)cin >> a[i + 1];
    REP(i, 6)REP(j, 202020)dp[i][j] = HINF<LL>();
    for(int i = 1;i <= 5;i++)dp[i][0] = 0;

    for(int j = 1;j <= l;j++){
        for(int k = 1;k <= 5;k++){
            for(int i = 1;i <= k;i++){
                dp[k][j] = min(dp[k][j], dp[i][j - 1] + calc(k, j));
            }
        }
    }
    LL ans = HINF<LL>();
    for(int i = 1;i <= 5;i++)ans = min(ans, dp[i][l]);
    cout << ans << endl;
}

Measured memory_bytes: 10496
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }
int bsr(int x) { return 31 - __builtin_clz(x); }

int main() {
    cout << setprecision(20);
    int n;
    cin >> n;
    int sm = 0;
    int m = 0;
    for (int i = 1; i <= n; i++) {
        sm += i;
        if (n <= sm) {
            m = i;
            break;
        }
    }
//    cout << m << endl;
    for (int i = m; i >= 1; i--) {
        if (i <= n) {
            cout << i << endl;
            n -= i;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

int main() {
  int N,M,C;
  cin >> N >> M >> C;
  int B[M];
  rep(i,M) {
    cin >> B[i];
  }
  int A[N][M];
  rep(i,N) {
    rep2(j,M) {
      cin >> A[i][j];
    }
  }
  int ans = 0;
  rep(i,N) {
    int num = 0;
    rep2(j,M) {
      num += A[i][j] * B[j];
    }
    if(num + C > 0) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int a,b,x;
    cin>>a>>b>>x;
    double t=(double)2*x/(a*a)-b;
    cout<<fixed<<setprecision(10);
    //if(t==0) cout<<45.000000;
    /*else */if(t>0)
    cout<<atan2(b-t,a)*(180/3.141592653);
    else
    {
        t=(double)2*x/(a*b);
        cout<<atan(b/t)*(180/3.141592653);
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int a;
		int b;
		//a,b2????????°??????????????????
		a = scan.nextInt();
		b = scan.nextInt();
		sizeComparison(a,b);
	}
	//a,b????????°?????§?°???¢??????????????????
	public static void sizeComparison(int a, int b){
		String i = "==";//?????????????????????????´???????
		if(a < b){
			i = "<";
		}else if(a > b){
			i = ">";
		}
		//??????
		System.out.println("a " + i + " b");
	}
}

Measured memory_bytes: 26252
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define RREPS(i,x) for(int i=((int)(x));i>=0;i--)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

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

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a * (b / g);
}*/

/*int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}*/

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	int n;
	cin >> n;
	VI d(n);
	rep(i, n)cin >> d[i];

	sort(all(d));

	int ans = 1, mem = d[n - 1];
	RREPS(i, n - 2) {
		if (mem > d[i]) {
			ans++;
			mem = d[i];
		}
	}

	cout << ans << endl;

}


 

Measured memory_bytes: 256
public class Main {

    private static final int BEGIN = 1;
    private static final int END = 9;

    /**
     * 九九の一覧を表示する
     *
     * @param args
     */
    public static void main(String[] args) {
        // 各オペランドにつき、9回ずつループを回し、全ての組み合わせを表示する
        for (int i = BEGIN; i <= END; i++) {
            for (int j = BEGIN; j <= END; j++) {
                System.out.println(createMultiplicationLine(i, j));
            }
        }
    }

    /**
     * 指定されたオペランドを用いて、掛け算の1行を表す文字列作成する。
     * 例： "1x2=2"
     *
     * @param i オペランド1
     * @param j オペランド2
     * @return 指定されたオペランドを用いて作成した掛け算を表す文字列
     */
    protected static String createMultiplicationLine(int i, int j) {
        StringBuilder buffer = new StringBuilder();
        buffer.append(i);
        buffer.append("x");
        buffer.append(j);
        buffer.append("=");
        buffer.append(i * j);
        return buffer.toString();
    }
}

Measured memory_bytes: 17048
l = input().split()
a,b = [int(x) for x in l]

def check(n, a, b):
    if int(n*0.08) == a and int(n*0.1) == b:
        return "1"
    else:
        if int(n*0.08) > a or int(n*0.1) > b:
            return "imp"
        return "0"

x1 = int(a/0.08)
x2 = int(b/0.1)
temp = max(x1,x2)
stat = "0"
while stat != "imp":
    stat = check(temp,a,b)
    if stat == "1":
        break
    else:
        temp += 1

if stat == "imp":
    print(-1)
else:
    print(temp)

Measured memory_bytes: 38384
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    そう甘くはないんだな〜w
*/

// from std...
use std::cmp::{
    max, min, Ordering,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::convert::TryInto;
use std::mem::swap;
use std::num::{NonZeroU32, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Index, IndexMut, Mul, MulAssign, Neg, Rem, RemAssign, Shl, ShlAssign, Shr, ShrAssign, Sub,
    SubAssign,
};
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, multinomial, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, Num, NumAssignOps, NumOps, One, Pow, Zero};
use permutohedron::Heap;
use proconio::{
    fastout, input, is_stdin_empty,
    marker::{Bytes, Chars, Isize1, Usize1},
};
use rand::random;

pub const MOD10E9_7: usize = 1000000007;
pub const MOD99_: usize = 998244353;
pub const MAX: usize = std::usize::MAX;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 65;

// code...
// #[fastout]
fn main() {
    input! {
        n: usize,
        s: [Chars; 2]
    }

    let mut d = Vec::new();
    let mut i = 0usize;
    while i < n {
        if s[0][i] != s[1][i] {
            d.push(false);
            i += 2;
        } else {
            d.push(true);
            i += 1;
        }
    }

    // dbg!(&d);

    let mut ans = if d[0] { 3 } else { 6 };
    for (a, b) in d.windows(2).map(|x| (x[0], x[1])) {
        if a && b {
            ans *= 2;
            ans %= MOD10E9_7;
        } else if a && !b {
            ans *= 2;
            ans %= MOD10E9_7;
        } else if !a && b {

        } else {
            ans *= 3;
            ans %= MOD10E9_7;
        }
    }

    println!("{}", ans);
}


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

template <typename T>
using matrix = std::vector<std::vector<T>>;

constexpr long long mod = 1e9 + 9;

template <typename T>
matrix<T> modmul(const matrix<T> &l, const matrix<T> &r) {
  matrix<T> ret(l.size(), std::vector<T>(r[0].size()));
  for (int i = 0; i < (int)l.size(); i++) {
    for (int k = 0; k < (int)r.size(); k++) {
      for (int j = 0; j < (int)r[0].size(); j++) {
        ret[i][j] += l[i][k] * r[k][j] % mod;
        ret[i][j] %= mod;
      }
    }
  }
  return ret;
}

template <typename T>
std::vector<T> modmul(const matrix<T> &a, const std::vector<T> &x) {
  const int n = a.size();
  const int m = x.size();
  std::vector<T> ret(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      ret[i] += a[i][j] * x[j] % mod;
      ret[i] %= mod;
    }
  }
  return ret;
}

template <typename T>
matrix<T> eye(const int n) {
  matrix<T> ret(n, std::vector<T>(n));
  for (int i = 0; i < n; i++) ret[i][i] = 1;
  return ret;
}

template <typename T>
matrix<T> modpow(matrix<T> x, long long n) {
  auto ret = eye<T>(x.size());
  while (n) {
    if (n & 1) ret = modmul(ret, x);
    x = modmul(x, x);
    n /= 2;
  }
  return ret;
}

using namespace std;

using ll = long long;

ll h, w, n;
int cs = 1;

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

  while (cin >> w >> h >> n, h || w || n) {
    cout << "Case " << cs << ": ";
    cs++;
    bool f = false;
    set<ll> st = {h};
    map<ll, vector<ll>> mp;
    for (int i = 0; i < n; i++) {
      ll x, y;
      cin >> y >> x;
      if (x == 1) continue;
      st.insert(x);
      y--;
      mp[x].push_back(y);
      if (x == h && y == w) {
        f = true;
      }
    }
    if (f) {
      cout << 0 << endl;
      continue;
    }
    vector<vector<ll>> id(w, vector<ll>(w, 0));
    for (int i = 0; i < w; i++) {
      id[i][i] = 1;
      if (i) id[i][i - 1] = 1;
      if (i + 1 < w) id[i][i + 1] = 1;
    }
    vector<ll> x(w, 0);
    x[0] = 1;
    ll pre = 1;
    for (auto v : st) {
      x = modmul(modpow(id, v - pre), x);
      for (auto y : mp[v]) x[y] = 0;
      pre = v;
    }
    cout << x[w - 1] << endl;
  }
}


Measured memory_bytes: 3264
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int n ;
string s , t ;

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

	cin >> n ;

	cout << 0 << endl ;
	cin >> s ;

	if (s == "Vacant") return 0 ;

	int low = 0 , high = n ;
	while (high - low > 1) {
		int mid = (low + high) >> 1 ;

		cout << mid << endl ;
		cin >> t ;

		if (t == "Vacant") return 0 ;

		if ((s == t) == (mid & 1)) high = mid ;
		else low = mid ;
	}
}

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

#define SZ(a) (int)a.size()
#define PB push_back
//#define cerr if(false)cerr
#define print(x) cerr<<"\n" << (#x) << " is " << (x) << endl;



int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	long long k, q;
	cin >> k >> q;
	long long d[k];
	for(int i =0; i<k; i++) cin >> d[i];
	while(q--){
		long long n, x, m;
		cin >> n >> x >> m;
		x%=m;
		long long sum = 0;
		for(long long i=0; i<k; i++){
			sum += d[i]%m==0?m:d[i]%m;
		}
		long long sum2 = 0;
		for(long long i=0; i<(n-1)%k; i++){
			sum2 += d[i]%m==0?m:d[i]%m;
		}
		long long an = x + (n-1)/k * sum + sum2;
		cout << n-1 - an/m<< endl;
	}		
}


Measured memory_bytes: 384
def insertionSort(a):
    n = len(a)
    print(*a)
    for i in range(1, n):
        v = a[i]
        j = i-1
        while j >= 0 and a[j] > v:
            a[j+1] = a[j]
            j += -1
        a[j+1] = v
        print(*a)


n = int(input())
a = [int(x) for x in input().split()]

insertionSort(a)


Measured memory_bytes: 5976
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MX 51000
#define all(x) (x).begin(), (x).end()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> vec(n);
    rep(i, n) cin >> vec[i];
    vector<ll> dp(n);
    dp[0] = 0;
    dp[1] = abs(vec[0] - vec[1]);
    ll state = 0;
    bool flag = true;
    for (ll i = 2; i < n; ++i)
    {
        dp[i] = min(dp[i - 2] + abs(vec[i - 2] - vec[i]), dp[i - 1] + abs(vec[i - 1] - vec[i]));
    }
    cout << dp.back() << endl;
}


Measured memory_bytes: 1792
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007


signed main(){
    int N,M;
    int a[100],b[100],c[100],d[100];
    cin>>N>>M;
    for(int i=0;i<N;i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<M;i++){
        cin>>c[i]>>d[i];
    }
    for(int i=0;i<N;i++){
        int minn=LLONG_MAX,mini=-1;
        for(int j=0;j<M;j++){
            int l=abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(l<minn){
                minn=l;
                mini=j+1;
            }
        }
        cout<<mini<<endl;
    }
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,n=0;
	cin>>a;
	while(a>0)
	{
		if(a%10==2)
		{
			n++;
		}
		a=a/10;
	}
	cout<<n<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void ABC084D();

#if 1
int main()
{
	ABC084D();
	fflush(stdout);
	return 0;
}
#endif
template <class _T> void tp_getPrimes(_T targ, std::map<_T, _T>& primes)
{
	_T target = targ;
	_T i = 2;
	while ((i * i) <= target) {
		if ((target % i) == 0) {
			target /= i;
			primes[i]++;
		}
		else {
			i++;
		}
	}
	if (target > 1) {
		primes[target]++;
	}
}

static void ABC084D()
{
	int Q;
	getint(Q);
	std::vector<int> pnCounts(100001, 0);
	pnCounts[0] = 0;
	pnCounts[1] = 0;
	
	for (int i = 2; i < 100001; i++) {
		std::map<int, int> primes, primes2;
		pnCounts[i] = pnCounts[i - 1];

		if ((i % 2) == 0) continue;

		tp_getPrimes(i, primes);
		if ((primes.size() == 1) && (primes.begin()->second == 1)) {
			tp_getPrimes((i + 1) / 2, primes2);
			if ((primes2.size() == 1) && (primes2.begin()->second == 1)) {
				pnCounts[i]++;
			}
		}
	}

	for (int i = 0; i < Q; i++) {
		int li, ri;
		getint(li, ri);
		printf("%d\n", pnCounts[ri] - pnCounts[li - 1]);
	}
}


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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N, K, heights[MAXN], dp[MAXN];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> K;
    for(int i=0; i<N; i++)
    {
        cin >> heights[i];
    }
    for(int i=1; i<N; i++)
    {
        dp[i] = INF;
    }
    dp[0] = 0;
    dp[1] = abs(heights[1] - heights[0]);
    for(int i=2; i<N; i++)
    {
        for(int j=max(i-K, 0); j<i; j++)
        {
            dp[i] = min(dp[i], dp[j]+abs(heights[i]-heights[j]));
        }
    }
    cout << dp[N-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int a, b, c, x, y;
    int ans=0;
    cin >> a >> b >> c >> x >> y;
    ans = a * x + b * y;
    for (int i=0; i<=max(x, y); i++){
        ans = min(ans, a*max(0, x-i) + b*max(0, y-i) + 2 * c * i);
    }
    out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string names[n];
    string temp;
    int t, i, j;
    int score[n];
    int pos[n];
    for(i=0; i<n; i++){
        cin>>names[i]>>score[i];
        pos[i]=i+1;
    }
   /* for(i=0; i<n; i++)
        cout<<names[i]<<" "<<score[i]<<" "<<pos[i]<<"\n";*/
    for (i = 0; i < n-1; i++)
       for (j = 0; j < n-i-1; j++)
           if (names[j].compare(names[j+1])>0){
                temp= names[j];
                names[j]= names[j+1];
                names[j+1]= temp;
                t= score[j];
                score[j]= score[j+1];
                score[j+1]= t;
                t=pos[j];
                pos[j]=pos[j+1];
                pos[j+1]=t;
           }
           else if(names[j].compare(names[j+1])==0 && score[j]<=score[j+1]){
                t=score[j];
                score[j]= score[j+1];
                score[j+1]=t;
                t=pos[j];
                pos[j]=pos[j+1];
                pos[j+1]=t;
           }
    for(i=0; i<n; i++)
        cout<<pos[i]<<"\n";
    return 0;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int64_t a,b,c; cin>>a>>b>>c;


    string ans="No";
    // a+2(ab)^(1/2)+b<c <=> 4bc<(c-a-b)^2
    int64_t l=4*a*b, r=a*a+b*b+c*c+2*a*b-2*b*c-2*c*a;
    if(c-a-b>0 && l<r) ans="Yes";

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int i;
    char S[20], T[20];
    scanf("%s%s", S, T);
    for(i=0;S[i]!='\0';i++){
        if(S[i]!=T[i]){
            printf("No\n");
            return 0;
        }
    
    }
    if(T[i+1]!='\0'){
        printf("No\n");
    }else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1588
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <sstream>
using namespace std;
  
priority_queue<string> top;
priority_queue<string, vector<string>, greater<string> > bottom;
string encrypt;
int answer = 0;
  
void rec(int index, string str) {
    if (index == encrypt.size()) {
        answer++;
        if (bottom.size() < 10) {
            bottom.push(str);
        } else {
            string temp = bottom.top();
            if (str > temp) {
                bottom.pop();
                bottom.push(str);
            }
        }
  
        if (top.size() < 5) {
            top.push(str);
        } else {
            string temp = top.top();
            if (str < temp) {
                top.pop();
                top.push(str);
            }
        }
        return;
    }
  
    bool can_change = encrypt[index] != 'z', can_remain = encrypt[index] == 'a';
    bool find_y = false;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == encrypt[index] + 1) {
            can_change = false;
        }
        if (str[i] == encrypt[index]) {
            can_remain = true;
        }
        if (str[i] == 'y') find_y = true;
    }
  
    if (can_change && encrypt[index] != 'z') {
        str.push_back(encrypt[index] + 1);
        rec(index + 1, str);
        str.pop_back();
    }
    if (can_remain) {
        str.push_back(encrypt[index]);
        rec(index + 1, str);
        str.pop_back();
    }
}
  
int main() {
    while (cin >> encrypt, encrypt != "#") {
        while (!top.empty()) top.pop();
        while (!bottom.empty()) bottom.pop();
        answer = 0;
  
        rec(0, "");
  
        cout << answer << endl;
  
        if (answer <= 10) {
            while (!bottom.empty()) {
                cout << bottom.top() << endl;
                bottom.pop();
            }
        } else {
            vector<string> S;
            for (int i = 0; i < 5; i++) {
                S.push_back(top.top()); top.pop();
            }
            for(int i=0;i<5;i++){
                cout << S[4-i] << endl;
            }
            for(int i=0;i<5;i++)bottom.pop();
            for (int i = 0; i < 5; i++) {
                cout << bottom.top() << endl;
                bottom.pop();
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3176
N=int(input())
A=list(map(int, input().split()))
#1000

#1300
#35
L=[0]*N
if A[0]<A[1]:
    L[0]=1
    up=1
elif A[0]==A[1]:
    up=0
else:
    up=-1

for i in range(1,N):
    if i==N-1:
        L[i]=-1
        break
    if up==1:
        if A[i]>A[i+1]:
            up=-1
            L[i]=-1
    elif up==0:
        if A[i-1]<A[i]:
            L[i-1]=1
            up=1
        elif A[i-1]>A[i]:
            up=-1

    else:
        if A[i]<A[i+1]:
            up=1
            L[i]=1

#print(L)
now=1000
have=0
for i in range(len(L)):
    l=L[i]
    if l==1:
        have=now//A[i]
        now=now%A[i]
    elif l==-1:
        now+=A[i]*have
        have=0
print(now)

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var judge = new bool[n];

            for (var i = 1; i <= n; i++)
                if (i == p[i - 1]) judge[i - 1] = true;

            var total = 0L;
            for (var i = 0; i < n; i++)
            {
                if (judge[i])
                {
                    if (i + 1 < n)
                        i++;

                    total++;
                }
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 22112
#include <iostream>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  std::string s,t;
  int n;
  
  std::cin >> n >> s >> t;
  
  rep(i, n) {
    std::cout << s.at(i) << t.at(i);
  }
  std::cout << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> ve(n,0);
    for(int i=0;i<n;i++){
        cin>>ve[i];
    }
    sort(ve.begin(),ve.end(),greater<int>());
    int sum=0;
    for(int i=0;i<k;i++){
        sum+=ve[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def read():
    N, A, B = map(int, input().strip().split())
    return N, A, B


def solve(N, A, B):
    low = (N-1) * A + B - 1
    high = A + (N-1) * B
    return max(high - low, 0)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 3060