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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    int cur = 0;
    vector<long long> T(N, -1);
    T[0] = 0;
    long long t = 0;
    while (K > 0) {
        ++t;
        --K;
        cur = A[cur] - 1;
        if (T[cur] != -1) {
            long long C = t - T[cur];
            K %= C;
        } else {
            T[cur] = t;
        }
    }
    cout << cur + 1 << '\n';
    return 0;
}

Measured memory_bytes: 5576
n=int(input())
a= list(map(int, input().split()))
v=[[0,0] for i in range(60)]

for i in range(n):
    for j in range(60):
        if (a[i]>>j)&1:
            v[j][1]+=1
        else:
            v[j][0]+=1

ans=0

for i in range(60):
    ans+=v[i][0]*v[i][1]*(2**i)
    ans%=10**9+7

print(ans)

Measured memory_bytes: 122936
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_8_D&lang=jp

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    s = input().strip()
    p = input().strip()

    s = s + s[:-1]
    if p in s:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7588
#include <iostream>
#include <vector>
#include <algorithm>

int main(){
	std::vector<int> a(4);
	
	while(std::cin >> a[0] >> a[1] >> a[2] >> a[3]){
		int hit = 0, blow = 0;
		
		for(int i = 0; i < 4; ++i){
			int b;
			std::cin >> b;
			
			auto it = std::find(a.begin(), a.end(), b);
			if(it == a.begin() + i) ++hit;
			else if(it != a.end()) ++blow;
		}
		
		std::cout << hit << " " << blow << std::endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 1188
N,M = map(int,input().split())
L = list(map(int,input().split()))
L = sorted(L)
A = []
for i in range(M-1) :
    A.append(L[i+1] - L[i])
A = sorted(A)
if N >= M :
    ans = 0
else :
    ans = sum(A[:M-N])
print(ans)


Measured memory_bytes: 13968
#include<bits/stdc++.h>
    using namespace std;
    #define ll long long
     
    int main()
    {
    	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        //std::numeric_limits<int>::max();
        map<string,int> mp;
        int n;
		string str;
        cin>>n;
        for(int i=0;i<n;i++)
        {
        	cin>>str;
        	mp[str]++;
		}
		int max=-1;
		for(auto it=mp.begin();it!=mp.end();++it)
			{
				if(it->second>max)
					max=it->second;
			}
			for(auto it=mp.begin();it!=mp.end();++it)
			{
				if(it->second==max)
					cout<<it->first<<endl;
			}
        
        
    }

Measured memory_bytes: 23808
s = input()
s = list(s)
to_black = 0
to_white = 0
last = '0' if s[0] == '1' else '1'
pos = 0
for c in s:
    if c == last and c == '0':
        to_white+=1
        s[pos] = '1'
        c = '1'
    elif c == last and c == '1':
        to_black+=1
        s[pos] = '0'
        c = '0'
    last = c
    pos+=1
print(to_black+to_white)

Measured memory_bytes: 3956
#include <iostream>
#include <stdio.h>
using namespace std;
 
int main() {
  int a[4][3][10]={0};
  
  int b,f,r,v,i,j,n;
  cin >> n;
  while(n--){
    cin >> b >> f >> r >> v ;
    a[b-1][f-1][r-1]+=v;
  }


  for(int i=0;i<3;i++){
    for(int j=0;j<10;j++)cout << " "<< a[0][i][j] ;
      cout << endl;
  }
  printf("####################\n");
  for(int i=0;i<3;i++){
    for(int j=0;j<10;j++)cout << " "<< a[1][i][j] ;
      cout << endl;
  }
  printf("####################\n");
  for(int i=0;i<3;i++){
    for(int j=0;j<10;j++)cout << " "<<a[2][i][j] ;
      cout << endl;
  }
  printf("####################\n");
  for(int i=0;i<3;i++){
    for(int j=0;j<10;j++)cout << " "<< a[3][i][j] ;
      cout << endl;
  } 
}

Measured memory_bytes: 1160
#include <stdio.h>

using namespace std;

int main(){
	int a,b;
	char op;
	while(true){
		scanf("%d %c %d",&a,&op,&b);
		if(op == '?') break;
		switch(op){
		case '+':
			printf("%d\n",a+b);
			break;
		case '-':
			printf("%d\n",a-b);
			break;
		case '/':
			printf("%d\n",a/b);
			break;
		case '*':
			printf("%d\n",a*b);
		
		}
	}
}




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

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

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

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
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)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
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;}

//Greatest Common Divisor
long long GCD(long long a, long long b) {
    return ((b == 0) ? a : GCD(b, a % b));
}


int main() {
	int N; cin >> N;
	V<ll> a(N),b(N),c(N);
	for(int i = 0; i < N; ++i) cin >> a[i];
	b[0] = a[0];
	for(int i = 1; i < N; ++i) b[i] = GCD(b[i-1],a[i]);
	c[N-1] = a[N-1];
	for(int i = N-2; 0 <= i; --i) c[i] = GCD(c[i+1],a[i]);
	ll ans = max({b[N-1],b[N-2],c[1]});
	for(int i = 1; i + 1 < N; ++i) chmax(ans,GCD(b[i-1],c[i+1]));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
from collections import defaultdict, deque
import sys, heapq, bisect, math, itertools, string, queue, copy, time
from fractions import gcd
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
EPS = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n, m = map(int,input().split())
a_list = list(map(int, input().split()))
bc_list = []
for i in range(m):
    b, c = map(int, input().split())
    bc_list.append(([b,c]))

# c is the number to which you change, you can change b cards

a_list.sort()
bc_list.sort(key = lambda x: x[1], reverse = True)

i = 0
j = 0
ans = 0
while i < n and j < m:
    if a_list[i] > bc_list[j][1]:
        break
    else:
        if bc_list[j][0] == 0:
            j += 1
        else:
            ans += bc_list[j][1]
            bc_list[j][0] -= 1
            i += 1

if i < n:
    ans += sum(a_list[i:])

print(ans)

Measured memory_bytes: 35520
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    while(true){
      int n = sc.nextInt();
      if(n==0){
        break;
      }
      int[] scores = new int[n];
      for(int i=0;i<scores.length;i++){
        scores[i]=sc.nextInt();
      }
      double average=0,variance=0;
      for(int i=0;i<scores.length;i++){
        average+=(double)scores[i]/n;
      }
      for(int i=0;i<scores.length;i++){
        variance+=(double)(scores[i]-average)*(scores[i]-average)/n;
      }
    System.out.println(Math.sqrt(variance));
    }
  }
}

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

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

    int m,k;

    cin >> m >> k;
    
    if(m==1)
    {
        if(k==0)
        {
            cout << "0 0 1 1" << '\n';
        }
        else
        {
            cout << -1 << '\n';
        }
        return 0;
    }
    if(k>=pow(2,m))
    {
        cout << -1 << '\n';
    }
    else
    {
        cout << 0 << ' ';
        if(k!=0)
        {
            cout << k << ' ';
        }
        cout << 0 << ' ';
        for(int i=1;i<pow(2,m);i++)
        {
            if(k==i)
            {
                continue;
            }
            cout << i << ' ';
        }
        if(k!=0)
        {
            cout << k << ' ';
        }
        for(int i=pow(2,m)-1;i>0;i--)
        {
            if(k==i)
            {
                continue;
            }
            cout << i << ' ';
        }
        cout << '\n';
    }

    return 0;
}

Measured memory_bytes: 1792
s=input()
n=len(s)
data=[0]*(n+1)
for i in range(n):
    if s[i]=="<":
        data[i+1]=data[i]+1
for i in range(n):
    if s[n-i-1]==">":
        data[n-1-i]=max(data[n-i]+1,data[n-1-i])
print(sum(data))

Measured memory_bytes: 46320
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <functional>
#include <math.h>
#include <utility>
using namespace std;
typedef pair<int,int> P;
int W,H,N,ans=0;
int x,y,s,t;
int main()
{
	cin>>W>>H>>N;
	cin>>x>>y;
	for(int i=1;i<N;i++){
		cin>>s>>t;int d;
		s-=x;t-=y;
		if(s*t>=0)d=abs(s-t)+min(abs(s),abs(t));
		else d=abs(s)+abs(t);
		ans+=d;
		x+=s;y+=t;
	}
	cout<<ans<<endl;
}

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

#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define MOD 1000000007
#define len(x) x.size()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define all(v) v.begin(), v.end()
#define alla(a, n) a, a + n
#define endl "\n";
#define MOD 1000000007

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef unordered_map<ll, ll> ump;

int32_t main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll d, t, s;
    cin >> d >> t >> s;

    if (t * s < d)
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }

    return 0;
}

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

int main()
{
  // 入力受け取り
  int N;
  string S;
  cin >> N;
  cin >> S;

  int ans =0;
  char before = '0';
  for (auto s: S) {
      if (s!=before) ans++; 
      before = s;
  }

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


Measured memory_bytes: 512
from collections import deque

h, w = map(int, input().split())
cx, cy = map(lambda x: int(x) - 1, input().split())
dx, dy = map(lambda x: int(x) - 1, input().split())
s = [input() for _ in range(h)]
c = [[10**6] * w for _ in range(h)]


def bfs():
    d = ((1, 0), (-1, 0), (0, 1), (0, -1))
    q = deque([(cx, cy)])

    c[cx][cy] = 0

    while q:
        x, y = q.pop()
        cp = c[x][y]
        if (x, y) == (dx, dy):
            c[x][y] = cp
            break
        for i, j in d:
            nx = x + i
            ny = y + j
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and c[nx][
                    ny] > cp:
                q.append((nx, ny))
                c[nx][ny] = cp
        cp += 1
        for i in range(-2, 3):
            for j in range(-2, 3):
                nx = x + i
                ny = y + j
                if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != "#" and c[nx][
                        ny] > cp:
                    c[nx][ny] = cp
                    q.appendleft((nx, ny))

    return -1 * (c[dx][dy] == 10**6) or c[dx][dy]


print(bfs())


Measured memory_bytes: 90780
// Dmitry _kun_ Sayutin (2020)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;
using std::queue;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

const int mod = 998244353;

void incr(int& a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

int mult(int a, int b) {
    return (int64_t(a) * b) % mod;
}

int dp[3005][3005];

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    for (int i = a; i <= c; ++i)
        for (int j = b; j <= d; ++j) {
            if (i == a and j == b)
                dp[i][j] = 1;
            else if (i != a and j == b)
                incr(dp[i][j], mult(dp[i - 1][j], b));
            else if (i == a and j != b)
                incr(dp[i][j], mult(dp[i][j - 1], a));
            else {
                incr(dp[i][j], mult(i, dp[i][j - 1]));
                incr(dp[i][j], mult(j, dp[i - 1][j]));
                incr(dp[i][j], mod - mult(mult(i - 1, j - 1), dp[i - 1][j - 1]));
            }
        }

    cout << dp[c][d] << "\n";
    
    return 0;
}


Measured memory_bytes: 38832
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;
 
int func(int ind, int flag) {
 
	if (ind == n) return 0;
 
	if (dp[ind][flag] != -1) return dp[ind][flag];
 
	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}
 
	return dp[ind][flag] = maxi;
}
 
int main() {
 
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
 
	memset(dp, -1, sizeof dp);
 
	cout << func(0, 0);
 
	return 0;
}

Measured memory_bytes: 9600
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        while (true) {
            int h = scanner.nextInt();
            int w = scanner.nextInt();
            for (int j = 0; j < h; j++) {
                String s = "";
                for (int i = 0; i < w; i++) {
                    if ((j % 2 == 0 && i % 2 == 0) || (j % 2 == 1 && i % 2 == 1)) {
                        s = s + "#";
                    } else {
                        s = s + ".";
                    }

                }
                System.out.println(s);

            }
            if (h == 0 || w == 0) {
                break;
            }
            System.out.print("\n");

        }

    }

}

Measured memory_bytes: 55564
import collections
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
dic = collections.Counter(a)
total = sum(a)

q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    try:
        num = dic[b]
        total += (c-b) * num
        print(total)
        dic[b] = 0
        dic[c] += num
    except KeyError:
        print(total)


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

int main() {
    int a, b, c, d, ans;
    cin >> a >> b >> c >> d;
    ans = max(0, min(b, d) - max(a, c));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string s;
int ans=114514;
main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		int m=0,k=0;
		for(int j=0;j<=s.size();j++)
		{
			if(j==s.size()||s[i]==s[j])
			{
				if(m<k)m=k;
				k=0;
			}
			else
			{
				k++;
			}
		}
		if(ans>m)ans=m;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int c = 0;
  if (a > b) {
    c+=a;
    a--;
  } else {
    c += b;
    b--;
  }
  if (a > b) {
    c += a;
    a--;
  } else {
    c += b;
    b--;
  }
  cout << c;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
  //配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

N = int(input())
edge = [[] for i in range(N)]
count = [0] * N
color = {}
egs = []
for i in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    count[a] += 1
    count[b] += 1
    edge[a].append(b)
    edge[b].append(a)
    egs.append(tuple(sorted([a, b])))


ans = max(count)
c = 1



def dfs(idx, pr):
    c = 1
    col = color[pr]
    for i in edge[idx]:
        if i in pr:
            continue
        if c == col:
            c+=1
        x, y = sorted([i, idx])
        color[(x, y)] = c
        dfs(i, (x, y))
        c+=1

color[(-1, -1)] = 0
dfs(0, (-1, -1))
print(ans)
for tpl in egs:
    print(color[tpl])




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

const int N = 100001;

int color[N];
bool vis[N][11];

vector<int> edges[N];

struct Query
{
	int v, d, c;
} queries[N];

void f(int v, int d, int c)
{
	if (!color[v]) {
		color[v] = c;
	}
	if (d > 0) {
		for (int i = 0; i < edges[v].size(); ++i) {
			if (!vis[edges[v][i]][d - 1]) {
				vis[edges[v][i]][d - 1] = true;
				f(edges[v][i], d - 1, c);
			}
		}
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		scanf("%d%d%d", &queries[i].v, &queries[i].d, &queries[i].c);
	}
	for (int i = q - 1; i >= 0; --i) {
		if (!vis[queries[i].v][queries[i].d]) {
			f(queries[i].v, queries[i].d, queries[i].c);
		}
	}
	for (int i = 1; i <= n; ++i) {
		printf("%d\n", color[i]);
	}
	return 0;
}



Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eb emplace_back
long power(long a,long b){return b?power(a*a%inf,b/2)*(b%2?a:1)%inf:1;}

int main() {
    int n; cin >> n;
    int h[n + 1]; rep(i, n) cin >> h[i + 1];
    int dp[n + 1]; fill_n(dp, n + 1, 0);
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    rrep(i, 3, n + 1) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n] << endl;
}


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

int main(){
    deque<int> a;
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int command;
        cin>>command;
        
        if(command==0){
            int d, x;
            cin>>d >>x;
            if(d==0){
                a.push_front(x);
            }else{
                a.push_back(x);
            }
            
        }else if(command==1){
            int p;
            cin>>p;
            cout<<a[p]<<endl;
            
        }else{
            int d;
            cin>>d;
            if(d==0){
                a.pop_front();
            }else{
                a.pop_back();
            }
        }
    }
    return 0;
}



Measured memory_bytes: 4644
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);

	static ArrayList<Integer> primes(int N) {
		ArrayList<Integer> ret = new ArrayList<Integer>();
		BitSet bs = new BitSet(N + 1);
		for (int i = 2; i <= N; i = bs.nextClearBit(i + 1)) {
			ret.add(i);
			for (int j = i * 2; j <= N; j += i) {
				bs.set(j);
			}
		}
		return ret;
	}

	static int ans = 0;
	static ArrayList<Integer> primes;
	static long L, H;

	public static void main(String[] args) throws Exception {
		long A = sc.nextLong();
		long B = sc.nextLong();
		L = Math.max(A - B, 2);
		H = A + B;
		primes = primes((int) (Math.sqrt(H) + 1));
		int[] count = new int[(int) (H - L + 1)];
		boolean[] ok = new boolean[(int) (H - L + 1)];
		Arrays.fill(ok, true);
		for (int i = primes.size() - 1; i >= 0; --i) {
			int p = primes.get(i);
			long div = (L + (p - 1)) / p;
//			System.out.println(p + " " + div + " " + (div * p));
			for (long pos = div * p; pos <= H; pos += p, ++div) {
				int cc = 1;
				long v = div;
				while (v % p == 0) {
					++cc;
					v /= p;
				}
//				System.out.println(p + " " + div + " " + cc + " " + count[(int) (pos - L)]);
				if (count[(int) (pos - L)] > cc) {
					ok[(int) (pos - L)] = false;
				}
				count[(int) (pos - L)] = cc;
			}
		}

		int ret = 0;
		for (int i = 0; i < ok.length; ++i) {
			if (ok[i]) {
//				System.out.println(i + L);
				++ret;
			}
		}
		System.out.println(ret);
	}
}

Measured memory_bytes: 19000
/*
    AUTHOR : TANMAY SINHA
    INFORMATION TECHNOLOGY
    BIT MESRA ,RANCHI
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ld long double
#define ull unsigned long long int
#define ll long long int
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define rep(i,L,R) for(i=L;i<R;i++)
#define DEBUG
#ifdef DEBUG
#define deb2(args...) {dbg,args; cerr<<endl;}
#else
#define deb2(args...)
#endif
struct debb{template<typename T> debb& operator,(const T &v){cerr<<v<<" ";return *this;}}dbg;
#define deb1(args...) do {cerr << #args << " : "; dbg,args; cerr << "\n";} while(0)
#define printa(a,L,R) rep(i,L,R) cout << a[i] <<' ';cout<<"\n";
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T>T gcd(T a,T b){if(b==0)return a;else return gcd(b,a%b);}
template<typename T>T lcm(T a,T b){return a/gcd(a,b)*b;}
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
const ll INF = 1e18l+10,N = 5e5,MAX = 5000000;
#define sq(X) ((X)*(X))

ll bit[27][N];
ll n;
ll ar[27];
void update(ll i,ll j,ll v)
{
    while(i<=n)
    {
        bit[j][i]+=v;
        i+= i & (-i);
    }
}
void sum(ll i,ll i1)
{
    ll s = 0,s1=0,k=i,k1=i1,j;
    for(j=1;j<27;j++)
    {
        while(i>0)
        {
            s+= bit[j][i];
            i-= i & (-i);
        }
        while(i1>0)
        {
            s1+= bit[j][i1];
            i1 -= i1 & (-i1);
        }
        ar[j]=s-s1;
        i = k;
        i1 = k1;
        s=0,s1=0;
    }
}
int main()
{
    ll i,j,q;
    string s;
    cin>>n>>s>>q;
    for(i=0;i<n;i++)
    update(i+1,s[i]-'a'+1,1);
    //cout<<"hell";
    while(q--)
    {
        ll t;
        cin>>t>>i;
        if(t==1)
        {
            char c;
            cin>>c;
            if(s[i-1]!=c)
            {
                update(i,s[i-1]-'a'+1,-1);
                update(i,c-'a'+1,1);
                s[i-1]=c;
            }
        }
            else
            {
                cin>>j;
                memset(ar,0,sizeof(ar));
                sum(j,i-1);
                ll cm = 0;
                for(i=1;i<27;i++)
                {
                    if(ar[i]>0)
                    cm++;
                }
                cout<<cm<<"\n";
            }
        
    }
}

Measured memory_bytes: 104324
fun main(args: Array<String>) {
    val (n,m,c) = readLine()!!.split(" ").map { it.toInt() }
    val b = readLine()!!.split(" ").map { it.toInt() }
    println((0 until n).filter {
        readLine()!!.split(" ")
            .mapIndexed{it,s->b[it]*s.toInt()}
            .sum()+c>0
    }.size)
}

Measured memory_bytes: 37952
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		int[] p=new int[n];
		int count=0;
		
		for(int i=0;i<n;i++) {
			p[i]=sc.nextInt();
		}
		
		for(int i=0;i<(n-2);i++) {
			
			if((p[i]<p[i+1]&&p[i+1]<p[i+2])||p[i+2]<p[i+1]&&p[i+1]<p[i]||(p[i]<p[i+1]&&p[i+1]==p[i+2])||p[i+2]<p[i+1]&&p[i+1]==p[i]) {
				count+=1;
			}
		}
		
		System.out.println(count);
		
		sc.close();
	}
}


Measured memory_bytes: 21588
#include<iostream>
#include<set>
#include<cstring>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s; cin >> s; 
	int n = s.length();

	int wins = 0, losses = 0;
	for(int i = 0; i < (n+1)/2; i++)
		if(s[i]=='p')
			losses++;
	for(int i = (n+1)/2; i < n; i++)
		if(s[i]=='g')
			wins++;
	cout<<wins-losses<<endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string.h>
using namespace std;

int main(){
    string s;
    cin >> s;
    int a=(s[5]-'0')*10+(s[6]-'0');
    if(a>4){
        cout << "TBD";
        return 0;
    }
    cout << "Heisei";
}

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


int main() {
int a[31]={0};
for(int u=0;u<28;u++){
	int w;
	cin>>w;
	a[w]=1;
}
for(int i=1;i<31;i++){
	if(a[i]==0) cout<<i<<endl;
	
}


	return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, d;
    set<int> s;
    cin >> N;
    REP(i, N) {
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
const int INF = 1e9;
const int MOD = 1e9 + 7;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    string m=s.substr(5,2);
    int M=stoi(m);
    if (M<=4) {
        cout<<"Heisei"<<endl;
    } else {
        cout<<"TBD"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mii map<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORD(i,a,n) for(int i=n-1;i>=0;i--)
using namespace std;
 
 
int32_t main(){
 
 
    int n,a[100001],b[100001],c[100001];
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];

    int dp[n+1][3];     //score and actitbity selected
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(j==0)
                dp[i][j]=max(dp[i-1][1],dp[i-1][2])+a[i];
            if(j==1)
                dp[i][j]=max(dp[i-1][0],dp[i-1][2])+b[i];
            if(j==2)
                dp[i][j]=max(dp[i-1][1],dp[i-1][0])+c[i];

            //cout<<dp[i][j]<<" ";
        }
    //    cout<<endl;
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2])<<endl;


 
    return 0;
 
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V){os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P){return os << "(" << P.first << "," << P.second << ")";}
#ifndef ONLINE_JUDGE
#define TRACE
#endif

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){ cout << name << " : " << arg1 << endl; }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...) 1
#endif
#define mp make_pair
#define pb push_back
#define endl '\n'
#define F first
#define S second
#define I insert
typedef long double ld;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pll> vpll;
typedef vector<pii> vpii;
const int N = 3005;
ll dp[N][N];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout<<setprecision(25);
    string s,t;
    cin>>s>>t;
    ll n,m;
    n = s.length();
    m = t.length();
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		if(s[i-1]==t[j-1])
    			dp[i][j] = 1+dp[i-1][j-1];
    		else
    			dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
    	}
    }	

    ll i,j;
    i = n; j = m;
    string r;
    while(i > 0 && j > 0){
    	// trace(i,j);
    	if(s[i-1]==t[j-1]) r += s[i-1], i--, j--;
    	else if(dp[i][j] == dp[i-1][j]) i--;
    	else j--;
    }
    reverse(r.begin(), r.end());
    assert(dp[n][m] == r.length());
    cout << r;
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        /// <summary>
        /// B - Easy Linear Programming
        /// https://atcoder.jp/contests/abc167/tasks/abc167_b
        /// </summary>
        /// <param name="args"></param>

        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列配列の入力
            int[] str_ABCK = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

            //マイナスカードの枚数
            int num_Minus = str_ABCK[3] - (str_ABCK[0] + str_ABCK[1]);

            int result = 0;

            if (str_ABCK[3] <= str_ABCK[0])   //引く枚数がＡより少ないときは引く枚数が答え
            {
                result = str_ABCK[3];
            }
            else if (str_ABCK[3] <= str_ABCK[0] + str_ABCK[1]) 
            {
                result = str_ABCK[0];
            }
            else result = str_ABCK[0] - num_Minus;


            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28204
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

typedef pair<int, int> P;

int N;

vector<int> G[2000];
int stone[2000];
int cnt[2000];
int sum_min[2000];
int sum_max[2000];
int depth[2000];
int depth_sum[2000];
bool used[2000];
void clear(){
    for(int i = 0; i < N; i++) used[i] = false;
}

void dfs(int v, int d){
    used[v] = true;
    depth[v] = d;
    cnt[v] = 0;
    sum_max[v] = 0;
    sum_min[v] = 0;
    for(int i = 0; i < G[v].size(); i++){
        if(!used[G[v][i]]){
            dfs(G[v][i], d+1);
            if((sum_min[v] > (sum_max[G[v][i]]+cnt[G[v][i]]))||(sum_max[v] < (sum_min[G[v][i]]+cnt[G[v][i]]))){
                sum_min[v] = max(sum_min[v]-(sum_max[G[v][i]]+cnt[G[v][i]]), (sum_min[G[v][i]]+cnt[G[v][i]])-sum_max[v]);
            }else{
                if((sum_max[G[v][i]]+cnt[G[v][i]]-sum_max[v])%2 == 0) sum_min[v] = 0;
                else sum_min[v] = 1;
            }
            sum_max[v] += (sum_max[G[v][i]]+cnt[G[v][i]]);
            cnt[v] += cnt[G[v][i]];
        }
    }
    if(stone[v] == 1) cnt[v]++;
}

const int INF = 1e+9;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++){
        char c;
        cin >> c;
        if(c == '0') stone[i] = 0;
        else stone[i] = 1;
    }
    for(int i = 0; i < N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int ans = INF;
    for(int i = 0; i < N; i++){
        clear();
        dfs(i, 0);
        // cout << i << ' ' << "dayooon" << endl;
        // for(int i = 0; i < N; i++){
        //     cout << sum_min[i] << ' ' << sum_max[i] << endl;
        // }
        if(sum_min[i] == 0){
            int tmp = 0;
            for(int i = 0; i < N; i++){
                if(stone[i] == 1)tmp += depth[i];
            }
            ans = min(ans, tmp);
        }
    }
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans/2 << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;
void solve(){
    char x;
    cin >> x;
    if(x == 'A') cout << 'T';
    if(x == 'T') cout << 'A';
    if(x == 'G') cout << 'C';
    if(x == 'C') cout << 'G';

}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}




Measured memory_bytes: 256
// #include <stdio.h>
// #include <string.h>
//#include <iostream>
#include <math.h>
#include <iostream>
#include <utility>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <set>


using namespace std;
typedef pair<int, int> XY;// Pair型変数の宣言
typedef long long ll;
const ll MOD = (ll)1e9 + 7;
    

int main()
{
  	int Qmax = 100001;
    int Nmax = 100001;
    int A[Qmax];
    int P[Nmax];
    int n,i,j,k;
    int len;   // 文字列の長さ
    int flag=0;

    int N,Q;
    ll K;
 
  
    
    // 数列
    scanf("%d %lld", &N,&K);
    scanf("%d", &Q);
    
    for(i=1;i<=Q;i++){
        scanf("%d ",&A[i]);
    }
    
    for(n=1;n<=N;n++){
        P[n] = K;
    }
    
    
    // 文字列の長さをチェック
    // 文字列は配列の0からlen-1に格納されてる
//    len = strlen( String );
//  	printf("%d\n",len);
    
    int win;
    
    for(i=1;i<=Q;i++){
        win = A[i];
        P[win] +=1;
    }
    
    for(n=1;n<=N;n++){
        P[n] = P[n] -Q;
    }
    
    
    for(n=1;n<=N;n++){
        if(P[n] > 0)  printf("Yes \n");
        else  printf("No \n");
    }
    
    
    
   
  
  return 0;
   
}

Measured memory_bytes: 1536
#include <iostream>
#include<vector>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#define pb push_back
#define mp make_pair

using namespace std;

int n,m,u,v;
     int color[710];
    int num[2];
    bool is[710][710];
    bool ende=false;
    vector<vector<int>> adjl;

void dfs( int x, int c )
{
    color[x]=c;
    num[c]++;
    //is[x]=true;
    for( int j = 0;j<adjl[x].size();j++ )
    {
        int v = adjl[x][j];
        if( color[v] == c )
        {
            ende=true;
            return;
        }
        if( color[v]==-1 ) dfs( v, 1-c );
    }
}

int main()
{

    cin>>n>>m;
    adjl.resize(n+1);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
            is[i][j]=false;
    }
    for( int i = 0;i<m;i++ )
    {
        cin>>u>>v;
        is[u][v]=true;
        is[v][u]=true;
    }
    /// napravimo kontra graf-  gdje su bili edgevi vise nisu i obratno
    for( int i = 1;i<=n;i++ )
    {
        for( int j = 1;j<=n;j++ )
        {
            if(j==i) continue;
            if( !is[i][j])
                adjl[i].pb(j);
        }
    }
    /// sad dfs na taj graf da nadjemo velicine grupa

    vector<pair<int,int>> g;
    for(int i=1;i<=n;i++){
            color[i]=-1;
    //is[i]=false;
    }
    for(int i=1;i<=n;i++)
            {
                if( ende==true )
                {
                    cout<<-1<<endl;
                    return 0;
                }
                if( color[i]==-1)
                    {
                        num[0]=num[1]=0;
                        dfs(i,0);
                        g.pb( mp( num[0],num[1] ) );
                    }
            }
        //    cout<<g.size() <<endl;
      //  cout<< g[0].first << " " << g[0].second<<endl;
      ///sad trazimo sumu najblizu sredini preko dp-a
      bool dp[710][710];
    for(int i=1;i<=n;i++)
    {
        for( int j =1;j<=n;j++ )
                dp[i][j]=false;
    }
    dp[0][0]=true;
    for(int i = 1;i<=n;i++)
    {
        for( int j = 1;j <= g.size();j++ )
        {
            if( i  - g[j-1].first >= 0 )
            dp[i][j] = max( dp[i][j], dp[ i - g[j-1].first ][ j-1 ]  );
            if( i - g[j-1].second >=0 )
            dp[i][j] =max(dp[i][j], dp[ i-g[j-1].second ][j-1] );
        }
    }
      //cout<<dp[3][1] <<endl;
      int sredina = n/2;
        int najblizi = -10000000000;
        int minn = 10000000000;
      for( int i = 1;i<=n;i++ )
      {
             if( dp[i][ g.size() ] && abs( sredina - i ) <minn   )
             {
                 najblizi=i;
                 minn= abs(sredina -i);
             }
      }
      int res = (najblizi*( najblizi-1 ))/2;
      res+= (( n - najblizi )*( n - najblizi - 1 ) )/2;

      cout<<res<<endl;

    return 0;
}




















Measured memory_bytes: 3584
#include<stdio.h>

int main(void)
{
	char x[1001];
	int sum[10000];
	int number;
	int i, j;
	int last = 0;
	
	for(i = 0; last != 1; i++)
	{
		scanf("%s", x);
		for(j = 0; x[j] != '\0'; j++)
		{
			if(j == 0)
			{
				sum[i] = (int)(x[j] - '0');
			}
			else
			{
				sum[i] += (int)(x[j] - '0');
			}

		}
		if(x[0] == '0' && x[1] == '\0')
		{
			last = 1;
			number = i;
		}
	}
	
	for(i = 0; i < number; i++)
	{
		printf("%d\n", sum[i]);
	}
	return 0;
}
	

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

int main(void){
  int d, e, i, j;
  double ans;
  while(1){
    cin >> d >> e;
    if(d == 0) break;
    ans = 100000;

    for(i=1;i<=d;i++){
      ans = min(ans, abs(pow(pow(i, 2) + pow(d - i, 2), 0.5) - e));
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int n; cin >> n;

   V<V<V<V<int>>>> dp(n+1, V<V<V<int>>>(5, V<V<int>>(5, V<int>(5))));
   V<int> CHAR{'$', 'A', 'G', 'C', 'T'};

   dp[0][0][0][0] = 1;
   for (int i = 0; i < n; i++) {
      for (int a = (i <= 2 ? 0 : 1); a < 5; a++) {
         for (int b = (i <= 1 ? 0 : 1); b < 5; b++) {
            for (int c = (i <= 0 ? 0 : 1); c < 5; c++) {
               for (int d = 1; d < 5; d++) {
                  string s1, s2, s3, s4;
                  s1 += CHAR[a]; s1 += CHAR[b]; s1 += CHAR[c]; s1 += CHAR[d];
                  s2 += CHAR[b]; s2 += CHAR[a]; s2 += CHAR[c]; s2 += CHAR[d];
                  s3 += CHAR[a]; s3 += CHAR[c]; s3 += CHAR[b]; s3 += CHAR[d];
                  s4 += CHAR[a]; s4 += CHAR[b]; s4 += CHAR[d]; s4 += CHAR[c];
                  if (
                      s1.substr(0,3) == "AGC" ||
                      s1.substr(1,3) == "AGC" ||
                      s2.substr(0,3) == "AGC" ||
                      s2.substr(1,3) == "AGC" ||
                      s3.substr(0,3) == "AGC" ||
                      s3.substr(1,3) == "AGC" ||
                      s4.substr(0,3) == "AGC" ||
                      s4.substr(1,3) == "AGC"
                      ) {
                     continue;
                  }
                  (dp[i+1][b][c][d] += dp[i][a][b][c]) %= MOD;
               }
            }
         }
      }
   }
   int ans = 0;
   for (int a = 0; a < 5; a++) {
      for (int b = 0; b < 5; b++) {
         for (int c = 0; c < 5; c++) {
            (ans += dp[n][a][b][c]) %= MOD;
         }
      }
   }
   cout << ans << endl;

   return 0;
}


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

int main()
{
    ll n,sum=0; cin >> n;
    for(ll i=1;i<=n;i++)
        for(ll j=1;j<=n;j++)
            for(ll k=1;k<=n;k++)
                sum += __gcd(__gcd(i,j),k);
    cout << sum;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  string S, T;
  cin >> S >> T;
  map<char, char> sm, tm;
  bool ok = true;
  REP(i, S.length()) {
    char s = S[i], t = T[i];
    if (sm.count(s)) {
      if (sm[s] != t) ok = false;
    }
    if (tm.count(t)) {
      if (tm[t] != s) ok = false;
    }
    sm[s] = t, tm[t] = s;
  }

  if (ok) {
    cout << "Yes";
  } else {
    cout << "No";
  }

  return 0;
}

Measured memory_bytes: 776
#include<iostream> 
#include<bits/stdc++.h> 
using namespace std;
const int mod=1000000007;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,K;
	cin>>N>>K;
	vector<int> a(N);
	for(int i=0;i<N;i++){ 
		cin>>a[i]; 
	} 
	vector<int> dp(K+1,0);
	vector<int> cp(K+1);
	dp[0]=1;
	for(int i=0;i<N;i++){ 
		cp=dp; 
		for(int j=1;j<=K;j++){ 
			if(j-a[i]>=1){
				dp[j]=cp[j]+(dp[j-1]-cp[j-a[i]-1]);
			}else{ 
				dp[j]=cp[j]+dp[j-1];
			}
			if(dp[j]>=mod){ 
				dp[j]-=mod; 
			}
			if(dp[j]<0){ 
				dp[j]+=mod;
			}
		} 
	}
	cout<<dp[K]; 





			

	return 0;
}



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

int main(void) {
    ll N,X,mod; cin >> N >> X >> mod;
    vector<ll> lib(mod,-1);
    vector<ll> A(10000000,0);
    A[1] = X;
    ll line1;
    for(ll i=2; i<=10000000; i++) {
        A[i] = (A[i-1]*A[i-1])%mod;
        if(lib[A[i]]>0) {
            line1 = i;
            break;
        }
        else lib[A[i]] = i;
    }

    ll a=0,b=0,e=0;
    for(int i=1; i<=lib[A[line1]]-1; i++) a+=A[i];
    //cout << "a:" << a << endl;
    for(int i=lib[A[line1]]; i<=line1-1; i++) b+=A[i];
    //cout << "b:" << b << endl;
    ll y = (N-lib[A[line1]]+1)/(line1-lib[A[line1]]);
    //cout << "y:" << y << endl;
    ll c = y*b;
    //cout << "c:" << c << endl;
    ll z = (N-lib[A[line1]]+1)%(line1-lib[A[line1]]);
    //cout << "z:" << z << endl;
    ll d;
    if(z==0) d=0;
    else {
        //d = A[lib[A[line1]]+z-1];
        for(int i=lib[A[line1]]; i<=lib[A[line1]]+z-1; i++) e+=A[i];
    }

    ll ans = a+c+e;
    cout << ans << endl;
}

Measured memory_bytes: 82156
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))

for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            continue
        else:
            print("DENIED")
            exit()

print("APPROVED")


Measured memory_bytes: 9148
//This code was made by Chinese_zjc_
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
inline int rd(int &ddd)
{
	char tmp=getchar();
	int xxx=1;
	ddd=0;
	while(('0'>tmp||tmp>'9')&&tmp!='-'&&tmp!=EOF)
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	if(tmp=='-')
	{
		xxx=-1;
		tmp=getchar();
	}
	while('0'<=tmp&&tmp<='9')
	{
		ddd=(ddd<<3)+(ddd<<1)+(tmp^48);
		tmp=getchar();
	}
	return ddd*=xxx;
}
inline char rd(char &ddd)
{
	char tmp=getchar();
	while(tmp==' '||tmp=='\n')
	{
		tmp=getchar();
	}
	if(tmp==EOF)
	{
		return EOF;
	}
	return ddd=tmp;
}
inline int max(const int &A,const int &B)
{
	return A<B?B:A;
}
inline int min(const int &A,const int &B)
{
	return A<B?A:B;
}
int n,p[51],no;
signed main()
{
	rd(n);
	for(int i=1;i<=n;++i)
	{
		rd(p[i]);
		if(p[i]!=i)
		{
			++no;
		}
	}
	if(no>2)
	{
		puts("NO");
	}
	else
	{
		puts("YES");
	}
	return 0;
}


Measured memory_bytes: 384
n = int(input())
a = [i for i in input()]
b = [i for i in input()]
c = [i for i in input()]
ans = 0

for j in range(len(a)):
	
	if a[j] == b[j] == c[j]:
		ans += 0
	elif a[j] != b[j] and b[j] != c[j] and a[j] != c[j]:
		ans += 2
	else:
		ans += 1

print(ans)


Measured memory_bytes: 3060
N,K=map(int,input().split())
ans=0
for b in range(K,N+1):
    if b==0:
        continue
    #aの数
    #N=pb+r
    #0<=r<bをp回ループした後、r個 or r+1個の余りがある
    #(b-K)でK<=r<bを表している
    #(N//b)でループ数を表している
    ans += (b-K)*int(N//b)

    if N%b>=K and K>0:
        #
        ans+=N%b-K+1
    #K=0のときのみ発動
    elif N%b>=K:
        ans+=N%b
print(ans)

Measured memory_bytes: 39024