akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, m;
	cin >> n >> m;
	
	int a = -1;
	int b = -1; 
	int c = -1;
	if (n == 1) {
		for (int i = 1; i <= m; i++) {
			int d, e;
			cin >> d >> e;
			if (c != -1 && e != c) {
				cout << -1 << endl;
				return 0;
			}

			if (d == 1)c = e;
			
		}
		if (c == -1)c = 0;
		cout << c << endl;
	}
	if (n == 2) {
		for (int i = 1; i <= m; i++) {
			int d, e;
			cin >> d >> e;
			if ((c != -1 &&d==2&& e != c)||(b!=-1&&d==1&&e!=b)||(d==1&&e==0) ){
				cout << -1 << endl;
				return 0;
			}

			if (d == 1)b = e;
			if (d == 2)c = e;
		}
		if (c == -1)c = 0;
		if (b == -1)b = 1;
		
		cout << b*10+c << endl;
	}
	if (n == 3) {
		for (int i = 1; i <= m; i++) {
			int d, e;
			cin >> d >> e;
			if ((c != -1 && d == 3 && e != c) || (b != -1 && d == 2 && e != b) || (a != -1 && d == 1 && e != a) || (d == 1 && e == 0)) {
				cout << -1 << endl;
				return 0;
			}
			if (d == 1)a = e;
			if (d == 2)b = e;
			if (d == 3)c = e;

		}
		if (c == -1)c = 0;
		if (b == -1)b = 0;
		if (a == -1)a = 1;

		cout <<a*100+ b * 10 + c << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,c,n,conteo;
	scanf("%d",&n);
	conteo=1;
	while(conteo<=n){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a==b*b+c*c || a*a+b*b==c*c || b*b==a*a+c*c){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
		conteo++;
	}
	return 0;
}	

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
bool F[110][10][5];
int P[110][15],ans=-1000000007;
int main()
{
	int N;
	cin>>N;
	for(int i=0;i<N;i++)
		for(int j=0;j<5;j++)
			for(int k=0;k<2;k++)
				cin>>F[i][j][k];
	for(int i=0;i<N;i++)
		for(int j=0;j<=10;j++)
			cin>>P[i][j];
	const int enu=(1<<10);
	for(int i=1;i<enu;i++)
	{
		int res=0;
		for(int j=0;j<N;j++)
		{
			int cnt=0;
			for(int k=0;k<10;k++)
				if(F[j][k/2][k%2]&&(i>>k&1))
					cnt++;
			res+=P[j][cnt];
		}
		ans=max(ans,res);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
def add_i1():
	abc[i1]+=1
	abc[i2]-=1
	res[i]=i1
	return

def add_i2():
	abc[i1]-=1
	abc[i2]+=1
	res[i]=i2

n,*abc=map(int,input().split())
ip=[0]*n

for i in range(n):
	ip[i]=list(map(lambda x:ord(x)-ord("A"),list(input())))

ans="Yes"
res=[0]*n
s=sum(abc)
if s==0:
	ans="No"
elif s==1:
	for i in range(n):
		i1=ip[i][0]
		i2=ip[i][1]
		ABC=[abc[i1],abc[i2]]
		if ABC==[0,0]:
			ans="No"
		elif ABC==[0,1]:
			add_i1()
		else:
			add_i2()
else:
	i1=ip[0][0]
	i2=ip[0][1]
	if [abc[i1],abc[i2]]==[0,0]:
		ans="No"
	else:
		for i in range(n):
			i1=ip[i][0]
			i2=ip[i][1]
			if abc[i1]==0:
				add_i1()
			elif abc[i2]==0:
				add_i2()
			elif i+1<n and ip[i+1]!=ip[i]:
				c=list(set(ip[i])&set(ip[i+1]))[0]
				if i1==c:
					add_i1()
				else:
					add_i2()
			else:
				add_i1()

dic={0:"A",1:"B",2:"C"}
print(ans)
if ans=="Yes":
	for i in range(n):
		print(dic[res[i]])

Measured memory_bytes: 21840
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s = sc.next();
      StringBuilder sb = new StringBuilder();
      for(int i = 0;i < s.length();i++){
      	String x = s.substring(i,i+1);
        if(x.equals("0")) sb.append("0");
        if(x.equals("1")) sb.append("1");
        if(x.equals("B") && sb.length() != 0) sb.delete(sb.length()-1,sb.length());
      }
      System.out.println(sb.toString());
    }
}

Measured memory_bytes: 22996
using System;

namespace AtCoder.ddcc2020_qual
{
    class _1
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int c = int.Parse(input[0]);
            int m = int.Parse(input[1]);

            int total = 0;
            total += getPrizeMoney(c);
            total += getPrizeMoney(m);
            if(c == 1 && m ==1)
            {
                total += 400000;
            }

            Console.WriteLine(total);
            Console.ReadKey();
        }

        static int getPrizeMoney(int rank)
        {
            switch (rank) { 
                case 1:
                    return 300000;
                case 2:
                    return 200000;
                case 3:
                    return 100000;
                default:
                    return 0;

            }
        }
    }
}


Measured memory_bytes: 11220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] strlist = str.split(" ");
		int sx = Integer.parseInt(strlist[0]);
		int sy = Integer.parseInt(strlist[1]);
		int tx = Integer.parseInt(strlist[2]);
		int ty = Integer.parseInt(strlist[3]);

		int x = tx -sx;
		int y = ty -sy;

		for(int i=0; i<y; i++){
			System.out.print("U");
		}
		for(int i=0; i<x; i++){
			System.out.print("R");
		}
		for(int i=0; i<y; i++){
			System.out.print("D");
		}
		for(int i=0; i<x; i++){
			System.out.print("L");
		}

		System.out.print("L");

		for(int i=0; i<y+1; i++){
			System.out.print("U");
		}
		for(int i=0; i<x+1; i++){
			System.out.print("R");
		}

		System.out.print("D");
		System.out.print("R");

		for(int i=0; i<y+1; i++){
			System.out.print("D");
		}
		for(int i=0; i<x+1; i++){
			System.out.print("L");
		}

		System.out.print("U");

	}

}


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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  int i,sum=0;

  //dainyu-
  for(i=0;i<N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  int max=0;
  for(i=0;i<N;i++){
    if(max<a.at(i)){
      sum++;
      max=a.at(i);
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

typedef long long ll;
const int Maxn = 1e9 + 10;
const int N = 1e5 + 10;
const int INF=(0x7fffffff)/2;
char a[200], b[200],c[200];

int main(){
	int x, a, b,c;
	while(~scanf("%d %d %d %d", &a, &b, &c, &x)){
		int sum = 0;
		for(int i = 0;i <= a; i++){
			for(int j = 0; j <= b; j++){
				for(int k = 0; k <= c; k++){
					if((500 * i + 100 * j + 50 * k) == x)
						sum++;
				}
			}
		}
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    long long int n,a[200005],i,c,d,sum=0;
    long long int b=1000000007;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    c=a[n-1];
    for(i=n-2;i>=0;i--)
    {
        d=c*a[i];
        d=d%b;
        sum=sum+d;
        sum=sum%b;
        c=c+a[i];
        c=c%b;
    }
    cout<<sum;
}


Measured memory_bytes: 5204
#include <cstdio>
#include <map>

#define N 30

using namespace std;

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int rank[ N + 1 ] = { 0 };
  map < int, int >  stk;
  int n;
  int i;

  for ( ; ; )
  {
    int r;

    scanf ( "%d,%d", &n, &r );
    if ( !( n | r ) ) break;

    stk[ n ] = r;
    ++rank[ r ];
  }

  n = 0;
  for ( i = N; i >= 0; --i )
  {
    if ( rank[ i ] )
    {
      rank[ i ] = ++n;
    }
  }

  while ( scanf ( "%d", &n ) == 1 )
  {
    printf ( "%d\n", rank[ stk[ n ] ] );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int D; std::cin >> D;
    std::vector<int> c(26);
    for(int i(0); i < 26; ++i) std::cin >> c[i];
    std::vector<std::vector<int>> s(D+1, std::vector<int>(26, 0));
    for(int i(1); i <= D; ++i){
        int mx(0), id(-1);
        for(int j(0); j < 26; ++j){
            std::cin >> s[i][j];
            if(chmax(mx, s[i][j])) id = j+1;
        }
        std::cout << id << "\n";
    }
    return 0;
}


Measured memory_bytes: 3668
#include <cstdio>
#include <algorithm>
using namespace std;

int main(void)
{
    int card[5];
    
    while (scanf("%d,%d,%d,%d,%d", &card[0], &card[1], &card[2], &card[3], &card[4]) != EOF){
        
        stable_sort(card, card + 5);
        
        if (((card[0] == card[1]) && (card[1] == card[2]) && (card[2] == card[3])) || ((card[1] == card[2]) && (card[2] == card[3]) && (card[3] == card[4]))){
            printf("four card\n");
        }
        else if (((card[0] == card[1]) && (card[2] == card[3]) && (card[3] == card[4])) || ( (card[4] == card[3]) && (card[0] == card[1]) && (card[1] == card[2]) )){
            printf("full house\n");
        }
        else if (((card[0] == 1) && (card[1] == 10) && (card[2] == 11) && (card[3] == 12) && (card[4] == 13)) || ((card[0] == card[1] - 1) && (card[1] == card[2] - 1) && (card[2] == card[3] - 1) && (card[3] == card[4] - 1))){
            printf("straight\n");
        }
        else if ( ((card[0] == card[1]) && (card[1] == card[2])) || ((card[1] == card[2]) && (card[2] == card[3])) || ((card[2] == card[3]) && (card[3] == card[4])) ){
            printf("three card\n");
        }
        else if (((card[0] == card[1]) && (card[2] == card[3])) || ((card[1] == card[2]) && (card[3] == card[4])) || ((card[0] == card[1]) && (card[3] == card[4]))){
            printf("two pair\n");
        }
        else if ((card[0] == card[1]) || (card[1] == card[2]) || (card[2] == card[3]) || (card[3] == card[4])){
            printf("one pair\n");
        }
        else {
            printf("null\n");
        }
    }
    
    return (0);
}

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

using namespace std;

#define int long long

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

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

    vector<char> good(n);
    int ma = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] > ma) {
            good[i] = true;
            ma = a[i];
        }
    }

    multiset<int, greater<int> > small;
    int cnt = 0;
    int sum = 0;
    vector<int> ans(n);
    int sumprev = 0;
    int prev = -1;
    for (int i = n - 1; i >= 0; --i) {
        if (good[i]) {
            while (!small.empty() && *small.begin() >= a[i]) {
                sum += *small.begin();
                ++cnt;
                small.erase(small.begin());
            }
            if (prev != -1) {
                ans[prev] = sum - cnt * a[i] - sumprev;
                sumprev += ans[prev];
            }
            prev = i;
        }
        small.insert(a[i]);
    }
    while (!small.empty()) {
        sum += *small.begin();
        ++cnt;
        small.erase(small.begin());
    }
    ans[0] = sum - sumprev;

    for (int i = 0; i < n; ++i) {
        cout << ans[i] << '\n';
    }
}



Measured memory_bytes: 8048
package main

import "fmt"

func main() {
	var res, n int
	fmt.Scanf("%d", &n)
	a := n / 1000 * 1000
	res = n - a
	if res == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1000 - res)
	}
}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//


int main() {
	int N;
	cin >> N;
	vector<int> P(N * N);
	REP(i, N * N) scanf("%d", &P[i]), --P[i];
	
	vector<vector<int>> d(N, vector<int>(N, INF));
	REP(i, N) REP(j, N) chmin(d[i][j], min({ i, N - 1 - i, j, N - 1 - j }));
	
	vector<vector<int>> done(N, vector<int>(N));
	int ans = 0;
	REP(i, N * N) {
		int y = P[i] / N, x = P[i] % N;
		
		ans += d[y][x];
		done[y][x] = true;
		deque<pii> que;
		que.emplace_back(y, x);
		
		while (!que.empty()) {
			int cy = que.front().fi, cx = que.front().se;
			que.pop_front();
			
			constexpr int dx[] = {0,1,0,-1}, dy[] = {-1,0,1,0};
			REP(dir, 4) {
				int ny = cy + dy[dir], nx = cx + dx[dir];
				if (nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
				if (chmin(d[ny][nx], !done[cy][cx] + d[cy][cx])) {
					if (done[cy][cx]) que.emplace_back(ny, nx);
					else que.emplace_front(ny, nx);
				}
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n, i##_len=(n); i>=0; i--)
#define FOR(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 




int main() {
  int N;
  cin >> N;
  int four = 0, two = 0, one = 0;
  REP(i, N){
    ll a;
    cin >> a;
    if(a % 4 == 0) four++;
    else if(a % 2 == 0) two++;
    else one++;
  }
if(two % 2 == 1){
if(four >= one) yes;
else no;
}else{
  if(four >= one - 1) yes;
  else no;
}

}

Measured memory_bytes: 384
def resolve():
    n,m=map(int,input().split())
    edges=[[] for _ in range(n)]
    for _ in range(m):
        s,t=map(int,input().split())
        s-=1; t-=1
        edges[s].append(t)
 
    # 確率DP
    p=[0]*n
    p[0]=1.0
    for v in range(n):
        for nv in edges[v]:
            p[nv]+=p[v]/len(edges[v])
 
    # 期待値DP
    E=[0]*n
    for v in range(n-2,-1,-1):
        for nv in edges[v]:
            E[v]+=E[nv]
        E[v]=1+E[v]/len(edges[v])
 
    ans=E[0]
    for v in range(n):
        if(len(edges[v])<=1): continue
        # 各vに対して、辺vwのうちE[w]が最大のものを削除する
        w=max(*((E[w],w) for w in edges[v]))[1]
        dE=0
        deg=len(edges[v])
        for nv in edges[v]:
            if(nv==w): dE-=E[nv]/deg
            else: dE+=E[nv]/(deg-1)/deg
        ans=min(ans,E[0]+p[v]*dE)
 
    print(ans)
resolve()

Measured memory_bytes: 59864
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
struct triplet{ll a,b,c;};bool operator < (const triplet &t1,const triplet &t2){   if(t1.a<t2.b)return true;if(t1.a==t2.a && t1.b <t2.b)return true;if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)return true;return false;}
ll mod1=998244353;
ll power(ll n,ll k){ll ans=1; while(k>0){if(k&1)ans=(ans*n);n=(n*n);k>>=1;}return ans;}
int main()
{
    fio;
    ll n,k;
    cin>>n>>k;
    if(k==1)
        cout<<0;
    else
        cout<<n-k;
}



Measured memory_bytes: 256
import sys

x, y, z, K = map(int, sys.stdin.readline().split())
a, b, c = (sorted(map(int, sys.stdin.readline().split()), reverse=True) for _ in range(3))
def main():
    res = []
    for i in range(1, min(K, x) + 1):
        for j in range(1, min(K // i, y) + 1):
            for k in range(1, min(K // (i * j), z) + 1):
                res.append(a[i-1] + b[j-1] + c[k-1])

    return sorted(res, reverse=True)[:K]

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

Measured memory_bytes: 9548
s = list(input())

ans = ""
add = ""

for i in range(len(s)):
    if s[i] == "0":
        ans += "0"
    elif s[i] == "1":
        ans += "1"
    elif s[i] == "B":
            ans = ans[:-1]

if len(ans) == 0:
    for i in range(len(s)):
        if s[i] != "B":
            add = s[i]
    ans = add

print(ans)


Measured memory_bytes: 3060
program ABC149E
    implicit none
    integer(16)::N,M
    integer(16),allocatable,dimension(:)::A,R
    integer(16)::ans,OK,NG,MD,tmp
    integer(16)::i,j
    read*,N,M
    allocate(A(N))
    read*,A
    call heapsort(N,A)
    allocate(R(200000+1))
    R=0
    do i=1,N
        R(A(i))=R(A(i))+1
    end do
    do i=2*10**5,1,-1
        R(i)=R(i)+R(i+1)
    end do
    
    OK=0;NG=A(N)*2+1
    MD=(OK+NG)/2
    do while(NG-OK>1)
        if(CNT(MD)>=M)then
            OK=MD
        else
            NG=MD
        endif
        MD=(OK+NG)/2
    end do

    ans=0
    do i=1,N
        if(A(i)>=MD)then
            tmp=N
        else
            tmp=R(MD-A(i))
        endif
        ans=ans+tmp*A(i)*2
    end do
    print"(i0)",ans-MD*(cnt(MD)-M)
contains
integer(16) function cnt(MID)
    integer(16),intent(in)::MID
    integer(16)::ii
    cnt=0
    do ii=1,N
        if(MID>A(ii))then
            cnt=cnt+R(MID-A(ii))
        else
            cnt=cnt+N
        endif
    end do
end function
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t
  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end program ABC149E

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int INF = 1e18+1;
const int MINF = -1e18-1;

signed main() {
    int N, K;
    cin >> N >> K;
    int z = 0;
    vi p, m;
    rep(i, N) {
        int a;
        cin >> a;
        if(a > 0) p.pb(a);
        else if(a < 0) m.pb(a);
        else z++;
    }
    SORT(p); SORT(m);
    int pn = (p.size()*(p.size()-1)/2)+(m.size()*(m.size()-1)/2); //積が正のペアの個数
    int mn = p.size()*m.size(); //積が負のペアの個数
    int zn = z*p.size()+z*m.size()+(z*(z-1))/2; //積が0のペアの個数

    int res;
    //K番目が負である場合
    if(K <= mn) {
        int l=MINF, r=0, mid;
        while(abs(l-r) > 1) {
            mid = (l+r)/2;
            int cnt = 0;
            rep(i, m.size()) {
                auto it = upper_bound(ALL(p), mid/m[i]);
                cnt += p.end()-it;
            }
            if(cnt < K) l = mid;
            else r = mid;
        }
        res = l;
    }

    //K番目が0である場合 
    else if(K <= mn+zn) {
        res = 0;
    }

    //K番目が正である場合 
    else {
        int l=0, r=INF, mid;
        while(abs(r-l) > 1) {
            mid = (l+r)/2;
            int cnt = 0;
            rep(i, p.size()) {
                auto it = upper_bound(ALL(p), mid/p[i]);
                cnt += it - p.begin();
                if(mid/p[i] >= p[i]) cnt--;
            }
            rep(i, m.size()) {
                auto it = lower_bound(ALL(m), mid/m[i]);
                cnt += m.end()-it;
                if(mid/m[i] <= m[i]) cnt--;
            }
            if(cnt/2+mn+zn < K) l = mid;
            else r = mid;
        }
        res = r;
    }

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

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    string S, T;
    cin >> S >> T;
    int n = S.length();
    rep(i,n) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3628
def main():
    n, m, x = map(int, input().split())
    a = tuple(map(int, input().split()))
    a_low = [i for i in a if i < x]
    a_high = [i for i in a if i > x]
    r = min(len(a_low), len(a_high))
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61732
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[][][] F = new int[N][5][2];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 5; j++) {
        F[i][j][0] = sc.nextInt();
        F[i][j][1] = sc.nextInt();
      }
    }
    int[][] P = new int[N][11];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j <= 10; j++) {
        P[i][j] = sc.nextInt();
      }
    }
    
    //
    int ans = Integer.MIN_VALUE;
    int m = 1 << 10;
    for (int b = 1; b < m; b++) {
      int sum = 0;
      for (int i = 0; i < N; i++) {
        int count = 0;
        int w = b;
        int j = 0;
        while (w != 0) {
          int am = w % 2;
          w /= 2;
          int pm = w % 2;
          w /= 2;
          if (F[i][j][0] == 1 && am == 1) {
            count++;
          }
          if (F[i][j][1] == 1 && pm == 1) {
            count++;
          }
          j++;
        }
        sum += P[i][count];
      }
      ans = Math.max(ans, sum);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27104
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

using DataStructures
function main()
    h,w=parseMap(split(readline()))
    sh,sw=parseMap(split(readline()))
    gh,gw=parseMap(split(readline()))
    s=[readline() for _=1:h]
    INF=1<<32
    warp=fill(INF,h,w)
    warp[sh,sw]=0
    dxy=[[1,-1,0,0],
         [0,0,1,-1]]
    wdxy=[[ 2, 2, 2, 2, 2,
            1, 1,    1, 1,
            0,          0,
           -1,-1,   -1,-1,
           -2,-2,-2,-2,-2],
          [-2,-1, 0, 1, 2,
           -2,-1,    1, 2,
           -2,          2,
           -2,-1,    1, 2,
           -2,-1, 0, 1, 2]]
    q=Deque{Tuple{Int,Int}}()
    push!(q,(sh,sw))
    while !isempty(q)
        (nowh,noww)=popfirst!(q)
        tmp=warp[nowh,noww]
        for i=1:4
            nexth=nowh+dxy[1][i]
            nextw=noww+dxy[2][i]
            1<=nexth<=h || continue
            1<=nextw<=w || continue
            s[nexth][nextw]=='.' || continue
            tmp<warp[nexth,nextw] || continue
            warp[nexth,nextw]=tmp
            pushfirst!(q,(nexth,nextw))
        end
        for i=1:20
            nexth=nowh+wdxy[1][i]
            nextw=noww+wdxy[2][i]
            1<=nexth<=h || continue
            1<=nextw<=w || continue
            s[nexth][nextw]=='.' || continue
            tmp+1<warp[nexth,nextw] || continue
            warp[nexth,nextw]=tmp+1
            push!(q,(nexth,nextw))
        end
    end
    ans=warp[gh,gw]
    if ans==INF
        ans=-1
    end
    println(ans)
end
main()

Measured memory_bytes: 228788
//Deep Godhani
//DAIICT

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

#define N 100000000000
#define PI acos(-1)
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define ll long long int
#define ld long double
#define precision(x,d) cout << fixed << setprecision(d) << x
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

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

bool checkPrime(int n)
{
	for(int i=0;i<=sqrt(n);i++)
	{
		if(n%i == 0)
		{
			return false;
		}
	}
	return true;
}


void solve()
{
	int n;
	cin >> n;
	ll sum = 0;
	for(int i=1;i<=n;i++)
	{
		if(i%15 && i%3 && i%5)
		{
			sum += i;
		}
	}
	cout << sum << endl;
}
int main()
{
    FAST;
    ll t=1;
    //cin >> t;
    while(t--)
    {
      //cout << "************" << endl;
      solve();
      //cout << "************"  << endl;
    }
		return 0;
}


Measured memory_bytes: 3664
from math import floor
def main():
    n = int(input())
    d, x = map(int, input().split())
    a = []
    for _ in range(n):
        a.append(int(input()))

    for ea in a:
        x += 1
        x += floor((d - 1) // ea)

    print(x)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static final String[] octave = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
	public static String[] step;
	public static String[] song;
	
	public static int n;
	public static int m;
	public static final String UNDEF = "undef";
	public static void main(String[] args) {
		doIt();

	}
	public static void doIt(){
		Scanner sc = new Scanner(System.in);
		int numOfData = sc.nextInt();
		
		for(int i = 0; i < numOfData; i++){
			n = sc.nextInt();
			m = sc.nextInt();
			//String[] step = new String[n];
			step = new String[n];

			for(int j = 0; j < n; j++){
				step[j] = sc.next();
			}
			//String[] song = new String[m];
			song = new String[m];
			
			for(int j = 0; j < m; j++){
				song[j] = sc.next();
			}
			
			if(singSong(n - 1) || singSong(n - 2)){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}
		}
		
	}
	
	public static boolean singSong(int start){
		boolean bMake = false;
		int point = start;
		int sp = m - 1;
		//int end = Math.min(n - 2, 0);
		//for(point = n - 1; n - 2 <= point; point--){
			if(ring(point, 1).equals(song[sp])){
				point += 1;
				bMake = true;
				//break;
			}
			else if(ring(point, -1).equals(song[sp])){
				point -= 1;
				bMake = true;
				//break;
			}
			else if(ring(point, -2).equals(song[sp])){
				point -= 2;
				bMake = true;
				//break;
			}
		//}
		boolean isOK = true;
		if(bMake == true){
			for(sp = m - 2; sp > - 1; sp--){
				if(ring(point, 1).equals(song[sp])){
					point += 1;
				}
				else if(ring(point, -1).equals(song[sp])){
					point -= 1;
				}
				else if(ring(point, -2).equals(song[sp])){
					point -= 2;
				}
				else{
					isOK = false;
					break;
				}
				if(point < 0){
					//isOK = false;
					break;
				}
			}
		}
		if(m == 1){
			sp++;
		}
		//System.out.println("point = " + point + ", sp = " + sp);
		if(point == -1 && sp == 0 && isOK == true){
			return true;
		}
		else{
			return false;
		}
	}

	public static String ring(int now, int num){
		//System.out.println("ring : now = " + now + ", num = " + num);
		int i = now + num;
		if(i < -1 || i >= n){
			return UNDEF;
		}
		if(now < 0 || now >= n){
			return UNDEF;
		}
		String ret = step[now];
		if(num == -2){
			for(int j = 0; j < 12; j++){
				if(ret.equals(octave[j])){
					j++;
					ret = octave[j % 12];
					break;
				}
			}
		}
		else if(num == 1){
			for(int j = 0; j < 12; j++){
				if(ret.equals(octave[j])){
					j--;
					if(j == -1){
						j = 11;
					}
					ret = octave[j];
					break;
				}
			}
		}
		//System.out.println("ring : now = " + now + ", num = " + num + ", ret = " + ret);
		return ret;
	}
}

Measured memory_bytes: 19000
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };
int par[100005], rnk[100005], heavy[100005];
int a[100006], b[100006];
int ans[100006];
void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		rnk[i] = 0;
		heavy[i] = 1;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (heavy[x] < heavy[y])swap(x, y);
	par[y] = x;
	heavy[x] += heavy[y];
}
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m)cin >> a[i] >> b[i];
	ans[m] = n*(n - 1) / 2;
	init(n);
	for (int i = m - 1; i >= 0; i--) {
		a[i]--; b[i]--;
		if (find(a[i]) != find(b[i])) {
			ans[i] = ans[i + 1] - heavy[find(a[i])] * heavy[find(b[i])];
		}
		else ans[i] = ans[i + 1];
		unite(a[i], b[i]);
	}
	rep(i, m)cout << ans[i+1] << endl;
}

Measured memory_bytes: 6016
#include<iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    string a;
    string b;
    string c;
    int i = 0, j =0, k = 0;
    cin >> a;
    cin >> b;
    cin >> c;
    
    
    alice:
    if(i==a.size()){
        cout << "A" << "\n";
        return 0;
        }  else{
   if(a[i] == 'a'){
   i++;
   goto alice;
   }
   else if(a[i]=='b'){
       i++;
       goto bob;
   }else if(a[i]=='c'){
       i++;
       goto c;
   }
   
        }
    
    bob:
       if(j==b.size()){
        cout << "B" << "\n";
        return 0;
        }  else{
   if(b[j] == 'a'){
   j++;
   goto alice;
   }
   else if(b[j]=='b'){
       j++;
       goto bob;
   }else if(b[j]=='c'){
       j++;
       goto c;
   }
   
        }
    
    c:
    
      if(k==c.size()){
        cout << "C" << "\n";
        return 0;
        }  else{
   if(c[k] == 'a'){
   k++;
   goto alice;
   }
   else if(c[k]=='b'){
       k++;
       goto bob;
   }else if(c[k]=='c'){
       k++;
       goto c;
   }
        }
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

ll cnt[10][10] = {};
int main(){
	int n; scanf("%d", &n);
	FOR(i, 1, n+1){
		int fst = i%10, lst;
		for(int j = i; j; j /= 10) lst = j % 10;
		cnt[fst][lst]++;
	}
	ll ans = 0;
	REP(i, 10){
		REP(j, 10){
			ans += cnt[i][j] * cnt[j][i];
		}
	}
	printf("%lld\n", ans);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <chrono>
 
using namespace __gnu_pbds;
using namespace std;
 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
 
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define pii pair<ll,pi >
#define ppi pair<pi,ll>
#define ppp pair<pi,pi >
#define ex(str,a,b) str.substr((int)(a),min((int)str.size()-a,(int)(b-a+1))) 
#define all(X) X.begin(),X.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
// for pair comparison function(ascending order) use return (i1.ff < i2.ff);
 
/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   __builtin_popcount(n) : no. of set bits in n.
*/
 
const int M = (1<<20)+5;
const int md = 1e9+7;
 
priority_queue<ll,vector<ll >,greater<ll > > pq;
 
ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << max({a*c,a*d,b*c,b*d}) << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n,m;
ll mat[3005][3005];
ll dp[3005][3005][5];

ll resi(int x, int y, int k){
    if(x <= 0 || y <= 0)return 0;
    if(dp[x][y][k] >= 0)return dp[x][y][k];
    dp[x][y][k] = max(resi(x - 1, y, 3), resi(x, y - 1, k));
    if(k){
        ll tmp = 0;
        tmp = max(resi(x - 1,y,3) + mat[x][y], resi(x,y - 1,k - 1) + mat[x][y]);
        dp[x][y][k] = max(dp[x][y][k], tmp);
    }
    return dp[x][y][k];
}


int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> m;
    ff(i,1,n){
        ff(j,1,m){
            ff(k,0,3)dp[i][j][k] = -1;
        }
    }
    int q;
    cin >> q;
    while(q -- ){
        int x,y,w;
        cin >> x >> y >> w;
        mat[x][y] = w;
    }
    ll ans = resi(n,m,3);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 426780
import java.util.*

fun main(args: Array<String>) {
    val argList = Scanner(System.`in`)


    val s = argList.next()
    val executor = Security()
    executor.execute(s)

}
class Security {
    fun execute(code: String) {

        if (code[0] == code[1] || code[1] == code[2] || code[2] == code[3]) {
            println("Bad")
            return
        }
        println("Good")
    }
}


Measured memory_bytes: 31252
#!/usr/bin/env python3
n = int(input())

ans = False

for j in range(25):  #4$
        for k in range(15):  #7$
            if j + k == 0:
                continue
            if n % ((j * 4) + (k * 7)) == 0:
                ans = True
                break
        if ans:
            break

print("Yes" if ans else "No")


Measured memory_bytes: 9120
#include<cstdio>
#include<algorithm>
using namespace std;

int a[5],cnt;

int main()
{
	scanf("%d %d %d",&a[1],&a[2],&a[3]);
	sort(a+1,a+4);
	while(a[2]<a[3])
		a[1]++,a[2]++,cnt++;
	while(a[1]<a[2])
		a[1]+=2,cnt++;
	if(a[1]!=a[2])
		cnt++;
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int64_t H;
  cin >> H;
  if (H == 1) {
    printf("1\n");
    return 0;
  }
  int64_t cnt = 1;
  int64_t i = 1;
  H /= 2;
  while (H > 0) {
    i <<= 1;
    cnt += i;
    H /= 2;
  }
  printf("%lld\n", cnt);
}


Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

typedef long long ll;
int main() {
	int n;
	int k;
	cin >> n >> k;
	
	vector<int> a(n);
	
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	
	sort(a.begin(),a.end());
	
	int sum = 0;
	for(int i = 0; i < k; i++){
		sum += a[i];
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3628
s = input()

del_list = [] 
l = 0
pointer = 0
for i,v in enumerate(s):
    if v == "S":
        del_list.append([i,-1])
        l += 1
    else:
        if l != 0 and pointer != l:
            del_list[pointer][1]  = i
            pointer += 1


rems = 0
delpair = 0
for i in del_list:
    if i[1] == -1:
        rems += 1
    else:
        delpair += 1

remt = s.count("T") - delpair
print(remt+rems)


Measured memory_bytes: 53580
import math
N = int(input())
min = N
for i in range(1,int(N**0.5)+1):
    if N%i == 0 and min > max(math.log10(i), math.log10(N//i)):
        min = max(math.floor(math.log10(i))+1,math.floor(math.log10(N//i))+1)
print(min)


Measured memory_bytes: 3060
from itertools import product


def solve(string):
    k = int(string)
    if k < 10:
        return str(k)

    t = [[0] * 12 for _ in range(10)]
    t[0] = [0] + [1] * 10 + [0]
    ac = 9
    for i, j in product(range(1, 10), range(1, 11)):
        t[i][j] = t[i - 1][j - 1] + t[i - 1][j] + t[i - 1][j + 1]
        ac += t[i][j] if j > 1 else 0
        if ac >= k:
            k -= ac - t[i][j]
            break
    ans = str(j - 1)
    while i > 0:
        i -= 1
        j -= 1
        tmp = t[i][j]
        while tmp < k:
            j += 1
            tmp += t[i][j]
        k -= tmp - t[i][j]
        ans += str(j - 1)
    return ans


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n;cin >> n;
    string s;cin >> s;
    ll counter ;
    int scount =0;
    rep(i,n){
        if(s[i]=='R')scount++;
    }
    counter = scount;
    scount=0;
    rep(i,n){
        if(s[i]=='G')scount++;
    }
    counter *= scount;
    scount=0;
    rep(i,n){
        if(s[i]=='B')scount++;
    }
    counter *= scount;
    for (int inter = 1;inter*2<n;inter++){
        for(int i = 0;i+inter*2<n;i++){
            if(s[i] != s[i+inter] && s[i+inter] != s[i+inter*2] && s[i] != s[i+inter*2]){
                counter--;
            }
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 3628
/*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/

/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	char word[21];
	cin >> word;
	int last=0;
	while(word[last] != '\0')	last++;
	int i = 0;
	char exc;
	while(i < last-i-1){
		exc = word[i];
		word[i] = word[last-i-1];
		word[last-i-1] = exc;
		i++;
	}
	i = 0;
	while(word[i] != '\0'){
		cout << word[i];
		i++;
	}
	cout << endl;
	/*****処理部*****/
	
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

Measured memory_bytes: 1132
#include <stdio.h>

int main(void) {
	int a, b, c;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
 
  if( a == 5 && b == 7 && c == 5 ||a == 7 && b == 5 && c == 5 || a == 5 && b == 5 && c == 7){
    printf("YES");
  }else{
    printf("NO");
    }
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 100005
#define eps 1e-8
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int num[2];
char s[15];
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    read(N);
    out(0);enter;fflush(stdout);
    scanf("%s",s + 1);

    if(s[1] == 'F') num[0] = 1;
    else if(s[1] == 'M') num[0] = 0;
    else return 0;
    out(N - 1);enter;fflush(stdout);
    scanf("%s",s + 1);

    if(s[1] == 'F') num[1] = 1;
    else if(s[1] == 'M') num[1] = 0;
    else return 0;
    int L = 1,R = N - 2;
    while(L < R) {
        int mid = (L + R) >> 1;
        out(mid);enter;fflush(stdout);
        scanf("%s",s + 1);

        if(s[1] == 'V') return 0;
        int a;
        if(s[1] == 'M') a = 0;
        else a = 1;
        int t = a ^ ((mid - L) & 1);
        if(t == num[0]) {R = mid - 1;num[1] = a;}
        else {L = mid + 1;num[0] = a;}
    }
    out(L);enter;fflush(stdout);scanf("%s",s + 1);
    return 0;
}


Measured memory_bytes: 852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A= sc.nextInt();
		int B = sc.nextInt();
		if (A<=8&&B<=8) {
			System.out.println("Yay!");
		} else {
			System.out.println(":(");
		}
	}
}

Measured memory_bytes: 22868
def get():
	return map(int,raw_input().split())
def cv(t):
	return t/100*60+t%100
while 1:
	n,p,q=get()
	if n==0: break
	v=[0]*1440
	for i in range(n):
		k=get()[0]; a=get()
		for j in range(k):
			for l in range(cv(a[::2][j]),cv(a[1::2][j])):
				v[l]+=1
	m=c=0
	for i in range(cv(p),cv(q)):
		c=(c+1)*(v[i]<n)
		m=max(m,c)
	print m

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

using namespace std;

const int MAX = 1e5+10;

int h[MAX];
int dp[MAX];

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;

    for(int i=1;i<=n;++i)
        cin >> h[i];
    
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=n;++i)
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));

    cout << dp[n] << '\n';

    return 0;
}

Measured memory_bytes: 1024
def group(n):
    a1 = [1,3,5,7,8,10,12]
    a2 = [4,6,9,11]
    a3 = [2]
    if n in a1:
        return 1
    if n in a2:
        return 2
    return 3

x,y = map(int,input().split())
if group(x) == group(y):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
def main():
    array = []
    a = int(input())
    for _ in range(4):
        array.append(int(input()))
    k = int(input())

    for p in array:
        if p - a > k:
            print(":(")
            exit()
    print("Yay!")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
N = int(input())
L = list(map(int,input().split()))
dp = [0 for i in range(N)]
if N >= 3 :
    
    for i in range(1,3) :
        dp[i] = abs(L[i]-L[0])
    for i in range(3,len(dp)) :
        a = dp[i-1] + abs(L[i]-L[i-1])
        b = dp[i-2] + abs(L[i]-L[i-2])
        dp[i] = min(a,b)
    print(dp[N-1])
    #print(dp)

else :
    print(abs(L[-1]-L[0]))
    


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

using namespace std;

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

    vector<int> a(n + 5, 0);
    vector<int> l(n + 5, 0);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        l[i] = max(l[i - 1], a[i]);
    }

    vector<int> r(n + 5, 0);
    for (int i = n; i >= 1; --i) {
        r[i] = max(r[i + 1], a[i]);
    }

    for (int i = 1; i <= n; ++i) {
        cout << max(l[i - 1], r[i + 1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

//階乗
int factorial(int k){
    int result=1;
    for (int i=1;i<=k;++i){
        result*=i;
    }
    return result;
}


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

    vector<ll>a(3*n);
    rep(i,3*n)cin>>a[i];

    sort(a.begin(),a.end());
    ll sum=0;

    for(ll i=n;i<3*n;i+=2)sum+=a[i];

    cout<<sum<<endl;
}



Measured memory_bytes: 2560
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Bits
import Data.Int
import Debug.Trace

main = do
  [n,q] <- map read . words <$> getLine :: IO [Int]
  queries <- replicateM q $ map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine :: IO [[Int]]

  seg <- stToIO $ newSegmentTree n 0 (+) :: IO (IOSegmentTree Int)

  forM_ queries $ \[com,x,y] -> do
    when (com == 0) $ do
      stToIO $ modifySegmentTree seg (x-1) y
    when (com == 1) $ do
      print =<< (stToIO $ findSegmentTree seg (x-1) y)

type IOSegmentTree a = STSegmentTree RealWorld a
type STSegmentTree s a = (VM.MVector s a, a, (a -> a -> a)) -- (セグメント木, 単位元, 二項演算)

newSegmentTree :: Num a => Int -> a -> (a -> a -> a) -> ST s (STSegmentTree s a)
newSegmentTree n e f = (,e,f) <$> (V.thaw $ V.replicate m e)
  where m = 2 * (2 ^ (ceiling $ logBase 2 (fromIntegral n))) - 1

modifySegmentTree :: Num a => STSegmentTree s a -> Int -> a -> ST s ()
modifySegmentTree (tree,e,f) i x= do
  VM.write tree j =<< (`f` x) <$> VM.read tree j
  aux ((j-1)`div`2)
  where
    n = (VM.length tree + 1) `div` 2
    j = i + n - 1
    aux i = do
      when (i >= 0) $ do
        VM.write tree i =<< f <$> VM.read tree (i*2+1) <*> VM.read tree (i*2+2)
        aux ((i-1)`div`2)

findSegmentTree :: Num a => STSegmentTree s a -> Int -> Int -> ST s a
findSegmentTree (tree,e,f) x y = do
  aux 0 0 n
  where
    n = (VM.length tree) `div` 2 + 1
    aux i l r
      | r <= x || y <= l = return e
      | x <= l && r <= y = VM.read tree i
      | otherwise = f <$> aux (i*2+1) l ((l+r)`div`2) <*> aux (i*2+2) ((l+r)`div`2) r



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

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

    vector<vector<int>> A;
    A.assign(h, vector<int>(w));

    int sum = 0;
    rep(i, h) rep(j, w)
    {
        char t;
        cin >> t;
        if (t == '.')
        {
            A[i][j] = 0;
            ++sum;
        }
        else
            A[i][j] = -1;
    }

    // BFS のためのデータ構造
    queue<pint> que;

    // initial state
    A[0][0] = 1;
    que.push(pint(0, 0));

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

    // bfs
    while (!que.empty())
    {
        pint v = que.front();
        que.pop();
        int i = v.first;
        int j = v.second;
        for (int k = 0; k < 4; ++k)
        {
            int ri = i + dx[k];
            int rj = j + dy[k];
            if (ri < 0 || ri >= h || rj < 0 || rj >= w)
                continue;
            if (A[ri][rj] == 0)
            {
                A[ri][rj] = A[i][j] + 1;
                que.push(pint(ri, rj));
            }
        }
    }

    // output
    if (A[h - 1][w - 1] == 0)
        cout << -1 << endl;
    else
    {
        cout << sum - A[h - 1][w - 1] << endl;
    }
}

Measured memory_bytes: 256