akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

vector<ll> A{1}, P{1};

ll recursive(ll n, ll x) {
    if(x == 1) return n == 0 ? 1 : 0;
    else if(x < A[n - 1] + 2) return recursive(n - 1, x - 1);
    else if(x == A[n - 1] + 2) return P[n - 1] + 1;
    else if(x < 2 * A[n - 1] + 3) return P[n - 1] + 1 + recursive(n - 1, x - 2 - A[n - 1]);
    else return 2 * P[n - 1] + 1;
}

int main(void) {
    ll N, X;
    cin >> N >> X;
    rep(i, N) {
        A.push_back(A.back() * 2 + 3);
        P.push_back(P.back() * 2 + 1);
    }
    cout << recursive(N, X) << endl;
    return 0;
}


Measured memory_bytes: 3632
h, w, k = map(int, input().split())
board = [list(input()) for _ in range(h)]
ans = 0
for paint_h in range(2**h):
  for paint_w in range(2**w):
    cnt = 0
    for i in range(h):
      for j in range(w):
        if (paint_h >> i) & 1 == 0 and (paint_w >> j) & 1 == 0:
          if board[i][j] == '#':
            cnt += 1
    if cnt == k:
      ans +=1
print(ans)

Measured memory_bytes: 9208
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A.sort()
    A_cum=[0]*n
    A_cum[0]=A[0]
    for i in range(1,n):
        A_cum[i]=A_cum[i-1]+A[i]
    for i in range(n-2,-1,-1):
        if 2*A_cum[i]<A[i+1]:
            print(n-1-i)
            break
    else:
        print(n)


if __name__=='__main__':
    main()

Measured memory_bytes: 63856
from itertools import permutations
import math

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

l = list(permutations(XY, N))
sum = 0
for i in l:
    d = 0
    for j in range(len(i)-1):
        d += math.sqrt((i[j][0] - i[j+1][0]) ** 2 + (i[j][1] - i[j+1][1]) ** 2)
    sum += d
print(sum/len(l))


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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
using tp = tuple<ll, ll, ll>;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

//グラフ関連
struct Edge {
    ll to, cap, rev;
    Edge(ll _to, ll _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve() {
    ll n, k;
    cin >> n >> k;

    vec<ll> a(n);
    REP(i, n) {
        cin >> a[i];
    }

    auto check = [&](ll x) {
        ll con = 0;
        REP(i, n) {
            con += (a[i] + (x - 1)) / x - 1;
        }
        return con <= k;
    };

    ll l = 0;
    ll r = 1e9 + 1;
    while(l + 1 < r) {
        ll m = l + r >> 1;
        if(check(m))
            r = m;
        else
            l = m;
    }
    cout << r << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*
    ll t;
    cin >> t;
    while(t--)*/
    solve();

    return 0;
}


Measured memory_bytes: 4776
s=list(input())
words=[]
for i in range(len(s)):words.append("".join(s[i:]))
words=sorted(words)

record=[]
k=int(input())
for i in words:
    for j in range(len(i)):
        if "".join(i[:j+1]) not in record:
            record.append("".join(i[:j+1]))
    if len(record)>=k:
        print(record[k-1])
        exit()

Measured memory_bytes: 121352
a = gets.split.map &:to_i
if a.any?(&:odd?)
    puts 0
    exit
end

if a.combination(2).all?{|i,j| i == j}
    puts -1
    exit
end

ans = 0
loop do
    if a.any?(&:odd?)
        puts ans
        exit
    end
    b = a.combination(2).map do |i,j|
        i/2 + j/2
    end
    a = b
    ans += 1
end


Measured memory_bytes: 1788
import sys
sys.setrecursionlimit(10**8)
def solve(n,pos):
    global data,helper
    if(n==-1):
        return 0
    if(helper[n][pos]!=-1):
        return helper[n][pos]
    if(pos==0):
        helper[n][pos]=max(data[n][1]+solve(n-1,1),data[n][2]+solve(n-1,2))
        return helper[n][pos]
    elif(pos==1):
        helper[n][pos] = max(data[n][0]+solve(n-1,0),data[n][2]+solve(n-1,2))
        return helper[n][pos]
    else:
        helper[n][pos] = max(data[n][1]+solve(n-1,1),data[n][0]+solve(n-1,0))
        return helper[n][pos]
n=int(input())
data=[]
helper=[[-1 for y in range(3)] for x in range(n)]
for _ in range(n):
    temp=[int(x) for x in input().split()]
    data.append(temp)
t1=data[-1][0]+solve(n-2,0)
t2=data[-1][1]+solve(n-2,1)
t3=data[-1][2]+solve(n-2,2)
print(max(t1,t2,t3))

Measured memory_bytes: 147804
s = input()

n = len(s)

s1 = "01" * n
# print(s1)
s1 = s1[:len(s)]
# print(s1)
s2 = "10" * n
s2 = s2[:len(s)]
# print(s2)

s1n, s2n = 0 , 0
for i in range(len(s)):
    if s[i] != s1[i]:
        s1n += 1
    if s[i] != s2[i]:
        s2n += 1
print(min(s1n, s2n))




Measured memory_bytes: 3504
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,x;
    while(~scanf("%d %d %d",&a,&b,&x))
    {
       if((a+b)<x)
        printf("NO\n");
       else if(a>x)
        printf("NO\n");
       else
         printf("YES\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())

int N;

bool check(set<int> &v, set<int> &k){
  for(set<int>::iterator it = k.begin(); it != k.end(); ++it) if(v.find((*it)) == v.end()) return false;
  return true;
}

int calc(vector< set<int> > &v, set<int> &k){
  int ret = -1;
  REP(i, N){
    bool ans = check(v[i], k);
    if(ans){
      if(ret == -1) ret = i + 1;
      else return -1;
    }
  }
  return ret;
}

int main() {
  while(cin >>N && N){
    vector< set<int> > v(N);
    set<int> k;
    REP(i, N){
      int M; cin >>M;
      REP(j, M){
        int tmp; cin >>tmp;
        v[i].insert(tmp);
      }
    }
    int M; cin >>M;
    REP(i, M){
      int tmp; cin >>tmp;
      k.insert(tmp);
    }
    cout <<calc(v, k) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1632
#include<bits/stdc++.h>
using namespace std;
int main() {
	char a[11];
	char b[11];
	char c[11];
	cin >> a >> b >> c;
	if (a[0] >= 'a' && a[0] <= 'z')
		a[0] -=32;
	 if (b[0] >= 'a' && a[0] <= 'z')
		b[0] -= 32;
	 if (c[0] >= 'a' && a[0] <= 'z')
		c[0] -= 32;
 
	cout << a[0] << b[0] << c[0];
 
}

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

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  vector<int> ans;
  ans.push_back(a[0]);
  rep(i, 1, n) {
    auto idx = lower_bound(ans.rbegin(), ans.rend(), a[i]);
    auto xxx = ans.size() - 1 - (idx - ans.rbegin());
    if (idx != ans.rend()) {
      if (xxx + 1 == ans.size()) {
        ans.push_back(a[i]);
      } else {
        ans[xxx + 1] = a[i]; 
      }
    } else if (idx == ans.rend()) {
      ans[0] = a[i];
    }
  }

  cout << ans.size() << endl;
}


Measured memory_bytes: 1276
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());

        String result = (((a == b) && (a != c)) || ((a == c) && (a != b)) || ((b == c) && (a != b))) ? "Yes" : "No";

        System.out.println(result);

        sc.close();
    }
}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

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

ll mul(ll a,ll b){
  return (a*b)%mod;
}

ll mpow(ll x,ll y){
  ll v=1;
  for(;y;x=mul(x,x),y>>=1)
    if(y&1)v=mul(v,x);
  return v;
}



#define MAX 1005

struct UF{
  int pa[MAX];
  int ra[MAX];
  void init(){
    for(int i=0;i<MAX;i++){
      pa[i]=i;
      ra[i]=0;
    }
  }

  int find(int x){
    if(pa[x]==x)return x;
    else return pa[x]=find(pa[x]);
  }

  void unite(int x,int y){
    x=find(x),y=find(y);
    if(x==y)return;
    if(ra[x]<ra[y])swap(x,y);
    pa[y]=x;
    if(ra[x]==ra[y])ra[x]++;
  }

  bool same(int x,int y){
    return (find(x)==find(y));
  }
};


struct edge{
  ll from,to,cost;
  bool operator < (const edge &e)const{
    return cost < e.cost;
  }
};

UF T;
ll N,M,X;
vector<edge> E;
vector<edge> G[1005];

bool dfs(int pos,int prev,int ti,ll &maxm){
  if(pos==ti)return true;
  
  for(int i=0;i<(int)G[pos].size();i++){
    edge e=G[pos][i];
    if(e.to==prev)continue;
    bool f=dfs(e.to,pos,ti,maxm);
    if(f){
      maxm=max(maxm, e.cost);
      return true;
    }
  }
  return false;
}

int main(){
  T.init();
  cin>>N>>M>>X;
  for(int i=0;i<M;i++){
    ll u,v,w;
    cin>>u>>v>>w;
    E.push_back( (edge){u,v,w} );
  }
  sort(E.begin(),E.end());
  ll value=0;
  
  vector<edge> g;
  for(int i=0;i<(int)E.size();i++){
    edge e=E[i];
    g.push_back(e);
    if(T.same(e.from,e.to)){
      continue;
    }
    T.unite(e.from,e.to);
    value+=e.cost;
    G[e.from].push_back( (edge){ e.from, e.to, e.cost } );
    G[e.to].push_back( (edge){ e.to, e.from, e.cost } );
  }
  
  if( value > X ){
    cout<<0<<endl;
    return 0;
  }
  
  if( value<X ){
    ll ans=0;
    ll ac=0;
    ll bc=0;
    for(int i=0;i<(int)g.size();i++){
      ll maxm=-1;
      edge e=g[i];
      dfs(e.from,-1,e.to,maxm);
      if( value-maxm+e.cost == X ){
        ac++;
      }else if( value-maxm+e.cost > X ){
        bc++;
      }
    }
    if(ac==0)ans=0;
    else ans= mul( add(mpow(2,ac),mod-1) , mpow(2,bc) );
    
    cout<< mul(2,ans) <<endl;
    
  }else {
    ll ans=0;
    ll ac=0;
    ll bc=0;
    for(int i=0;i<(int)g.size();i++){
      ll maxm=-1;
      edge e=g[i];
      dfs(e.from,-1,e.to,maxm);
      if( value-maxm+e.cost == X ){
        ac++;
      }else if( value-maxm+e.cost > X ){
        bc++;
      }
    }
    ans=mul( add(mpow(2,ac),mod-2) , mpow(2,bc) ) ;
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int a;
    scanf("%d",&a);
    if(1<=a & a<=999)
    {
        printf("ABC\n");
    }
    
    if(1000<=a & a<=1998)
    {
        printf("ABD\n");
    }
       
       return 0;
       }


Measured memory_bytes: 128
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    long long int n, temp;
    cin >> n;
    temp = sqrt(n);
    while(n%temp != 0){
        temp--;
    }
    cout << temp+n/temp-2 << endl;
}


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

int A,B,a[100000],b[100000],M,res,mina,minb;

int main(){
	cin>>A>>B>>M;
	mina=minb=1e9;
	for(int i=0;i<A;i++){
		cin>>a[i];
		mina=min(mina,a[i]);
	}
	for(int i=0;i<B;i++){
		cin>>b[i];
		minb=min(minb,b[i]);
	}
	res=mina+minb;
	for(int i=0;i<M;i++){
		int x,y,c;
		cin>>x>>y>>c;
		x--;
		y--;
		res=min(res,a[x]+b[y]-c);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 1024
n = int(input())
a = map(int, input().split())

f = 0
o = 0
t = 0
for i in a:
    if i % 4 == 0:
        f += 1
    elif i % 2 == 0:
        t += 1
    else:
        o += 1
isok = True;
if t%2 == 1:
    f -= 1
if o > f+1:
    isok = False


print('Yes' if isok else 'No')


Measured memory_bytes: 11096
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n;
    int t[100010], x[100010], y[100010];
    cin >> n;
    imfor(i, n) {
        cin >> t[i] >> x[i] >> y[i];
    }
    int posx = 0; int posy = 0;
    imfor(i, n) {
        int tmpt = t[i];
        if (i != 0) {
            tmpt -= t[i - 1];
        }
        if (tmpt < abs(x[i] - posx) + abs(y[i] - posy)) {
            cout << "No" << endl;
            return 0;
        }
        if ((tmpt - (abs(x[i] - posx) + abs(y[i] - posy))) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
        posx = x[i];
        posy = y[i];
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>


using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const ll MOD = 1e9 + 7;
vi alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };


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


int main() {
    ll A, B;
    cin >> A >> B;
    ll g = gcd(A, B);
    ll ans = 1;
    for (ll i = 2; i*i <= g+10; i++) {
        if (g % i == 0) {
            ans++;
            while (g % i == 0) g = g / i;
        }
    }
    if (g > 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
from queue import Queue
k = int(input())
q = Queue()
Lunlun = []
for i in range(1, 10):
    q.put(i)
while True:
    if len(Lunlun) >= 10**5:
        break
    now = q.get()
    Lunlun.append(now)
    for i in range(-1, 2):
        if (now % 10) + i < 0 or 9 < (now % 10) + i:
            continue
        q.put(now*10 + (now % 10) + i)

print(Lunlun[k-1])

Measured memory_bytes: 16672
#include <bits/stdc++.h>
#define M 1000005
#define FI first
#define SE second
#define MP std::make_pair
#define PB push_back
#define mod 1000000007
#define base 233
#define INF 1000000000
typedef long long ll;
ll n;
ll read() {
	ll ans = 0; char c = getchar(); bool flag = 1;
	while (c < '0' || c > '9') flag &= (c != '-'), c = getchar();
	while (c >= '0' && c <= '9') ans = ans * 10 + c - '0', c = getchar();
	return flag ? ans : -ans;
}
void Write(ll x) {
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + '0');
	else Write(x / 10), putchar(x % 10 + '0');
	return;
}
ll max(ll x, ll y) {return x > y ? x : y;}
ll power(ll x, ll y, ll ans = 1) {
	for (; y; y >>= 1, x = x * x % mod)
		if (y & 1) ans = ans * x % mod;
	return ans;
}
int main() {
	n = read();
	Write(((power(10, n) - power(9, n) * 2 + power(8, n)) % mod + mod) % mod);
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;


int main(){
    int n; cin >> n;
    vector<ll> l(n); rep(i,n) cin >> l[i];

    sort(all(l));

    ll ans = 0;
    rep(i,n){
        for(int j= i+1; j<= n-1; j++){
            int k;
            k = lower_bound(l.begin(), l.end(), l[i] + l[j]) -l.begin();

            ans += max(0, k-j-1);
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main(){
	string s,sample="CODEFESTIVAL2016";
	cin>>s;
	int c=0;
	
	for(int i=0;i<16;i++){
		if(s[i]!=sample[i]) c++;
	}
	
	cout<<c<<endl;
	return 0;	
}

Measured memory_bytes: 256
use proconio::{fastout, input};
use proconio::marker::Chars;

#[fastout]
fn main() {
    input! {
        n: usize,
      	mut stones: Chars,
    }

    let cnt_W = stones.iter().filter(|&n| n == &'W').count() as usize;
  	let border = n - cnt_W;
    
    let mut iter = stones.iter().enumerate();
    let mut W_pos = std::vec::Vec::with_capacity(cnt_W);
    loop {
        let mut ret = iter.next();
        match ret {
            Some((i, val)) => {
                if val == &'W' && i < border{
                    W_pos.push(i);
                }
            },
            _ => break,
        }
    }

    println!("{}", W_pos.iter().count());
    /* for pos in W_pos {
        let R_pos = stones.iter().rposition(|&x| x == &'R');
        stones.swap(pos, R_pos);
    } */

}


Measured memory_bytes: 3772
from sys import stdin

D, G = [int(x) for x in stdin.readline().rstrip().split()]

list = []
for i in range(D):
    tmp = [int(x) for x in stdin.readline().rstrip().split()]
    list.append(tmp)

ans = 1e9

for mask in range(1 << D):
    s = 0
    num = 0
    rest_max = -1
    for i in range(D):
        if mask >> i & 1:
            s += 100 * (i + 1) * list[i][0] + list[i][1]
            num += list[i][0]
        else:
            rest_max = i
    if s < G:
        s1 = 100 * (rest_max + 1)
        need = (G - s + s1 - 1) // s1
        if need >= list[rest_max][0]:
            continue
        num += need
    ans = min(ans, num)

print(ans)


Measured memory_bytes: 3064
import java.io.FileNotFoundException;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");

		//コード
		//    	Scanner sc = new Scanner(file);
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] a = new int[N];
		int X = 0;
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			X = X ^ a[i];
		}
		for (int i=0;i<N;i++) {
			if(i<N-1) {
				System.out.print(X^a[i]);
				System.out.print(" ");
			} else {
				System.out.println(X^a[i]);
			}
		}
	}
}

Measured memory_bytes: 57060
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int x;cin>>x;
    int cur=100,cnt=0;
    while(cur<x){
        cur+=(cur/100);
        cnt++;
    }
    cout<<cnt;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        String st = sc.next();
        for (int i = st.length()-2; i > 0; i -= 2) {
            if (st.substring(0, i/2).equals(st.substring(i/2, i))) {
                System.out.print(i);
                break;
            }
        }
    }
}

Measured memory_bytes: 25556
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }




int main() {
	int N;
	int tmp = 0, ans = 0;
	scanf("%d", &N);
	int *L = (int *)malloc(sizeof(int) * N);
	int *R = (int *)malloc(sizeof(int) * N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &L[i], &R[i]);
	}
	for (int i = 0; i < N; i++) {
		tmp = tmp + R[i] - L[i] + 1;
	}
	ans = tmp;
	printf("%d\n", ans);


#ifdef DEBUGF
	getch();
#endif
	return 0;
}

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

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

long long lcm(long long a, long long b)
{
   return a * b / gcd(a, b);
}


int main(){
    long long a,b;
    cin >> a >> b;
    cout << lcm(a,b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<vector>
#include<queue>
#include<map>
#define rep(i, n) for(int i = 0; i < (n); i++ )
#define MAX 100000
#define NIL -1
using namespace std;
typedef long long ll;

priority_queue<ll> q, jobs[MAX];
vector<pair<int, int>> tasks(MAX);
vector<int> days[MAX];
int n, m;

bool sortbytwo(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first < b.first) return true;
  else if (a.first == b.first && a.second > b.second) return true;
  return false;
}

int main() {
  int a ,b;
  cin >> n >> m;
  rep(i,n) {
    scanf("%d %d", &a, &b);
    // auto task = make_pair(a, -b);
    // tasks.push_back(task);
    a--;
    days[a].push_back(b);
    // jobs[a].push(b);
  }
  // sort(tasks.begin(), tasks.end(), sortbytwo);

  int ans = 0;
  rep(i, m) {
    rep(j, days[i].size()) q.push(days[i][j]);
    if (!q.empty()) {
      ans += q.top(); q.pop();
    }
  }
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 9600
N,A,B = map(int,raw_input().split(" "))
S = raw_input()
C = A+B


a = 0
b = 0

for i in range(N):
    if S[i] == "a":
        if a < A+B:
            print "Yes"
            a += 1
        else:
            print "No"
    elif S[i] == "b":
        if a  < A+B and b < B:
            print "Yes"
            a+=1
            b+=1
        else:
            print "No"
    else:
        print "No"


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

using namespace std;

using ll = long long int;
using ld = long double;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, k;
	cin >> n >> k;

	vi l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	sort(l.begin(), l.end(), greater<int>());

	int res = 0;
	for (int i = 0; i < k; i++) {
		res += l[i];
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
object Main extends App {
	// your code goes here
    def h(c:Int, ub:Int):Boolean = {
      if (c>=ub){true} else {
        val strAry = io.StdIn.readLine().split(' ')
        (strAry(0).toLong, strAry(1).toLong, strAry(2).toLong) match {
          case (t, x, y) if (x.abs + y.abs) > t.abs => false
          case (t, x, y) if ((x.abs + y.abs - t.abs)&1) == 1 => false
          case (t, x, y) => h(c+1, ub)
        }
      }
    }
  
   val n = io.StdIn.readLine().toInt
   h(0, n) match {
      case true => println("Yes")
      case false => println("No")
    }
}

Measured memory_bytes: 42680
#include<iostream>

using namespace std;
long long int max(long long int a,long long int b)
{
    if(a>=b)
    return a;
    return b;
}
int main()
{

  long long int n,w;
	    cin>>n;
	    cin>>w;
	    long long int value[n];
	    long long int weight[n];
	    for(long long int i=0;i<n;i++)
        { cin>>weight[i];
	    cin>>value[i];
        }
  

  
long long int dp[n+1][w+1];
for(long long int i=0;i<n+1;i++)
{
for(long long int j=0;j<w+1;j++)
{
  if(i==0||j==0)
    dp[i][j]=0;
  else if(weight[i-1]>j)
    dp[i][j]=dp[i-1][j];
  else
    dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]); 
  }
}
	    
 cout<<dp[n][w]<<endl;
 
  
  return 0;
}
  


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
		ll n, m;
		cin >> n >> m;
	int a[m], b[m];
	for(int i=0;i<m;i++)
	{
		cin>>a[i]>>b[i];
	}
	
 
	cout<<max(*min_element(b,b+m) - *max_element(a,a+m)+1, 0) << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

signed main() {
    int A, B, K;
    cin >> A >> B >> K;
    for (int i = 0; i < K; i++) {
        if (i % 2 == 0) {
            A -= (A % 2 == 1);
            B += (A /= 2);
        } else {
            B -= (B % 2 == 1);
            A += (B /= 2);
        }
    }
    cout << A << " " << B << endl;
}


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

# In[1]:


N,K,S = map(int, input().split())


# In[4]:


if S < 10**9:
    ans = [S]*K + [S+1]*(N-K)
elif S == 10**9:
    ans = [S]*K + [1]*(N-K)
print(*ans)


# In[ ]:






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

const int mod = 1e9 + 7;

template <class T>
T add(T a, T b)
{
	T r = a + b;
	
	if (r >= mod)
		r -= mod;
		
	return r;
}

template <class T>
T mul(T a, T b)
{
	T r = 0;
	
	while (b)
	{
		if (b & 1)
			r = add(r, a);
			
		b >>= 1;
		a <<= 1;
		
		if (a >= mod)
			a -= mod;
	}
	
	return r;
}

template <class T>
T pow(T a, T b)
{
	T r = 1;
	
	while (b)
	{
		if (b & 1)
			r = mul(r, a);
		
		b >>= 1;
		a = mul(a, a);
	}
	
	return r;
}

signed main(void)
{
	int a, b;
	cin >> a >> b;
	cout << pow(a, b) << endl;
}

Measured memory_bytes: 3108
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		//お年玉問題
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int y=scan.nextInt();
		int value[]= {10000,5000,1000};
		int cnt[]= {-1,-1,-1};
		scan.close();
		int flg=0;
		for(int i=0;i<=n;i++) {
			for(int j=0;j<=n;j++) {
				if(n-i-j>=0) {
					if(value[0]*i+value[1]*j+value[2]*(n-i-j)==y) {
						flg=1;
						cnt[0]=i;
						cnt[1]=j;
						cnt[2]=n-i-j;
						break;
					}
				}
			}
			if(flg==1)break;
		}

		System.out.println(cnt[0]+" "+cnt[1]+" "+cnt[2]);
	}

}

Measured memory_bytes: 23764
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  t,*s,_=input()
  if t==46:c,f=0,False
  else:c,f=1,True
  p=[(c,f)]
  for t in s:
    g=t==35
    if g!=f:
      c+=1
      f=not f
    p+=(c,f),
  d=p
  for _ in range(h-1):
    t,*s,_=input()
    c,f=d[0]
    g=t==35
    if g!=f:
      c+=1
      f=not f
    p=[(c,f)]
    for i,t in enumerate(s,1):
      e,h=d[i]
      g=t==35
      if h!=g:
        e+=1
        h=not h
      if f!=g:
        c+=1
        f=not f
      if e<c:
        c,f=e,h
      p+=(c,f),
    d=p
  print(d[-1][0]+1>>1)
main()

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

int main(){
   int a,b;
  cin >> a >> b;
  if(a == 1 && b == 2 )
    cout << 3 << endl;
  if(a == 2 && b == 1 )
    cout << 3 << endl;
  if(a == 3 && b == 2 )
    cout << 1 << endl;
  if(a == 2 && b == 3 )
    cout << 1 << endl;
  if(a == 1 && b == 3 )
    cout << 2 << endl;
  if(a == 3 && b == 1 )
    cout << 2 << endl;
}
    
    
     
   
   
    

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

int main() {
  int64_t N,K,total;
  cin>>N>>K;
  for(int64_t i=K; i<N+2; i++){
    total+=N*i-i*(i-1)+1;
  }
  total %=1000000007LL;
  cout<< total;
}


Measured memory_bytes: 3596
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String args[]) {
      Scanner sc = new Scanner(System.in);
      PrintWriter w = new PrintWriter(System.out);
      
      int n = sc.nextInt();
      long a[] = new long[n];
      for(int i = 0; i < n; i++)
      {
          a[i] = sc.nextLong();
      }
      long suf_sum[] = new long[n+1];
      long Mod = (long)1e9+7;
      //w.println(Mod);
      for(int i = n-1; i > 0; i--)
      {
          suf_sum[i] = (suf_sum[i+1] + a[i]) % Mod;    
      }
      long ans = 0;
      for(int i = 0; i < n-1; i++)
      {
          ans += (a[i]*suf_sum[i+1]) % Mod;
          ans %= Mod;
      }
      w.println(ans);
      w.close();
    }
}

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

int main()
{
        long long N, M;
        cin >> N >> M;
        vector<long long> H;
        for (int i = 0; i < N; ++i) {
                long long tmp;
                cin >> tmp;
                H.push_back(tmp);
        }
        vector<int> good(N, 1);
        for (int i = 0; i < M; ++i) {
                int a, b;
                cin >> a >> b;
                if (H[a-1] <= H[b-1]) {
                        good[a-1] = 0;
                }
                if (H[b-1] <= H[a-1]) {
                        good[b-1] = 0;
                }
        }
        int ans = 0;
        for (int i = 0; i < N; ++i) {
                if (good[i] == 1) ans++;
        }
        cout << ans << endl;



}


Measured memory_bytes: 4504
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int ans = 0;
        int point = 0;
        for (int i = 0; i < N; i++) {
            int A = scan.nextInt();
            int B = scan.nextInt();
            if (ans <= A) {
                ans = A;
                point = B;
            }
        }
        ans += point;
        System.out.println(ans);

    }
}


Measured memory_bytes: 66460
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
int main()
{
    fio;
    int n;
    cin>>n;
    double c=2*3.14159*n;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define OK puts("OK");
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define allr(s) s.rbegin(), s.rend()
#define rep(i,n) for (i=0;i<(n);++i)
#define rep1(i,n) for (i=1;i<=(n);++i)
#define ret return
#define int long long
#define scan1(a) scanf("%lld",&(a));
#define scan2(a,b) scanf("%lld %lld",&(a),&(b));
#define scan3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c));
#define nemeshay ios::sync_with_stdio(0),cin.tie(0);
const int INF=1e9+7,N=1e6+12;
int dp[3001][3001];
main(){
    string a,b,s="";
    cin>>a>>b;
    a = " "+a;
    b = " "+b;
    int n=a.size(),m=b.size(),i,j;
    for (i=1;i<n;++i){
        for (j=1;j<m;++j){
            if (a[i]==b[j])
                dp[i][j] = dp[i-1][j-1]+1;
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    n--;
    m--;
    while (n>0 && m>0){
        if (dp[n][m]-1 == dp[n][m-1] && dp[n][m]-1==dp[n-1][m]){
            s = a[n]+s;
            n--;
            m--;
        }
        else {
            if (dp[n-1][m]>dp[n][m-1])n--;
            else m--;
        }
    }
    cout <<s;
}










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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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


int main(void) {
	
	while (1) {
		int h, w;
		int wall;
		bool flag = true;
		bool check = false;
		int dp[65][65] = {};
		int checked[65][65] = {};
		pair<int, int>now;
		queue < pair <int, int > > que;

		cin >> w >> h;
		FOR(i, 0, 2*h) {
			dp[i][0] = 1;
			dp[i][2*w] = 1;
		}
		FOR(i, 0, 2*w) {
			dp[0][i] = 1;
			dp[2*h][i] = 1;
		}

		if (w == 0) {
			break;
		}
		FOR(i, 1, 2 * h - 1) {
			if (flag) {
				FOR(j, 1, w - 1) {
					cin >> wall;
					if (wall == 1) {
						dp[i][j * 2] = 1;
					}
				}
				flag = false;
			}
			else {
				FOR(j, 1, w) {
					cin >> wall;
					if (wall == 1) {
						dp[i][j * 2 - 1] = 1;
					}
				}
				flag = true;
			}
		}
		checked[1][1] = 1;
		now.first = 1;
		now.second = 1;
		que.push(now);
		while (!que.empty()) {
			now = que.front();
			que.pop();
			if (now.second == 2 * w - 1 && now.first == 2 * h - 1) {
				cout << checked[now.first][now.second] << endl;
				check = true;
				break;
			}
			if (now.second + 2 <= 2 * w) {
				if (dp[now.first][now.second+1] == 0 && dp[now.first][now.second + 2] == 0&&checked[now.first][now.second+2]==0) {
					checked[now.first][now.second+2] = checked[now.first][now.second] + 1;
					que.push(make_pair(now.first,now.second+2));
				}
			}
			if (now.second - 2 >=0) {
				if (dp[now.first][now.second - 1] == 0 && dp[now.first][now.second - 2] == 0 && checked[now.first][now.second - 2] == 0) {
					checked[now.first][now.second - 2] = checked[now.first][now.second] + 1;
					que.push(make_pair(now.first, now.second-2));
				}
			}
			if (now.first + 2 <= 2 * h) {
				if (dp[now.first+1][now.second] == 0 && dp[now.first+2][now.second] == 0 && checked[now.first+2][now.second] == 0) {
					checked[now.first+2][now.second ] = checked[now.first][now.second] + 1;
					que.push(make_pair(now.first+2, now.second));
				}
			}
			if (now.first - 2 >= 0) {
				if (dp[now.first - 1][now.second] == 0 && dp[now.first - 2][now.second] == 0 && checked[now.first - 2][now.second] == 0) {
					checked[now.first - 2][now.second] = checked[now.first][now.second] + 1;
					que.push(make_pair(now.first - 2, now.second));
				}
			}
		}
		if (!check) {
			cout << 0 << endl;
		}
	}
	
}


Measured memory_bytes: 3084
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
AA = []
for _ in range(N):
    AA.append(list(map(int, input().split())))

def func(A, B, C):
    ret = 0
    for a, b in zip(A, B):
        ret += a*b
    if ret + C > 0:
        return True
    else:
        return False

tot = 0
for A in AA:
    tot += func(A, B, C)
print(tot)

Measured memory_bytes: 3064
import java.util.*;



public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();
        
        System.out.println(Math.max(Math.max(a*c, a*d), Math.max(b*c, b*d)));
    }
}

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

using namespace std;
int n;
long long a[200500];
int main()
{
    ios::sync_with_stdio(false);
    int k,n,i;
    cin >> n >> k;
    for (i=1;i<=n;i++)
    {
        cin >> a[i];
    }
    long long ans=1e18+7;
    for (i=1;i+k-1<=n;i++)
    {
        long long tmp=a[i+k-1]-a[i];
        if ((a[i]<0) && (a[i+k-1]<0)) tmp+=abs(a[i+k-1]);
        if ((a[i]>0) && (a[i+k-1]>0)) tmp+=a[i];
        if ((a[i]<0) && (a[i+k-1]>0)) tmp+=min(-a[i],a[i+k-1]);
        ans=min(ans,tmp);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
object Main extends App {
  val read = scala.io.StdIn.readLine()
  val array =  read.split(" ").map(_.toInt).toVector
  val x = array(1)
  var resultArray = Vector(x)
  val addCount = array(0) - 1
  for(i<-1 to addCount) {
    resultArray :+= (x - i)
    resultArray :+= (x + i)
  }
  println(resultArray.sorted.mkString(" "))
}

Measured memory_bytes: 25500
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll
//struct edge {int to,cost;};

bool rullonz = false;

typedef tuple<int,int,int> t;
set<t> s;

void dfs(int n,int a,int b,int c){
    t k = MT(a,b,c);
    if(s.find(k)!=s.end()) return;

    if(rullonz) return;
    if(a+b+c==n){
        printf("%d %d %d\n",c,b,a);
        rullonz = true;
        return;
    }
    s.insert(k);
    if(a+b+c>n){
        if(a>=5) dfs(n,a-5,b+1,c);
        if(a>=10) dfs(n,a-10,b,c+1);
        if(b>=2) dfs(n,a,b-2,c+1);
    } else {
        if(c>=1) dfs(n,a+10,b,c-1);
        if(c>=1) dfs(n,a,b+2,c-1);
        if(b>=1) dfs(n,a+5,b-1,c);
    }
}

signed main(){
    int n,y;
    cin >> n >> y;
    int b = y/5000;
    y -= b*5000;
    int a = y/1000;
    dfs(n,a,b,0);
    if(!rullonz) puts("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define rep0(i,n) for (int i=0; i<=(int)(n); ++i)
#define rep1(i,n) for (int i=1; i<=(int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
template<typename T> using Graph = vector<vector<T>>;
template<typename T> using Spacial = vector<vector<vector<T>>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

template<typename T> struct is_pair : false_type{};
template<typename T1, typename T2> struct is_pair<pair<T1, T2>> : true_type{};
template<typename T> struct is_vector : false_type{};
template<typename T> struct is_vector<vector<T>> : true_type{};

template<typename T1, typename T2>
istream &operator >> (istream &istr, pair<T1, T2> &p) {
  istr >> p.first >> p.second;
  return istr;
} 
template<typename T1, typename T2>
ostream &operator << (ostream &ostr, const pair<T1, T2> &p) {
  ostr << p.first << " " << p.second;
  return ostr;
}
template<typename T>
ostream &operator << (ostream &ostr, const vector<T> &vec) {
  if (vec.empty()) return ostr;
  bool vp = is_vector<T>() || is_pair<T>();
  ostr << vec.front();
  for (auto itr = ++vec.begin(); itr != vec.end(); ++itr) {
    ostr << (vp ? "\n" : " ") << *itr;
  }
  return ostr;
}

template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int modpow(int a, long long n, int mod = MOD) {
  int ret = 1;
  do {
    if (n & 1) ret = 1LL * ret * a % mod;
    a = 1LL * a * a % mod;
  } while (n >>= 1);
  return ret;
}

template<typename T>
T GCD(T a, T b) { return b ? GCD(b, a%b) : a; }
template<typename T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

template<typename T1, typename T2>
bool CompareBySecond(pair<T1, T2> a, pair<T1, T2> b) {
  return a.second != b.second ? a.second < b.second : a.first < b.first;
}
template<typename T>
bool CompareBySlope(pair<T, T> a, pair<T, T> b) {
// counterclockwise from 12 o'clock direction
  if (a.first * b.first < 0) return a.first < b.first;
  if (a.first == 0) return a.second >= 0 || b.first > 0;
  if (b.first == 0) return b.second < 0 && a.first < 0;
  return a.second * b.first < a.first * b.second;
}


/* -------- <templates end> -------- */


void solve() {
  int n; string s; cin >> n >> s;
  int ans = 0;
  rep(i,n-2) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') ++ans;
  }
  cout << ans << endl;
}


/* -------- <programs end> -------- */


signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        long c=sc.nextLong();
        if(a-c<0&&a+b>=c){
            System.out.println("0 "+(b-(c-a)));
        }else if(a+b<=c){
            System.out.println("0 0");
        }else{
            System.out.println(a-c+" "+b);
        }
    }
    
}


Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main()
{

    string s;
    string answer = "TBD";

    cin >> s; //~2019/04/30

    int year, month, day;
    year = stoi(s.substr(0, 4));
    month = stoi(s.substr(5, 2));
    // day = stoi(s.substr(8, 2));

    if (year < 2019)
    {
        answer = "Heisei";
    }
    else if (year == 2019)
    {
        if (month < 5)
            answer = "Heisei";
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,l[100],ans=0;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++) scanf("%d",&l[i]);
      sort(l,l+n);
    for(int i=n-1;i>=n-k;i--) ans+=l[i];
      printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256