akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define p(x,y) pair<x,y>
#define pb push_back
#define fo(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main()
{


string s,p;
cin>>s>>p;

ll u,v;
u=s.length();
v=p.length();

ll dp[u+1][v+1];


for(int i=0;i<=u;i++)
{
    for(int j=0;j<=v;j++)
    {
      if(i==0 || j==0 )
      {
          dp[i][j]=0;
      }

      else if(s[i-1]==p[j-1])
      {

          dp[i][j]=1+dp[i-1][j-1];
      }

      else
      {

          dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }

    }
}


string ans="";

while(u!=0 && v!=0)
{

    if(s[u-1]==p[v-1])
    {

        ans+=s[u-1];
        u--;
        v--;


    }
    else if(dp[u][v]==dp[u][v-1])
    {
        v--;
    }

    else if(dp[u][v]==dp[u-1][v])
    {
        u--;
    }



}


reverse(ans.begin(),ans.end());

cout<<ans<<endl;


}


Measured memory_bytes: 70656
import sys
sys.setrecursionlimit(10 ** 7)

from collections import deque
INF = float('inf')
def resolve():
    H, W, K = map(int, input().split())
    sx, sy, gx, gy = map(lambda x:int(x)-1, input().split())
    G = [list(input()) for _ in range(H)]

    dist = [[INF] * W for i in range(H)]
    dist[sx][sy] = 0
    q = deque([(sx, sy)])

    drc = [(-1, 0), (0, 1), (1, 0), (0, -1)]
    while q:
        x, y = q.popleft()
        if (x, y) == (gx, gy):
            print(dist[x][y])
            return
        for dx, dy in drc:
            nx = x
            ny = y
            for k in range(K):
                nx += dx
                ny += dy
                if 0 <= nx < H and 0 <= ny < W and G[nx][ny] != '@':
                    if dist[nx][ny] <= dist[x][y]:
                        break
                    if dist[nx][ny] == INF:
                        q.append((nx, ny))
                    dist[nx][ny] = dist[x][y] + 1
                else:
                    break
    print(-1)

if __name__ == "__main__":
    resolve()


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

int main(){
    int n;
    cin >> n;
    vector<tuple<string,int,int>> ms(n);
    string ct;
    int pnt,num;
    for(int i=0;i<n;i++){
        cin >> ct >> pnt;
        ms.at(i) = make_tuple(ct,-1*pnt,i);
    }
    sort(ms.begin(),ms.end());

    for(auto a:ms){
        tie(ignore, ignore, num) = a;
        cout << num+1 << endl;
    }
}

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

int main(){
    string s1, s2;
    cin >> s1 >> s2;
    reverse(s2.begin(), s2.end());
    if(s1 == s2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> dp(n, INT_MAX);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for (int i = 2; i < n; i++)
	{
		dp[i] = min((dp[i - 1] + abs(a[i] - a[i - 1])), (dp[i - 2] + abs(a[i] - a[i - 2])));
	}
	cout << dp[n - 1];
	return 0;
}

Measured memory_bytes: 1024
Public Class Program
  Shared Sub Main()
    Dim n As Long = Cin.Lng()
    Dim ans As Long = 0
    If n Mod 2 = 0 Then
      Dim x As Long = 10
      For i As Long = 0 To n - 1
        x = 10 * Math.Pow(5, i)
        If x > n Then Exit For
        ans += (n \ x)
      Next
    End If
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Public Class Cin
  Public Shared Function Str() As String
    Return Console.ReadLine().Trim()
  End Function
  Public Shared Function Int() As Integer
    Return Integer.Parse(Str())
  End Function
  Public Shared Function Lng() As Long
    Return Long.Parse(Str())
  End Function
  Public Shared Function Dbl() As Double
    Return Double.Parse(Str())
  End Function
  Public Shared Function StrArr(Optional separator As String = " ") As String()
    Return Str().Split(separator)
  End Function
  Public Shared Function IntArr(Optional separator As String = " ") As Integer()
    Return Array.ConvertAll(Of String, Integer)(StrArr(separator), AddressOf Integer.Parse)
  End Function
  Public Shared Function LngArr(Optional separator As String = " ") As Long()
    Return Array.ConvertAll(Of String, Long)(StrArr(separator), AddressOf Long.Parse)
  End Function
  Public Shared Function DblArr(Optional separator As String = " ") As Double()
    Return Array.ConvertAll(Of String, Double)(StrArr(separator), AddressOf Double.Parse)
  End Function
End Class

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
    int i, j;
    long long n, a, b, m, amari;
    long long ans;

    cin >> n >> a >> b;

    if (a + b == 0) {
        cout << 0 << endl;
        return 0;
    }

    m = (n / (a + b)) * a;

    amari = n % (a + b);
    if (amari < a) {
        ans = m + amari;
    } else {
        ans = m + a;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int i, n; 
     int arr[100]; 
     scanf("%d", &n); 
     for(i=0;i<n;i++){ 
         scanf(" %d", &arr[i]); 
     } 
     for(i=0;i<n;i++){ 
         if(i)printf(" "); 
         printf("%d", arr[n-i-1]); 
     } 
     printf("\n"); 
     return 0; 
 } 



Measured memory_bytes: 2052
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> >g[110000];
bool th=true;
int v[110000];
int num[110000];
int cnt[3];
int tc;
void dfs(int a,int b){
 
	num[a]=b;
	cnt[b]++;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i].second==1)tc++;
		if(!v[g[a][i].first]){
			v[g[a][i].first]=1;
			dfs(g[a][i].first,(b+g[a][i].second)%3);
		}else{
			if(num[g[a][i].first]!=(b+g[a][i].second)%3)th=false;
		}
	}
}
 
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int p,q;scanf("%d%d",&p,&q);
		p--;q--;
		g[p].push_back(make_pair(q,1));
		g[q].push_back(make_pair(p,2));
	}
	long long ret=0;
	for(int i=0;i<a;i++){
		if(!v[i]){
			for(int j=0;j<3;j++)cnt[j]=0;
			th=true;
			v[i]=1;
			tc=0;
			dfs(i,0);
			if(th){
				if(cnt[0]&&cnt[1]&&cnt[2])ret+=(long long)cnt[0]*cnt[1]+(long long)cnt[1]*cnt[2]+(long long)cnt[2]*cnt[0];
				else ret+=tc;
			}else{
				int tot=cnt[0]+cnt[1]+cnt[2];
				ret+=(long long)tot*tot;
			}
		}
	}
	printf("%lld\n",ret);
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a[ohara],b,c,d,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n;
      ll cmp[n];
      rep(i,n){
        cin>>a[i];
        cmp[i]=a[i]-i-1;
      }
      sort(cmp,cmp+n);
      //rep(i,n)Cout(cmp[i]);
      pos=cmp[n/2];
      pos*=-1;
      rep(i,n)cmp[i]+=pos;
      rep(i,n)ans+=abs(cmp[i]);
      Cout(ans);
     
     

       
return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <list>
#include <utility>
using namespace std;
#define MAXN 100
#define MAXW 2001

int main(){
    int weight[MAXN][MAXN];
    int n; cin >> n;
    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> weight[i][j];
        }
    }
    
    list<int> MST;
    MST.push_back(0);
    list<int> nonMST;
    for(int i=1; i<n; i++) nonMST.push_back(i);
    
    int weightSum = 0;
    while(!nonMST.empty()){
        int tmpv;
        int tmpWeight = MAXW;
        for(list<int>::iterator it=MST.begin(); it!=MST.end(); it++){
            for(list<int>::iterator it2=nonMST.begin(); it2!=nonMST.end(); it2++){
                if (weight[*it][*it2] < tmpWeight && weight[*it][*it2] != -1){
                    //cout << "tmpWeight update with " << *it2 << endl;
                    tmpWeight = weight[*it][*it2];
                    tmpv = *it2;
                }
            }
        }
        //cout << "MST pushback :" << tmpv << endl; 
        MST.push_back(tmpv);
        nonMST.remove(tmpv);
        weightSum += tmpWeight;
        /*for(list<int>::iterator it=MST.begin(); it!=MST.end(); it++){
            cout << *it << " ";
        }
        cout << endl;
        for(list<int>::iterator it=nonMST.begin(); it!=nonMST.end(); it++){
            cout << *it << " ";
        }
        cout << endl;*/
    }
    
    cout << weightSum << endl;
}

Measured memory_bytes: 1232
from functools import reduce

(r,c)=  map(int,input().split())

l = []
for i in range(0,r):
    t = list(map(int,input().split()))
    t.append(reduce(lambda a,b:a+b,t))
    l.append(t)

l2 = []
for i in list(map(list, zip(*l))):
    l2.append(reduce(lambda a,b:a+b,i))
l.append(l2)

for i in range(0,r+1):
    print (' '.join(map(str,l[i]))) 


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

int main(){
    int n, x[105], y[105], h[105], it;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d%d%d", &x[i], &y[i], &h[i]);
        if(h[i]) it = i;
    }
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            int hi = h[it] + abs(i-x[it]) + abs(j-y[it]);
            bool t = true;
            for(int k = 0; k < n; k++){
                int hij = h[k] + abs(i-x[k]) + abs(j-y[k]);
                if(hi > hij || (h[k] && hi != hij)) t = false;
            }
            if(t) printf("%d %d %d\n", i, j, hi);
        }
    }
}

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

int main()
{
	int n;
	
	while (cin >> n , n){
		int c = 0, line[12][12] = {0};

		for (int i = 0; i < n; i++){
			cin >> line[c][i];
		}

		for (int i = 0; i < n; i++){
			line[c + 1][i] = count(line[c], line[c] + n, line[c][i]);
		}

		while (1){
			int cnt = 0;
			for (int i = 0; i < n; i++){
				if (line[c][i] == line[c + 1][i]){
					cnt++;
				}
			}
			
			if (cnt == n){
				cout << c << endl;
				cout << line[c][0];
				for (int i = 1; i < n; i++){
					cout << " " << line[c][i];
				}
				cout << endl;
				break;
			}

			c++;

			for (int i = 0; i < n; i++){
				line[c + 1][i] = count(line[c], line[c] + n, line[c][i]);
			}
		}
	}
	return (0);
}

Measured memory_bytes: 1156
from sys import stdin, stdout
from time import perf_counter

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

# import sys
# sys.stdout = open("e:/cp/output.txt","w")
# sys.stdin = open("e:/cp/input.txt","r")
l=sorted(map(int,input().split()))
print("YES" if l == [5,5,7] else "NO")


Measured memory_bytes: 9080
#include <cstdio>
#include <iostream>
#include <algorithm>
#define INT unsigned long long

INT n, s, b, ans = -1;

inline INT f(INT x, INT y)
{
    INT ret = 0;
    if( y == 1 ) return x;
    while( x )
    {
        ret += x%y;
        x/=y;
    }
    return ret;
}

int main()
{
    scanf("%lld%lld", &n, &s);
    if( n < s )
    {
        puts("-1");
        return 0;
    }
    if( n == s )
    {
        printf("%lld\n", n+1);
        return 0;
    }
    for(INT i = 2 ; i*i <= n ; i++ )
    {
        if( f(n, i)== s )
        {
            printf("%lld\n", i);
            return 0;
        }
    }
    for(INT i = 1 ; i*i <= n ; i++ )
    {
        if( f(n, (n-s)/i + 1) == s  )
            ans = (n-s)/i+1;
    }
    printf("%lld\n", ans);
}


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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int,int> P;
typedef vector<int> vi;

int n,a,b,c,d;
string s;

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

    cin>>n>>a>>b>>c>>d>>s;
    a--; b--; c--; d--;

    bool goalisok1 = true;
    int ctn = 0;
    for(int i = a;i<=c;i++) {
        if(s[i] == '.') ctn=0;
        else{
            ctn++;
            if(ctn == 2) {
                goalisok1=false;
                break;
            }
        }
    }
    bool goalisok2 = true;
    ctn=0;
    for(int i = b;i<=d;i++) {
        if(s[i] =='.') ctn=0;
        else{
            ctn++;
            if(ctn==2) {
                goalisok2=false;
                break;
            }
        }
    }

    if(goalisok1==false or goalisok2==false) {
        cout<<"No"<<endl;
    }else{
        if(c<d) cout<<"Yes"<<endl;
        else{
            bool flag = false;
            int ctn1=0;
            rep(i,b-1,d+2) {
                if(s[i] == '.') {
                    ctn1++;
                    if(ctn1==3) {
                        flag=true;
                        break;
                    }
                }else{
                    ctn1=0;
                }
            }


            if(flag==true) cout<<"Yes"<<endl;
            else cout<<"No"<<endl;
        }
    }
    return 0;
}





Measured memory_bytes: 592
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int i = a * 800;

		if (i <= 12000) {

			System.out.println(i);

		} else {

			System.out.println(i - (200 * (a / 15)));

		}
	}
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		System.out.println(arr[n / 2] - arr[n / 2 - 1]);
	}
}


Measured memory_bytes: 51044
N, M, X = map(int, input().split())
#マス0かNに行きたい、M個料金所がある、いまマスXにいる
#問題文が読みづらすぎる
chkptList = list(map(int,input().split()))
TollToOrigin = 0
TollToN = 0
for i in range(X):
    TollToOrigin += chkptList.count(i)
for i in range(X,N):
    TollToN += chkptList.count(i)

print(min(TollToOrigin, TollToN))

Measured memory_bytes: 3060
using System;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{

    public class Program
    {
        const long MOD = 1000000007;
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long K = cin.ReadLong;
            long ans = 0;
            for(int i =1; i<=K; i++)
            {
                for(int j =1;j<=K;j++)
                {
                    for(int k =1;k<=K;k++)
                    {
                        ans += Gcd(Gcd(i, j), k);
                    }
                }
            }
            WriteLine(ans);
        }


        static long Gcd(long p, long q)
        {
            if (p % q == 0) return q;
            return Gcd(q, p % q);
        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }

    }
}

Measured memory_bytes: 27924
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)

/*
 // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, ll v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} */

/*
//桁数の計算
ll keta(ll num){
  ll ans= 0 ;
  ll rem;

  for (ll i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}
*/


int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    ll pos_ans,neg_ans, ans_can, ans_can2;
    ll div;
    //vector<ll> a(N);
    //vector<vector<int>> data(3, vector<int>(4));
    if(X > 0){
      pos_ans = X % D;
      neg_ans = abs(X % D - D); 
      
      if(pos_ans > neg_ans){
        ans_can = neg_ans;
        ans_can2 = pos_ans;
        div = X/ D + 1;
      }else if(pos_ans == neg_ans){
        cout << pos_ans << endl;
        return 0;
      }else{
        ans_can = pos_ans;
        ans_can2 = neg_ans;
        div = X/ D;
      }

    }else{
      pos_ans = abs(X % D);
      neg_ans = X % D + D;
      
      if(pos_ans > neg_ans){
        ans_can = neg_ans;
        ans_can2 = pos_ans;
        div = (-1) * X / D + 1;
      }else if(pos_ans == neg_ans){
        cout << pos_ans << endl;
        return 0;
      }else{
        ans_can = pos_ans;
        ans_can2 = neg_ans;
        div = (-1) * X / D;
      }
    }

    if(K >= div){
      if((K-div)%2 == 0){
        cout << ans_can << endl;
      }else{
        cout << ans_can2 << endl;
      }
    }else{
      ll ans = min(abs(X+K*D), abs(X-K*D));
      cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll unsigned long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

int main() {
    ll n;
    cin>>n;
    ll ans=1;
    V a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    if(a[0]==0){
        cout<<0<<endl;
        return 0;
    }
    rep(i,n){
        ll k=(to_string(ans)[0]-'0')*(to_string(a[i])[0]-'0');
        if(to_string(ans).size()+to_string(a[i]).size()+to_string(k).size()-2>19){
            cout<<-1<<endl;
            return 0;
        }
        ans*=a[i];
    }
    if(ans>1000000000000000000){
        cout<<-1<<endl;
    }else{
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3972
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S, T;
  cin >> S >> T;
  cout << T + S << '\n';
  return 0;
}


Measured memory_bytes: 3580
# Aizu Problem 0012: Point in Triangle
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def point_in_triangle(trig, x, y):
    x1, y1, x2, y2, x3, y3 = trig[:]
    a = ((y2 - y3)*(x - x3) + (x3 - x2)*(y - y3)) / ((y2 - y3)*(x1 - x3) + (x3 - x2)*(y1 - y3))
    b = ((y3 - y1)*(x - x3) + (x1 - x3)*(y - y3)) / ((y2 - y3)*(x1 - x3) + (x3 - x2)*(y1 - y3))
    c = 1 - a - b
    return 0 < a < 1 and 0 < b < 1 and 0 < c < 1

          
for line in sys.stdin:
    inp = [float(_) for _ in line.split()]
    print("YES" if point_in_triangle(inp[:6], inp[6], inp[7]) else "NO")

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

ans = 0
if K > A:
    ans += 1 * A
    K -= A
else:
    ans += 1 * K
    print(ans)
    exit()

if K > B:
    ans += 0 * B
    K -= B
else:
    ans += 0 * K
    print(ans)
    exit()

if K > C:
    ans += -1 * C
    K -= C
else:
    ans += -1 * K
    print(ans)
    exit()

print(ans)


Measured memory_bytes: 9196
N, C = map(int, input().split())

if N == 1:
    x, v = map(int, input().split())
    print(max(0, v-x, v-(C-x)))
    exit()


Cost = [] #[x, v, left_cumsum, left_cummax, right_cumsum, right_cummax]

cum = 0
x, v = map(int, input().split())
cum += v
Cost.append([x, v, cum-x, max(0, cum-x), 0, 0])
for _ in range(N-1):
    x, v = map(int, input().split())
    cum += v
    Cost.append([x, v, cum-x, max(Cost[-1][3], cum-x), 0, 0])

cum = 0
cum += Cost[-1][1]
Cost[-1][4] = cum - (C - Cost[-1][0])
Cost[-1][5] = max(0, Cost[-1][4])
for i in range(N-2, -1, -1):
    cum += Cost[i][1]
    Cost[i][4] = cum - (C - Cost[i][0])
    Cost[i][5] = max(Cost[i+1][5], Cost[i][4])
    
max_val = 0
max_val = max(max_val, Cost[0][3], Cost[0][5],\
        Cost[0][2] + Cost[1][5] - Cost[0][0])
max_val = max(max_val, Cost[-1][3], Cost[-1][5],\
        Cost[-1][4] + Cost[-2][3] - (C-Cost[-1][0]))
for i in range(1, N-1):
    max_val = max(max_val, Cost[i][3], Cost[i][5],\
            Cost[i][2] + Cost[i+1][5] - Cost[i][0],\
            Cost[i][4] + Cost[i-1][3] - (C-Cost[i][0]))

print(max_val)


Measured memory_bytes: 32272
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	a := make([]int, 3*n)

	for i := 0; i < 3*n; i++ {
		a[i] = nextInt()
	}

	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	m := 0
	for i := 0; i < n; i++ {
		m += a[2*i+1]
	}

	fmt.Println(m)
}


Measured memory_bytes: 7424
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
 
using namespace std;
 
vector<int> d;
int input1, input2;
int sum;
stringstream ss;
 
int main(){
    
 while(cin >> input1 >> input2) {
     sum=input1+input2;
     ss << sum;
     cout << ss.str().size() << endl;
     ss.str("");
     ss.clear(stringstream::goodbit);
 }
}

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

int main(){
	int a,b;
	cin>>a>>b;
	if(a>b){
		cout<<"a > b"<<endl;
	}
	if(a<b){
		cout<<"a < b"<<endl;
	}
	if(a==b){
		cout<<"a == b"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
signed main(){
    vector<int> prime;
    int i=2;
    while(i<=100000){
        bool p=true;
        for(int j=0;j<prime.size();j++){
            if(i%prime[j]==0){
                p=false;
                break;
            }
        }
        if(p==true)prime.push_back(i);
        i++;
    }
    int cnt[114514]={};
    for(int i=0;i<100000;i++){
        if((i+1)%2==1){
            if(binary_search(prime.begin(), prime.end(),i+1)&&binary_search(prime.begin(), prime.end(), (i+1+1)/2)){
                cnt[i]=cnt[i-1]+1;
            }else{
                cnt[i]=cnt[i-1];
            }
        }else{
            cnt[i]=cnt[i-1];
        }
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int l,r;
        cin>>l>>r;
        if(l==1)cout<<cnt[r-1]<<endl;
        else{
            cout<<cnt[r-1]-cnt[l-2]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#define WMAX 10000
#define HMAX 10000

//コメントアウトするとdebug()を実行しない
#define DEBUG

using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

struct edge{
  int to,cost;
};

int A,B,C,N = 0,W,H,ans,dp[HMAX][WMAX];
string S;
static const int dx[8] = {0,1,1,1,0,-1,-1,-1},
					dy[8] = {1,1,0,-1,-1,-1,0,1};

void solve(){
	ans = A + B + C;
	N = A;
	N = max(N,B);
	N = max(N,C);
	ans -= N;
}

void debug(){

}

void answer(){
	cout << ans << "\n";
}

int main(){
	cin >> A >> B >> C;
	solve();
	#ifdef DEBUG
	debug();
	#endif
	answer();

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int res = N;
  rep2(i, 1, N) {
    int a = i, b = N - i, sum = 0;
    while(a > 0) {
      sum += a % 10;
      a /= 10;
    }
    while(b > 0) {
      sum += b % 10;
      b /= 10;
    }
    res = min(res, sum);
  }
  cout << res << endl;
}

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

class LazySegmentTree {
public:
    LazySegmentTree(int n) : n(n), tree(vector<int>(4*n)), lazy(vector<int>(4*n)) {}

    // add value to all elements in range [l .. r]
    void update(int l, int r, int value) {
        update(l, r, value, 1, n, 1);
    }

    // get the value at index
    int query(int index) {
        return query(index, 1, n, 1);
    }

private:
    // push lazy to childes
    void push(int low, int high, int pos) {
        tree[pos]+=lazy[pos];
        if (low!=high) {
            lazy[2*pos]+=lazy[pos];
            lazy[2*pos+1]+=lazy[pos];
        }

        lazy[pos]=0;
    }

    // add value to all elements in range [l .. r]
    void update(int l, int r, int value, int low, int high, int pos) {
        push(low, high, pos); // push lazy

        if (l>high || r<low) { // no overlap
            return;
        }

        if (l<=low && r>=high) { // total overlap
            tree[pos]+=value;
            if (low!=high) {
                lazy[2*pos]+=value;
                lazy[2*pos+1]+=value;
            }

            return;
        }

        int mid=(low+high)/2;
        update(l, r, value, low, mid, 2*pos);
        update(l, r, value, mid+1, high, 2*pos+1);
    }

    // get the value at index
    int query(int index, int low, int high, int pos) {
        push(low, high, pos); // push lazy
        if (low==high) {
            return tree[pos];
        }

        int mid=(low+high)/2;
        if (index<=mid)         return query(index, low, mid, 2*pos);
        else                    return query(index, mid+1, high, 2*pos+1);
    }

    int n;
    vector<int> tree, lazy;
};

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

    int n, q;
    cin >> n >> q;

    vector<int> c(n+1);
    for (int i=1; i<=n; ++i) {
        cin >> c[i];
    }

    vector< vector< pair<int, int> > > queries(n+1); // queries[i] stores the queries that ends in position i
    for (int i=1; i<=q; ++i) {
        int l, r;
        cin >> l >> r;
        queries[r].push_back({l, i}); // {start, old index}
    }

    vector<int> answer(q+1); // the answers to the ith query
    vector<int> lastPosition(n+1); // the last position of a[i] till now
    LazySegmentTree LST(n);

    for (int i=1; i<=n; ++i) {
        // add position i
        int l=lastPosition[c[i]];
        int r=i;
        LST.update(l+1, r, 1); // increase elements in range [ last[a[i]] + 1, i] by 1

        // calculate the answer for all queries that ends in position i
        for (int j=0; j<queries[i].size(); ++j) {
            int start=queries[i][j].first;
            int queryIndex=queries[i][j].second;

            int distinctsCount=LST.query(start);
            answer[queryIndex]=distinctsCount;
        }

        // update last position of a[i]
        lastPosition[c[i]]=i;
    }

    for (int i=1; i<=q; ++i) {
        cout << answer[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 46964
# abc166 B
n, k = gets.split.map(&:to_i)
a = []

sn = Array.new(n, 0)

k.times  {
  d = gets.to_i
  a << gets.split.map(&:to_i)
}


a.each do |aa|
  aa.each do |x|
    sn[x-1] += 1
  end
end

p sn.count(&:zero?)


Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%1000==0)
  {cout<<0<<endl;
     return 0;}
  int val = n/1000;
  cout<<(((val+1)*1000)-n)<<endl;
  return 0;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n;
int arr[N];
long long ans;
int cur;
int main(){
    scanf("%d" , &n);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , arr + i);
    }
    ans = arr[1] - 1;
    cur = 2;
    for(int i = 2 ; i <= n ; ++i){
        ans += (arr[i] - 1) / cur;
        if(arr[i] == cur){
            ++cur;
        }
    }
    printf("%lld\n" , ans);
}

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

int main()
{
    priority_queue<pair<ll, ll> > pq;
    ll n, m;
    cin >> n >> m;

    for (ll i = 0; i < n; i++) {
        ll coin, num;
        scanf("%lld %lld", &coin, &num);

        pq.push({-coin, num});
    }

    ll cnt = 0;
    ll koyta_nilam = 0;
    while (!pq.empty()) {
        auto tmp = pq.top();
        pq.pop();

        ll curcoin = -tmp.first;
        ll curnum = tmp.second;

        if (curnum + koyta_nilam > m) cnt += (m - koyta_nilam) * curcoin, koyta_nilam = m;
        else cnt += curnum * curcoin, koyta_nilam += curnum;

        if (koyta_nilam == m) break;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 2420
using System;
using System.Linq;


class Program
{
    static void Main(string[] args)
    {
        string tenki_yoho = Console.ReadLine();
        string tenki = Console.ReadLine();
        char[] y = new char[3];
        char[] t = new char[3];
        int i = 0;
        int cnt = 0;
        foreach (char c in tenki_yoho)
        {
            y[i] = c;
            i++;
        }
        i = 0;
        foreach (char tc in tenki)
        {
            t[i] = tc;
            i++;
        }
        for (i = 0; i < 3; i++)
        {
            if (y[i] == t[i])
            {
                cnt++;
            }
        }
        Console.WriteLine(cnt);

    }

}



Measured memory_bytes: 13140
#include<cstdio>
#include<cstring>
#include<algorithm>
int n, m;
int c[310];
int dp[310][310];
int solve(int di, int sum, int x[]){
  if(di == n) return 0;
  if(dp[di][sum] != -1) return dp[di][sum];
  int a = 0;
  for(int i = 0;i * c[di] + sum <= m; i++) a = std::max(a, solve(di + 1, sum + i * c[di], x) + i * x[di]);
  return dp[di][sum] = a;
}
void foo(int v[], int d[], int l[]){
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  ans = std::max(ans, solve(0, 0, v));
  memset(dp, -1, sizeof(dp));
  ans = std::max(ans, solve(0, 0, d));
  memset(dp, -1, sizeof(dp));
  ans = std::max(ans, solve(0, 0, l));
  printf("%d\n",ans);
}
int main(void){
  char s[50];
  int v[310],d[310],l[310];
  while(scanf("%d %d",&n,&m) != EOF){
    for(int i = 0;i < n; i++){
      fgets(s, sizeof(s), stdin); fgets(s, sizeof(s), stdin);
      scanf("%d %d %d %d",&c[i],&v[i],&d[i],&l[i]);
    }
    foo(v, d, l);
  }
}


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

int main()
{
    int n , m;
    cin>>n>>m;
    int L = INT_MIN , M = INT_MAX;
    for(int i=0;i<m;i++)
    {
        int l , m;
        cin>>l>>m;
        L = max( L , l);
        M = min( m , M);
    }
    int ans =0;
    for(int i=1;i<=n;i++)
    {
        if( L<= i && M>= i)
            ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3640
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n), b(n), c(n - 1);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n - 1) cin >> c[i];
    int ans=b[a[0]-1];
    for (int i = 1; i < n; i++)
    {
        ans += b[a[i] - 1];
        if (a[i] - a[i - 1] == 1)
        {
            ans += c[a[i - 1] - 1];
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <cstdio>
int get(int a, int b, int p) {
	int mn = a;
	if (mn > b) mn = b;
	int mx = a + b - mn;
	int k = (mx + mn) / (mn + 1);
	int lo = 0, hi = a + 1;
	while (lo + 1 < hi) {
		int mid = (lo + hi) / 2;
		int cb = b - (mid == 0 ? 0 : (mid - 1) / k);
		int ca = a - mid;
		if ((long long)(ca + 1) * k < cb) {
			hi = mid;
		} else {
			lo = mid;
		}
	}
	int s = (lo - 1) / k;
	if (p < s * (k + 1)) {
		return p % (k + 1) == k ? 'B' : 'A';
	}
	if (p < lo + s) {
		return 'A';
	}
	lo = b - s;
	p = a + b - 1 - p;
	s = (lo - 1) / k;
	if (p < s * (k + 1)) {
		return p % (k + 1) == k ? 'A' : 'B';
	}
	return 'B';
}
int main() {
	int q;
	scanf("%d", &q);
	while (q--) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		for (int i = c; i <= d; i++) {
			putchar(get(a, b, i-1));
		}
		puts("");
	}
	return 0;
}


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

using namespace std;

int main()
{
    int i,j;
    char a[3][3];
    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
    {
        cin>>a[i][j];
    }
    printf("%c%c%c\n",a[0][0],a[1][1],a[2][2]);
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	A, B, C, X := ReadInt(), ReadInt(), ReadInt(), ReadInt()
	ans := 0
	for a := 0; a <= A; a++ {
		for b := 0; b <= B; b++ {
			s := 500*a + 100*b
			r := X - s
			if r%50 != 0 {
				continue
			}
			c := r / 50
			if 0 <= c && c <= C {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 1840
#include<stdio.h>
#include<math.h>
#define N 10000

int main(){
  int n,num[N],i,j,count=0;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&num[i]);

  for(i=0;i<n;i++){
    if(num[i]==2)continue;
    if(num[i]%2==0){
      count+=1;
      continue;
    }
    for(j=3;j<=sqrt(num[i]);j+=2){
      if(num[i]%j==0){
	count+=1;
	break;
      }
    }
  }
  printf("%d\n",n-count);
  
  return 0;
}

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

int N;
int as[214514];
int bs[214514];

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    scanf("%d", &as[i]);
    bs[i] = as[i];
  }
  sort(as, as+N);
  int l = as[N/2-1];
  int r = as[N/2];

  for (int i=0; i<N; i++) {
    if (bs[i] <= l) printf("%d\n", r);
    else printf("%d\n", l);
  }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define m 1000000007
using namespace std;

long long int dp1[100004],dp2[100004];
bool mark[100004];

void dfs(vector<int> arr[],int i)
{
	mark[i]=true;
	long long int sum1=1,sum2=1;
	for(int j=0;j<arr[i].size();j++)
	{
		if(mark[arr[i][j]]==false)
		{
			dfs(arr,arr[i][j]);
			sum1=(sum1%m*(dp1[arr[i][j]]+dp2[arr[i][j]])%m)%m;
			sum2=(sum2%m*dp1[arr[i][j]]%m)%m;
		}
	}
	dp1[i]=sum1;
	dp2[i]=sum2;
}


 int main() 
{  
  int n;
  cin>>n;
  vector<int> arr[n+1];
  for(int i=1;i<=n-1;i++)
  {
   	 int a,b;
  	 cin>>a>>b;
  	 arr[a].push_back(b);
  	 arr[b].push_back(a);
  	 
  }
  dfs(arr,1);
  cout<<(dp1[1]+dp2[1])%m<<endl;
	return 0;
} 

Measured memory_bytes: 14336
#include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>

using namespace std;

typedef std::complex<double> xy_t;
xy_t P[110];

double calc_edge_len(xy_t X, xy_t Y){
    return sqrt(pow((X.real()-Y.real()),2.0)+pow((X.imag()-Y.imag()),2.0));
}

double calc_area(xy_t A, xy_t B, xy_t C){
    double area = 0.0;
    double edge_a = calc_edge_len(B, C);
    double edge_b = calc_edge_len(A, C);
    double edge_c = calc_edge_len(B, A);

    double z = (edge_a + edge_b + edge_c)/2;
    area = sqrt(z*(z-edge_a)*(z-edge_b)*(z-edge_c));
    return area;
}

int main(){
    int N = 0;
    double x, y;
    while(scanf("%lf, %lf", &x, &y) != EOF){
        P[N++] = xy_t(x, y);
    }  

    double sum = 0.00000;

    for(int i = 0; i < (N-2); ++i){
        xy_t A = P[0], B = P[i+1], C = P[i+2];
        sum += calc_area(A, B, C);
    }

    printf("%.6f\n", sum);
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int x[5];
    for(int i = 0; i < 5; i ++) {
        cin >> x[i];
        if(x[i] == 0) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 3684
val len = LongArray(51, { 1L })
val nPans = LongArray(51, { 1L })

fun count(N: Int, X: Long): Long {
    val mid = (len[N]+1L)/2L
    return if(N==0 && X==1L) {
        1L
    } else if (X==1L) {
        0L
    }
    else if(X==len[N]) {
        nPans[N]
    } else if(X == mid) {
        nPans[N-1] + 1
    } else if (X < mid) {
        count(N - 1, X-1)
    } else if (X > mid){
        nPans[N-1] + count(N-1, X-mid) + 1
    } else {
        0L
    }
}


fun main(args: Array<String>) {
    val (N,X) = readLine()!!.split(" ").map { it.toLong() }
    val NN = N.toInt()

    // preprocessing
    for (i in 1 until 51) {
        len[i] = 2 * len[i-1] + 3
        nPans[i] = 2 * nPans[i-1] + 1
    }
//    assert(len[0] == 1L)
//    assert(len[1] == 5L)
//    assert(len[2] == 13L)
//    assert(nPans[0] == 1L)
//    assert(nPans[1] == 3L)
//    assert(nPans[2] == 7L)
//    assert(count(2, 1L) == 0L)
//    assert(count(2, 4L) == 2L)
//    assert(count(2, 7L) == 4L)
//    assert(count(2, 9L) == 5L)
//    assert(count(2, 10L) == 6L)
//    assert(count(2, 11L) == 7L)
//    assert(count(2, 13L) == 7L)
//    assert(count(50, 4321098765432109L) == 2160549382716056L)

    val ans = count(NN, X)
    println(ans)
}

Measured memory_bytes: 37820
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,d;
    cin>>n>>d;
    int ls;
    ls=n/(d*2+1);
    if(ls*(d*2+1)==n)
        cout<<ls<<endl;
    else
        cout<<ls+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    map <string,int> m;
    int n;
    cin >> n;
    while(n--){
        string s;
        cin >>s;
        m[s]++;
    }
    cin >> n;
    while(n--){
        string s;
        cin >>s;
        auto itr =m.find(s);
        if(itr==m.end()){
        }else{
            m[s]--;
        }
    }
    int ans=0;
    for(auto itr=m.begin();itr!=m.end();itr++){
        if(ans< itr->second){
            ans=itr->second;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

	set<string> s;
	for (int i = 0; i < n; i++) {
		string in;
		cin >> in;
		s.insert(in);
	}

	cout << s.size();

	return 0;
}

Measured memory_bytes: 19236
from collections import deque
n,k=map(int,input().split())
p=list(map(int,input().split()))

minp=[0]*(n-k+1)
maxp=[0]*(n-k+1)
q1=deque([0])
q2=deque([0])
for i in range(1,k):
    while p[q1[-1]]>p[i]:
        q1.pop()
        if len(q1)==0:
            break
    while p[q2[-1]]<p[i]:
        q2.pop()
        if len(q2)==0:
            break
    q1.append(i)
    q2.append(i)
for i in range(n-k+1):
    minp[i]=p[q1[0]]
    maxp[i]=p[q2[0]]
    if i==n-k:
        break
    if q1[0]==i:
        q1.popleft()
    if q2[0]==i:
        q2.popleft()
    while p[q1[-1]]>p[i+k]:
        q1.pop()
        if len(q1)==0:
            break
    while p[q2[-1]]<p[i+k]:
        q2.pop()
        if len(q2)==0:
            break
    q1.append(i+k)
    q2.append(i+k)

d=[0]*n
d[0]=1
for i in range(1,n):
    if p[i]>p[i-1]:
        d[i]=d[i-1]+1
    else:
        d[i]=1

ans=int(k in d)
if d[k-1]!=k:
    ans+=1
for i in range(n-k):
    if d[i+k]>=k:
        continue
    if not (p[i]==minp[i] and p[i+k]==maxp[i+1]):
        ans+=1

print(ans)

Measured memory_bytes: 27072
X = int(input())
A = (X%100)//10 #下2桁目
B = X%10 #下一桁目
count = X//100 #回数
if B>5:
    C = 2
elif B:
    C = 1
else:
    C = 0
if X>99 and count >= (A*2)+C:
    print(1)
else:
    print(0)

Measured memory_bytes: 3060
N=int(input())
a=list(map(int,input().split()))

A=[]
for i in range(N):
  if a[i]%2==0:
    A.append(a[i])

ans=0
for i in range(len(A)):
  for j in range(31):
    if A[i]%2==0:
      ans+=1
      A[i]//=2
    else:
      break
print(ans)

Measured memory_bytes: 4148
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    print(*A)
    for i in range(1, N):
        while(i >= 1 and A[i-1] > A[i]):
            A[i], A[i-1] = A[i-1], A[i]
            i -= 1
        print(*A)


Measured memory_bytes: 5980
#include<bits/stdc++.h>
#define endl "\n"
#define PI acos(-1)
#define BMW_GTR ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

typedef long long ll;
using namespace std;

//ll const n = 50005;

int main()
{
    BMW_GTR;

    int N, flag = 0;
    cin >> N;

    int arr[N];

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

    sort(arr, arr + N);

    for(int i = 1; i < N; i++)
    {
        if(arr[i] == arr[i - 1])
        {
            flag++;
            break;
        }
    }

    if(flag == 0)cout << "YES";
    else cout << "NO";

    return 0;
}


Measured memory_bytes: 4344
#include <algorithm>
#include <iostream>

using namespace std;

const int CountWhite(const string &S)
{
    int whiteNum = 0;
    return std::count(S.cbegin(), S.cend(), '.');
}

int main()
{
    int N;
    string S;
    cin >> N >> S;
    
    int minReverseNum, reverseNum;
    minReverseNum = reverseNum = CountWhite(S);
    for(int i = 0; i < N; ++i){
        if(S[i] == '#'){
            ++reverseNum;
        }
        else{
            --reverseNum;
        }
        if(reverseNum < minReverseNum){
            minReverseNum = reverseNum;
        }
    }

    cout << minReverseNum;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pii pair<int, int>
using namespace std;
vector<pii> v[4];
bool visit[4],b[3],vis[4];
vector<int> vv;
void dfs(int x,int y)
{
	//cout <<x<<" "<<y<<" ##\n";
	visit[x]=1;
	if (y==3)
	{
		cout <<"YES";
		exit(0);
	}
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		int yi=v[x][i].second;
		if (visit[xi] || b[yi]) continue;
		b[yi]=1;
		dfs(xi,y+1);
	}
}
void d(int x)
{
	vis[x]=1;
	for (int i=0;i<v[x].size();i++)
	{
		int xi=v[x][i].first;
		if (!vis[xi]) d(xi);
	}
	vv.push_back(x);
}
int main()
{
	for (int i=0;i<3;i++)
	{
		int x,y;
		cin >>x>>y;
		x--,y--;
		v[x].push_back(mp(y,i));
		v[y].push_back(mp(x,i));
	}
	for (int i=0;i<4;i++) if (!vis[i]) d(i);
	dfs(vv[3],0);
	cout <<"NO";
	return 0;
}

Measured memory_bytes: 256
import bisect
import sys
input = sys.stdin.readline


def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))

    x = bisect.bisect_left(A, X)
    ans = min(len(A[:x]), len(A[x:]))

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

ll f(string s) {
	ll res = 0, a = 0;
	rep(i, s.size()) {
		if (s[i] == 'a') a++;
		else res += a;
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	string t;
	ll ans = 0;
	int n = s.size(); s += 'X';
	rep(i, n) {
		if (s[i] == 'A') t += 'a';
		else if (s[i] == 'C') {
			ans += f(t);
			t = "";
		}
		else {
			if (s[i + 1] == 'C') t += 'b', ++i;
			else ans += f(t), t = "";
		}
	}
	ans += f(t);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 916
import java.util.*;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			int n = scan.nextInt();
			int sum = 0;
			for (int i = 1; i <= n; i++) {
				if (isPrime(i)) {
					sum++;
				}
			}
			System.out.println(sum);
		}
	}
	
	boolean isPrime(int n){
	    int i;
	 
	    if(n < 2)
	        return false;
	    else if(n == 2)
	        return true;
	 
	    if(n % 2 == 0)
	        return false;
	 
	    for(i = 3; i * i <= n; i += 2)
	         if(n % i == 0)
	            return false;
	    return true;
	}

}

Measured memory_bytes: 19064