akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  a <- unsafeTextToInt <$> T.getLine :: IO Int
  print $ a + a * a + a * a * a

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,n;
	cin >> n >> a >> b;
	if(n<1){
		cout << 0 << endl;
		return 0;
	}else if(b<a){
		cout << 0 << endl;
		return 0;
	}else if(n==1 && a!=b){
		cout << 0 << endl;
		return 0;
	}
	ll ans = (n-2)*(b-a) + 1;
	cout << ans << endl;
	return 0;
}

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

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
  
  ll p,q,r,s;
  cin>>p>>q>>r>>s;
  
  ll maximum = -1000000000000000000;
  
  if(maximum<(q*s)){
    maximum = (q*s) ;
  }
  if(maximum<(p*s)){
    maximum = (p*s);
  }
  if(maximum<(q*r)){
    maximum = (q*r);
  }
  if(maximum<(p*r)){
    maximum = (p*r);
  }
  
  cout<<maximum<<endl;
  return 0;
}



Measured memory_bytes: 3632
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int n, x, max;
	int a, b, c;
	int ans;

	while (1) {
		scanf("%d%d", &n, &x);
		if (n == 0 && x == 0) break;

		ans = 0;
		max = x; if (max > n) max = n;
		for (a = 1; a <= max; a++) {
			for (b = a + 1; b <= max; b++) {
				c = x - a - b;
				if (c > b && c <= n) ans++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2076
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        DJSet dj = new DJSet(n);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < q; i++) {
            int t = sc.nextInt();
            int u = sc.nextInt();
            int v = sc.nextInt();
            if(t == 0) {
                dj.union(u, v);
            }else {
                if(dj.same(u, v)) {
                    sb.append("1\n");
                }else {
                    sb.append("0\n");
                }
            }
        }
        System.out.println(sb.toString());
        sc.close();

    }

}

class DJSet {
    /**
     * 各要素の親を保持する配列.<br>
     * 自信が根である要素は負の数を持つ.
     * （負の数の場合、絶対値がその集合の要素数）
     */
    public int[] upper;

    /**
     * コンストラクタ.
     * @param n 対象となる要素数
     */
    public DJSet(int n){
        upper = new int[n];
        Arrays.fill(upper, -1);
    }

    /**
     * 要素xが含まれる集合のrootを求める.<br>
     * rootを求める過程で経路圧縮しrootが親になるようにする.
     * @param x 要素x
     * @return 要素xが含まれる集合のroot
     */
    public int root(int x){
        return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
    }

    /**
     * 要素xと要素yが同じ集合か判定する.
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yが同じ集合であればtrue、そうでなければfalseを返す。
     */
    public boolean same(int x, int y){
        return root(x) == root(y);
    }

    /**
     * 要素xと要素yを含むそれぞれの集合を合併する.
     * 要素数の多い集合のrootを残し、少ないほうのrootをその下に合併する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yを含むそれぞれの集合を合併できたらtrue、もともと同じ集合で合併しなかったらfalseを返す。
     */
    public boolean union(int x, int y){
        x = root(x);
        y = root(y);
        if(x != y){
            if(upper[y] < upper[x]){
                int t = x;
                x = y;
                y = t;
            }
            upper[x] += upper[y];
            upper[y] = x;
        }
        return x != y;
    }

    /**
     * 集合の数を数える.
     * @return 集合の数
     */
    public int countSet(){
        int c = 0;
        for(int u :upper){
            if(u < 0) c++;
        }
        return c;
    }

    /**
     * 要素ｘが含まれる集合の要素数を数える.
     * @param x 要素ｘ
     * @return 要素ｘが含まれる集合の要素数
     */
    public int countElement(int x){
        return upper[root(x)] * -1;
    }

    /**
     * 連結成分ごとの頂点リストのリストを取得する.
     * @return 連結成分ごとの頂点リストのリスト
     */
    public List<List<Integer>> groups(){
        List<List<Integer>> groups = new ArrayList<>();
        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < upper.length; i++) {
            Integer root = upper[i] < 0 ? i : upper[i];
            if(!map.containsKey(root)) {
                List<Integer> list = new ArrayList<>();
                map.put(root, list);
                groups.add(list);
            }
            map.get(root).add(i);
        }
        return groups;
    }
}


Measured memory_bytes: 59992
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;


int main() {
  int x, n; cin >> x >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  sort(all(p));

  vector<int> q;

  for (int i = 1; i <= 100; i++) {
    bool exist = false;
    rep(j, n) {
      if (p[j] == i) {
        exist = true;
        break;
      }
    }
    if (!exist) q.push_back(i);
  }

  q.push_back(0);
  q.push_back(101);

  for (int i = 0; i < q.size(); ++i) q[i] = abs(q[i] - x);

  sort(all(q));

  int ans1 = x - q[0];
  int ans2 = x + q[0];

  int ans = min(ans1, ans2);

  rep(i, n) {
    if (ans1 == p[i]) {
      ans = ans2;
      break;
    } else if (ans2 == p[i]) {
      ans = ans1;
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char c;
    cin>>c;
    if(c=='A')cout<<'T';
    else if(c=='C')cout<<'G';
    else if(c=='T')cout<<'A';
    else cout<<'C';
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int i;
  int N = rd_int();
  long long res = 0;
  for(i=(1);i<(N+1);i++){
    if(i%3 && i%5){
      res += i;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200412-1

// --- original code ---
// {
//   int N = rd_int();
//   ll res = 0;
//   rep(i,1,N+1) if(i%3 && i%5) res += i;
//   wt(res);
// }


Measured memory_bytes: 3628
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

fn cost(ij: (i32, i32), xy: (i32, i32)) -> i32 {
  (xy.0 - ij.0).abs() + (xy.1 - ij.1).abs()
}

fn main() {
  input! {
    h: usize,
    w: usize,
    d: usize,
    field: [[usize1; w]; h],
    q: usize,
    query: [(usize1, usize1); q],
  }
  let mut rev = vec![(0, 0); h * w];
  for i in 0 .. h {
    for j in 0 .. w {
      rev[field[i][j]] = (i as i32, j as i32);
    }
  }
  let mut total = vec![0; h * w];
  for k in d .. h * w {
    total[k] = total[k - d] + cost(rev[k - d], rev[k]);
  }
  for &(l, r) in &query {
    println!("{}", total[r] - total[l]);
  }
}


Measured memory_bytes: 11388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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; }
int main(){
    ll n,a,b; cin>>n>>a>>b;
    string s; cin>>s;
    ll dom=0, foreign=0;
    rep(i,n){
        if(s[i]=='a'){
            if(dom+foreign<a+b){cout<<"Yes"<<endl; dom++;}
            else cout<<"No"<<endl;
        }
        else if(s[i]=='b'){
            if(dom+foreign<a+b && foreign<b){cout<<"Yes"<<endl; foreign++;}
            else cout<<"No"<<endl;
        }
        else{
            cout<<"No"<<endl;
            continue;
        }
    }
    return 0;
}

Measured memory_bytes: 896
# C - Energy Drink cntlector

N, M = map(int, input().split())
AB = []
for i in range(N):
    ab = list(map(int, input().split()))
    AB.append(ab)

AB = sorted(AB, key=lambda x: x[0])

cnt = 0
ans = 0
for i in range(N):
    cnt = min(M, AB[i][1])
    M -= cnt
    ans += AB[i][0] * cnt
    if M==0:
        break

print(ans)

Measured memory_bytes: 29792
#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;

int main() 
{
	int n = -100000;
	int a, b;
	while (cin >> a >> b, a || b) {
		vector<int>s(a);
		for (int c = 0; c < a; c++)cin >> s[c];
		int m = 0;
		for (int e = 0; e < b; e++) {
			m += s[e];
		}
		if (n < m)n = m;
		for (int d = 0; d < a - b; d++) {
			m -= s[d];
			m += s[d + b];
			if (n < m)n = m;
		}
		cout << n << endl;
	}
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define int LL
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef pair<ut,ut> prs;
const int SIZE=2*1e6;
const LL p=7+1e9;
LL BIT[SIZE];
void add(int x,LL val){
	while(x<=SIZE){
		BIT[x]+=val+p;
		BIT[x]%=p;
		x+=x&-x;
	}
}
void add(int a,int b,LL val){
	add(a,val);
	add(b+1,p-val);
}
LL sum(int x){
	LL ans=0;
	while(x>0){
		ans+=BIT[x]+p;
		x-=x&-x;
		ans%=p;
	}
	return ans;
}
LL getval(int x){
	if(x==0) return 1;
	return sum(x);
}
signed main(){
	int n;
	cin >> n;
	LL ans=0;
	REP(i,n){
		if(i!=n-1)ans+=getval(i)*((n-1)*(n)%p+p-max(0LL,n-i-3))%p;
		else ans+=getval(i)*n;
		add(i+1,i+1,getval(i));
		add(i+3,n,getval(i));
		ans%=p;
	}
	cout << (ans)%p << endl;
	return 0;
}

Measured memory_bytes: 10496
A, B, C = map(int, input().split())

# 問題：
#     水を入れる容器が 2つあります。
#     容器 1には水を A ミリリットルまで入れることができ、
#     水が B ミリリットル入っています。
#     容器 2 には水が C ミリリットル入っています。
#     容器 2 から容器 1 に入るだけ水を移します。
#     容器 2 の中には何ミリリットルの水が残るでしょうか。

i = B + C - A
if i > 0:
    print(i)
else:
    print(0)

Measured memory_bytes: 9112
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1E9 + 9;
const int INF = 1<<29; 

int main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    vector<vector<int> > dp(N + 1, vector<int>(H + 10000, INF));
    dp[0][0] = 0;
    rep(i, N){
        rep(j, H + 10000){
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i]);
        }
    }

    int ans = INF;
    for(int j = H; j < H + 10000; j++){
        ans = min(ans, dp[N][j]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 78592
#include <bits/stdc++.h>
using ll= long long ;
#define rep(i,n) for (ll i = 1; i<=(ll)(n); i++)
using namespace std;
using P = pair<ll,ll>;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}

int main() {
    string s;
    cin>> s;
    if(s.find("7")!= string::npos)
    cout<<"Yes"<<endl;
    else
    cout << "No"<<endl;
    return 0;
    }
    

Measured memory_bytes: 3628
n=int(input())
l=sorted(list(map(int,input().split())))
ans=0
for i in range(n):
  for j in range(i+1,n):
    left=j+1
    right=n
    while left<right:
      mid=(left+right)//2
      if l[mid]>=l[i]+l[j]:
        right=mid
      else:
        left=mid+1
    ans+=right-j-1
print(ans)

Measured memory_bytes: 73924
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <unordered_set>

using namespace std;

int main()
{
	long long val, sum = 0;
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		cin >> val;
		sum += val;
	}
	if (sum > n) cout << -1;
	else cout << n - sum;
	return 0;
}

Measured memory_bytes: 3636
// AOJ 2494 Sliding GCD
// 2018.3.18 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX   100000
#define DMAX     130	// max 126

int t[MAX+1][DMAX+1], w[MAX+1];
int c[MAX+1];

void divisor_tble(int N)
{
	int i, k;
	for (i = 2; i <= N; i++) {
		for (k = i<<1; k <= N; k += i) t[k][w[k]++] = i;
	}
}

int main()
{
	int  N, W, nw, i, j, k, lo, hi, ans;

	scanf("%d%d", &N, &W), nw = N-W+1;
	if (W == 1) {
		putchar('1');
		for (k = 2; k <= nw; k++) putchar(' '), putchar('1');
		putchar('\n');
		return 0;
	}

	divisor_tble(N);

	printf("%d", W);
	ans = 0;
	for (i = 1; i <= W; i++) {
		for (j = 0; j < w[i]; j++) {
			if (++c[t[i][j]] == 2) ans++;
		}
	}

	lo = 1, hi = W+1;
	for (k = 2; k <= nw; k++) {
		for (i = 0; i < w[lo]; i++) {
			if (--c[t[lo][i]] == 1) ans--;
		}
		lo++;
		for (i = 0; i < w[hi]; i++) {
			if (++c[t[hi][i]] == 2) ans++;
		}
		hi++;
		j = 0; for (i = lo; i <= hi; i++) if (c[i] < 2) j++;
//printf("\nk %d, lo %d, hi %d, ans %d, j %d\n", k, lo, hi, ans, j);
		printf(" %d", ans+j);
	}
	putchar('\n');
	return 0;
}


Measured memory_bytes: 53520
#include<stdio.h>
int main(void){
int N,l,i;scanf("%d",&N);
int A[N],E[N+1];
for(i=0;i<=N-1;i++){
scanf("%d",&A[i]);
E[A[i]]=i+1;}
for(l=1;l<=N;l++)printf("%d ",E[l]);
return 0;}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int ans=-1;
    map<int,int>m;
    r(i,n){
      int a;
      scanf("%d",&a);
      m[a]++;
      if(m[a]>n/2)ans=a;
    }
    if(ans==-1)cout<<"NO COLOR"<<endl;
    else cout<<ans<<endl;
  }
}


Measured memory_bytes: 4688
#include<iostream>
#include<algorithm>
#include <vector>
#include <set>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
		cout<<"YES"<<endl;
	else cout<<"NO";
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))

mainasu=[]
purasu=[]
for aa in a:
    if aa>=0:
        purasu.append(aa)
    else:
        mainasu.append(aa*(-1))



mod=10**9+7

#回答がプラスになるケース
if (k<n and len(purasu)>0) or (k<n and k%2==0) or (k==n and len(mainasu)%2==0):
    p_pos=0
    m_pos=0
    mainasu.sort(reverse=True)
    purasu.sort(reverse=True)
    ans=1
    cnt=0
    while cnt<k:
        ans=ans%mod
        #どっちからでも選べる
        if p_pos<len(purasu) and m_pos+1 < len(mainasu) and cnt<k-1:
            #もし最後から2つ目
            if cnt<=k-2:
                if p_pos==len(purasu)-1:
                    ans*=mainasu[m_pos]%mod
                    m_pos+=1
                    ans*=mainasu[m_pos]%mod
                    m_pos+=1
                    cnt+=2
                elif purasu[p_pos]*purasu[p_pos+1]>mainasu[m_pos]*mainasu[m_pos+1]:
                    if cnt==k-2:
                        ans*=purasu[p_pos]%mod
                        p_pos+=1
                        ans*=purasu[p_pos]%mod
                        p_pos+=1
                        cnt+=2
                    else:
                        ans*=purasu[p_pos]%mod
                        p_pos+=1
                        cnt+=1

                else:
                    ans*=mainasu[m_pos]%mod
                    m_pos+=1
                    ans*=mainasu[m_pos]%mod
                    m_pos+=1
                    cnt+=2
            else:
                if purasu[p_pos]>mainasu[m_pos+1]:
                    ans=ans*purasu[p_pos]%mod
                    cnt+=1
                    p_pos+=1
                else:
                    ans*=mainasu[m_pos]%mod
                    m_pos+=1
                    ans*=mainasu[m_pos]%mod
                    m_pos+=1
                    cnt+=2
        elif p_pos<len(purasu):
            ans=ans*purasu[p_pos]%mod
            cnt+=1
            p_pos+=1
        else:
            ans*=mainasu[m_pos]%mod
            m_pos+=1
            ans*=mainasu[m_pos]%mod
            m_pos+=1
            cnt+=2
    print(ans%mod)









#回答がマイナスになるケース
else:
    pm=purasu+mainasu
    pm.sort()
    ans=1
    for i in range(k):
        ans=ans*pm[i]%mod
        ans=ans%mod
    #print(-1*ans)
    print((-1*ans)%mod)








Measured memory_bytes: 108552
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
    int k;
    cin>>k;
    set<int> st;
    ll cnt=1;
    ll sum=7%k;
    st.insert(sum);
    int f=1;
    while(sum!=0)
    {
         sum=(10LL*sum+7)%k;
           cnt++;
        if(st.count(sum)>0)
        {
            f=0;
            break;

        }
        st.insert(sum);
       
        
    }
    if(!f) cout<<"-1\n";
    else cout<<cnt<<endl;
}


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

int main() {
    ll n, k;
    cin >> n >> k;
    map<int, ll> s;
    for(int i=0; i<n; i++){
        int a, b;
        cin >> a >> b;
        s[a] += b;
    }
    for(auto itr=s.begin(); itr!=s.end(); itr++){
        if(k<=itr->second){
            cout << itr->first << endl;
            break;
        }
        k-=itr->second;
    }
    return 0;
}

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

int main()
{
	int n, p;
	while (cin >> n >> p, n || p) {
		int save_p = p;
		vector<int> keeps(n, 0);
		for (int i = 0; true; ++i) {
			i %= n;
			if (p) {
				++keeps[i];
				--p;
				if (keeps[i] == save_p) {
					cout << i << endl;
					break;
				}
			} else {
				p = keeps[i];
				keeps[i] = 0;
			}
		}
	}
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
char s[300000];
int d[300001];

int main(void){
  int n, i, min;
  scanf("%d",&n);
  scanf("%s",s);
  d[0] = 0;
  for(i=0;i<n;i++){
    d[i+1] = 0;
    if(s[i] == 'E'){
      d[0]++;   d[i]--;
    } else {
      d[i+1]++;
    }
  }
  min = d[0];
  for(i=1;i<n;i++){
    d[i] += d[i-1];
    if(min > d[i]) min = d[i];
  }
  printf("%d\n",min);

  return 0;
}


Measured memory_bytes: 1664
#include<iostream>
using namespace std;
const int maxn=100005;
const int inf=0x3f3f3f3f;
long long n,w,k,dp[maxn],a[maxn],v[maxn];
int main()
{
	cin>>n>>w;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i]>>v[i];
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=w;j>=a[i];j--)
		{
			dp[j]=max(dp[j],dp[j-a[i]]+v[i]);
		}
	}
	cout<<dp[w]<<endl;
	return 0;
}

Measured memory_bytes: 4400
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	
	if((a^b)==0&&(b^c)!=0||(a^c)==0&&(b^c)!=0||(b^c)==0&&(a^c)!=0)
	{
	
		cout<<"Yes"<<endl;
}
	else
	{
	
	cout<<"No"<<endl;
}
	return 0;
} 

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int H,W;
	int h,w;
	int white;
	
	scanf("%d%d",&H,&W);
	scanf("%d%d",&h,&w);
	white=(H*W)-(h*W)-(H*w)+(h*w);
	printf("%d",white);
return 0;
}


Measured memory_bytes: 128
n,k = map(int,input().split())
if n % k == 0:
    print(0)
else:
    a = [n]
    b = n//k
    c = n-(b*k)
    half = k//2
    while c > half:
        c = abs(c-k)
    a.append(c)
    print(min(a))

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


int MinSteps(int arr[],int N,int K)
{
  int dp[N];

  dp[N-1] = 0;
  dp[N-2] = abs(arr[N-1]-arr[N-2]);

  for (int i = N-3; i>= 0; i--)
  {     long int min = 10000000000;
        for (int j = 1;(j<=K && (i+j < N));j++)
       {
           if ( min > (dp[i+j]+abs(arr[i]-arr[i+j])))
           min = dp[i+j]+abs(arr[i]-arr[i+j]);
       }
       dp[i] = min;
  }

  return dp[0];
}

int main()
{
  int N,K;
  cin >> N >> K;
  int arr[N];
  for (int i = 0;i<N;i++)
  cin >> arr[i];

  cout << MinSteps(arr,N,K) << endl;

  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <math.h>
#include <limits.h>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> vec(n, -1);
	for (int i = 0; i < m; i++) {
		int pos, num;
		cin >> pos >> num;
		if (vec[pos - 1] != -1 && vec[pos-1] != num) {
			cout << -1 << endl;
			return 0;
		}
		vec[pos - 1] = num;
	}
	string ans = "";
	for (int i = 0; i < n; i++) {
		if (i == 0 && vec[0] == -1 && n == 1) {
			cout << 0 << endl;
			return 0;
		}
		else if (i == 0 && vec[0] == -1) {
			ans += "1";
		}
		else {
			if (vec[i] == -1) {
				ans += "0";
			}
			else {
				ans += to_string(vec[i]);
			}
		}
	}
	int res = stoi(ans);
	if (to_string(res).length() != n) {
		cout << -1 << endl;
	}
	else cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h;
    int n;
    cin >> h >> n;
    ll sum = 0;
    rep(i,n){
        ll a;
        cin >> a;
        sum += a;
    }
    if(h <= sum) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.stream.Collectors;

class Main{
    public void run(){
        parseInput().stream()
            .forEach(n -> resultPrint(n));
    }
    public void resultPrint(String[] array){
        Deque<Integer> num = new ArrayDeque<>();
        Arrays.stream(array).forEach(n -> {
            if(Objects.equals(n ,"+")){
                num.addFirst(num.removeFirst() + num.removeFirst());
            }
            else if(Objects.equals(n ,"-")){
                int a = num.removeFirst();
                int b = num.removeFirst();
                num.addFirst((b - a));
            }
            else if(Objects.equals(n ,"*")){
                num.addFirst((num.removeFirst() * num.removeFirst()));
            }else{
                num.addFirst(Integer.parseInt(n));
            }
        });
        System.out.println(num.removeFirst());
    }

    public List<String[]> parseInput(){
        return new BufferedReader(new InputStreamReader(System.in)).lines()
            .filter(n -> !Objects.equals(n, ""))
            .map(i -> i.split(" "))
            .collect(Collectors.toList());
    }
    public static void main(String[] args){
        new Main().run();
    }
}

Measured memory_bytes: 31028
#include<iostream>
using namespace std;
int main(){
	int a[10000], i;
	
	
	for (i = 0; i < 10000; i++){
		cin >> a[i]; 
		if (a[i]!=0){
			cout << "Case " << i+1 << ": " << a[i] << endl;
		}
		if (a[i] == 0){
			break;
		}
	}
	
		
	

	return 0;
}


Measured memory_bytes: 3092
#include <algorithm>
#include <iostream>
using namespace std;
using ll = long long;

int L, n, x[200005], x2[200005];

ll solve() {
    ll sum = x[n];
    ll ans = sum;
    for (int i = n - 1; i > 0; --i) {
        int cntr = n - i;  // 2*n-2i+1<=n+1
        int cntl = i;
        if (cntr <= cntl) {
            sum += 2LL * (L - x[i + 1]);
            sum -= 2LL * (x[i] - x[i - cntr + 1]);
            sum -= x[i + 1] - x[i];
            sum += 2LL * x[i - cntr];
            // printf("+ %lld - %lld - %lld + %lld\n", 2LL * (L - x[n + 1]), 2LL * (x[i] - x[i - cnt + 1]), x[i + 1] - x[i], 2LL * x[i - cnt]);
            // printf("Round 1.1 i = %d, sum = %lld\n", i, sum);
        } else {
            sum -= 2LL * x[i];
            sum -= x[i + 1] - x[i];
            sum += 2LL * (x[i + 1 + cntl] - x[i + 1]);
            // if cntr > cntl, n-i > i, i+i < n, i+i+1 <= n
            sum -= 2LL * (L - x[i + cntl + 2]);
            // printf("Round 1.2 i = %d, sum = %lld\n", i, sum);
        }
        ans = max(ans, sum);
    }
    return ans;
}

int main() {
    // freopen("data.txt", "r", stdin);
    scanf("%d%d", &L, &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", x + i);
    }
    x[n + 1] = L;

    ll ans = solve();

    for (int i = 1; i <= n; ++i) {
        x2[i] = -x[n - i + 1] + L;
    }
    for (int i = 1; i <= n; ++i) {
        x[i] = x2[i];
        // printf("%d ", x[i]);
    }
    // printf("\n");
    ans = max(ans, solve());
    printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <cmath>
#include <numeric>
#include <functional>
#include <stack>
#include <iomanip>
#include <map>
#include <cstdio>

int main() {
	long long n, k;

	std::cin >> n >> k;

	std::vector<long long> v(n);

	for (long long i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}

	std::sort(v.begin(), v.end());
	std::reverse(v.begin(), v.end());

	long long ans = 0;
	for (long long i = k; i < n; i++)
	{
		ans += v[i];
	}

	std::cout << ans << std::endl;

	return 0;
}


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

int main()
{
	std::string s, p;
	std::cin >> s >> p;
	s += s;
	if (s.find(p) != std::string::npos)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";

    return 0;
}




Measured memory_bytes: 3236
//By Don4ick
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

using namespace std;


string s[10];
int n, m , cnt;

int get(int i,int j){
	if(i < n && j < m)
    	return max(get(i + 1, j), get(i, j + 1)) + (s[i][j] == '#');
	else
		return 0;
}
int main()
{
	//ios_base::sync_with_stdio(false);
	//cin.tie(NULL);
	//cout.tie(NULL);

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		for(int j = 0; j < m; j++)
			if(s[i][j] == '#')
				cnt++;
	}
	for(int i = 0;i < n; i++)
		for(int j = 0; j < m; j++)
			if(get(i, j) == cnt)
				cout << "Possible", exit(0);
	cout << "Impossible";
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:52:46 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

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

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break

"""
S = input()

tmp = 0
cnt = 0
for i in range(len(S)):
    if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
        cnt += 1
        if tmp < cnt:
            tmp = cnt
    else:
        if tmp < cnt:
            tmp = cnt
        else:
            pass
        cnt = 0
res = tmp
print(tmp)
        

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

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

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

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: [[usize; 3]; 3],
        n: usize,
        bs: [usize; n]
    }
    let mut f = vec![vec![false; 3]; 3];
    for &b in &bs {
        for i in 0..3 {
            for j in 0..3 {
                if a[i][j] == b {
                    f[i][j] = true;
                }
            }
        }
    }
    for i in 0..3 {
        if f[i][0] && f[i][1] && f[i][2] {
            println!("Yes");
            return;
        }
        if f[0][i] && f[1][i] && f[2][i] {
            println!("Yes");
            return;
        }
    }
    if f[0][0] && f[1][1] && f[2][2] || f[2][0] && f[1][1] && f[0][2] {
        println!("Yes");
        return;
    }
    println!("No");
}


Measured memory_bytes: 4352
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int A, B;
	cin >> A >> B;



	co(6 - A - B);

	Would you please return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
struct process {
  char name[11];
  int time = 0;
};

class Queue {
  private:
    process tmp,*queue;
    int num,start,last;
  public:
    Queue(int n) {
      start = last = 0;
      num = n;
      queue = new process[200000];
    }
    ~Queue() {
      delete[] queue;
    }
    void enqueue(process p) {
      queue[last++] = p;
    }

    process dequeue() {
      return queue[start++];
    }

    bool is_empty() {
      if (start == last) return true;
      return false;
    }
};

int main() {
  int n, q, time, count = 0;
  char name[11];
  process tmp;
  scanf("%d %d", &n, &q);
  Queue queue(n);
  for (int i = 0; i < n; i++) {
    scanf("%s %d", tmp.name, &tmp.time);
    queue.enqueue(tmp);
  }
  while(!queue.is_empty()) {
    tmp = queue.dequeue();
    for (int i = 0; i < q; i++) {
      tmp.time -= 1;
      count++;
      if (tmp.time == 0) {
        printf("%s %d\n", tmp.name, count);
        break;
      }
    }
    if (tmp.time > 0) queue.enqueue(tmp);
  }
  return 0;
}



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

#define ll long long
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define MAX 1000000

vector<bool>prime(MAX, true);
vector<ll>fact(MAX);
vector<ll>factinv(MAX);

ll  fastpower(ll a, ll n)
{
	ll res = 1;
	while(n > 0)
	{
		if(n % 2 != 0)
		{
			res = (res * a) % MOD;
		}
		n /= 2;
		a=(a * a) % MOD;
	}
	return res;
}

void getprime()
{
	for(ll i = 2;i < MAX; i++)
	{
		if(prime[i-1])
		{
			for(ll j = i*i; j < MAX; j += i)
				prime[j-1] = false;
		}
	}
}

void getfact()
{
	fact[0] = 1;
	factinv[0] = 1;
	
	for(ll i = 1; i < MAX; i++)
		fact[i] = (fact[i-1] * i)%MOD;
	
	for(ll i = 1; i < MAX; i++)
		factinv[i] = (factinv[i-1] * fastpower(i, MOD -2) )%MOD;

}
/*
char find(char x, vector<char>&par)
{
	if(par[x]=='$')
		return x;
	else
		return find(par[x], par);
}
void unionn(char x, char y, vector<char>par)
{
	char a=find(x,par);
	char b=find(y,pR);
	if(a!=b)
	{
		par[a]=b;
	}
}
*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll t,n,m,q;
	cin>>n>>m;
	vector<ll>a(m);
	for(ll i=0;i<m;i++) cin>>a[i];
	ll sum=0;
	for(ll i=0;i<m;i++) sum+=a[i];
	if(n>=sum)
		cout<<(n-sum);
	else
		cout<<"-1";
	return 0;
}

Measured memory_bytes: 19228
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 1000005
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define P pair<int,int> 
#define INF 1000000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
	int k;
    cin>>k;
    int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    OUT(a[k-1]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
   int i,N;
   char a[100];
   int y;
   
   scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%c",&a[i]);
  }
  
  for(i=0;i<N;i++){
    if(a[i]=='Y'){
      printf("Four");
      return 0;
    }
    else{
    }
  }
  printf("Three");
  return 0;
}

Measured memory_bytes: 1704
#include <iostream>

using namespace std;

void solve(int n)
{
    int even = n/2, odd = (n + 1)/2;
    //cout << even << endl << odd << endl;
    cout << even * odd << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    solve(n);

    return 0;
}

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

int main()
{
  int64_t K, A, B;
  cin >> K >> A >> B;
  int64_t ans = K + 1; // 叩いて増やした場合
  if (B - A <= 2 || (1 + K) <= A)
  {
    cout << ans << endl;
  }
  else
  {
    int64_t plus = B - A, init = A - 1;
    cout << A + plus * ((K - init) / 2) + (K - init) % 2 << endl;
  }
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int n,l,ans=100000,sum=0;
    scanf("%d %d",&n,&l);
    sum+=n*l;
    for(int i=0;i<n;i++){
        sum+=i;
    }
    for(int i=0;i<n;i++){
        if(abs(ans-sum)>abs(l+i)){
            ans=sum-(l+i);
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int n;
  long int d;
  scanf("%d %ld", &n, &d);
  
  long int x, y;
  int count = 0;
  for (int i=0; i<n; i++){
    scanf("%ld %ld", &x, &y);
    if (x*x+y*y <= d*d){
      count++;
    }
  }
  
  printf("%d", count);

  return 0;
}


Measured memory_bytes: 1736
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e4+9;
stack<int>st;
int scc=0;
int pre[MAX];
int id[MAX];
int low[MAX];
vector<int>adj[MAX];
vector<int>ans[MAX];
int cnt=0;
int n,m;
void dfs(int s){
	pre[s]=low[s]=cnt++;
	for(int i=0;i<adj[s].size();i++){
		if(pre[adj[s][i]]==-1){
			st.push(adj[s][i]);
			dfs(adj[s][i]);
		}
		low[s]=min(low[s], low[adj[s][i]]);
	}
	if(low[s]==pre[s]){
		//cout<<st.size()<<"\n";
		while(!st.empty()){
			int x=st.top();
			id[x]=scc;
		//	cout<<x<<" ";
			low[x]=INT_MAX;
			if(x==s)
				break;
		st.pop();
		}
		//cout<<"\n";
		st.pop();
		scc++;
	}
}
int main(){
	int i,j,k;
	cin>>n>>m;
	memset(pre, -1, sizeof(pre));
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
	}
	//dfs(0);
	//cout<<scc;
	for(i=0;i<n;i++)
		if(pre[i]==-1){
			st.push(i);
			dfs(i);
		}
	//for(i=0;i<n;i++)
		//cout<<id[i]<<" ";
		int q;
		cin>>q;
		while(q--){
			int u,v;
			cin>>u>>v;
			if(id[u]==id[v])
				cout<<1<<"\n";
			else
				cout<<0<<"\n";
		}

}


Measured memory_bytes: 4308
import heapq

def calc(front_sum, back_sum):
    heapq.heapify(a_front)
    heapq.heapify(a_back)
    front_sums = [front_sum]
    back_sums = [back_sum]
    for i in range(n):
        front_sum += a_center[i] - heapq.heappushpop(a_front, a_center[i])
        front_sums += [front_sum]
        back_sum += a_center[-i - 1] + heapq.heappushpop(a_back, -a_center[-i - 1])
        back_sums += [back_sum]
    return max([front_sums[i] - back_sums[-i-1] for i in range(n+1)])



if __name__ == "__main__":
    n = int(input())
    a = [int(i) for i in input().split()]
    k = 0
    a_front = []
    a_center = []
    a_back = []
    front_sum = 0
    back_sum = 0

    for i in a:
        k += 1
        if k <= n:
            a_front += [i]
            front_sum += i
        elif k <= 2 * n:
            a_center += [i]
        else:
            a_back += [-i]
            back_sum += i

    print(calc(front_sum, back_sum))



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

int main()
{
    int input_data_01[3000], input_data_02[3000];
    int id_data = 0;

    while(1) {
        int input_01, input_02;
        cin >> input_01 >> input_02;

        // ?????????????°????????????????????????????
        int tmp;
        if(input_01 > input_02) {
            tmp = input_01;
            input_01 = input_02;
            input_02 = tmp;
        }

        input_data_01[id_data] = input_01;
        input_data_02[id_data] = input_02;
        id_data++;

        // ?????¶????????????????????\????????????
        if(input_01 == 0 && input_02 == 0) break;
    }

    for(int i = 0; i < id_data-1; i++) cout << input_data_01[i] << " " << input_data_02[i] << endl;

    return 0;
}

Measured memory_bytes: 1180
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <numeric>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, k, a, b, c, d, e, H, W;
long long A[200000] = {};
long long B[2][10000] = {};
bool f;
bool ff;
string S;
set <long long>sll;
pl buf;
vector <long long>vl;

struct ST
{
	long long total;
	long long aki;
	long long itta;
};

vector <ST> vst;
ST st;


int main() {

	cin >> N>> k >> S;

	S[k - 1] = S[k - 1] - 'A' + 'a';

	cout << S<<endl;

	return 0;

}


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

using namespace std;

int n, m;
int cnt[N];
int ansa, ansb;
char s[10];

int main() {
#ifdef local
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int x;
		scanf("%d%s", &x, s);
		if (cnt[x] == -1) continue;
		if (s[0] == 'A') {
			++ansa;
			ansb += cnt[x];
			cnt[x] = -1;
		} else ++cnt[x];
	}

	printf("%d %d\n", ansa, ansb);
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define rep(i,a,b,c)            for(int i=(a);i<=(b);i+=(c))
#define repb(i,a,b,c)           for(int i=(a);i>=(b);i-=(c))
#define MOD                     1000000007
#define inf                     3e18
#define vpii                    vector<pair<int,int>>
#define si                      set<int>
#define usi                     unordered_set<int>
#define vi                      vector<int>
#define vld                     vector<ld>
#define vvi                     vector<vector<int>>
#define vvld                    vector<vector<ld>>
#define pii                     pair<int,int>
#define vvpii                   vector<vector<pair<int,int>>>
#define pqi                     priority_queue<int>
#define mii                     map<int,int>
#define mic                     map<int,char>
#define um                      unordered_map
#define umii                    um<int,int>
#define umic                    um<int,char>
#define umci                    um<char,int>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    int Testcases;cin>>Testcases;while(Testcases--)
#define input(a,n)              for(int i=0;i<n;++i) cin>>a[i];
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int32_t main()
{
	fastIO
	inp_out();
	int n,m;
	cin>>n>>m;
	vi a(n);
	input(a,n);
	si st;
	for(int i=0;i<n;++i)
		st.insert(i);
	for(int i=0;i<m;++i)
	{
		int x,y;
		cin>>x>>y;
		--x,--y;
		if(a[x]<=a[y])
			st.erase(x);
		if(a[y]<=a[x])
			st.erase(y);
	}
	cout<<st.size();


	return 0;
}

Measured memory_bytes: 8744
from itertools import permutations

n = int(input())
XY = [tuple(map(int, input().split())) for i in range(n)]

num = 0
path_length = 0
for p in permutations(XY):
    num += 1
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1-x2)**2 +(y1-y2)**2)**0.5

print(path_length/num)

Measured memory_bytes: 41964
#include<iostream>
#include<string>
using namespace std;
int main(){
  string S;
  cin>>S;
  if(S=="Sunny")cout<<"Cloudy"<<endl;
  if (S=="Cloudy")cout<<"Rainy"<<endl;
  if (S=="Rainy")cout<<"Sunny"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int a = in.nextInt();
        int b = in.nextInt();

        int towers = 999;
        int[] heights = new int[towers + 1];
        for (int i = 1; i <= towers; i++) {
            heights[i] = heights[i - 1] + i;
        }

        for (int i = 1; i < towers; i++) {
            int west = heights[i] - a;
            int east = heights[i + 1] - b;
            if (west == east) {
                out.println(west);
                break;
            }
        }
    }

}


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

void PrimeFactorization(int n, map<int, int>& primes) {
  for (int i = 2; i <= n && n != 1; ++i) {
    if (n % i == 0) {
      while (n % i == 0) {
        primes[i]++;
        n /= i;
      }
    }
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  map<int, int> primes;
  for (int i = 2; i <= n; ++i) {
    PrimeFactorization(i, primes);
  }

  int cnt_74 = 0;
  int cnt_24 = 0;
  int cnt_14 = 0;
  int cnt_4 = 0;
  int cnt_2 = 0;
  for (const auto& p : primes) {
    if (p.second >= 74) cnt_74++;
    if (p.second >= 24) cnt_24++;
    if (p.second >= 14) cnt_14++;
    if (p.second >= 4) cnt_4++;
    if (p.second >= 2) cnt_2++;
  }

  int ans = 0;
  ans += cnt_74;                                 // 75 = x^74
  ans += cnt_24 * (cnt_2 - 1);                   // 75 = x^24 * y^2
  ans += cnt_14 * (cnt_4 - 1);                   // 75 = x^14 * y^4
  ans += (cnt_4 * (cnt_4 - 1))/2 * (cnt_2 - 2);  // 75 = x^4 * y^4 * z^2
  cout << ans << endl;
  return 0;
}


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

bool isKeyence(string s) {
    string k = "keyence";
    int pos = s.find(k);
    if(pos != string::npos) {
        if(pos == 0 || pos + k.size() == s.size()) return true;
    }
    for(int i = 1; i < k.size(); i++) {
        string l = k.substr(0, k.size()-i);
        pos = s.find(l);
        if(pos != string::npos) {
            if(pos != 0) continue;
            string m = k.substr(l.size(), k.size()-l.size());
            string n = s.substr(s.size()-m.size(), s.size()-1);
            if(m == n) return true;
        }
    }
    return false;
}

int main() {
    string s;
    cin >> s;
    if(isKeyence(s)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256