akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace atcoder
{
    class test
    {
        static void Main(string[] args)
        {
            int N=int.Parse(Console.ReadLine());
            string[] A=Console.ReadLine().Split(' ');
            string[] B=Console.ReadLine().Split(' ');
            string[] C=Console.ReadLine().Split(' ');
            List<string> stringA=new List<string>();
            List<string> stringB=new List<string>();
            List<string> stringC=new List<string>();
            List<int> intA=new List<int>();
            List<int> intB=new List<int>();
            List<int> intC=new List<int>();


            stringA.AddRange(A);
            stringB.AddRange(B);
            stringC.AddRange(C);
            intA=stringA.ConvertAll(x=>int.Parse(x));
            intB=stringB.ConvertAll(x=>int.Parse(x));
            intC=stringC.ConvertAll(x=>int.Parse(x));


            int satuation=0;
            int menu=0;
          	int prevmenu=0;
            for(int i=0; i<N; i++)
            {	
              	prevmenu=menu;
                menu=intA[i];
                satuation+=intB[menu-1];
                if(i>0)
                {
                  if((menu-prevmenu)==1)
                  {
                    satuation+=intC[prevmenu-1];
                  }
                }
            }
            Console.WriteLine(satuation);




            

        }
    }
}

Measured memory_bytes: 13268
N, K = map(int, input().split())
S = input()

tank = []
counter = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        tank.append(counter)
        counter = 0
    counter += 1
    if i == N-1:
        tank.append(counter)

if S[0] == '0' and (len(tank)+1)//2 <= K:
    print(N)
    exit()
if len(tank)//2 <= K and S[0] == '1':
    print(N)
    exit()

ans = 0
res = 0
if S[0] == '0':
    for i in range(2*K):
        res += tank[i]
    ans = res
    for i in range(2*K, len(tank)):
        if i == 2*K:
            res -= tank[0]
        elif i%2 == 0:
            res = res - tank[i-2*K] - tank[i-2*K-1]
        res += tank[i]
        ans = max(ans, res)
else:
    for i in range(2*K+1):
        res += tank[i]
    ans = res
    for i in range(2*K+1, len(tank)):
        if i % 2 == 1:
            res = res - tank [i-2*K-1] - tank[i-2*K]
        res += tank[i]
        ans = max(ans, res)

print(ans)

Measured memory_bytes: 4092
#include<stdio.h>

int main()
{
    int r,c;
    scanf("%d %d",&r,&c);
    int rc[r+1][c+1];
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++){
            scanf("%d ",&rc[i][j]);
        }
    }
    for(int i=0;i<r;i++)
    {
        rc[i][c]=0;
        for(int j=0;j<c;j++){
            printf("%d ",rc[i][j]);
            rc[i][c] += rc[i][j];
        }
        printf("%d\n",rc[i][c]);
    }
    rc[r][c]=0;
    for(int i=0;i<c;i++){
        rc[r][i]=0;
        for(int j=0;j<r;j++){
            rc[r][i] += rc[j][i];
        }
        printf("%d ",rc[r][i]);
        rc[r][c] += rc[r][i];
    }
    printf("%d\n",rc[r][c]);
    return 0;
}


Measured memory_bytes: 2112
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        String n = sc.next();

        n = n.replaceAll("1", "0");
        n = n.replaceAll("9", "1");
        n = n.replaceAll("0", "9");
        System.out.println(n);
    }
}


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

int main()
{
	string s;
	cin >> s;
	vector<int> d(2);
	scanf("%d %d", &d[0], &d[1]);

	vector<vector<int>> a(2);
	vector<int> sum(2);
	int t = 0, now = 0;
	for (int i = 0; i < s.length(); i++)
		if (s[i] == 'F')
		{
			now++;
			if (i + 1 == s.length() || s[i + 1] == 'T')
			{
				if (!t)
					d[0] -= now;
				else
				{
					a[t & 1].push_back(now);
					sum[t & 1] += now;
				}
				now = 0;
			}
		}
		else
			++t;

	bool f = true;
	for (int _ = 0; _ < 2; _++)
	{
		d[_] = abs(d[_]);
		if (d[_] > sum[_] || (d[_] & 1) != (sum[_] & 1))
		{
			 f = false;
			 break;
		}

		vector<bool> v(sum[_] + 1, false);
		v[0] = true;
		for (int i = 0; i < a[_].size(); i++)
			for (int j = sum[_] - a[_][i]; j >= 0; j--)
				if (v[j])
					v[j + a[_][i]] = true;
		if (!v[(sum[_] - d[_]) >> 1])
		{
			f = false;
			break;
		}
	}
	if (f)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int a, b, h;
	std::cin >> a >> b >> h;
	std::cout << ((a+b)*h/2) << "\n";
}


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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define read(x) int x; cin>>x;
#define print(x) for(int i=0; i<(int) x.size(); i++) cout<<x[i]<<" "; cout<<endl;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;

const ll INFLL = (ll) 1e16;
const int INF = (int) 1e8;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string a, b;
	cin>>a>>b;
	if(b.size() != a.size()+1) cout<<"No"<<endl;
	for(int i=0; i<(int) a.size(); i++) {
		if(a[i]!=b[i]) {
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

const int MAX_N = 100000, INF = 1e9;

int N, h[MAX_N];

int m[MAX_N];

int dp(int n) {
	if (m[n] != -1) return m[n];

	if (n == 0) return m[n] = 0;
	int ret = INF;
	ret = min(ret, dp(n - 1) + abs(h[n] - h[n - 1]));
	if (n - 2 >= 0) ret = min(ret, dp(n - 2) + abs(h[n] - h[n - 2]));
	return m[n] = ret;
}

void solve() {
	memset(m, -1, sizeof(m));

	int res = dp(N - 1);
	printf("%d\n", res);
}

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &h[i]);
	}

	solve();
}

Measured memory_bytes: 4096
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element

string S;
int Q;

list<char> str;
bool is_rev = false;

signed main()
{
	cin >> S;
	for (char s : S)
	{
		str.push_back(s);
	}
	cin >> Q;
	REP(i, Q)
	{
		int t;
		cin >> t;
		if (t == 1)
		{
			is_rev = !is_rev;
		}
		else if (t == 2)
		{
			int f;
			char c;
			cin >> f >> c;

			if (is_rev)
			{
				if (f == 1) str.push_back(c);
				else str.push_front(c);
			}
			else
			{
				if (f == 2) str.push_back(c);
				else str.push_front(c);
			}
		}
	}

	
	if (is_rev)
	{
		REVERSE(str);
	}

	string ans;
	for(char ch : str) ans += ch;
	cout << ans << endl;
}




Measured memory_bytes: 10500
#### import ####
import sys
sys.setrecursionlimit(10**7)
import math
from collections import defaultdict

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

N = I()
a = III()

ans = 0
for i in range(N):
  if a[a[i]-1]==i+1:
    ans += 1
print(ans//2)

Measured memory_bytes: 52336
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cout<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}


typedef long long int64;


int main() {
    int n;
    int ans = 0;
    cin >> n;
    vector<int> p(n);
    for (int i=0; i<n; i++) cin >> p[i];
    int pre = INT_MAX;
    for (int i=0; i<n; i++) {
        if (p[i] < pre) ans++;
        pre = min(pre, p[i]);
    }

    cout << ans << endl;
}

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

int Exp(long long int exp_n,long long int exp_e, long long exp_mod);


int main(){
  string S,T;
  int C=0,c;
  cin >> S >> T;
  for(int i=0;i<S.length()-T.length()+1;i++){
    c=0;
    for(int j=0;j<T.length();j++){
      if(S[i+j]==T[j]){
        c++;
      }
    }
    C=max(C,c);
  }
  cout << T.length()-C <<endl;
}


int Exp(long long int exp_n,long long int exp_e, long long int exp_mod){
  long long int exp_o = 1;
  long long int exp_x=exp_n;
  long long int exp_tmp;
  
  while(0<exp_e){
    exp_tmp = exp_e/2;
    if(exp_e - exp_tmp*2 == 1){
      exp_o = exp_o*exp_x;
      if(exp_o>exp_mod){
        exp_o=exp_o%exp_mod;
      }
    }
    
    exp_x = exp_x*exp_x;
    if(exp_x>exp_mod){
      exp_x=exp_x%exp_mod;
    }
    exp_e = exp_tmp;
  }
  return exp_o;
}


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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define TIME_MAX 1265

typedef vector<int> vi;
typedef vector<vi> vvi;

int main()
{
	while (1)
	{
		int N, M;
		cin >> N >> M;
		if (N == 0) return 0;

		int r; cin >> r;
		vvi count(M + 1, vi(TIME_MAX));
		rep(m, 1, M + 1) rep(t, 0, TIME_MAX) count[m][t] = 0;

		rep(i, 0, r)
		{
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if (s == 1)
				count[m][t]++;
			else
				count[m][t+1]--;
		}

		rep(m, 1, M + 1) rep(t, 1, TIME_MAX) count[m][t] += count[m][t - 1];
		rep(m, 1, M + 1) rep(t, 0, TIME_MAX) if (count[m][t] > 0) count[m][t] = 1;

		int q; cin >> q;
		rep(i, 0, q)
		{
			int ts, te, m;
			cin >> ts >> te >> m;

			int ans = 0;
			int left = -1;
			rep(t, ts, te + 1)
			{
				if (count[m][t] > 0)
				{
					if (left < 0)
						left = t;
				}
				else
				{
					if (left >= 0)
					{
						ans += t-1 - left;
						left = -1;
					}
				}
			}
			if (left >= 0) ans += te - left;

			cout << ans << endl;
		}
	}
}

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

int main(void)
{
    int a,b,c,num;
    cin >> a >> b >> c;
    num = a * 100 +  b * 10 + c;
    if(num % 4 == 0) cout << "YES" << endl;
    else cout << "NO" << endl; 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i=0;i<h;i++)
        for(int j=0;j<w;j++) cin >> s[i][j];

    int x[h][w]={};
    int y[h][w]={};

    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++){
            if(s[i][j] == '#') continue;

            y[i][j] = (0<i?y[i-1][j]:0) + 1;
            x[i][j] = (0<j?x[i][j-1]:0) + 1;
        }
    }
    int ans = 0;
    for(int i=h-1;i>=0;i--) {
        for(int j=w-1;j>=0;j--){
            if(s[i][j] == '#') continue;
            if(i<h-1) y[i][j]=max(y[i+1][j], y[i][j]);
            if(j<w-1) x[i][j]=max(x[i][j+1], x[i][j]);
            ans = max(ans, x[i][j]+y[i][j]-1);
        }
    }

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


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
string s[22];
int n,m,vis[22][22];
queue<pair<int,int>>q;
int dx[]={-1,1,0,0};
int dy[]={0,0,1,-1};
int BFS(int st,int en)
{
    memset(vis,-1,sizeof(vis));
    int i,x,xx,y,yy,mx=0;
    vis[st][en]=0;
    q.push({st,en});
    while(!q.empty())
    {
        x=q.front().first;
        y=q.front().second;
        q.pop();
        for(i=0;i<4;i++)
        {
            xx=x+dx[i];
            yy=y+dy[i];
            if(xx>=0 && xx<n && yy>=0 && yy<m && s[xx][yy]=='.' && vis[xx][yy]==-1)
            {
                vis[xx][yy]=vis[x][y]+1;
                mx=max(mx,vis[xx][yy]);
                q.push({xx,yy});
            }
        }
    }
    return mx;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int i,j,ans=0;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(s[i][j]=='.')
            {
                ans=max(ans,BFS(i,j));
            }
        }
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 256
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

def dfs(i, A, ans):
    if i == 10:
        ans.append(A)
        return ans
    B = A[:]
    B.append(0)
    ans = dfs(i+1, B, ans)
    C = A[:]
    C.append(1)
    ans = dfs(i+1, C, ans)
    return ans

def main():
    D = dfs(0, [], [])
    for ind, A in enumerate(D):
        if ind == 0:
            continue
        gain = 0
        for i in range(N):
            c = 0
            for day in range(10):
                c += F[i][day]*A[day]
            gain += P[i][c]
        if ind == 1:
            ans = gain
            continue
        ans = max(ans, gain)

    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

/*
1
268435455
1

あとソート
*/
const int MB = 29;
int N;
vector<int> A,B;
void solve(){
	cin >> N;
	A = vector<int>(N);
	B = vector<int>(N);
	
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	for(int i=0;i<N;++i){
		cin >> B[i];
	}
	////
	int mask = (1<<29)-1;
	int ans = 0;
	
	int ter,T;
	LL count;
	vector<int>::iterator LeftItr,RightItr;
	
	for(;mask;){
		T = (mask+1)>>1;
		count = 0;
		for(int i=0;i<N;++i){
			A[i] &= mask;
		}
		sort(A.begin(),A.end());//////////これが必要

		for(int i=0;i<N;++i){
			ter = B[i] & mask;
			LeftItr = lower_bound(A.begin(),A.end(),T-ter);
			RightItr = lower_bound(A.begin(),A.end(),2*T-ter);
			count += RightItr - LeftItr;
			
			LeftItr = lower_bound(A.begin(),A.end(),3*T-ter);
			RightItr = lower_bound(A.begin(),A.end(),4*T-ter);
			//RightItr = A.end();
			count += RightItr - LeftItr;
		}
		if( count&1 ){
			ans ^= T;
		}
		//次への処理
		mask >>= 1;
	}
	
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

c_dic = {}
for i in range(1,n+1):
    c_dic[i] = 0

for i in a:
    c_dic[i] += 1

ans_dic = {}
ans = 0
for i in range(1,n+1):
    ans_dic[i] = (c_dic[i] * (c_dic[i] -1) )//2
    ans += ans_dic[i]

for i in range(n):
    print(ans - max(c_dic[a[i]] -1 , 0))

Measured memory_bytes: 121028
s = input()

n = len(s)
ans = n
for i in range(1, n):
    if s[i - 1] != s[i]:
        # left:  [0, i) -> length = i
        # right: [i, n) -> length = n - i
        ans = min(ans, max(i, n - i))

print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    map<string, int> omikuji;
    for (int i = 0; i < N; i++) {
        cin >> S.at(i);
        if (omikuji.find(S.at(i)) == omikuji.end()) {
            omikuji[S.at(i)] = 1;
        }
    }
    cout << omikuji.size() << endl;
}

Measured memory_bytes: 25080
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {int p, l, r;};

Node T[MAX];
int n,D[MAX];
void print(int u) {

  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if ( T[u].p == NIL ) cout << "root, ";
  else if (T[u].l == NIL ) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for( i = 0,c = T[u].l;c != NIL; i++, c = T[c].r) {
    if (i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

int rec(int u, int p){
  D[u] = p;
  if ( T[u].r != NIL ) rec(T[u].r, p);
  if ( T[u].l != NIL ) rec(T[u].l, p + 1);
}

int main(){
  int i,j,d,v,c,l,r;
  cin >> n;
  for( i = 0; i < n; i++ ) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0;i<n;i++){
    cin >> v >> d;
    for(j=0;j<d;j++){
      cin >> c;
      if(j==0) T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
    }
  }


  for( i = 0; i < n; i++ ){
    if(T[i].p==NIL)r=i;
  }

  rec(r,0);

  for(i=0;i<n;i++) print(i);

  return 0;
}

Measured memory_bytes: 5840
n = int(input())
ans = 0
for i in range(1, n+1):
    ans += i*(n-i+1)

for _ in range(n-1):
    u, v = map(lambda x: int(x)-1, input().split())
    if u > v: u, v = v, u
    ans -= (u+1) * (n-v)

print(ans)


Measured memory_bytes: 9184
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

int x , y , now ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> x >> y ;
	if ( x % y == 0 )
		return cout << -1 << '\n' , 0 ;
	cout << x << '\n' ; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const double oo = 1E9;
const double EPS = 1E-9;

vector<double> GetTim(double v0, double v1, double T, double LIMIT){
  double t1 = (T + v1 - v0) / 2;
  relaxMin(t1, LIMIT - v0);
  double t2 = t1 + v0 - v1;
  double t_mid = T - t1 - t2;

  if(t1 < -EPS || t2 < -EPS || t_mid < -EPS)
    return {};

  return {t1, t_mid, t2};
}

double OneDist(double v, double a, double t){
  return v * t + a * SQR(t) / 2;
}

double Dist(double v0, const vector<double>& tims){
  return OneDist(v0, +1, tims[0]) +
         OneDist(v0 + tims[0], 0, tims[1]) +
         OneDist(v0 + tims[0], -1, tims[2]);
}

int n;
vector<double> t;
vector<double> v;

double dp[210][110];

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

  cin >> n;
  t.resize(n);
  v.resize(n);
  for(int i = 0;i < n;++i) cin >> t[i];
  for(int i = 0;i < n;++i) cin >> v[i];

  for(int i = 0;i < n;++i)
    for(int j = 0;j < 110;++j)
      dp[i][j] = -oo;

  for(int ev = 0;ev <= v[0];++ev){
    auto s = GetTim(0, ev, t[0], v[0]);
    if(!s.empty()) dp[0][ev] = Dist(0, s);
  }

  for(int i = 1;i < n;++i)
    for(int ev = 0;ev <= v[i];++ev)
      for(int sv = 0;sv <= v[i];++sv){
        if(dp[i - 1][sv] < 0) continue;
        auto s = GetTim(sv, ev, t[i], v[i]);
        if(s.empty()) continue;
        relaxMax(dp[i][ev],
                 dp[i - 1][sv] + Dist(sv, s));
      }

  printf("%.12f\n", dp[n - 1][0]);

  return 0;
}


Measured memory_bytes: 384
N = int(input())
A = [0] * (N+1)

for i in range(1, N+1):
    A[i] = int(input())

sorted_A = sorted(A)
sorted_dict_A = { sorted_A[i]: i for i in range(1, N+1) }

cnt = 0
for i in range(1, N+1):
    ind = sorted_dict_A[A[i]]
    if ind % 2 != i % 2:
        cnt += 1

print(cnt // 2)


Measured memory_bytes: 57432
//#pragma GCC         optimize("O3")
#include            <bits/stdc++.h>
#include            <ext/pb_ds/assoc_container.hpp>
#include            <ext/pb_ds/tree_policy.hpp>
#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define mp          make_pair
#define mem(x,i)    memset(x,i,sizeof(x))
#define ff          first
#define ss          second
#define popcount(x) __builtin_popcount(x)
#define all(x)      x.begin(),x.end()
#define Case(t)     for(int ks=1;ks<=t;ks++)
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define D(x)        cerr<< __LINE__ <<": "<< #x << " = "<<(x) <<'\n';
#define endl        '\n'

using namespace std;
using namespace __gnu_pbds;

using ll  = long long;
using ld  = long double;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;

const int INF    = 0x3f3f3f3f;
const ll LL_INF  = 0x3f3f3f3f3f3f3f3f;
const double PI  = acos(-1);
const double eps = 1e-4;
const int mod    = 1e9+7;
const int mx     = 5e5+5;
template <typename T>  using orderedSet =
    tree<T, null_type, less_equal<T>,
    rb_tree_tag, tree_order_statistics_node_update>;//find_by_order,order_of_key*/

/*------------------------------Graph Moves----------------------------*/
//const int fx[]= {+1,-1,+0,+0};
//const int fy[]= {+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

//ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
/*----------------------BitMask-----------------------------------------*/
//inline int setBit(int N,int pos){return N=N | (1<<pos);}
//inline int resetBit(int N,int pos){return N= N & ~(1<<pos);}
//inline bool checkBit(int N,int pos){return (bool) (N& (1<<pos));}
int arr[mx];
int main()
{
    int n;
    cin>>n;
    map<string,int>mm;
    map<int,string>m2;
    int cur=1;
    for(int i=0;i<n;i++)
    {
        string str;
        cin>>str;
        if(mm[str]==0) {mm[str]=cur;m2[cur]=str;cur++;}
        arr[mm[str]]++;
    }
    int val=0;
    for(int i=1;i<cur;i++) val=max(val,arr[i]);
    vector<string>ans;
    for(int i=1;i<cur;i++) if(arr[i]==val) ans.pb(m2[i]);
    sort(all(ans));
    for(string s:ans) cout<<s<<endl;

}


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

int main(){
    int n;
    cin >> n;
    vector<vector<bool>> A(n, vector<bool>(n, true));

    vector<int> P(n * n);
    for (auto &p: P){
        cin >> p;
        p--;
    }

    vector<array<int, 2>> f(n * n);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            f[i * n + j] = {i, j};
        }
    }

    vector<vector<int>> D(n, vector<int>(n));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            D[i][j] = min({i, n - i - 1, j, n - j - 1});
        }
    }

    int ans = 0;
    vector<int> dh = {0, 0, 1, -1}, dw = {1, -1, 0, 0};
    for (const auto &p: P){
        ans += D[f[p][0]][f[p][1]];
        A[f[p][0]][f[p][1]] = false;
        queue<array<int, 2>> Q;
        Q.push(f[p]);
        while (!Q.empty()){
            auto cur = Q.front();
            Q.pop();
            for (int i = 0; i < 4; i++){
                int nh = cur[0] + dh[i];
                int nw = cur[1] + dw[i];
                if (nh < 0 or nh >= n or nw < 0 or nw >= n)
                    continue;
                if (D[nh][nw] > D[cur[0]][cur[1]] + A[cur[0]][cur[1]]){
                    Q.push({nh, nw});
                    D[nh][nw] = D[cur[0]][cur[1]] + A[cur[0]][cur[1]];
                }
            }
        }
    }

    cout << ans << endl;
}

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

class Vector2{
public:
	Vector2(){}
	Vector2( double aX, double aY ) : x( aX ), y( aY ){}

	double dot( Vector2& a ){
		return ( x * a.x ) + ( y * a.y );
	}

	double x;
	double y;
};


int main(){
	Vector2 p0, p1, p2, q;

	while ( cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> q.x >> q.y ){
		bool isInner = false;
		Vector2 a( p1.x - p0.x, p1.y - p0.y );
		Vector2 b( p2.x - p0.x, p2.y - p0.y );
		Vector2 c( q.x - p0.x, q.y - p0.y );

		double aa = a.dot( a );
		double ab = a.dot( b );
		double ac = a.dot( c );
		double bb = b.dot( b );
		double bc = b.dot( c );

		double s = ( bc*ab - ac*bb ) / ( ab*ab - aa*bb );
		if ( ( s > 0.0 ) && ( s < 1.0 ) ){
			double t = ( ac*ab - bc*aa ) / ( ab*ab - aa*bb );
			if ( ( t > 0.0 ) && ( s + t < 1.0 ) ){
				isInner = true;
			}
		}

		cout << ( isInner ? "YES" : "NO" ) << endl;
	}


	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int h; cin >> h;
    int w; cin >> w;
    int n; cin >> n;
    cout << (n + max(h,w) -1) / max(h,w) << endl;
}


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

int main(){
    int num;
    string c;
    cin >> c;
    c[0]+=1;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
def factorization(n):
 arr = []
 temp = n
 for i in range(2, int(-(-n**0.5//1))+1):
  if temp%i==0:
   cnt=0
   while temp%i==0:
    cnt+=1
    temp //= i
   arr.append([i, cnt])
 if temp!=1:
  arr.append([temp, 1])
 if arr==[]:
  arr.append([n, 1])
 return arr

C=1
A,B=map(int,input().split())
a=factorization(A)
b=factorization(B)
for i in range(len(a)):
 a[i][1]=0
for i in range(len(b)):
 b[i][1]=0
for i in range(len(a)):
 if a[i] in b:
  if a[i][0]>1:
   C+=1
print(C)


Measured memory_bytes: 38512
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main()
{
	int i,a,b,c,key=0,x;
	scanf("%d%d%d",&a,&b,&c);
	for(i=1;i<=2000000;i++)
	{
		x=a*i;
		if(x%b==c)
		key=1;
	}
	if(key)
    printf("YES\n");
    else
	printf("NO\n");
    return 0;
}

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

using namespace std;

int main(void)
{
	string s;
	cin >> s;
	int a = 0;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+') {
			a++;
		}
		else {
			a--;
		}
	}
	cout << a << endl;
	
	return 0;
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
  if p[i-1] < p[i] and p[i] < p[i+1]: ans += 1
  if p[i-1] > p[i] and p[i] > p[i+1]: ans += 1
print(ans)

Measured memory_bytes: 9084
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		int ans = 0;
		
		for(int loop = 0; loop < n; loop++){
			int x, y, h, w;
			cin >> x >> y >> h >> w;
			int length = x + y + h;
			if(length <= 60 && w <= 2){
				ans += 600;
			}else if(length <= 80 && w <= 5){
				ans += 800;
			}else if(length <= 100 && w <= 10){
				ans += 1000;
			}else if(length <= 120 && w <= 15){
				ans += 1200;
			}else if(length <= 140 && w <= 20){
				ans += 1400;
			}else if(length <= 160 && w <= 25){
				ans += 1600;
			}
		}
		
		cout << ans << endl;
		
	}
	return 0;
}

Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
using namespace std;
char c;
int a[5];
int main()
{
	for(int i=1;i<=4;i++){
		cin>>c;
		a[i]=c-'0';
	}
	for(int i=2;i<=4;i++)
	  if(a[i]==a[i-1]){
	  	printf("Bad\n");
	  	return 0;
	  }
	printf("Good\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 100100100100100100
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep2(i,a,n) for(int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

using namespace std;

typedef long long ll;
typedef pair<ll, ll> PLL;

int main() 
{
    int n,m;
    int ans = 0;
    cin >> n >> m;
    vector<int> dish(m,0);
    
    rep(i,n) {
        int k;
        cin >> k;
        rep(j,k) {
            int tmp;
            cin >> tmp;
            dish[--tmp]++;
        }
    }
    rep(i,m) {
        if(dish[i] == n) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};



#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define gap ' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)
#define r return 0

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///

 int main()
 { ll x,n;
 cin>>x>>n;
 if(x*500>=n)cout<<"Yes"<<endl;
 else
    cout<<"No"<<endl;


 r;


}


///Thanking you by Roxy





Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll a;cin>>a;
    ll b=a/500;b*=1000;
    ll c=a%500;c/=5;c*=5;
    cout<<b+c<<"\n";
}



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

using namespace std;

#define int long long
#define reg register
#define Raed Read
#define clr(a,b) memset(a,b,sizeof a)
#define Mod(x) (x>=mod)&&(x-=mod)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define rep(a,b,c) for(reg int a=(b),a##_end_=(c); a<=a##_end_; ++a)
#define ret(a,b,c) for(reg int a=(b),a##_end_=(c); a<a##_end_; ++a)
#define drep(a,b,c) for(reg int a=(b),a##_end_=(c); a>=a##_end_; --a)
#define erep(i,G,x) for(int i=(G).Head[x]; i; i=(G).Nxt[i])
#pragma GCC target("avx,avx2,sse4.2")
#pragma GCC optimize(3)

inline int Read(void) {
	int res=0,f=1;
	char c;
	while(c=getchar(),c<48||c>57)if(c=='-')f=0;
	do res=(res<<3)+(res<<1)+(c^48);
	while(c=getchar(),c>=48&&c<=57);
	return f?res:-res;
}

template<class T>inline bool Min(T &a, T const&b) {
	return a>b?a=b,1:0;
}
template<class T>inline bool Max(T &a, T const&b) {
	return a<b?a=b,1:0;
}
const int N=15,M=1e5+5;

bool MOP1;

int A[100005];

bool MOP2;

void _main(void) {
//	cerr<<"M="<<(&MOP2-&MOP1)/1024.0/1024.0<<endl;
	int n=Read(),Ans=0;
	Ans=n*(n-1)/2;
	printf("%lld\n",Ans);
}

signed main() {
	_main();
}

Measured memory_bytes: 256
S=input()

if 0 < int(S[:2]) < 13 and 0 < int(S[2:]) < 13:
    print('AMBIGUOUS')
    exit()

if 0 <= int(S[:2]) and 0 < int(S[2:]) < 13:
    print('YYMM')
    exit()
if 0 < int(S[:2]) < 13 and 0 <= int(S[2:]):
    print('MMYY')
    exit()
else:
    print('NA')


Measured memory_bytes: 3060
import java.util.Scanner;

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

	public static void atcode() {
		Integer N=Integer.valueOf(new Scanner(System.in).nextLine());
		boolean yes=false;
		for(int d=N/7;d>=0;d--) {
			for(int c=N/4;c>=0;c--) {
				if(7*d+4*c==N)yes=true;
			}
		}
		System.out.println(yes?"Yes":"No");
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll A[3005],dp[3005][3005][2];            
int main(){
    int n; cin >> n;
	vector<ll> a(n);
 
	for(int i=0;i<n;i++) {cin >> a[i]; dp[i][i][0] = a[i]; dp[i][i][1] = -a[i];}
 
	for(int i=n-1;i>=0;i--) {
		for(int j=i+1;j<n;j++) {
			dp[i][j][0] = max(a[i] + dp[i+1][j][1],a[j] + dp[i][j-1][1]);
			dp[i][j][1] = min(-a[i] + dp[i+1][j][0],-a[j] + dp[i][j-1][0]);
		}
	}
 
	cout << dp[0][n-1][0] << endl;
}


Measured memory_bytes: 139648
#include<stdio.h>
#define MAX 10000

int main(){
    char x[MAX];
    int i, j;
    int sum1 = 0;
    int sum2[MAX] = {};
    for(i = 0; i < MAX; i++){
        scanf("%s", x);
        if(x[0] == '0') break;
        for(j = 0; x[j] != '\0'; j++){
            sum1 += x[j] - '0';
        }
        sum2[i] = sum1;
        sum1 = 0;
    }
    for(i = 0; i < MAX; i++){
        if(sum2[i] == 0) break;
        printf("%d\n", sum2[i]);   
    }
    return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define pii pair<int,int>
using namespace std;
const int N=1e5+5;
int n,cnt; pii e[N]; char s[N];
int main(){
	scanf("%s",s+1); n=strlen(s+1);
	if (s[n]=='1'||s[1]=='0') return puts("-1"),0;
	rep (i,1,n/2) if (s[i]^s[n-i]) return puts("-1"),0;
	int x=1,y=1;
	rep (i,1,n-1){ e[++cnt]=pii(x,++y); if (s[i]=='1') x=y; }
	rep (i,1,n-1) printf("%d %d\n",e[i].first,e[i].second);
	return 0;
}

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

using namespace std;

int main()
{
    int n, arr[300], sum=0;
    cin>>n;
    for(int i=0;i<2*n;++i)
    cin>>arr[i];
    sort(arr, arr+2*n);
    for(int i=0;i<2*n;i+=2)
    sum+=arr[i];
    cout<<sum;
}

Measured memory_bytes: 256
n = int(input())
g = [[-1 for _ in range(15)] for _ in range(15)]
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
    g[i][x-1] = y
    
ans = 0
for bit in range(1<<n):
  honests = [0]*n
  for i in range(n):
    if bit & 1<<i: honests[i] = 1
  flg = True
  for i in range(n):
    if honests[i]:
      for j in range(n):
        if g[i][j] == -1: continue
        if g[i][j] != honests[j]: flg = False
  if flg:
    ans = max(ans, honests.count(1))
print(ans)

Measured memory_bytes: 9248
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

const string YES = "Yes";
const string NO = "No";

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

  char a[1] = {0};
  cin >> a;
  a[0]++;
  cout << a[0] << endl;







}


Measured memory_bytes: 256
s = input()
arr = list(s)

first0 = 0
# first0
for i in range(len(arr)):
    if i % 2 == 0:
        if arr[i] == '1':
            first0 += 1
    else:
        if arr[i] == '0':
            first0 += 1

#first1
first1 = 0
for i in range(len(arr)):
    if i % 2 == 0:
        if arr[i] == '0':
            first1 += 1
    else:
        if arr[i] == '1':
            first1 += 1

ans = min(first0, first1)

print(ans)

Measured memory_bytes: 3956
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(int a, int n) {//aのn乗を計算します。
	int x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

ll layer[51];
ll all_pate[51];
ll pate(int n,ll k){
	if(n==0){
		if(k==0)return 0;
		else return 1;
	}
	if(k==0)return 0;
	if(k==layer[n]){
		return all_pate[n];
	}
	if(k<=layer[n-1]+1){
		return pate(n-1,k-1);
	}
	else if(k==layer[n-1]+2){
		return all_pate[n-1]+1;
	}
	else if(k>=layer[n-1]+3){
		ll dif=k-layer[n-1]-2;
		return all_pate[n-1]+1+pate(n-1,dif);
	}
}
int main() {
	layer[0]=1;
	all_pate[0]=1;
	FOR(i,1,51){
		layer[i]=2*layer[i-1]+3;
		all_pate[i]=all_pate[i-1]*2+1;
	}
	int N;
	ll K;
	cin>>N>>K;
	ll ans=pate(N,K);
	cout<<ans<<endl;
}

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

int mylog(int N){
  int s=1;
  int i=0;
  while(N>s){
    s*=2;
    i++;
  }
  return i;
}

int main(){
  int N,K; cin >> N >> K;
  vector<long long> A(N,0);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  
  vector<long long> B(N,0);
  K=min(K,100*mylog(N));
  for(int c=0; c<K; c++){
    for(int i=0; i<N; i++) B[i]=0;
    for(int i=0; i<N; i++){
      if(i-A[i]>=0){
        B[i-A[i]]++;
      }else{
        B[0]++;
      }
      
      if(i+A[i]+1<N){
        B[i+A[i]+1]--;
      }
    }
    for(int i=1; i<N; i++) B[i]+=B[i-1];
    for(int i=0; i<N; i++) A[i]=B[i];
  }
  
  for(int i=0; i<N; i++){
    cout << B[i];
    if(i==N-1) cout << endl;
    else cout << " ";
  }
}

Measured memory_bytes: 6424
#include <iostream>  
#include <stdlib.h>  
using namespace std;


int main() {
	int tate, yoko;
	while (true)
	{
		cin >> tate >> yoko;
		if (tate == 0 && yoko == 0)
			break;
		for (int i = 0; i < tate; i++){
			for (int j = 0; j < yoko; j++) 

				if (i != 0 && j != 0 && i != tate - 1 && j != yoko - 1)
					cout << ".";
				else
					cout << "#";
				cout << "\n";
			}
		cout << "\n";
	}
	

}

Measured memory_bytes: 1120
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
	int c[26]={0}, flag, i, len;
	char w[110];
	scanf("%s", &w);
	len = strlen(w);
	for (i=0;i<len;i++) c[w[i]-'a']++;
	for (i=0;i<26;i++) {
		if (c[i]%2 == 0) flag = 0;
		else { flag = 1; break; }
	}
	if (flag) printf("No\n");
	else printf("Yes\n");

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
  int a;
    scanf("%d", &a);
  if (a>=400&&a<=599)
    printf("8\n");
   if (a>=600&&a<=799)
    printf("7\n");
   if (a>=800&&a<=999)
    printf("6\n");
   if (a>=1000&&a<=1199)
    printf("5\n");
   if (a>=1200&&a<=1399)
    printf("4\n");
   if (a>=1400&&a<=1599)
    printf("3\n");
   if (a>=1600&&a<=1799)
    printf("2\n");
   if (a>=1800&&a<=1999)
    printf("1\n");
  return 0;
}

Measured memory_bytes: 1660
n = int(input())
a = []
b = []
for i in range(n):
	a_1, b_1 = input().split()
	a.append(int(a_1))
	b.append(int(b_1))
a.sort()
b.sort()
is_odds = n % 2 == 0
a_med = a[(n + 1) // 2 - 1] if not is_odds else (a[n // 2 - 1] + a[n // 2]) / 2
b_med = b[(n + 1) // 2 - 1] if not is_odds else (b[n // 2 - 1] + b[n // 2]) / 2
from_a = a_med if not is_odds else int(a_med * 2)
to_b = b_med if not is_odds else int(b_med * 2)
print(to_b - from_a + 1)

Measured memory_bytes: 25560
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    while (1)
    {
        int n, s, ba=0;
        bool c[210], check, ok[210];
        memset(c,true,sizeof(c)); memset(ok, true, sizeof(ok));
        cin>>n;
        if (n==0) break;
        for (int i=0; i<n; i++) { cin>>s; c[s]=false; }
        for (bool f=false; ; f=!f)
        {
            check=false;
            for (int i=ba+1; i<=2*n; i++)
            {
                if (c[i]==f && ok[i]) { ba=i; ok[i]=false; i=3*n; check=true; }
            }
            if (!check) ba=0;
            check=false;
            for (int i=1; i<=2*n; i++)
            {
                if (ok[i]) if (c[i]) check=true;
            }
            if (!check)
            {
                s=0;
                for (int i=1; i<=2*n; i++) if (ok[i]) s++;
                cout<<"0\n"<<s<<'\n';
                goto Exit;
            }
            check=false;
            for (int i=1; i<=2*n; i++)
            {
                if (ok[i]) if (!c[i]) check=true;
            }
            if (!check)
            {
                s=0;
                for (int i=1; i<=2*n; i++) if (ok[i]) s++;
                cout<<s<<"\n0\n";
                goto Exit;
            }
        }
        Exit: ;
    }
    return 0;
}



Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> rs(n + 1);
    for (int i = 0; i < n; i++) {
        int r, c;
        cin >> r >> c;
        rs[i] = r;
        rs[i + 1] = c;
    }

    vector<vector<int>> dp(n + 1, vector<int>(n + 1, 1 << 25));
    for (int i = 0; i <= n; i++) {
        dp[i][i] = 0;
    }

    for (int j = 1; j < n; j++) {
        for (int i = 0; i <= n - j; i++) {
            for (int k = i + 1; k <= i + j; k++) {
                dp[i][i + j] = min(dp[i][i + j], dp[i][k - 1] + dp[k][i + j] + rs[i] * rs[k] * rs[i + j + 1]);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
}

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

int main(){
    int N;
    cin >> N;
    int n = N;
    int Sn = 0;
    bool flag = true;
    while(flag){
        Sn += n%10;
        if(n>0){
            n /= 10;
        }else{
            flag = false;
        }
    }
    if(N%Sn == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 256
from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from collections import Counter

def main():
    n, m = map(int, input().split())
    par = [i for i in range(n)]
    size = [1] * n

    def root(x):
        if par[x] == x:
            return x
        else:
            par[x] = root(par[x])
            return par[x]

    def same(x, y):
        return root(x) == root(y)

    def unite(x, y):
        x = root(x)
        y = root(y)
        if x == y:
            return
        par[x] = y
        size[y] += size[x]
    
    for _ in range(m):
        x, y, z = map(int, input().split())
        unite(x - 1, y - 1)
    for i in range(n):
        root(i)
    print(len(Counter(par)))

main()

Measured memory_bytes: 40936
#include<cstdio>
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
ll a[101010];
int n;
ll ans;
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
		scanf("%lld",&a[i]);
	for (int i=0;i<=n;++i)
		ans+=abs(a[i+1]-a[i]);
	for (int i=1;i<=n;++i)
		printf("%lld\n",ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]) );

	return 0;
}

Measured memory_bytes: 2048