akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <numeric>
#include <functional>
#include <stdio.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <deque>
#include <queue>
#include <map>

#define rep(i, m, n) for (int (i)(m); (i)<(n); ++(i))
#define repr(i, m, n) for (int (i)(m - 1); (i)>=(n); --(i))
#define repv(i, v) for (unsigned (i)(0); (i)<(v.size()); ++(i))
#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define sortgi(v) sort(all(v), greater<int>())
#define sortgd(v) sort(all(v), greater<double>())
#define sortgll(v) sort(all(v), greater<ll>())
#define debug(x) cerr << #x << ": " << x << '\n'

using namespace std;
using pii = pair<int, int>;
using pss = pair<string, string>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using ll = long long;
using pllll = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vpii = vector<pii>;
using pqi = priority_queue<int>;
using pqd = priority_queue<double>;
using pqll = priority_queue<ll>;
using pqvi = priority_queue<vi>;
using pqvll = priority_queue<vll>;

int main() {
	int n;
	cin >> n;
	int sum = 0;
	rep(i, 1, n + 1) {
		if (i % 2 == 0) {
			continue;
		}
		int y = 0;
		rep(j, 1, i + 1) {
			if (i % j == 0) {
				++y;
			}
		}
		if (y == 8) {
			++sum;
		}
	}
	cout << sum << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl
 
 
template<class T>
vector<vector<T>> cumsum2d(const vector<vector<T>> &v){
    int height = v.size();
    int width = v[0].size();
    vector<vector<T>> cumtmp(height+1,vector<T>(width+1,0));
    vector<vector<T>> cum(height+1,vector<T>(width+1,0));
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            cumtmp[i+1][j+1] = v[i][j] + cumtmp[i+1][j];
        }
    }
    for(int i = 0; i < width; i++){
        for(int j = 0; j < height; j++){
            cum[j+1][i+1] = cumtmp[j+1][i+1] + cum[j][i+1];
        }
    }
    return cum;
}
 
int main(){
    int h, w, k;
    cin >> h >> w >> k;
 
    const int HMAX = 10;
    const int WMAX = 1000;
    vector<vector<int>> field(HMAX, vector<int>(WMAX));
    for(int i = 0; i < h; i++){
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            field[i][j] = s[j]-'0';
        }
    }
 
    vector<vector<int>> cum_field = cumsum2d(field);
  
    int ans = HMAX*WMAX;
    for(int i = 0; i < (1<<(HMAX-1)); i++){
        int cut_cnt = 0;
        vector<int> cut;
        cut.push_back(0);
        for(int j = 0; j < HMAX; j++){
            if(i & 1<<j){
                cut.push_back(j+1);
            }
        }
        cut.push_back(HMAX);
        cut_cnt += cut.size()-2;
 
        int l = 0;
        for(int r = 1; r <= WMAX; r++){
            bool isOK = true;
            for(int j = 0; j < cut.size()-1; j++){
                int white = cum_field[cut[j+1]][r] - cum_field[cut[j+1]][l] - cum_field[cut[j]][r] + cum_field[cut[j]][l];
                if(white>k){isOK = false;}
            }
            if(!isOK){
                if(l == r-1){cut_cnt = HMAX*WMAX; break;}
                l = r-1;
                cut_cnt++;
            }
        }
 
 
 
        ans = min(ans, cut_cnt);
    }
 
    cout << ans << endl;
    return 0;
 
}

Measured memory_bytes: 384
using System;
					
public class Program
{
	public static void Main()
	{
		int[] height, highest;
		
		height = new int[11];
		highest = new int[4]{0,0,0,0};
		
		for(int i = 1; i <= 10; i++)
		{
		height[i] = Int32.Parse(Console.ReadLine());
		
		  for(int j = 1; j<=3; j++)
		  {
		
		    if(height[i] > highest[j])
			{
			 highest[j-1]=highest[j];
			 highest[j]=height[i];
									
		    }
		
		  }
		
		}
		
		
		Console.WriteLine(Convert.ToString(highest[3]) + "\n" + Convert.ToString(highest[2]) +"\n"+ Convert.ToString(highest[1]));
	
}
}


Measured memory_bytes: 17980
package main

import "fmt"

func main() {
	var a, b int

	fmt.Scan(&a)
	fmt.Scan(&b)

	if a < b {
		fmt.Println("a < b")
	} else if a > b {
		fmt.Println("a > b")
	} else {
		fmt.Println("a == b")
	}
}



Measured memory_bytes: 1108
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt();
		int max = a+b;
		if(max < a-b) max = a-b;
		if(max < a*b) max = a*b;
		System.out.println(max);
	}
}



Measured memory_bytes: 23124
n = [int(i) for i in input().split()]
s = input()


class Dice(object):
    def __init__(self,num):
        self.n = num[4]
        self.e = num[2]
        self.w = num[3]
        self.s = num[1]
        self.center = num[0]
        self.back = num[5]

    def move(self,str):
        if str == 'N':
            x = self.n
            self.n = self.center
            self.center = self.s
            self.s = self.back
            self.back = x
            return self.center
        elif str == 'S':
            x = self.s
            self.s = self.center
            self.center = self.n
            self.n = self.back
            self.back = x
            return self.center
        elif str== 'E':
            x = self.e
            self.e = self.center
            self.center = self.w
            self.w = self.back
            self.back = x
            return self.center
        elif str == 'W':
            x = self.w
            self.w = self.center
            self.center = self.e
            self.e = self.back
            self.back = x
            return self.center

dice = Dice(n)
status = 0

for i in range(len(s)):
    status = dice.move(s[i])

print(status)

Measured memory_bytes: 7832
class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1] * (n+1)

    def FindRoot(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.FindRoot(self.parents[x])
            return self.parents[x]
    
    def Union(self,x,y):
        x = self.FindRoot(x)
        y = self.FindRoot(y)

        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def isSame(self,x,y):
        return self.FindRoot(x) == self.FindRoot(y)

    def Size(self,x):
        return -self.parents[self.FindRoot(x)]

n,m,k = [int(x) for x in input().split()]
obj = UnionFind(n)
cnt = [0]*(n+1)
for _ in range(m):
    a,b = [int(x) for x in input().split()]
    obj.Union(a,b)
    cnt[a] += 1
    cnt[b] += 1
for _ in range(k):
    c,d = [int(x) for x in input().split()]
    if obj.isSame(c,d):
        cnt[c] += 1
        cnt[d] += 1
ans = 0
for i in range(1,n+1):
    ans = obj.Size(i)-1-cnt[i]
    print(ans,end=" ")

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int x;
    cin >> x;
    vector<bool> prime(1000000, true);
    for (int i = 2; i < 1000000; ++i) {
        if (!prime[i]) continue;

        for (int j = 2 * i; j < 1000000; j += i) {
            prime[j] = false;
        }
    }

    for (int i = x; i < 1000000; ++i) {
        if (prime[i]){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3732
(* O(n^2) *)
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let _ =
  for x = 0 to n do
    for y = 0 to n - x do
      let z = n - x - y in
      if 10000 * x + 5000 * y + 1000 * z = m then (Printf.printf "%d %d %d \n" x y z; exit 0) done done;
  print_endline "-1 -1 -1"

Measured memory_bytes: 384
def gcd(a,b):
    if b==0:
        return a
    return (gcd(b,a%b))
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
if n==1:
    print(int(input()))
    exit()
ans=1
for i in range(n):
    ans=lcm(ans,int(input()))
print(int(ans))


Measured memory_bytes: 2820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n;
ll a[100005];
ll ans1,ans2;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=n-1;i>=0;i--){
        if(a[i]==a[i-1]){
            if(ans1==0){
                ans1=a[i];
                i=i-1;
            }else{
                ans2=a[i];
                cout<<ans1*ans2<<endl;
                return 0;
            }
        }
    }
    cout<<0<<endl;

}



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

long long f(long long a, long long b){
	return b == 0 ? a: f(b, a % b);
}

int main(){
	long long n, x;
	cin >> n >> x;
	long long ans = n, g = f(n, x);
	cout << n + (n - g) * 2  - g << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int a,b,c; cin >> a >> b >> c;
  set<int> se;
  se.insert(a);
  se.insert(b);
  se.insert(c);

  if(se.size()==2) cout << "Yes";
  else cout << "No";

  

  return 0;
}

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

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



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

    string S, T;
    cin >> S >> T;
    S += S;

    cout << (S.find(T) == string::npos ? "No" : "Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
//#define Mfc_Tanzim
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first
#define ss second
#define all(v) (v.begin(), v.end())
#define pi acos(-1.0)
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define bug(a) cerr << #a << " : " << a << endl
#define pq dp
using namespace std;
const ll mx = 4444444444;

ll posx[] = {1,-1, 0, 0};
ll posy[] = {0, 0, 1,-1};
vector<ll>v, v2;
ll ret = INT_MIN;

int main()
{
    FastRead

#ifdef Mfc_Tanzim
    freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
#endif /// Mfc_Tanzim

    int t=1, n, k, m, a, b, c, d;
    //cin >> t;

    while(t--){
              cin >> n >> k;
              v.resize(n);
              v2.resize(n);
              for(auto &i: v){
                       cin >> i;
              }
              for(auto &i: v2){
                       cin >> i;
              }
              bool vis[n+1];
              ll ans = INT_MIN, nn = n;
              for(int j=0; j<nn; j++){
                       n = j+1;
                       //check(i+1, k, vis);
                       vector<ll>res;
                       ll r = 0;
                       memset(vis, false, sizeof(vis));
                       while(!vis[n-1]){
                                  r+=v2[n-1];
                                  vis[n-1] = true;
                                  res.pb(v2[n-1]);
                                  n = v[n-1];
                       }
                       for(int i=0; i<res.size(); i++){
                                     if(i){
                                            res[i]+=res[i-1];
                                     }
                                     if(i+1<=k){
                                            ans = max(ans, res[i]);
                                     }
                                     else{
                                            break;
                                     }
                                     if(r){
                                            ll kk = res[i]+((k-i-1)/res.size())*r;
                                            ans = max(ans, kk);
                                     }
                       }
              }
              cout << ans << endl;
    }
    return 0;
}





Measured memory_bytes: 3824
H, W = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(H)]

ans = []
for h in range(H):
    for w in range(W - 1):
        if A[h][w] % 2 == 1:
            A[h][w + 1] += 1
            ans.append([h + 1, w + 1, h + 1, w + 2])
    if h < H - 1 and A[h][W - 1] % 2 == 1:
        A[h + 1][W - 1] += 1
        ans.append([h + 1, W, h + 2, W])

print(len(ans))
for a in ans:
    print(*a)

Measured memory_bytes: 30124
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx
  
n,l = map(int, input().split())

a = (list(l + i -1 for i in range(1,n+1)))

print(sum(a) - a[getNearestValue(a, 0)])

Measured memory_bytes: 13224
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();

		StringBuilder builder = new StringBuilder();
		for (char c : s) {
			switch (c) {
			case '0':
				builder.append('0');
				break;
			case '1':
				builder.append('1');
				break;
			case 'B':
				if (builder.length() > 0) {
					builder.deleteCharAt(builder.length() - 1);
				}
				break;
			}
		}

		System.out.println(builder.toString());
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 7892
import math
import itertools
a = int(input())
b = map(int,input().split(' '))
c = map(int,input().split(' '))
x = []
d = 0
e = 0
b = tuple(b)
c = tuple(c)
for i in range(a):
    x.append(i + 1)
y = itertools.permutations(x)
j = 1
for i in y:
    if i == b:
        d = j
    if i == c:
        e = j
    j += 1
print(abs(d - e))

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
//abc170
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    V<int> a(5);
    int ans;
    rep(i,5){
        cin>>a[i];
        if(a[i]==0){
            ans=i+1;
            break;
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int mod = 1e9+7;
//26

int solve(int a, int b){
	int aa = 0, bb = 0;
	while(a != 0){
		aa += a%10;
		a /= 10;
	}
	while(b != 0){
		bb += b%10;
		b /= 10;
	}
	return aa+bb;
}

signed main(){
	int n, ans = INF;
	scanf("%lld", &n);
	rrep(i,n-1){
		int t = solve(i, n-i);
		chmin(ans, t);
	}
	printf("%lld\n", ans);
	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  int n;
  cin >>n;
  int a[n];
  rep(i,n) cin >> a[i];
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0){
	if(a[i]%5!=0){
	  cout << "DENIED" << endl;
	  return 0;
	}
      }
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
	while(true) {
	
		int n;
		
		scanf("%d", &n);
		if(n == 0)
			break;
	
		int up = 1, right = 3, front = 2;
		int sum = 1;
		
		for(int i = 0; i < n; ++i) {
		
			int t;
			char str[64], c;
			
			scanf("%s", str);
			c = str[0];
			
			if(c == 'N') {
			
				t = 7 - up;
				up = front;
				front = t;
			
			} else if(c == 'E') {
			
				t = 7 - right;
				right = up;
				up = t;
			
			} else if(c == 'S') {
			
				t = 7 - front;
				front = up;
				up = t;
			
			} else if(c == 'W') {
			
				t = 7 - up;
				up = right;
				right = t;
			
			} else if(c == 'R') {
			
				t = 7 - front;
				front = right;
				right = t;
			
			} else if(c == 'L') {
			
				t = 7 - right;
				right = front;
				front = t;
			}
			
			sum += up;
		}
		
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, b, n) for (int i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void solve(int N, string S) {
  auto itr = S.begin();
  int l(0), r(0);
  REP(i, N) {
    if (S[i] == '(')
      l++;
    else
      r++;

    if (l < r) {
      S.insert(S.begin(), '(');
      i++;
      N++;
      l++;
     }
  }
  REP(i, l - r)
    S.insert(S.end(), ')');
 
  cout << S << endl;
}

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

  int N;
  string S;
  cin >> N >> S;

  solve(N, S);

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


SIN60 = 0.86602540378
COS60 = 0.5


class KochCurve(object):

    def __init__(self, n, p1=(0.0, 0.0), p2=(100.0, 0.0)):
        self.depth = n
        self.p1_init = p1
        self.p2_init = p2
        self.points = [p1]

    def koch(self, n=None, p1=None, p2=None):
        if n is None:
            n = self.depth
        if p1 is None:
            p1 = self.p1_init
        if p2 is None:
            p2 = self.p2_init
        if n != 0:
            s = ((2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3)
            t = ((p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3)
            ux = (t[0] - s[0]) * COS60 - (t[1] - s[1]) * SIN60 + s[0]
            uy = (t[0] - s[0]) * SIN60 + (t[1] - s[1]) * COS60 + s[1]
            u = (ux, uy)
            self.koch(n - 1, p1, s)
            self.points.append(s)
            self.koch(n - 1, s, u)
            self.points.append(u)
            self.koch(n - 1, u, t)
            self.points.append(t)
            self.koch(n - 1, t, p2)

    def draw_koch(self):
        self.koch()
        self.points.append(self.p2_init)


def main():
    k = KochCurve(n=int(input()))
    k.draw_koch()
    for p in k.points:
        print("{x:.8f} {y:.8f}".format(x=p[0], y=p[1]))


if __name__ == "__main__":
    main()

Measured memory_bytes: 8176
#include <iostream>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
int a[100000];
bool used[100001];

int main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i + 1];
	
	int ans = 0;
	int pos = 1;
	used[1] = true;
	while (true) {
		if (pos == 2) { break; }
		pos = a[pos];
		if (used[pos]) { ans = -1; break; }
		used[pos] = true;
		ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>

#define MAX_N 200010

using namespace std;

int main() {
    int n;
    cin >> n;
    int appear[MAX_N]={0}, longest=0;
    for (int i=0; i<n; i++) {
        int p;
        cin >> p;
        appear[p] = appear[p-1] + 1;
        longest = max(appear[p], longest);
    }
    cout << n - longest << '\n';
    return 0;
}

Measured memory_bytes: 1024
s = input()
q = int(input())
flag = False
l = ''
r = ''
for _ in range(q):
  Q = input().split()
  if Q[0] == '1':
    flag = not flag
  else:
    if flag:
      if Q[1] == '1':
        r += Q[2]
      else:
        l += Q[2]
    else:
      if Q[1] == '1':
        l += Q[2]
      else:
        r += Q[2]
if flag:
  print(''.join(reversed(r)), ''.join(reversed(s)), l, sep='')
else:
  print(''.join(reversed(l)), s, r, sep='')

Measured memory_bytes: 4852
#include<bits/stdc++.h>
#define ll long long int 
#define N 1e6 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef unsigned long long int  uint64;
	
vector<vector<int>> gV(100005+1);
 
int dP[100005]= {0};	
bool vis[100005] = {false};


void dfs(int i){
 
if(vis[i] == true){
	return;
}
 
	vis[i] = true;
	FOR(j, 0, gV[i].size(), 1){
		int nei = gV[i][j];
		
		if(!vis[nei]){
			dfs(nei);
		}
		dP[i] = max(dP[i], dP[nei]+1);
 
	
}
}
 
int main(){

    	ios_base::sync_with_stdio(false); cin.tie(0);
 
    int n, m;
    	cin>> n>> m;
    	
    	
    	FOR(i, 0, m, 1){
    		int x, y;
    		cin>> x>> y;
    		gV[x].PB(y);
    	}
    	
    	FOR(i, 1, n+1, 1){
    		if(!vis[i]){
    			dfs(i);
 
    		}
    	}
    	int max = INT_MIN;
 
    	FOR(i, 1, n+1, 1){
    		if(dP[i]> max){
    			max = dP[i];
    		}
    		
    	}
    	
    	cout<< max<< endl;
 
    		}
    	


Measured memory_bytes: 8320
n, m = map(int, input().split())
hl = list(map(int, input().split()))
ans = [0]*n

for _ in range(m):
    a, b = map(int, input().split())
    if hl[a-1] < hl[b-1]:
        ans[a-1] = 1
    elif hl[a-1] > hl[b-1]:
        ans[b-1] = 1
    else:
        ans[a-1] = 1
        ans[b-1] = 1

print(ans.count(0))


Measured memory_bytes: 20036
use std::collections::{BinaryHeap,BTreeMap};
use std::cmp::Reverse;
fn main() {
    proconio::input! {
        t: usize,
        nabcd: [(i64,i64,i64,i64,i64);t],
    }
    for (n,a,b,c,d) in nabcd {
        let mut e = BTreeMap::new();
        let mut q = BinaryHeap::new();
        q.push((Reverse(0),n));
        while let Some((Reverse(s),i))=q.pop() {
            if e.contains_key(&i) {continue;}
            e.insert(i, s);
            if i==0 {
                break;
            }
            for (k,v) in &[(2,a),(3,b),(5,c)] {
                let r=i%k;
                let c=r*d+v;
                let j=i/k;
                if c>=d.saturating_mul(i-j) {
                    q.push((Reverse(s+i*d),0));
                }
                else {
                    if !e.contains_key(&j) {
                        q.push((Reverse(s+c),j));
                    }
                    if r>0 {
                        let c=(k-r)*d+v;
                        let j=j+1;
                        if c<d.saturating_mul(i-j) && !e.contains_key(&j) {
                            q.push((Reverse(s+c),j));
                        }
                    }
                }
            }
        }
        println!("{}",e.get(&0).unwrap_or(&-1));
    }
}

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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  if (A >= K){
    cout << K << endl;
  }
  else if (A + B >= K){
      cout << A << endl;
    }
  else {
    cout << A + (K - A - B) * -1 << endl;
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int,int>>> edge(N,vector<pair<int,int>>());
    rep(i,N-1){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        edge[a].push_back({b,c});
        edge[b].push_back({a,c});
    }
    vector<ll> dist(N,-1);
    int Q,K;
    cin >> Q >> K;
    K--;
    dist[K]=0;
    deque<int> dq;
    dq.push_back(K);
    while(!dq.empty()){
        int now = dq.front();
        dq.pop_front();
        for(auto e:edge[now]){
            if(dist[e.first]!=-1) continue;
            dist[e.first] = dist[now] + e.second;
            dq.push_back(e.first);
        }
    }
    rep(i,Q){
        int x,y;
        cin >> x >> y;
        x--; y--;
        cout << dist[x] + dist[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 10632
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a ;
    //*/
    
    /*
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(a.begin(), a.end());
    */
    
    /*
    if( a % 3 == 0 || b % 3 == 0 || ( a + b ) % 3 == 0  ){
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    */
    
    cout << "ABC" << a << endl;

    return 0; 
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  int K,T;cin>>K>>T;
  int a,b;cin>>a;
  for(int i=0;i<T-1;i++){
    cin>>b;
    a=max(a,b);
  }
  int ans=a*2-K-1;
  if(ans<0)cout<<0<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main(){

  int r;
  cin >> r;

  cout << 3 * r * r << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define mo 1000000007
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;a
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
  	 int l,r,x;
     cin>>l>>r>>x;
  	 int sum{0};
  	 for(int i=l;i<=r;i++){
       if(i%x==0)
         sum++;
     }
  cout<<sum<<endl;
 return 0; 
}

Measured memory_bytes: 3612
import math


def my_round(x, d=0):
    p = 10 ** d
    return float(math.floor((x * p) + math.copysign(0.5, x))) / p


def solve():
    a, b = list(map(int, input().split(" ")))
    print(int(my_round((a + b) / 2)))


solve()


Measured memory_bytes: 2940
// https://atcoder.jp/contests/abc133/tasks/abc133_c

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) cout << a[_i] << (_i + 1 == n ? endl : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) cout << a[_i][_j] << (_j + 1 == m ? endl : ' '); cout << endl

const int R_MAX = 2*1e9;
const int MOD = 2019;

int L, R;

int main() {
  cin >> L >> R;

  if (R - L + 1 >= MOD){
    cout << 0 << endl;
    return 0;
  }

  int ans = MOD;
  L %= MOD;
  R %= MOD;
  if (R < L) R += MOD;
  FOR(i, L, R) FOR(j, i + 1, R) ans = min(ans, i * j % MOD);
  cout << ans << endl;
}


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

int main() {
	int N;
	cin >> N;
	ll mon = 1000, K = 0;
	vector<ll> A(N + 1, 0);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}

	for (int i = 0;i < N;i++) {
		K += mon / A[i];
		mon %= A[i];
		if (A[i] >= A[i + 1]) {
			mon += K * A[i];
			K = 0;
		}
	}
	cout << mon << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int ans=0, cnt=0;
  string s;
  cin>>s;
  for(int i=0; i<s.length(); i++){
    if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T'){
      cnt++;
      ans=max(ans,cnt);
    }
    else{
      cnt=0;
    }
  }
  cout<<ans<<endl;
}


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

int main()
{
    string s;
    getline(cin, s );


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



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

using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<int> > vvi;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define DEBUG(x) cout<< '>' << #x << ':' << x << "\n";
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define sd(n) scanf("%d",&n)
#define dsd(n) int n; scanf("%d",&n)
#define sd2(a,b) scanf("%d%d",&a,&b)
#define dsd2(a,b) int a,b; scanf("%d%d",&a,&b)
#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dsd3(a,b,c) int a,b,c; scanf("%d%d%d",&a,&b,&c)
#define pd(n) printf("%d\n",n)
#define pds(n) printf("%d ",n)
#define sll(n) scanf("%lld",&n)
#define dsll(n) ll n; scanf("%lld",&n)
#define sll2(a,b) scanf("%lld%lld",&a,&b)
#define dsll2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define sll3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define dsll3(a,b,c) ll a,b,c; scanf("%lld%lld%lld",&a,&b,&c)
#define pll(n) printf("%lld\n",n)	
#define plls(n) printf("%lld ",n)	
#define print(x) cout<< x << "\n"

#define trace(x) cout << '>' << #x << ':' << x << "\n"
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << "\n"
#define trace3(a,b,c) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cout<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

/////////////////////////////////////////////////////////////////////

const int MAX_N = 200010;
const int MAXN = 1010;
//int arr[MAXN][MAXN];

int main(){
    dsd2(N,W);
    vll dp(W+1);
    REP(i,N){
        dsd2(w,v);
        REV(i,W-w+1){
            dp[i+w]=max(dp[i+w],dp[i]+v);
        }
    }
    ll ans=0;
    REP(i,W+1) ans=max(ans,dp[i]);
    pll(ans);
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
  public static void main(String args[]){
    Scanner scan=new Scanner(System.in);
    int a=scan.nextInt();
    int b=scan.nextInt();
    boolean flag=true;
    long aa=a, bb=b;
    while(flag){
      if(aa<bb){
        aa+=a;
      }else if(bb<aa){
        bb+=b;
      }else if(aa==bb){
        flag=false;
      }
    }
    System.out.println(aa);
  }
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int m;
    cin >> m;
    OP(48 - m);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  set<string> st;
  rep(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 19224
S = input()

ans = 0
lenS = len(S)
divider = lenS - 1  # +を入れることのできる個数

for i in range(1, lenS + 1) :
    now = int(S[-i])
    mask = 0
    for j in range(i) :
        mask *= 10
        mask += now * 2**(max(0,j-1))

    ans += mask * 2**(divider - i + 1)

print(ans)

Measured memory_bytes: 3060
let input = "3 8 730\n60 90 120\n80 150 80 150 11 11 11 11 11";

function main(input){
	input = input.trim();
 	let N = parseInt(input.split("\n")[0].split(" ")[0]);
 	let M = parseInt(input.split("\n")[0].split(" ")[1]);
	let K = parseInt(input.split("\n")[0].split(" ")[2]);
  
	let nBooks = input.split("\n")[1].split(" ");
  	for(let i=0; i<nBooks.length; i++){nBooks[i] = parseInt(nBooks[i]);}
	let mBooks = input.split("\n")[2].split(" ");
  	for(let i=0; i<mBooks.length; i++){mBooks[i] = parseInt(mBooks[i]);}
  
 	function getRuiseki(books){
 	  	let ruiseki = 0;
		let Yomu = [];
  		for(let i=0; ruiseki<=K; i++){
          ruiseki += books[i];
          if(ruiseki<=K){Yomu.push(ruiseki);}
        }
      	return(Yomu);
    }

	let nBooksKei = getRuiseki(nBooks);
	let mBooksKei = getRuiseki(mBooks);
 
  	nBooksKei.unshift(0);
  	mBooksKei.unshift(0);
 /* 
  	console.log(K);
	console.log(nBooksKei);
 	console.log(mBooksKei);
  */
	let kiroku = 0;
 	let sinKiroku = 0;
  	let bestJ = M;
 	for(let i=0; i<nBooksKei.length; i++){
      for(let j=bestJ; j>-1; j--){
        if(nBooksKei[i] + mBooksKei[j] <= K){
          	kiroku = i + j;
          	bestJ = j;
          	// console.log(i + ":" + j);
        	if(kiroku>sinKiroku){sinKiroku=kiroku;}
            break;
        }
      }
    }
  	console.log(sinKiroku);
}
//main(input);
main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 58464
#include <bits/stdc++.h>
using namespace std;
int H, W, N, K;
int query(int xa, int ya, int xb, int yb) {
	cout << "? " << xa << ' ' << ya << ' ' << xb - 1 << ' ' << yb - 1 << endl;
	int ret; cin >> ret;
	return ret;
}
int modpow(int a, int b, int m) {
	int ret = 1;
	while(b) {
		if(b & 1) ret = 1LL * ret * a % m;
		a = 1LL * a * a % m;
		b >>= 1;
	}
	return ret;
}
int a[55][55];
int main() {
	cin >> H >> W >> N >> K;
	int r = 3, b = H / r;
	for(int i = 0; i < b; i++) {
		for(int j = 0; j < b; j++) {
			int xl = i * H / b, xr = (i + 1) * H / b, yl = j * W / b, yr = (j + 1) * W / b;
			int cnt = query(xl, yl, xr, yr);
			for(int k = xl; k < xr && cnt > 0; k++) {
				for(int l = yl; l < yr && cnt > 0; l++) {
					a[k][l] = query(k, l, k + 1, l + 1);
					cnt -= a[k][l];
				}
			}
		}
	}
	int ret = 0;
	for(int i = 0; i < H; i++) {
		for(int j = 0; j < W; j++) {
			ret += a[i][j] * modpow(2, i * W + j, K);
			ret %= K;
		}
	}
	cout << "! " << ret << endl;
	return 0;
}

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

int main()
{
	int q, lim, query, x;
	vector<int> List;
	vector<int>::iterator it;
	while(scanf("%d %d", &q, &lim) && q > 0)
	{
		for(int f1 = 1; f1 <= q; f1++){
			scanf("%d %d",&query, &x);
			switch(query)
			{
				case 0:
					List.push_back(x);
					if((int)List.size() > lim){
						it = List.begin();
						List.erase(it);
					}
				break;
				case 1:		
					it = List.begin() + (x - 1);
					List.erase(it);
				break;
				case 2:
					it = List.begin() + (x - 1);
					printf("%d\n", *it);
				break;
				default:
					it = List.begin();
					while(*it != x)
						it++;
					List.erase(it);
				break;
			}
		}
		printf("end\n");
		List.clear();
	}
	return 0;
}

Measured memory_bytes: 1720
// AOJ 0171: Dice Puzzle
// 2017.8.17 bal4u@uu
// 2017.12.29
// ?????????????????¢??¨??????????????????????????°

#include <stdio.h>

int rot[24][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };

int con[8][7][2] = {{{0}},
	{{0},{0},{0},{0},{0,3},{0},{0}},		// ?????????????????¨??¢??????
	{{0},{0},{0,5},{0},{0},{0},{0}},		//   6  7  -- Floor 2
	{{0},{0},{0},{0},{0},{0},{0,1}},		//   3  5  -- Floor 2
	{{0},{0},{1,5},{0},{2,3},{0},{0}},		//   2  4  -- Floor 1 --> Right
	{{0},{0},{0},{0},{3,3},{0},{1,1}},		//   0  1  -- Floor 1
	{{0},{0},{3,5},{0},{0},{0},{2,1}},		//   Front
	{{0},{0},{5,5},{0},{6,3},{0},{4,1}}};

char dice[8][8];
char kari[8][8], f[9];
char tr[128];

char check(int i, char c2)
{
	int j, c1;

	c1 = tr[c2];
	for (j = 1; j <= 6; j++) {
		if (dice[i][j] == c1) return c1;
	}
	return 0;
}

int rec(int n)
{
	int i, j, k, n0, p0, goal, cnt;
	char tbl[7][2], c;


	if (n == 8) return 1;
	for (i = 0; i < 8; i++) {
		if (f[i]) continue;
		goal = cnt = 0;
		for (j = 1; j <= 6; j++) {
			if (!con[n][j][1]) continue;
			goal++;
			n0 = con[n][j][0], p0 = con[n][j][1];
			if (c = check(i, kari[n0][p0])) tbl[cnt][0] = j, tbl[cnt++][1] = c;
		}
		if (cnt != goal) continue;

		for (j = 0; j < 24; j++) {
			for (k = 1; k <= 6; k++) kari[n][k] = dice[i][rot[j][k]];
			for (k = 0; k < cnt; k++) {
				if (kari[n][tbl[k][0]] != tbl[k][1]) break;
			}
			if (k < cnt) continue;
			f[i] = 1;
			if (rec(n+1)) return 1;
			f[i] = 0;
		}
	}
	return 0;
}

int main()
{
	int i, j, k;
	char buf[10];

	for (i = 0; i < 26; i++) tr['a'+i] = 'A'+i, tr['A'+i] = 'a'+i;

	while (1) {
		for (i = 0; i < 8; i++) {
			fgets(buf, 10, stdin);
			if (*buf == '0') return 0;
			for (j = 0; j < 6; j++) dice[i][j+1] = buf[j];
			f[i] = 0;
		}
		for (i = 0; ; i++) {
			if (i == 8) { puts("NO"); break; }
			f[i] = 1;
			for (j = 0; j < 24; j++) {
				for (k = 1; k <= 6; k++) kari[0][k] = dice[i][rot[j][k]];
				if (rec(1)) { puts("YES"); goto next; }
			}
			f[i] = 0;
		}
		next:;
	}
	return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
using namespace std;

int n, k;
long long w[100000];

int check(long long P){
    int i = 0;
    for(int j = 0; j < k; j++){
        long long s = 0;
        while(s + w[i] <= P){
            s += w[i];
            i++;
            if(i == n){
                return n;
            }
        }
    }
    return i;
}

int solve(){
    long long mid,  left = 0, right = 100000*10000;
    while(right - left > 1){
        mid = (left + right)/2;
        int v = check(mid);
        if(v >= n){
            right = mid;
        }
        else{
            left = mid;
        }
    }
    return right;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    cin>>k;
    rep(i, n){
        cin>>w[i];
    }
    long long ans;
    ans = solve();

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4000
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	string s; cin >> s;
	int n = s.length();
	bool ok = (n % 2 == 0);
	string t = "hi";
	for (int i = 0; i < n; ++i) {
		ok &= (s[i] == t[i & 1]);
	}
	if (ok) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

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

int A,B;

void DFS(queue<char> array,char c,int Acount,int Bcount){

  array.push(c);

  if(A == Acount && B == Bcount){
    for(int i=0;i<A+B;i++){
      cout << array.front();
      array.pop();
    }
    cout << endl;
    return;
  }

  if( (Acount == 5 && Bcount <= 3) || (Bcount == 5 && Acount <= 3) ){ //???????????????????????¶????????????????????????????????¶?????¨?????´??????????????????
    return;
  }

  if(A>Acount){
    DFS(array,'A',Acount+1,Bcount);
  }
  if(B>Bcount){
    DFS(array,'B',Acount,Bcount+1);
  }

}

int main(){

  cin >> A >> B;
  queue<char> s;
  DFS(s,'A',1,0);
  DFS(s,'B',0,1);
  return 0;
}

Measured memory_bytes: 3096
#!python3.4.3

n = input()
a_list = list(map(int, input().split(' ')))
 
result = 'APPROVED'
 
for a in a_list:
    if a%2 == 0 and (a%3 != 0 and a%5 != 0):
        result = 'DENIED'
        break
 
print(result)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ii = pair<int, int>;
using ll = long long;

int32_t main(){
	ios::sync_with_stdio(0);
	int p, n;
	cin >> p >> n;
	vector<int> vs(n);
	vector<int> dff(n-1);

	int ans = 0;
	for(int i=0; i<n; ++i){
		cin >> vs[i];
		if(i>0) dff[i-1] = vs[i]-vs[i-1], ans += dff[i-1];
	}
	int rest = p-ans;
	int w = ans;
	for(auto x:dff)
		w = min(w, ans-x+rest);
	cout << w << endl;
}


Measured memory_bytes: 4828
import java.io.IOException;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		int m = sc.nextInt();
		int f = sc.nextInt();
		int b = sc.nextInt();
		
		if(m >= b) {
			System.out.println(0);
		}else if(m + f >= b) {
			System.out.println(b - m);
		}else {
			System.out.println("NA");
		}
	}
}


Measured memory_bytes: 26136