akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
    int n,k,x,y,l;
    cin>>n>>k>>x>>y;

    if(n>=k)
    {
        l=(k*x);
        l+=((n-k)*y);
        cout<<l<<endl;
    }
    else
    {
        cout<<n*x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace debug
{
    class ProgramA
    {
        static void Main(string[] args)
        {

            //入力
            string[] a = Console.ReadLine().Split(' ');
            long s = long.Parse(a[0]);
            long l = long.Parse(a[1]);


            //答え出力
            if (s > l)
                Console.WriteLine("safe");
            else
                Console.WriteLine("unsafe");


        }
    }

}


Measured memory_bytes: 27472
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <functional>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define INT_MAX 2147483647
#define ll long long

#define MOD 1000000007

ll max(ll a, ll b) { return (a < b) ? b : a; }


// DP !!
int main() {
    int h, w;
    cin >> h >> w;

    vector<int> prev(w + 1);
    vector<int> curr(w + 1);

    curr[1] = 1;

    for (int i = 0; i < h; i++) {
        for (int j = 1; j <= w; j++) {
            char c;
            cin >> c;
            if (i == 0 && j == 1)
                continue;
            if (c == '.')
                curr[j] = (curr[j - 1] + prev[j]) % MOD;
            else
                curr[j] = 0;
        }
        prev = curr;
    }



    cout << curr[w] << endl;
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)

	s := next()
	letters := strings.Split(s, "")

	var first = ""
	var firstCnt = 0
	var second = ""
	var secondCnt = 0

	for _, l := range letters {
		if first == "" {
			first = l
			firstCnt++
			continue
		}

		if first != l && second == "" {
			second = l
			secondCnt++
			continue
		}

		if first == l {
			firstCnt++
		} else if second == l {
			secondCnt++
		}
	}

	if firstCnt == 2 && secondCnt == 2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <iomanip>
using namespace std;
long Nchoose2(long n){
    return n*(n-1)/2;
}
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 0;
    sort(a.begin(), a.end());
    for(int i = 0; i < k; i++){
        ans += a[i];
    }
    cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, k, ans = 0;
	cin >> n >> k;
	int dp[n + 1][6001] = {};
	pi a[n + 1];
	FOR (i, 1, n) cin >> a[i].fi >> a[i].se;
	sort(a + 1, a + n + 1);
	
	FOR (i, 1, n)
	    FOR (j, 1, 6000)
	    {
	        dp[i][j] = dp[i - 1][j];
	        if (j - a[i].fi < k && j >= a[i].fi) dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i].fi] + a[i].se);
	        ans = max(ans, dp[i][j]);
	    }
	
	cout << ans;
}

Measured memory_bytes: 141056
N,P=map(int,input().split())
A=list(map(int,input().split()))
a=0
for i in A:
  if i%2==0:
    a+=1
b=N-a
c=0
import math
def comb(n,r):
  return math.factorial(n) // (math.factorial(n-r)*math.factorial(r))  
for i in range(b//2+1):
  c+=comb(b,2*i)
if P==0:
  print((2**a)*c)
else:
  print(2**N-(2**a)*c)

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

using ll = long long;
using lli = long long int;

int n;
lli a;
std::vector<lli> vec;
std::deque<lli> dec;

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> a;
        vec.push_back(a);
    }
    bool reversed = false;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 1) {
            dec.push_back(vec[i-1]);
        }
        else {
            dec.push_front(vec[i-1]);
        }
    }
    if (n%2 == 1) {
        std::reverse(dec.begin(), dec.end());
    }
    
    for (int i = 0; i < dec.size(); i++) {
        std::cout << dec[i];
        if (i < n-1) {
            std::cout << " ";
        }
        else {
            std::cout << std::endl;
        }
    }
}


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

#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

#define Grt ch = getchar()
#define DeBug(x) std::cout << #x << '=' << x << std::endl

const int MaxN = 1e5 + 10, MaxM = 1 << 15 + 10;

namespace IO
{
	char buf[1<<15], *fs, *ft;
	inline char getc() { return ft == fs && (ft = (fs = buf) + fread(buf, 1, 1<<15, stdin), ft == fs) ? 0 : *fs++; }
	template <typename T> inline void read(T &x)
	{
		x = 0;
		T f = 1, Grt;
		while (!isdigit(ch) && ch ^ '-') Grt;
		if (ch == '-') f = -1, Grt;
		while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), Grt;
		x *= f;
	}


	template <typename T, typename... Args>
	inline void read(T &x, Args &...args) { read(x); read(args...); }

	char Out[1<<24], *fe = Out;
	inline void flush() { fwrite(Out, 1, fe-Out, stdout); fe = Out; }
	template <typename T> inline void write(T x, char str)
	{
		if (!x) *fe++ = 48;
		if (x < 0) *fe++ = '-', x = -x;
		T num = 0, ch[20];
		while (x) ch[++ num] = x % 10 + 48, x /= 10;
		while (num) *fe++ = ch[num --];
		*fe++ = str;
	}
}

using IO::read;
using IO::write;

template <typename T> inline bool chkMin(T &a, const T &b) { return a > b ? (a = b, true) : false; }
template <typename T> inline bool chkMax(T &a, const T &b) { return a < b ? (a = b, true) : false; }
template <typename T> inline T min(T a, T b) { return a < b ? a : b; }
template <typename T> inline T max(T a, T b) { return a > b ? a : b; }

int v[MaxN], f[MaxM], cnt[20], xr[MaxM];
int main()
{
	int n, ans = 0, state = 0; read(n);
	for (int i = 1, x, y, z; i < n; ++ i) read(x, y, z), v[x] ^= z, v[y] ^= z;
	for (int i = 0; i < n; ++ i) ++ cnt[v[i]];
	for (int i = 1; i <= 15; ++ i)
	{
		ans += cnt[i] >> 1;
		state |= (cnt[i] & 1) << (i - 1);
	}
	for (int i = 1; i < (1 << 15); ++ i) f[i] = f[i >> 1] + (i & 1);
	for (int i = 1; i < (1 << 15); ++ i) -- f[i];
	for (int i = 1; i < (1 << 15); ++ i)
		for (int j = 1; j <= 15; ++ j)
			if ((i >> (j - 1)) & 1) xr[i] ^= j;
	for (int s = 1; s < (1 << 15); ++ s)
	{
		if (xr[s]) continue;
		for (int t = (s - 1) & s; t; t = (t - 1) & s)
			if (!xr[t]) chkMin(f[s], f[t] + f[t ^ s]);
	}
	write(ans + f[state], '\n');
	IO::flush();
	return 0;
}

Measured memory_bytes: 4480
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			// x,y??賊???0?????????????????????
			if (x == 0 && y == 0) break;
			if (x < y) {
				System.out.println(x+" "+y);
			} else {
				System.out.println(y+" "+x);
			}
		}
		scanner.close();
	}
}

Measured memory_bytes: 27220
#include<cstdio>
#include<cmath>
const double PI=acos(-1);
double min(double a,double b)
{
	return a<b?a:b;
}
int main(void)
{
	double a,b,h,m;
	scanf("%lf%lf%lf%lf",&a,&b,&h,&m);
	double r1,r2,R;
	r1=h*PI/6.0+PI*m/360.0;
	r2=m*PI/30.0;
	r1=fabs(r1-r2);
	R=min(r1,2.0*PI-r1);
	printf("%.20lf\n",sqrt(fabs(a*a+b*b-2.0*a*b*cos(R))));
	return 0;
 } 
// min(fabs(h*360.0/12.0-m*360.0/60.0),fabs(360.0-fabs(h*360.0/12-m*360.0/60.0)))

Measured memory_bytes: 2536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			int h = scan.nextInt();
			int w = scan.nextInt();
			
			if(h == 0 && w == 0) break;
			
			for(int i = 0; i < h; i++) {
				for(int j = 0; j < w; j++) {
					System.out.print('#');
				}
				System.out.println();
			}
			
			System.out.println();
		}
		
	}

}



Measured memory_bytes: 36080
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,string> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	vvi dp(5,vi(50000));
	dp[0][0]=1;
	for(int i=1;i*i<=50000;i++){
		int t=i*i;
		rep(k,4)rep(j,50000-1-t)if(dp[k][j])dp[k+1][j+t]+=dp[k][j];
	}
	int n;
	while(cin>>n,n){
		cout<<dp[1][n]+dp[2][n]+dp[3][n]+dp[4][n]<<endl;
	}
//	rep(i,5){rep(j,10)cout<<" "<<dp[i][j];cout<<endl;}
}

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

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

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let v = read_vec::<u32>();
    let n = v[0];
    let a = v[1];
    let b = v[2];

    let ans = std::cmp::min(a * n, b);
    println!("{}", ans);
}


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

int main(){
    int n;cin>>n;
    int a, b;cin>>a>>b;
    vector<int> scores(n);for (int i=0;i<n;i++){cin>>scores[i];}

    int one, two, three;
    one = two = three = 0;
    for (auto s: scores){
        if (s <= a){
            one++;
        } else if (b + 1 <= s){
            three++;
        } else {
            two++;
        }
    }
    cout << min(min(one, two), three) <<endl;
    return 0;

}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + n + 1);
	int ans = INF;
	for (int i = k; i <= n; i++)
	{
		ans = min(ans, a[i] - a[i - k + 1]);
	}
	cout << ans << endl;
	return 0;
}

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

const int N = 500010;
using ll = long long;

char s[N];
int a[N];

int main(){
    scanf("%s", s);
    int n = strlen(s);
    a[n] = 0;
    for (int i = n - 1; i >= 0; -- i){
        if (s[i] == '>'){
            a[i] = std::max(0, a[i + 1] + 1);
        }
        else{
            a[i] = 0;
        }
    }
    ll ans = a[0];
    int now = a[0];
    for (int i = 1; i <= n; ++ i){
        if (s[i - 1] == '<'){
            now = std::max(now + 1, a[i]);
        }
        else{
            now = a[i];
        }
        ans += now;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2688
#include "stdio.h"

int main()
{

  int s[4][3][10],i,j,k,x,a,b,c,d;


  for (i = 0; i < 4; i++)
  {
      for (j = 0; j < 3; j++)
      {
        for (k = 0; k < 10; k++)
        {
          s[i][j][k]=0;
        }
      }
  } //all 0

  scanf("%d\n",&x );


 for (i = 0; i < x; i++)
 {

   scanf("%d %d %d %d\n", &a,&b,&c,&d);

   s[a-1][b-1][c-1]+=d;

 }


 for (i = 0; i < 4; i++)
 {
     for (j = 0; j < 3; j++)
     {
       for (k = 0; k < 10; k++)
       {
         printf(" %d",s[i][j][k] );
       }
       printf("\n");
     }
     if (i!=3)
     {
     printf("####################\n");
     }
 }






  return 0;
}



Measured memory_bytes: 2048
// Vicfred
// https://atcoder.jp/contests/abc176/tasks/abc176_b
// implementation
import std.stdio;
import std.string;

void main() {
    string n = readln.strip;

    int sum = 0;
    foreach(ch; n) {
        sum += ch - '0';
        sum %= 9;
    }

    if(sum == 0)
        "Yes".writeln;
    else
        "No".writeln;
}



Measured memory_bytes: 2796
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define Sq(x) ((x)*(x))

#define Foreach(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)

const double PI = M_PI;
const double EPS = 0.0001;

struct Point{
  double x,y;

  Point(){}
  Point(double x, double y) : x(x), y(y) {}
};

Point operator+(const Point &a, const Point &b){
  return Point(a.x + b.x, a.y + b.y);
}

Point operator-(const Point &a, const Point &b){
  return Point(a.x - b.x, a.y - b.y);
}

Point operator*(const Point &a, const double k){
  return Point(a.x * k, a.y * k);
}

Point operator*(const Point &a,const Point &b){
  return Point(a.x*b.x-a.y*b.y, a.x*b.y+a.y*b.x);
}

Point operator/(const Point &p, const double k){
  return Point(p.x / k, p.y / k);
}

double dot(const Point &a, const Point &b){
  return a.x * b.x + a.y * b.y;
}

double cross(const Point &a, const Point &b){
  return a.x * b.y - a.y * b.x;
}

double norm(const Point &p){
  return dot(p, p);
}

double abs(const Point &p){
  return sqrt(norm(p));
}

typedef Point Vector;

struct Circle : Point{
  double r;
  Circle(Point p = Point(0,0), double r = 0) : Point(p), r(r) {}
};

double distPP(const Point &a, const Point &b) {
  return sqrt(Sq(a.x-b.x) + Sq(a.y-b.y));
}

bool isPointInCircle(const Point &p, const Circle &c) {
  return abs(p - c) <= c.r + EPS;
}
 
vector<Point> crossPointCC(const Circle &c1, const Circle &c2) {
  vector<Point> res;
  
  if(abs(c1-c2) < EPS) return vector<Point>();
  
  double d = abs( c1 - c2 );
  double rc = ( d*d+c1.r * c1.r-c2.r * c2.r ) / ( 2*d );
  double rs = sqrt(c1.r*c1.r-rc*rc);
  Point diff = ( c2 - c1 ) / d;
  res.push_back( Point(c1 + diff * Point(rc,rs)) );
  res.push_back( Point(c1 + diff * Point(rc,-rs)) );
  return res;
}

Point rotate90(const Point &p) {
  return Point(-p.y, p.x);
}

/*
テ」ツ??」ツ?セテ」ツ?湘・ツ仰陛」ツ?凝」ツ?ェテ」ツ??
Point rotateVector(const Vector &p, double th) {
  return Point(p.x * cos(th) - p.y*sin(th), p.x * sin(th) + p.y * cos(th));
}
*/

int main() {
  int n;
  Point p[300];
  
  while(cin >> n && n) {
    for(int i=0; i<n; i++) {
      cin >> p[i].x >> p[i].y;
    }
    
    int ans = 1;
    for(int i=0; i<n-1; i++) {
      for(int j=i+1; j<n; j++) {
	if(distPP(p[i], p[j]) + EPS > 2.0) continue;
	
	Point cent((p[i]+p[j])/2);
	double a = distPP(p[i], cent);
	double b = sqrt(1.0 - a*a);
	
	Vector v1 = p[i] - cent;
	Vector v2 = rotate90(v1);
	Point center = cent + ((v2/abs(v2)) * b);
	Circle c1(center, 1.0);
	int cnt = 0;
	for(int k=0; k<n; k++) {
	  cnt += isPointInCircle(p[k], c1);
	}
	ans = max(ans, cnt);
	
	center = cent + ((v2/abs(v2)) * -b);
	Circle c2(center, 1.0);
	cnt = 0;
	for(int k=0; k<n; k++) {
	  cnt += isPointInCircle(p[k], c2);
	}
	ans = max(ans, cnt);
      }
    }
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MAX(a,b) (((a)>(b))?a:b)

LL dp[101][100001];
LL value[101]={0};
LL weight[101]={0};

LL cal(LL left,LL remweight)
{
    if(left==0 || remweight<=0)
    {
        return 0;
    }
    else 
    {
        if(dp[left][remweight]==-1)
        {
            if(dp[left-1][remweight]==-1)
            {
               dp[left-1][remweight]=cal(left-1,remweight); 
            }
            if(remweight-weight[left]<0)
            {
                dp[left][remweight]=dp[left-1][remweight];
            }
            else if(dp[left-1][remweight-weight[left]]==-1)
            {
                dp[left-1][remweight-weight[left]]=cal(left-1,remweight-weight[left]);
                dp[left][remweight]=MAX(dp[left-1][remweight],value[left]+dp[left-1][remweight-weight[left]]);                
            }
            else
            {
                dp[left][remweight]=MAX(dp[left-1][remweight],value[left]+dp[left-1][remweight-weight[left]]);
            }
            
            return dp[left][remweight];
            
        }
    }
}

int main()
{
    LL n,w,i,j,k;
    cin>>n>>w;
    
    for(i=1;i<=n;i++)
    {
        cin>>weight[i]>>value[i];
    }

    for(i=0;i<101;i++)
    {
        for(j=0;j<100001;j++)
        {
            dp[i][j]=-1;
        }
    }

    LL ans=cal(n,w);

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); i++)


int main() {
    char c;cin >> c;
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
        cout << "vowel" << endl;
    }else{
        cout << "consonant" << endl;
    }



}       

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();

        if(input.Distinct().Count() == 2) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 13268
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll N;
  (void)scanf("%lld", &N);
  vector<ll> vll;
  for (int i = 0; i < 5; i++) {
    ll tmp;
    (void)scanf("%lld", &tmp);
    vll.push_back(tmp);
  }
  sort(vll.begin(), vll.end());
  
  printf("%lld", N / vll[0] + 5 - (((N % vll[0]) == 0)?1:0));
  
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
mod = 1000000007
INF = float("inf")
n,m = map(int,input().split())
dp = [0]*(n+2)
goods = [True] * (n+2)
for _ in range(m):
     x = int(input())
     goods[x] = False

dp[0] = 1
for i in range(n):
    if goods[i]:
        dp[i + 1] += dp[i]
        dp[i + 2] += dp[i]
print(dp[n]%mod)

Measured memory_bytes: 472392
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int N, K;

	cin >> N >> K;

	double ans = 0.0,tmp;

	for (int i = 1; i <= N; i++) {
		tmp = 1;
		int now = i;
		while (now < K) {
			now *= 2;
			tmp /= 2;
		}
		ans += 1.0 / N * tmp;
	}

	printf("%.14f\n", ans);


	return 0;
}

Measured memory_bytes: 256
use proconio::input;


fn solve(a: i128, b: i128, _: i128, k: i128) {
    if k % 2 == 0 {
        println!("{}", a-b);
    }
    else {
        println!("{}", b-a);
    }
}


fn main() {
    input! {
        a: i128,
        b: i128,
        c: i128,
        k: i128,
    }

    solve(a, b, c, k);
}


Measured memory_bytes: 2140
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  cout << (x-a)%b;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
#include <unordered_set>

using namespace std;
using Int = long long;

constexpr double EPS = 1e-10;
constexpr long long MOD = 998244353;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

long long my_mod_pow(long long x, long long n) {
	long long ret = 1;
	for (; n > 0; n >>= 1, x = x * x % MOD) {
		if (n & 1) {
			ret = ret * x % MOD;
		}
	}
	return ret;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int dp[105][105];
int field[105][105];

int main(void) {
    int inf = 100000000;
    int H, W; cin >> H >> W;
    for (int i = 0; i < 105; i++) {
        for (int j = 0; j < 105; j++) {
            dp[i][j] = inf;
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c; cin >> c;
            if (c == '.') field[i][j] = 0;
            else field[i][j] = 1;
        }
    }

    if (field[0][0]) dp[0][0] = 1;
    else dp[0][0] = 0;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j != 0) {
                if (field[i][j] == 1 && field[i][j-1] == 0) {
                    dp[i][j] = min(dp[i][j-1] + 1, dp[i][j]);
                } else {
                    dp[i][j] = min(dp[i][j-1], dp[i][j]);
                }
            }
            if (i != 0) {
                if (field[i][j] == 1 && field[i-1][j] == 0) {
                    dp[i][j] = min(dp[i-1][j] + 1, dp[i][j]);
                } else {
                    dp[i][j] = min(dp[i-1][j], dp[i][j]);
                }
            }
        }
    }

    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 1016
#include<cstdio>
#include<algorithm>
const int inf=1<<30;
int W,H,N;
struct Point{
	int x,y;
	void read(){scanf("%d%d",&x,&y);}
	bool operator<(const Point&p)const{return x<p.x;}
}P[300010],Sd[300010],Su[300010];
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int T[1<<20],tag[1<<20];
#define Def int o,int L,int R
#define Mid (L+R>>1)
#define Ls o<<1,L,Mid
#define Rs o<<1|1,Mid,R
void build(Def){
	T[o]=-inf;tag[o]=0;
	if(R-L>1)build(Ls),build(Rs);
}
void modify(Def,int i,int x){
	if(R-L==1)T[o]=x;
	else{
		if(i<Mid)modify(Ls,i,x);
		else modify(Rs,i,x);
		T[o]=max(T[o<<1],T[o<<1|1])-tag[o];
	}
}
void minus(Def,int l,int r,int x){
	if(l==L&&r==R)T[o]-=x,tag[o]+=x;
	else{
		if(r<=Mid)minus(Ls,l,r,x);
		else if(l>=Mid)minus(Rs,l,r,x);
		else minus(Ls,l,Mid,x),minus(Rs,Mid,r,x);
		T[o]=max(T[o<<1],T[o<<1|1])-tag[o];
	}
}
int solve(int xr,int yr){
	int ymid=yr/2,ans=0;
	Point*td=Sd,*tu=Su;
	*++td=(Point){0,0};
	*++tu=(Point){0,yr};
	build(1,0,N+1);
	modify(1,0,N+1,0,yr);
	for(int i=0;i<N;i++){
		ans=max(ans,P[i].x+T[1]);
		if(P[i].y<ymid){
			while(td>Sd&&td->y<P[i].y){
				if(td-1>Sd&&td[-1].y<P[i].y)minus(1,0,N+1,td->x,i+1,td[-1].y-td->y),--td;
				else minus(1,0,N+1,td->x,i+1,P[i].y-td->y),td->y=P[i].y;
			}
			*++td=(Point){i+1,0};
		}
		else{
			while(tu>Su&&tu->y>P[i].y){
				if(tu-1>Su&&tu[-1].y>P[i].y)minus(1,0,N+1,tu->x,i+1,tu->y-tu[-1].y),--tu;
				else minus(1,0,N+1,tu->x,i+1,tu->y-P[i].y),tu->y=P[i].y;
			}
			*++tu=(Point){i+1,yr};
		}
		modify(1,0,N+1,i+1,yr-P[i].x);
	}
	return max(ans,xr+T[1]);
}
int main(){
	scanf("%d%d%d",&W,&H,&N);
	for(int i=0;i<N;i++)P[i].read();
	std::sort(P,P+N);
	int ans=solve(W,H);
	for(int i=0;i<N;i++)std::swap(P[i].x,P[i].y);
	std::sort(P,P+N);
	ans=max(ans,solve(H,W));
	printf("%d\n",ans*2);
}

Measured memory_bytes: 15360
n = int(input())
scoreT = 0
scoreH = 0
for i in range(0, n):
    words = input().split(" ")
    if words[0] < words[1]:
        scoreH += 3
    elif words[1] < words[0]:
        scoreT += 3
    elif words[0] == words[1]:
        scoreT += 1
        scoreH += 1
print(str(scoreT)+" "+str(scoreH))
    


Measured memory_bytes: 5596
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

N = int(input())
A = list(map(int,input().split()))

gcdf = [0 for i in range(N)]
gcdf[0] = A[0]
for i in range(1,N):
    gcdf[i] = gcd(gcdf[i-1],A[i])

#print(gcdf)

gcdb = [0 for i in range(N)]
gcdb[-1] = A[-1]
for i in range(N-2,-1,-1):
    gcdb[i] = gcd(gcdb[i+1],A[i])

#print(gcdb)

ans = max(gcdf[-2],gcdb[1])

for i in range(1,N-1):
    ans = max(ans,gcd(gcdf[i-1],gcdb[i+1]))

print(ans)

Measured memory_bytes: 14052
#include<stdio.h>

int main(void)
{
  int ans[9][9] = { {0},
		    {0},
		    {0},
		    {0},
		    {0},
		    {0},
		    {0},
		    {0},
		    {0} };
  int i, j;

  for(i=0; i<9; i++){
    for(j=0; j<9; j++){
      ans[i][j] = (i+1)*(j+1);
      printf("%dx%d=%d\n", i+1, j+1, ans[i][j]);
    }
  }

  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000005];
void insert(int k){
	a[++n]=k;
	int i=n;
	while(i/2>=1&&a[i/2]<a[i])swap(a[i/2],a[i]),i/=2;
}
void adjust(int i){
	int l=i*2;int r=i*2+1;
	int jb;
	if(l<=n&&a[l]>a[i])jb=l;else jb=i;
	if(r<=n&&a[r]>a[jb])jb=r;
	if(jb!=i)swap(a[i],a[jb]),adjust(jb);
}
void extract(){
	printf("%d\n",a[1]);
	a[1]=a[n];n--;
	adjust(1);
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	string s;int k;
	n=0;
	while(cin>>s){
		if(s=="insert")cin>>k,insert(k);
		else if(s=="extract")extract();
		else break;
	}
	return 0;
}


Measured memory_bytes: 7176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

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

#include <functional>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, s;
    while (cin >> n >> s, n + s) {
        auto dp = make_v(n + 1, 110, s + 1, -1LL);
        function<ll(int, int, int)> rec = [&](int cnt, int lst, int sum) -> ll {
            if (sum < 0 || cnt > n || lst > 110) {
                return 0;
            }
            if (dp[cnt][lst][sum] != -1) {
                return dp[cnt][lst][sum];
            }
            if (cnt == n && sum == 0) {
                return 1;
            }
            ll ans = 0;
            REP(i, lst, 101) {
                ans += rec(cnt + 1, i + 1, sum - i);
            }
            return dp[cnt][lst][sum] = ans;
        };
        cout << rec(0, 0, s) << endl;
    }
    return 0;
}



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


int main(){
  int x,i,m,n;
  m=0;
  cin >> x;
  n=x/100;
  if(n*5+n*100<x){
    m=0;
  }else{
    m=1;
  }
  cout << m << endl;
  return 0;

}


Measured memory_bytes: 256
def test():
    a = list(map(int,input()))
    for i in range(len(a)):
        if a[i] == 1:
            a[i] = 9
        elif a[i] == 9:
            a[i] = 1

    print("".join(map(str,a)))



if __name__ == "__main__":
    test()


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
string S[505];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) cin>>S[y];
	FOR(x,W) S[0][x]='$', S[H-1][x]='&';
	FOR(y,H) FOR(x,W) if(S[y][x]=='.') S[y][x]="$&"[x%2];
	
	FOR(y,H) {
		FOR(x,W) cout<<((S[y][x]=='&')?'.':'#');
		cout<<endl;
	}
	cout<<endl;
	FOR(y,H) {
		FOR(x,W) cout<<((S[y][x]=='$')?'.':'#');
		cout<<endl;
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{   long long x;
    scanf("%lld",&x);
    long long ans=x/11*2;
    if(x%11==0)
    printf("%lld",ans);
    else if(x%11<=6)
    printf("%lld",ans+1);
    else printf("%lld",ans+2);
    
}


Measured memory_bytes: 128
import sys
s=input()
def wa(i):
  return (i+1)*i/2
sa=s.split("<")
sb=s.split(">")
ta=[i for i in [len(i) for i in sa] if i!=0]
tb=[i for i in [len(i) for i in sb] if i!=0]
ma=[wa(i) for i in ta]
mb=[wa(i) for i in tb]
goukei=sum(ma)+sum(mb)
n=max(len(ta),len(tb))
so=list(s)
if len(ma)==0 or len(mb)==0:
  print(int(goukei))
  sys.exit()
if so[0]=="<":
  if so[len(s)-1]=="<":
    for i in range(n-1):
      if ma[i]<mb[i]:
        goukei=goukei-ta[i]
      else:
        goukei=goukei-tb[i]
    print(int(goukei))
  else:
    for i in range(n):
      if ma[i]<mb[i]:
        goukei=goukei-ta[i]
      else:
        goukei=goukei-tb[i]
    print(int(goukei))
else:
  if so[len(s)-1]==">":
    for i in range(n-1):
      if ma[i+1]<mb[i]:
        goukei=goukei-ta[i+1]
      else:
        goukei=goukei-tb[i]
    print(int(goukei))
  else:
    if len(ta)==1:
      print(int(goukei))
    else:
      for i in range(n-1):
        if ma[i+1]<mb[i]:
          goukei=goukei-ta[i+1]
        else:
          goukei=goukei-tb[i]
      print(int(goukei))

Measured memory_bytes: 28276
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();

		PriorityQueue<Integer> a = new PriorityQueue<>();
		for ( int i = 0; i < n; i++ ) {
			a.add(in.nextInt());
		}

		int[][] bc = new int[m][2];
		for ( int i = 0; i < m; i++ ) {
			bc[i][0] = in.nextInt();
			bc[i][1] = in.nextInt();
		}

		Arrays.sort(bc, (o1, o2) -> o2[1] - o1[1]);

		for ( int i = 0; i < m; i++ ) {
			while ( !a.isEmpty() && a.peek() < bc[i][1] && 0 < bc[i][0] ) {
				a.poll();
				a.add(bc[i][1]);
				bc[i][0]--;
			}
		}

		long ans = 0L;
		for ( Integer i : a ) {
			ans += i;
		}
		System.out.println(ans);
		in.close();
	}
}

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

int main() {
  string odd, even, ans;
  cin >> odd >> even;
  for(int i = 0; i < odd.size(); i++) {
    ans += odd[i];
    ans += even[i];
  }
  if(odd.size() > even.size()) ans.pop_back();
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cstdio>
#include <queue>

using namespace std;

int main()
{
    int32_t k;
    cin >> k;
    queue<uint64_t> q;
    q.push(1);
    q.push(2);
    q.push(3);
    q.push(4);
    q.push(5);
    q.push(6);
    q.push(7);
    q.push(8);
    q.push(9);
    uint64_t a;
    for (; 0 < k; --k)
    {
        a = q.front();
        q.pop();
        int d = a % 10;
        if (d == 0)
        {
            q.push(a * 10 + 0);
            q.push(a * 10 + 1);
        }
        else if (d == 9)
        {
            q.push(a * 10 + 8);
            q.push(a * 10 + 9);
        }
        else
        {
            q.push(a * 10 + d - 1);
            q.push(a * 10 + d);
            q.push(a * 10 + d + 1);
        }
    }
    cout << a;
}


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

int main(){
	int n,m,l,o,r;
	
	cin>>n>>m;
	
	int a[n+2],b[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	a[n+1]=m;
	
	sort(a+1,a+n+2);
	
	for(int i=1;i<=n;i++){
		b[i]=a[i+1]-a[i];
	}
	
	for(int i=1;i<n;i++){
		l=b[i];
		o=b[i+1];
		r=0;
		while(o%l!=0){
			r=o%l;
			o=l;
			l=r;
		}
		b[i+1]=l;
	}
	cout<<b[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
//N×Nのマス目があります。
//このマス目の各マスを白色または黒色に塗ることにしました (すべてのマスをどちらか片方の色に塗ります)。
//ちょうど Aマスを白色に塗るとき、黒色に塗ることになるマスはいくつあるでしょうか。

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

int main(){
  	int N, A;
  	cin >> N >> A;
  	cout << N * N - A << endl; 
  
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 101

int max(int a,int b)
{
	int M;
	M=a;
	if(M < b) M=b;
	return M;
}

int main(void)
{
	int i,j,N,W,v[MAX],w[MAX],dp[MAX][10001];
	
	scanf("%d%d",&N,&W);
	v[0]=0;
	w[0]=0;
	for(i=1;i<=N;i++)
	{
		scanf("%d%d",&v[i],&w[i]);
	}
	for(i=0;i<=W;i++)
	{
		dp[0][i]=0;
	}
	for(i=1;i<=N;i++)
	{
		for(j=0;j<=W;j++)
		{
			if(w[i]<=j)
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	printf("%d\n",dp[N][W]);
	return 0;
}

Measured memory_bytes: 4544
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        write("Cloudy");
    }
    else if (S == "Cloudy") {
        write("Rainy");
    }
    else {
        write("Sunny");
    }
}

Measured memory_bytes: 256
S = input()
S_list = []
for i in S:
    S_list.append(i)

w_count = S.count("W")
b_count = S.count("B")
c = 0

for i in range(len(S)):

    if S[i] == "B":
        c += w_count
    else:
        w_count -= 1

print(c)



Measured memory_bytes: 5096
def c(N):
    return int(N * (N-1) / 2)

N = int(input())
A = [int(s)-1 for s in input().split()]

cnt = [0] * N
for Ai in A:
    cnt[Ai] = cnt[Ai]+1

cmb = [0] * N
cmb_sum = 0
for i in range(0,N):
    cmb_sum = cmb_sum + c(cnt[i])

for i in range(0,N):
    print (cmb_sum - c(cnt[A[i]]) + c(cnt[A[i]]-1) )

Measured memory_bytes: 24748
while 1:
    h,w = map(int,input().split())
    if h==0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if i ==0 or i == h-1:
                print("#",end="")
            elif j == 0 or j == w-1:
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")
            


Measured memory_bytes: 7012
#include <iostream>
#include <algorithm>
using  namespace std;
int main()
{
    int n;
    cin>>n;
    int x[n];
    int x2[n];
    for(int i=0;i<n;i++){
        cin>>x[i];
        x2[i]=x[i];
    }

    sort(x,x+n);
    for(int i=0;i<n;i++){
        if(x2[i]<x[n/2])cout<<x[n/2]<<endl;
        else cout<<x[n/2-1]<<endl;
    }
}


Measured memory_bytes: 3712
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N;
    cin >> N;
    vector<ll> Ais(N);
    rep(i,0,N) {
        cin >> Ais[i];
    }
    vector<ll> sum(N+1);
    rep(n,1,N+1) {
        sum[n] = sum[n-1] + Ais[n-1];
    }
    vector<ll> good_divide_left(N);
    ll left = 1;
    rep(n,2,N-2+1) {
        while (left+1 <= n-1
               && abs(sum[left] - (sum[n]-sum[left])) > abs(sum[left+1] - (sum[n]-sum[left+1]))) {
            left++;
        }
        good_divide_left[n] = left;
    }
    vector<ll> good_divide_right(N);
    ll right = 1;
    rrep(n,N-2+1,2) {
        while (right+1 <= N-n-1
               && abs((sum[N]-sum[N-right])-(sum[N-right]-sum[n])) > abs((sum[N]-sum[N-(right+1)])-(sum[N-(right+1)]-sum[n]))) {
            right++;
        }
        good_divide_right[n] = right;
    }
    ll ans = numeric_limits<ll>::max();
    rep(n,2,N-2+1) {
        ll left = good_divide_left[n];
        ll right = good_divide_right[n];
        vector<ll> nums = {sum[left], sum[n] - sum[left], sum[N] - sum[N-right], sum[N-right] - sum[n]};
        ans = min(ans, *max_element(nums.begin(), nums.end()) - *min_element(nums.begin(), nums.end()));
    }
    cout << ans << endl;
}



Measured memory_bytes: 6528
n = gets.to_i
a = gets.chomp.split.map(&:to_i)

a.each.with_index do |key, i|
  j = i - 1
  while j >= 0 && a[j] > key
    a[j+1] = a[j]
    j -= 1
  end
  a[j+1] = key
  puts a.join(' ')
end

Measured memory_bytes: 6120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, x, y, k;
    cin >> a >> b >> c >> k;
    if (k <= a)
    {
        cout << k << endl;
    } else if (k > a)
    {
        x = a;
        k = k - a;
        if (b >= k)
        {
            cout << x << endl;
        } else
        {
            k = k - b;
            x = x - k;
            cout << x << endl;
        }
    }
}

Measured memory_bytes: 3636
import sys
import math
import collections
import bisect
import copy
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    a = na()
    bit = [[0] * 20 for _ in range(n)]
    bitidx = [[] * 20 for _ in range(20)]

    for i, ai in enumerate(a):
        cnt = 0
        while ai > 0:
            if ai & 1:
                bit[i][cnt] = 1
                bitidx[cnt].append(i)
            cnt += 1
            ai >>= 1

    ans = n

    for i in range(n):
        min_idx = n
        for j in range(20):
            # jbit目でiの次に1になるidxを探す　ない場合はlen(bitidx[j])が返ってくる
            tmp = bisect.bisect_left(bitidx[j], i + 1)
            if bit[i][j]:
                # 1のときは次の1を探す
                if tmp < len(bitidx[j]):
                    tmp = bitidx[j][tmp]
                else:
                    tmp = n
            else:
                # 0のときは2つ目の1を探す
                tmp += 1
                if tmp < len(bitidx[j]):
                    tmp = bitidx[j][tmp]
                else:
                    tmp = n
            min_idx = min(min_idx, tmp)
        ans += min_idx - i - 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 221064
s = input()
q = int(input())
ans_list1 = []
ans_list2 = []
flag = 1
for i in range(q):
    i = input().split()
    if i[0]=="1":
        flag *= -1
    else:
        if i[1]=='1':
            if flag==1:
                ans_list1.append(i[2])
            else:
                ans_list2.append(i[2])
        else:
            if flag==1:
                ans_list2.append(i[2])
            else:
                ans_list1.append(i[2])

if flag==1:
    print(''.join(ans_list1[::-1]) + s +''.join(ans_list2))
else:
    print(''.join(ans_list2[::-1]) + s[::-1] +''.join(ans_list1))

Measured memory_bytes: 69848
#include <stdio.h>

#define MAX_NAME_LENGTH 10+1
#define MAX_PROCESS 100000

typedef struct{
    char name[MAX_NAME_LENGTH];
    int time;
}Process;

Process Q[MAX_PROCESS];
int head=0,tail=0;

//?????\??????????´?x?????????????????¢??°
void enqueue(Process x){
    Q[tail]=x;
    if(tail+1 == MAX_PROCESS){
        tail=0;
    }else{
        tail++;
    }
}

//?????\??????????????????????´??????????????????¢??°
Process dequeue(){
    Process x = Q[head];
    if(head+1 == MAX_PROCESS){
        head=0;
    }else{
        head++;
    }
    return x;
}

int main(){
    int n,q,i,count=0;
    Process x;
    scanf("%d %d",&n,&q);   //??????????????°n??¨???????????????n?????\???
    
    for(i=0;i<n;i++){
        scanf("%s %d",x.name,&x.time);
        enqueue(x);         //?????\??????????´?x???????????????
    }
    
    while(1){
        x=dequeue();    //?????\????????????????´????????????????
        if(x.time<=q){  //???????????????????????????????????????????????\????????£?????´???
            count+=x.time;
            printf("%s %d\n",x.name,count);
        }else {         //?????????????????????????????????????????????????????§????????£?????´???
            count+=q;
            x.time-=q;
            enqueue(x); //???????????\?????´???
        }
        if(tail==head)break;//?????\??????head??¨tail????????´??????????????\??????????????????????????£????????´???break
    }
}

Measured memory_bytes: 3272
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

const INF: i64 = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut robots = Vec::new();
    for _ in 0..N {
        let X: i64 = sc.get();
        let L: i64 = sc.get();
        let s = X - L;
        let e = X + L;
        robots.push((s, e));
    }
    robots.sort_by_key(|&(_, e)| e);
    let mut cur = -INF;
    let mut ans = 0;
    for &(s, e) in &robots {
        if cur <= s {
            ans += 1;
            cur = e;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  int i,j,k;
  vector<int> a(M),b(M);
  for ( i=0; i<M; i++ ) {
    cin >> a.at(i) >> b.at(i);
  }
  for ( i=0; i<N; i++) {
    int sum=0;
    for ( j=0; j<M; j++ ){
      if ( a.at(j)==i+1 || b.at(j)==i+1 ) sum++;
    }
    cout << sum << endl;
  }  
}

Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())
A = list(map(lambda x: -int(x), input().split()))
res = -sum(A)
heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)
    a *= -1
    res -= (a - a // 2)
    a //= 2
    heapq.heappush(A, - a)
print(res)

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

int main() {
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == t[i]) cnt++;
  }
  cout << cnt << endl;
  return 0;
  
}

Measured memory_bytes: 256