akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

V<ll> dp1(60,0),dp2(60,0);
ll N,X,idx = 0,ans = 0;

void dfs(int deep){

	if (deep == 0){
		if (idx + 1 <= X) {
			idx += 1;
			ans += 1;
		}
		return;
	}

	if (idx == X) return;

	if(idx + 1 <= X){
		idx += 1;
	}

	if (idx == X) return;

	if (idx + dp1[deep-1] <= X) {
		idx += dp1[deep - 1];
		ans += dp2[deep - 1];
	}
	else dfs(deep - 1);

	if (idx == X) return;

	if (idx + 1 <= X) {
		idx += 1;
		ans += 1;
	}

	if (idx == X) return;

	if (idx + dp1[deep - 1] <= X) {
		idx += dp1[deep - 1];
		ans += dp2[deep - 1];
	}
	else dfs(deep - 1);

	if (idx == X) return;

	if (idx + 1 <= X) {
		idx += 1;
	}
}

int main() {
	dp1[0] = dp2[0] = 1;
	FOR(i, 1, 51) dp1[i] = 2LL * dp1[i-1] + 3LL;
	FOR(i, 1, 51) dp2[i] = 2LL * dp2[i-1] + 1LL;
	
	cin >> N >> X;
	dfs(N);
	cout << ans << endl;
	

	return 0;
}



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

using namespace std;

int main(){
  string s; cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]=='1'){
      s[i]='9';
    }
    else if(s[i]=='9'){
      s[i]='1';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
#define INF 1<<30
#define mp make_pair
#define pb push_back

#define fi first
#define se second

#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
 
int L;
typedef long long ll;
int saisyou(int a[]){
	int res=0;
	for(int i=0;i<L;i++){
		res *= 10;
		res += a[i];
	}
	return res;
}
int saidai(int a[]){
	int res=0;
	for(int i=L;i>=0;i--){
		res *= 10;
		res += a[i];
	}
	return res;
}
int main(){
	while(1){
		int s[1000100];
		rep(i,1000100){
			s[i]=-1;
		}
		int a[6] = {0};

		int t ;
		cin >> t >> L;
		if(t==0&&L==0) break;
		s[t]=0;
		rep(i,L){
			a[i] = t%10;
			t/=10;
		}
		sort(a,a+L);
		int cnt = 1;
		while(1){
			t = saidai(a)-saisyou(a);
			// cout << saisyou(a) << endl;
			if(s[t]!=-1) break;
			else s[t] = cnt;
			rep(i,L){
				a[i] = t%10;
				t/=10;
				
			}
			sort(a,a+L);
			cnt++;
		}
		cout << s[t] << " " << t << " " << cnt-s[t] << endl;
	}
	return 0;
}

Measured memory_bytes: 6996
S = input()[::-1]
l = len(S)
dp = [[0]*2 for _ in range(l+1)]
for i in range(l):
  dp[i+1][0]=min(dp[i][0]+int(S[i]),dp[i][1]+int(S[i])+1)
  if i!=0:
    dp[i+1][1]=min(dp[i][0]+10-int(S[i]),dp[i][1]+10-(int(S[i])+1))
  else:
    dp[i+1][1]=dp[i][0]+10-int(S[i])
print(min(dp[-1][0],dp[-1][1]+1))

Measured memory_bytes: 140208
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from collections import deque

def logical_and(x, y):
    z = deque([])

    for i in range(len(x)):
        a = x.popleft()
        for j in range(len(y)):
            b = y[j]
            if a == b:
                del y[j]
                z.append(a)
                break
    # print(z)
    return z

def solve():
    n = II()
    S = [deque(sorted(list(input()))) for _ in range(n)]

    c = S[0]
    for i in range(1, n):
        s = S[i]
        c = logical_and(c, s)

    c = sorted(c)
    print(''.join(c))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

int A, B;

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

    cin>>A>>B;
    cout<<(A-1)*(B-1)<<'\n';

    return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> p(N),q(N);
  for(int i=0;i<N;i++)cin>>p[i];
  for(int i=0;i<N;i++)cin>>q[i];
  for(int i=0;i<N;i++)p[i]--,q[i]--;
  typedef pair<int,int> P;
  set<P> s;
  for(int i=0;i<N;i++){
    int cnt=0,one=-1,roop=0,now=p[i];
    while(!roop){
      if(now==i)one=cnt;
      now=q[now];cnt++;
      if(now==p[i])roop=cnt;
    }
    if(one<0)fin(-1);
    s.insert(P(one,roop));
  }
  int pre=-1;
  for(auto p:s){
    int roop=p.second;
    if(roop==pre)fin(-1);
    pre=roop;
  }
  int ans=-1,b=1;
  for(auto p:s){
    int one=p.first,roop=p.second;
    if(ans<0)ans=one;
    else{
      if((abs(ans-one)%__gcd(b,roop)))fin(-1);
      while((ans%roop)!=one)ans+=b;
    }
    b=(b*roop)/__gcd(b,roop);
  }
  fin(ans);
}



Measured memory_bytes: 3092
h,w = map(int,input().split())
ff = [list(input()) for _ in range(h)]

d = [[-1,-1],[0,-1],[1,-1],
     [-1, 0],       [1, 0],
     [-1, 1],[0, 1],[1, 1]]

for hi in range(h):
  for wi in range(w):
    if ff[hi][wi]=='#':
      pass
    else:
      count = 0
      for dx,dy in d:
        x = dx+wi
        y = dy+hi        
        if (0<= x < w) and (0<= y <h) :
          if ff[y][x] == '#':
            count += 1
      ff[hi][wi] = str(count)
      
for fi in ff:
  print(''.join(fi))      

Measured memory_bytes: 3188
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


class UnionFind:
    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        return False

    def subsetall(self):
        a = []
        for i in range(len(self.table)):
            if self.table[i] < 0:
                a.append((i, -self.table[i]))
        return a

def main():
    n,k,l = list(map(int, input().split()))
    uk = UnionFind(n)
    ul = UnionFind(n)
    for _ in range(k):
        p,q = list(map(int, input().split()))
        uk.union(p-1,q-1)
    for _ in range(l):
        p,q = list(map(int, input().split()))
        ul.union(p-1,q-1)

    sk = collections.defaultdict(set)
    sl = collections.defaultdict(set)
    m = {}

    for i in range(n):
        sk[uk.find(i)].add(i)
        sl[ul.find(i)].add(i)
    r = []
    for i in range(n):
        if i in m:
            r.append(m[i])
            continue
        ss = sk[uk.find(i)] & sl[ul.find(i)]
        ssl = len(ss)
        for sc in ss:
            m[sc] = ssl
        r.append(m[i])

    return " ".join(map(str, r))



print(main())


Measured memory_bytes: 155816
#include <iostream>

using namespace std;

int main()
{
    double a, t, h;
    int n,m=0;
    cin>>n>>t>>a;
    double v[n];
    for(int i=0; i<n ; i++){
        cin>>h;
        v[i]=t-h*0.006;
        v[i]=a-v[i];
        v[i]*=v[i];
        if(v[i]<=v[m])
            m=i;
    }
    cout<<m+1;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int A[1000000], n;
 
int binarySearch(int key) {
    int left = 0, right = n, mid;
    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid])return 1;
        if (key > A[mid])left = mid + 1;
        else if (key < A[mid])right = mid;
    }
    return 0;
}
 
int main() {
    int i, q, k, sum = 0;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &k);
        if (binarySearch(k))sum++;
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 980
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def ccw(a, b, c):
    ax = b[0] - a[0]
    ay = b[1] - a[1]
    bx = c[0] - a[0]
    by = c[1] - a[1]
    t = ax*by - ay*bx;
    if t > 0:
        return 1
    if t < 0:
        return -1
    if ax*bx + ay*by < 0:
        return 2
    if ax*ax + ay*ay < bx*bx + by*by:
        return -2
    return 0

def convex_hull(ps):
    n = len(ps)
    k = 0
    ps.sort()
    ch = [[-1,-1] for _ in range(n*2)]
    for i in range(n):
        while k >= 2 and ccw(ch[k-2], ch[k-1], ps[i]) <= 0:
            k -= 1
        ch[k] = ps[i]
        k += 1
    t = k + 1
    for i in range(n-2,-1,-1):
        while k >= t and ccw(ch[k-2], ch[k-1], ps[i]) <= 0:
            k -= 1
        ch[k] = ps[i]
        k += 1
    ch = ch[:k-1]
    return ch

def radian(a, b):
    return math.atan2(b[1]-a[1], b[0]-a[0])

def main():
    n = I()
    a = [LI() + [_] for _ in range(n)]
    t = convex_hull(a)
    l = len(t)
    r = [0] * n
    if l == 2:
        r[t[0][2]] = 0.5
        r[t[1][2]] = 0.5
    else:
        for i in range(l):
            r1 = radian(t[i], t[i-1])
            r2 = radian(t[i], t[(i+1) % l])
            k = r2 - r1
            while k < 0:
                k += math.pi * 2
            e = (k-math.pi) / math.pi / 2
            r[t[i][2]] = e

    return '\n'.join(map(str,r))


print(main())


Measured memory_bytes: 5972
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <cstdint>

using namespace std;

int main() {
	int64_t a, b, x;
	cin >> a >> b >> x;
	int64_t cnt = 0;

	if (a == 0) {
		cnt = b / x + 1;
	}
	else {
		cnt = b / x - (a - 1) / x;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <stdio.h>
#include <set>
#include <vector>
using namespace std;


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

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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n;
string s;

bool check()
{
    for (int i=1;i<=n;++i)
    {
        if (i%2==1)
        {
            if (s[i]=='L') return false;
        }
        else
        {
            if (s[i]=='R') return false;
        }
    }
    return true;
}

int main()
{
    cin>>s;
    n=s.length();
    s="1"+s;
    if (check()) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
#define MAX_N 10

int N;
int ball[MAX_N];

int used[MAX_N];

bool dfs(int max_l, int max_r, int next) {
    if (next == MAX_N) return true;
    if(ball[next] > max_l)
        return dfs(ball[next],max_r,next+1);
    if(ball[next] > max_r) 
        return dfs(max_l,ball[next],next+1);
    return false;
}

string solve() {
   memset(used,0,sizeof(used));
   return dfs(0,0,0) ? "YES" : "NO";
}

main() {
    cin>>N;
    for(int i=0;i<N;i++) {
        for(int j=0;j<MAX_N;j++) {
            cin>>ball[j];
        }
        cout << solve() << endl;
    }
}

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

using namespace std;

#define int long long
#define double long double
int a[100005];
int inf = 1e18;

main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int ans = 1, n, x;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (a[i] == 0) {
            cout << 0;
            exit(0);
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (ans > inf / (double)a[i]) {
            cout << -1;
            exit(0);
        }
        ans *= a[i];
    }
    cout << ans << '\n';
    return 0;
}



Measured memory_bytes: 4424
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sati = 0

for i in range(len(A)):
    sati += B[A[i] - 1]
    if i > 0:
        if A[i] - A[i-1] == 1:
            sati += C[A[i - 1] - 1]
print(sati)


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

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<int> k(Q);
    rep(i, Q) cin >> k[i];
    vector<ll> D(N + 1, 0), M(N + 1, 0);
    rep(i, N) {
        D[i + 1] = D[i] + (S[i] == 'D');
        M[i + 1] = M[i] + (S[i] == 'M');
    }
    rep(i, Q) {
        ll ans = 0, DM = 0;
        rep(j, N) {
            if (j >= k[i] && S[j - k[i]] == 'D') DM -= M[j] - M[j - k[i] + 1];
            if (S[j] == 'M') {
                DM += D[j] - D[max(0, j - k[i] + 1)];
            }
            if (S[j] == 'C') ans += DM;
            //cout << j << " " << DM << endl;
        }
        cout << ans << endl;
    }
    //rep(i, N + 1) cout << i << " " << D[i] << " " << M[i] << endl;
}

Measured memory_bytes: 17028
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, L;
int dp[1 << 16];

signed main() {
    while(cin >> N, N) {
        memset(dp, -1, sizeof(dp));
        dp[0] = 0;

        int ans = 0;
        rep(p,0,N) {
            int info = 0;
            cin >> M >> L;
            rep(i,0,M) {
                int S, E; cin >> S >> E;
                S -= 6, E -= 6;

                int val = 0;
                rep(j,S,E) val += (1 << j);
                info += val;
            }

            repr(bit,(1<<16)-1,0) {
                if(bit & info) continue;
                if(dp[bit] == -1) continue;
                chmax(dp[bit | info], dp[bit] + L);
            }
        }
        rep(i,0,1<<16) chmax(ans, dp[i]);
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

multiset<int> a;

void extract(){
    cout << *(--a.end()) << endl;
    a.erase(--a.end());
}

int main(void){
    char command[10];
    int temp;
    while(true){
        scanf("%s", command);
        if(command[0] == 'i'){
            cin >> temp;
            a.insert(temp);
        }else if(command[1] == 'x'){
            extract();
        }else{
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 50000
#include <cstdio>
#include <queue>
using namespace std;

const int MAX_H = 30;
const int MAX_W = 30;
int iswall[2 * MAX_H][MAX_W];
const int INF = 1e9;

int solve(int w, int h) {
	int memo[MAX_H][MAX_W];
	const static int dy[] = {1, 0, -1, 0};
	const static int dx[] = {0, 1, 0, -1};
	for (int i = 0; i < MAX_H; ++i) for (int j = 0; j < MAX_W; ++j) memo[i][j] = INF;

	queue<pair<int, int> > que;
	memo[0][0] = 1;
	que.push(make_pair(0, 0));
	while(!que.empty()) {
		pair<int, int> tmp = que.front(); que.pop();
		int y = tmp.first, x = tmp.second;
		for (int i = 0; i < 4; ++i) {
			int ny = y + dy[i], nx = x + dx[i];
			if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue; // ?????????
			if(memo[ny][nx] != INF) continue; // ?????§?????°???????????????
			if(i % 2 == 0) { //????§????
				if(iswall[2 * min(y, ny) + 1][x]) continue;
			} else { //?¨??§????
				if(iswall[2 * y][min(x, nx)]) continue;
			}
			que.push(make_pair(ny, nx));
			memo[ny][nx] = memo[y][x] + 1;
		}
	}
	return memo[h - 1][w - 1] == INF ? 0 : memo[h - 1][w - 1];
}

int main(void) {
	while(1) {
		int w, h; scanf("%d %d", &w, &h);
		if(w == 0 && h == 0) break;

		for (int i = 0; i < 2 * h - 1; ++i) {
			for (int j = 0; j < w - (i % 2 ? 0 : 1); ++j) {
				scanf("%d", &iswall[i][j]);
			}
		}

		printf("%d\n", solve(w, h));
	}
	return 0;
}

Measured memory_bytes: 2772
#include <cstdio>
using namespace std;
 
int k;

int sumDig(long long x) {
  int res = 0;
	while (x) {
		res += x % 10;
		x /= 10;
  }
	return res;
}
 
int main() {
  scanf("%d", &k);
 	long long num = 1, add = 1;
  while (k--) {
    printf("%lld\n", num);
    while (double(num + add) / sumDig(num + add) > double(num + 2 * add) / sumDig(num + 2 * add)) add *= 10;
    num += add;
  }
  return 0;
}

Measured memory_bytes: 128
n= int(input());
ls=list(map(int,input().split()));
x=int(sum(ls)/len(ls))
y=x+1;
ans1=0;
ans2=0;
for i in ls:
    ans1+=(x-i)**2;
    ans2+=(y-i)**2;
print(min(ans1,ans2))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
string ans;
int input;
void solve(int n)
{
    while (n)
    {
        if (n % -2)
        {
            n--;
            ans.push_back('1');
        }
        else
            ans.push_back('0');
        n /= -2;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}
int main()
{
    cin >> input;
    if (!input)
    {
        cout << 0 << endl;
        return 0;
    }
    solve(input);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

LL dp[8][1050][1050];

signed main(){
    
    int n, m;
    cin >> n >> m;
    vector<LL> x(n), y(n), z(n);
    REP(i, n) cin >> x[i] >> y[i] >> z[i];
    REP(k, 8) REP(i, 1050) REP(j, 1050) dp[k][i][j] = 0LL;

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[0][i+1][j+1] = max(dp[0][i][j+1], dp[0][i][j] + x[i] + y[i] + z[i]);
            else dp[0][i+1][j+1] = dp[0][i][j] + x[i] + y[i] + z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[1][i+1][j+1] = max(dp[1][i][j+1], dp[1][i][j] - x[i] + y[i] + z[i]);
            else dp[1][i+1][j+1] = dp[1][i][j] - x[i] + y[i] + z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[2][i+1][j+1] = max(dp[2][i][j+1], dp[2][i][j] + x[i] - y[i] + z[i]);
            else dp[2][i+1][j+1] = dp[2][i][j] + x[i] - y[i] + z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[3][i+1][j+1] = max(dp[3][i][j+1], dp[3][i][j] + x[i] + y[i] - z[i]);
            else dp[3][i+1][j+1] = dp[3][i][j] + x[i] + y[i] - z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[4][i+1][j+1] = max(dp[4][i][j+1], dp[4][i][j] - x[i] - y[i] + z[i]);
            else dp[4][i+1][j+1] = dp[4][i][j] - x[i] - y[i] + z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[5][i+1][j+1] = max(dp[5][i][j+1], dp[5][i][j] - x[i] + y[i] - z[i]);
            else dp[5][i+1][j+1] = dp[5][i][j] - x[i] + y[i] - z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[6][i+1][j+1] = max(dp[6][i][j+1], dp[6][i][j] + x[i] - y[i] - z[i]);
            else dp[6][i+1][j+1] = dp[6][i][j] + x[i] - y[i] - z[i];
        }
    }

    REP(i, n){
        REP(j, i+1){
            if(j != i) dp[7][i+1][j+1] = max(dp[7][i][j+1], dp[7][i][j] - x[i] - y[i] - z[i]);
            else dp[7][i+1][j+1] = dp[7][i][j] - x[i] - y[i] - z[i];
        }
    }

    LL ans = 0;
    REP(i, 8) ans = max(ans, dp[i][n][m]);
    
    cout << ans << endl;
}


Measured memory_bytes: 69120
def dist(p, q):
    return p ** 2 + q ** 2


def resolve():
    n, d = map(int, input().split())
    d2 = d ** 2
    a = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for x, y in a:
        if dist(x, y) <= d2:
            ans += 1
    print(ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 102460
// in the name of god 
// vaght hast vali kam ast !

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

const int MAXN = 1e6 + 100 ;
const int MAXM = 900 ; 

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

int q[MAXN] ; 
int vis[MAXM][MAXM] , dis[MAXM][MAXM] ;
char ch[MAXM][MAXM] ; 
int32_t main(){
	ios_base::sync_with_stdio(0) ;
	cin . tie(0) ; cout . tie(0) ; 

	int n , m ; cin >> n >> m ; 
	int k ; cin >> k ; 
	int sx , sy ; 
	for(int i = 0 ; i < n ; i ++)
		for(int j = 0 ; j < m ; j ++){
			cin >> ch[i][j] ; 
			if(ch[i][j] == 'S')sx = i , sy = j ; 
		}
	int sz = 0 ;

	vis[sx][sy] = true ; 
	q[sz ++] = sx ; 
	q[sz ++] = sy ; 
	int ans = MAXN ; 
	for(int i = 0 ; i < sz ; i += 2){
		int nx = q[i] ; 
		int ny = q[i + 1] ; 
		if(dis[nx][ny] > k)continue ; 
		if(! nx || ! ny || nx == n - 1 || ny == m - 1)return cout << 1 , 0 ; 
		int d = min (min(nx , ny) , min(n - nx - 1 , m - ny - 1)) ; 
		ans = min(ans , 1 + (d + k - 1) / k) ; 
		for(int j = 0 ; j < 4 ; j ++){
			int x = nx + dx[j] ; 
			int y = ny + dy[j] ; 
			if(ch[x][y] == '.' && vis[x][y] == false){
				vis[x][y] = true ; 
				dis[x][y] = dis[nx][ny] + 1 ; 
				q[sz ++] = x ; 
				q[sz ++] = y ; 
			}
		}
	}
	cout << ans ; 
}

Measured memory_bytes: 7808
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
signed main(){
  ll n,k,tk,l,r,len,tmp,ans;
  string s,ts;
  ans=0;
  char ch;
  cin >> n >> k>>s;
  vector<ll> seg;
  vector<ll> ls;
  ch=s[0];
  len=1;
  for(int i=1;i<n;i++){
    if(s[i]!=ch){
      ch=s[i];
      seg.push_back(len);
      len=1;
    }else{
      len++;
    }
  }
      seg.push_back(len);
  while(k!=0){
    if(seg.size()==1){
      break;
    }else if(seg.size()==2){
      seg[0]+=seg[1];
      seg.erase(seg.begin()+1);
      k--;
      break;
    }else{
      seg[1]+=seg[0]+seg[2];
      seg.erase(seg.begin()+2);
      seg.erase(seg.begin());
      k--;
    }
  }
  for(int i=0;i<seg.size();i++){
    ans+=seg[i]-1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1528
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <time.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)

void solve()
{
    ll n, k, x, y;
    cin >> n >> k >> x >> y;
    
    ll t = min(n, k);
    
    cout << x * t + (n - t) * y << "\n";
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0);
    //freopen(FILE ".in", "r", stdin);freopen(FILE ".out", "w", stdout);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	 int a[32];
	   
	   
	       a[0]=1,a[1]= 1,a[2]= 1,a[3]= 2,a[4]= 1,a[5]= 2,a[6]= 1,a[7]= 5, a[8]=2,a[9]= 2, a[10]=1,a[11]= 5,a[12]= 1,a[13]= 2,a[14]= 1, a[15]=14, a[16]=1,a[17]= 5, a[18]=1, a[19]=5,a[20]= 2,a[21]= 2,a[22]= 1,a[23]= 15,a[24]= 2,a[25]= 2,a[26]= 5,a[27]= 4,a[28]= 1,a[29]= 4, a[30]=1,a[31]= 51;
	   
	int t;
	cin>>t;
	
	{
	   cout<<a[t-1]<<endl;
	   
	    
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int h, w;
    cin >> h >> w;

    char s[100][101];
    int a[100][101];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
        for (int j = 0; j < w; j++) {
            s[i][j] = s[i][j] == '#';
        }
    }

    a[0][0] = s[0][0];
    for (int j = 1; j < w; j++) {
        a[0][j] = a[0][j - 1] + (!s[0][j - 1] && s[0][j]);
    }
    for (int i = 1; i < h; i++) {
        a[i][0] = a[i - 1][0] + (!s[i - 1][0] && s[i][0]);
        for (int j = 1; j < w; j++) {
            a[i][j] = min(a[i][j - 1] + (!s[i][j - 1] && s[i][j]), a[i - 1][j] + (!s[i - 1][j] && s[i][j]));
        }
    }

    cout << a[h - 1][w - 1] << endl;

    //高々100回くらいでできそう 連続してたら一気に変えれるし
    //ある地点まで進んだらその右下しか関係なくなる

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P =pair<ll,ll>;
const ll INF =ll(1e18)+5;

int main() {
    ll N;
    cin >> N;
    vector<ll> v(N);
    map<ll,ll> oddMp;
    map<ll,ll> evenMp;
    for(int i=0;i<N;i++){
        cin >> v[i];
        if(i %2 ==0){
            oddMp[v[i]]++;
        }else{
            evenMp[v[i]]++;
        }
    }
    vector<P> oddP,evenP;
    for(auto itr = oddMp.begin();itr != oddMp.end();++itr){
        // cerr <<itr->first <<" "<< itr->second << endl;
        oddP.emplace_back(itr->second,itr->first);
    }
    for(auto itr = evenMp.begin();itr != evenMp.end();++itr){
        evenP.emplace_back(itr->second,itr->first);
    }
    sort(oddP.rbegin(),oddP.rend());
    sort(evenP.rbegin(),evenP.rend());

    // sort(oddMp.rbegin(),oddMp.rend());
    // sort(evenMp.rbegin(),evenMp.rend());
    ll ans = INF;
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            int oddNum=0;
            ll oddValue =0;
            int evenNum =0;
            ll evenValue =0;
            if(oddP.size()>i){
                oddNum = oddP[i].second;
                oddValue = oddP[i].first;
            }
            if(evenP.size()>j){
                evenNum = evenP[j].second;
                evenValue = evenP[j].first;
            }
            // cerr <<"evenNum=" << evenNum <<", oddNum=" << oddNum << endl;
            if(evenNum == oddNum){
                continue;
            }
            ans = min(ans,N-oddValue-evenValue);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9592
MOD = 1000000007
n = int(input())
l = list(map(int,input().split()))
a = {}
for i in l:
    if i in a:
        a[i] += 1
    else:
        a[i] = 1

cur = 1 if n % 2 == 0 else 0

ok = True
while cur < n:
    x = 1 if cur == 0 else 2
    if not cur in a or a[cur] != x:
        ok = False
        break
    cur += 2

ans = 0
if ok:
    ans = 1
    for _ in range(n // 2):
        ans = ans * 2 % MOD

print(ans)

Measured memory_bytes: 14436
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int n, d, x;
	cin >> n >> d >> x;
	vi a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int j = 0; j < a.size(); j++) {
		x += (d-1) / a[j]+1;
	}

	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// 2의 제곱수 판정
#define POW2(X) (X) == ((X)&(-(X)))

// 기본설정
typedef long long ll;
using namespace std;
int dirx[4] = {1, 0, -1, 0};
int diry[4] = {0, 1, 0, -1};

// 전역변수
ll n, m, k, ans = 0;
vector<ll> a, b;

int main(void) {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	cin >> n >> m >> k;
	a.push_back(0);
	b.push_back(0);
	for(int i = 0; i < n; i++) {
		ll book;
		cin >> book;
		a.push_back(a[i] + book);
	}
	for(int i = 0; i < m; i++) {
		ll book;
		cin >> book;
		b.push_back(b[i] + book);
	}
	
	int le = 0, ri = n + m;
	while(le <= ri) {
		// 총 확인할 책의 권수
		int mid = (le + ri) / 2;
		// 만족하는지
		bool flag = false;
		// 각각의 책상에서 볼 책의 권수
		for(int ab = 0; ab <= mid; ab++) {
			int bb = mid - ab;
			if(n < ab || m < bb) continue;
			if(a[ab] + b[bb] <= k) {
				flag = true;
				break;
			}
		}
		if(flag) {
			ans = max(ans, (ll)mid);
			le = mid + 1;
		} else {
			ri = mid - 1;
		}
	}
	
	cout << ans;

	return 0;
}

Measured memory_bytes: 7940
#%%
n = int(input())

ans = 0
c = 1

while True:
    ans += (n // (5 ** c))//2
    c += 1
    if n // (5 ** c) == 0:
        break

anss = 0


if n % 2 == 0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int[] NM = IntLine();
        int N = NM[0], M = NM[1];
        string S = Console.ReadLine();
        string T = Console.ReadLine();

        int n = N / GCD(N, M);
        int m = M / GCD(N, M);

        for (int i = 0; i < GCD(N, M); i++)
        {
            if (S[i * n] != T[i * m])
            {
                Console.WriteLine(-1);
                return;
            }
        }
        Console.WriteLine(LCM(N, M));
    }
}

public class Atcoder
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int GCD(int a, int b)
    {
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (b != 0)
        {
            d = a % b;
            a = b;
            b = d;
        }
        return a;
    }
    public static long LCM(int a, int b)
    {
        return (long)a * b / GCD(a, b);
    }
    public static string StrReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int IntRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static long[] LSRead()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static long Combination(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r + 1), r).ToList().Aggregate((now, next) => now * next) /
            Enumerable.Range(1, r).ToList().Aggregate((now, next) => now * next);
    }
    public static long Permutation(int n, int r)
    {
        if (n == r) return 1;
        return
            Enumerable.Range((n - r), r).ToList().Aggregate((now, next) => now * next);
    }
    public static long LongRead()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] LongLine()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }
    public static int[] IntLine()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
}


Measured memory_bytes: 11744
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <string>
using namespace std;

#define For(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Rep(i,n) For(i,0,n)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

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

#define INF 1000000000

int H, W, C;
int p[100][8][8];

void draw(int x, int y, int c, int pc, int bn){
	p[bn][x][y] = c;
	For(dx,-1,2)For(dy,-1,2){
		if((dx != 0 && dy != 0) || (dx == 0 && dy == 0)) continue;
		if(x+dx >= 0 && x+dx < W && y+dy >= 0 && y+dy < H && p[bn][x+dx][y+dy] == pc) draw(x+dx,y+dy,c,pc,bn);
	}
}

int count_color(int x, int y, int bn){
	if(p[bn][x][y] != C) return 0;
	else{
		int res = 1;
		p[bn][x][y] = -1;
		For(dx,-1,2)For(dy,-1,2){
			if((dx != 0 && dy != 0) || (dx == 0 && dy == 0)) continue;
			if(x+dx >= 0 && x+dx < W && y+dy >= 0 && y+dy < H) res += count_color(x+dx,y+dy,bn);
		}
		return res;
	}
}

void change_board(int bn, int c){
	draw(0, 0, c, p[bn][0][0], bn);
}

int dfs(int t){//?????§????????£????????´?????°
	int res = 0;
	//printf("%d\n", t);
	if(t == 5){
		res = count_color(0, 0, t);
	}else{
		if(t == 4){
			Rep(i,H)Rep(j,W) p[t+1][j][i] = p[t][j][i];
			if(p[t+1][0][0] != C) change_board(t+1, C);
			res = dfs(t+1);
		}else{
			Rep(i,6){
				if(i != p[t][0][0]){
					//printf("t=%d i=%d\n", t, i);
					Rep(j,H)Rep(k,W) p[t+1][k][j] = p[t][k][j];
					change_board(t+1, i);
					res = max(res, dfs(t+1));
				}
			}
		}
	}

	return res;
}

int main(){
	while(1){
		scanf("%d %d %d", &H, &W, &C);
		if(H == 0 && W == 0) break;
		C--;
		Rep(i,H)Rep(j,W){
			scanf("%d", &p[0][j][i]);
			p[0][j][i]--;
		}
		printf("%d\n", dfs(0));
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int n;
	cin>>n;
	long long sum=0;
	for(int i=1;i<=n;i++)
	{
		if(i%3 and i%5) sum+=i;
	}	
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  string s;
  int i;
  cin >> s;
  size_t c = s.length();
  for(i = 0; i < c; i++){
    cout << "x";
  }
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

type Station struct {
	c, s, f int
}

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	S := make([]Station, N-1)
	for i := 0; i < N-1; i++ {
		S[i] = Station{sc.nextInt(), sc.nextInt(), sc.nextInt()}
	}
	for i := 0; i < N-1; i++ {
		count := S[i].s + S[i].c
		for j := i + 1; j < N-1; j++ {
			if count < S[j].s {
				count += S[j].s - count + S[j].c
			} else if count%S[j].f == 0 {
				count += S[j].c
			} else {
				count += (count/S[j].f+1)*S[j].f - count + S[j].c
			}
		}
		fmt.Fprintln(wtr, count)
	}
	fmt.Fprintln(wtr, 0)

	wtr.Flush()
}


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

//dp[i+1][j]はi番目の品物の中から重さjを超えないように選んだ時 の価値の最大値
int dp[110][10005];

int main(){
	int N,W;
	cin >> N >> W;
	vector<int> v(N);
	vector<int> w(N);
	rep(i,N){
		cin >> v[i] >> w[i];
	}
	
	rep(i,N+1){
		rep(j,W+1){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
			if(j>=w[i]){
				dp[i+1][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
			}
		}
	}
	
	cout << dp[N][W] << endl;
	
    return 0;
}




Measured memory_bytes: 7048
//B Card Game for Two
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

int main()
{
  int n,ans;
  cin>>n;
  ans=0;
  vector<int> point(n);
  for(int i=0;i<n;i++)
  {
    cin>>point.at(i);
  }
  sort(point.begin(),point.end());
  reverse(point.begin(),point.end());
  for(int i=0;i<n;i++)
  {
    if(i%2==0)
    {
      ans+=point.at(i);
    }
    else
    {
      ans-=point.at(i);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Objects;

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

    Scanner sc = new Scanner(System.in);

    int A = sc.nextInt();
    int B = sc.nextInt();

    int value = 0;
    if (A >= 13){
      value = B;
    } else if (A >= 6){
      value = B / 2;
    }
    System.out.println(value);
  }
}


Measured memory_bytes: 21972
#include<stdio.h>
#include<string.h>
int main(void){
    int a,b,ab,o,g;
    char x[2];
    a=b=ab=o=0;
    while(scanf("%d,%s",&g,x)!=EOF){
        if(x[0]=='A')(x[1]=='B')?ab++:a++;
        else if(x[0]=='B')b++;

        else o++;
    }
    printf("%d\n%d\n%d\n%d\n",a,b,ab,o);
    return 0;
}

Measured memory_bytes: 596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int t = Integer.parseInt(br.readLine());
		
		for(int i = 0; i < t; i++){
			String[] tmpArray = br.readLine().split(" ");
			
			int n = Integer.parseInt(tmpArray[0]);
			int k = Integer.parseInt(tmpArray[1]);
			
			int pos[] = new int[n];
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < n; j++){
				pos[j] = Integer.parseInt(tmpArray[j]);
			}
			
			System.out.println(solve(pos, k));
			
		}
	}
	
	static int solve(int[] pos, int k){
		int n = pos.length;
		
		House[] houses = new House[n];
		for(int i = 0; i < n; i++){
			houses[i] = new House(i, pos[i]);
			if(i != 0){
				houses[i].dist = houses[i].x - houses[i - 1].x;
			}
		}
		
		Arrays.sort(houses);
		//debug
//		for(int i = 0; i < n; i++){
//			System.out.print(houses[i].dist+" ");
//		}
//		
//		System.out.println();
		
		int result = pos[n - 1] - pos[0];
		
		int tmp = 0;
		for(int i = n - 1 ; i > 0  && tmp < k - 1; i--){
//			System.out.println("i = "+i);
			result -= houses[i].dist;
			tmp++;
		}
		
		return result; 
	}

}

class House implements Comparable<House>{
	int x;
	int id;
	int dist;
	
	public House(int id, int x){
		this.id = id;
		this.x = x;
		this.dist = 0;
	}

	@Override
	public int compareTo(House h) {
		// TODO Auto-generated method stub
		return (this.dist - h.dist);
	}
}


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


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


Measured memory_bytes: 256
n, m, q = map(int, input().split())
image = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    image[l - 1][r - 1] += 1
sumimage = [[0] * (n + 1) for _ in range(n + 1)]
for l in range(1, n + 1):
    s = 0
    for r in range(1, n + 1):
        s += image[l - 1][r - 1]
        sumimage[l][r] = sumimage[l - 1][r] + s
for _ in range(q):
    a, b = map(int, input().split())
    c = sumimage[b][b] - sumimage[a - 1][b]
    print(c)


Measured memory_bytes: 15284
#!/usr/bin/env python3
import sys
INF = float("inf")

import sys
import cmath
import math
INF = float("inf")

EPS = 1e-9


def ctc(p1, r1, p2, r2):
    # 二つの円の共通接線の数
    # common tangent of circles
    # 2円の関係性は、同一(=INF), 離れている(=4)、外接(=3)、交わる(=2)、内接(=1)、内包(=0)がある
    # r1 <= r2として一般性を失わない
    if r2 < r1:
        p1, p2 = p2, p1
        r1, r2 = r2, r1

    d = abs(p1-p2)

    if p1 == p2 and d < EPS:    # 同一の円
        return INF
    elif (d - (r2+r1)) > EPS:   # 離れている
        return 4
    elif (d - (r2+r1)) > -EPS:  # 外接している
        return 3
    elif (d-(r2-r1)) > EPS:     # 交わっている
        return 2
    elif (d-(r2-r1)) > -EPS:    # 内接している
        return 1
    else:                       # 内包している
        return 0


def inner(p1, c1, p2, c2):
    coeff1 = c1/(c1+c2)
    coeff2 = c2/(c1+c2)
    return p1*coeff1+p2*coeff2


def intersection(p1, r1, p2, r2):
    status = ctc(p1, r1, p2, r2)
    d = abs(p1-p2)
    if not (1 <= status <= 3):
        return []
    elif status == 3:           # 外接
        return [inner(p1, r1, p2, r2)]
    elif status == 1:           # 内接
        return [p1 + r1*(p1-p2)/d]
    else:                       # 交わっている場合
        if r1 > r2:
            p1, p2 = p2, p1
            r1, r2 = r2, r1
        d = abs(p1-p2)
        cos = (r1**2+d**2-r2**2)/(2*r1*d)
        angle = math.acos(cos)
        phi = cmath.phase(p2-p1)
        return [
            p1 + cmath.rect(r1, phi+angle),
            p1 + cmath.rect(r1, phi-angle)
        ]


def circle_in(p, o, r1, allow_on_edge=True):
    if allow_on_edge:
        return abs(o-p)-r1 < EPS
    else:
        return abs(o-p)-r1 < -EPS


def solve(N: int, x: "List[int]", y: "List[int]"):
    circles = [xx + 1j*yy for xx, yy in zip(x, y)]
    left = -1
    right = 1500
    while right - left > 1e-7:
        mid = (left + right)/2.0
        # 半径をmidとする二つの円の交点を数え上げる
        flag = False
        intsecs = []
        for i in range(N):
            for j in range(i+1, N):
                a = intersection(circles[i], mid, circles[j], mid)
                if len(a) == 0:
                    flag = True
                    break
                intsecs += a
            if flag:
                break
        if flag:
            left = mid
            continue

        # いずれかの交点で、N個全ての円の含まれるetんがあると良い
        for p in intsecs:       # O(N^3)
            all_in_one = True
            for i in range(N):
                if not circle_in(p, circles[i], mid):
                    all_in_one = False
                    break
            if all_in_one:
                flag = True
                break
        if flag:
            right = mid
        else:
            left = mid
    print(right)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44264
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    while(cin>>a)
    {
        int len=a.length();
        int flag=0;
        //cout<<a<<endl;
        for(int i=1;i<len-1;i++)
        if(a[i-1]==a[i]&&a[i]==a[i+1]){cout<<"Yes"<<endl;flag=1;break;}
        if(!flag)cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
  string s;
  int input[4], ans;
  cin >> s;
  for(int i = 0; i < 4; i++){
    input[i] = s[i] - '0';
  }
  for(int i = 0; i < 8; i++){
    ans = 0;
    if(i % 2 == 0) ans = input[0] + input[1];
    else ans = input[0] - input[1];
    if(i % 4 == 0 || i % 4 == 1) ans += input[2];
    else ans -= input[2];
    if(i < 4) ans += input[3];
    else ans -= input[3];
    if(ans == 7){
      cout << input[0];
      if(i % 2 == 0) cout << '+';
      else cout << '-';
      cout << input[1];
      if(i % 4 == 0 || i % 4 == 1) cout << '+';
      else cout << '-';
      cout << input[2];
      if(i < 4) cout << '+';
      else cout << '-';
      cout << input[3] << "=7" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;

int main()
{
	short i[5]; int a = 0, m = 0;
	for (int k = 0; k < 5; k++)
	{
		cin >> i[k];
		if (10 - (i[k] % 10)>m&&i[k]%10!=0) { m = 10 - (i[k] % 10); }
		if (i[k] % 10 != 0) { i[k] += 10 - (i[k] % 10); } a += i[k];
	}
	a -= m;
	cout << a;
	return 0;
}

Measured memory_bytes: 256
let input = require('fs').readFileSync('/dev/stdin', 'utf8')
.split(/\n| /)
.map(item => parseInt(item))
.slice(0,-1)

let [takahashi_hp, takahashi_atk, aoki_hp, aoki_atk] = input

while(true){
    aoki_hp -= takahashi_atk
    if(aoki_hp <= 0){
        console.log("Yes")
        break
    }
    takahashi_hp -= aoki_atk
    if(takahashi_hp <= 0){
        console.log("No")
        break
    }
}

Measured memory_bytes: 29636