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

typedef signed long long ll;
const int MX = 1e5 + 5;
const int INF = 1e9 + 5;
int n, A[MX][3], dp[MX][4];

int solve(int pos, int prev) {
    if(pos >= n) return 0;
    if(dp[pos][prev] != -1) return dp[pos][prev];
    int ans = 0;
    if(prev == 1) 
        ans = max(ans, max(A[pos][1] + solve(pos + 1, 2), A[pos][2] + solve(pos + 1, 3)));
    else if(prev == 2) 
        ans = max(ans, max(A[pos][0] + solve(pos + 1, 1), A[pos][2] + solve(pos + 1, 3)));
    else if(prev == 3) 
        ans = max(ans, max(A[pos][1] + solve(pos + 1, 2), A[pos][0] + solve(pos + 1, 1)));
    else
        ans = max(A[pos][0] + solve(pos + 1, 1), max(A[pos][1] + solve(pos + 1, 2), A[pos][2] + solve(pos + 1, 3)));
    return dp[pos][prev] = ans;
}

int main() {
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%d %d %d", &A[i][0], &A[i][1], &A[i][2]);
    }
    memset(dp, -1, sizeof(dp));
    int ans = solve(0, 0);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 9216
#include <stdio.h>

/*
3 ????????°?????´???

3????????´??°?????????????????????????????????????°??????????????????????????????????????????°?????????????????????????????????

Input
3????????´??°???????????§????????????????????????????????????

Output
?°????????????????????????????3????????´??°???1????????????????????????????????´??°?????????1?????????????????\??????????????????

*/

#define	NUM_MAX	3

int main( void )
{
	int a[ 3 ], i, j, wk;

	scanf( "%d %d %d", &a[ 0 ], &a[ 1 ], &a[ 2 ] );

	for ( i = 0 ; i < NUM_MAX - 1 ; i++ ) {
		for ( j = i + 1 ; j < NUM_MAX ; j++ ) {
			if ( a[ i ] > a[ j ] ) {
				wk		= a[ i ];
				a[ i ]	= a[ j ];
				a[ j ]	= wk;
			}
		}
	}
	printf( "%d %d %d\n", a[ 0 ], a[ 1 ], a[ 2 ] );
	
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<string.h>
int main(void)
{
	int i,len;
	char c[21];
	scanf("%s",c);
	len=strlen(c);
	for(i=len-1;i>=0;i--){
		printf("%c",c[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 932
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

int main() {

    ll A, B, N;
    cin >> A >> B >> N;


    ll tmp = min(B - 1, N);
    ll ans = A * tmp / B - A * (tmp / B);
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

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

        String[] a = scanner.nextLine().split(" ");
        int N = Integer.parseInt(a[0]);
        int K = Integer.parseInt(a[1]);

        if (K % 2 == 0) {
            long p = N / K;
            p = p * p * p;
            long p2 = (N + (K / 2)) / K;
            p2 = p2 * p2 * p2;
            System.out.println(p + p2);
        } else {
            long p = N / K;
            p = p * p * p;
            System.out.println(p);
        }
    }
}

Measured memory_bytes: 22228
from collections import deque
def main():
  h,w = map(int,input().split())
  ch,cw = map(lambda x:int(x)+1,input().split())
  dh,dw = map(lambda x:int(x)+1,input().split())
  s = [["#"]*(w+4) for _ in range(2)]+[["#"]*2+list(input())+["#"]*2 for _ in range(h)]+[["#"]*(w+4) for _ in range(2)]
  m1 = ((-1,0),(0,-1),(0,1),(1,0))
  m2 = [(i,j) for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)>1]
  a = deque([(ch,cw)])
  b = deque()
  i = 0
  while a:
    while a:
      ah,aw = a.popleft()
      if s[ah][aw]!=".":
        continue
      b.append((ah,aw))
      s[ah][aw] = i
      for bh,bw in m1:
        bh,bw = ah+bh,aw+bw
        if s[bh][bw]==".":
          a.append((bh,bw))
    while b:
      ah,aw = b.popleft()
      for bh,bw in m2:
        bh,bw = ah+bh,aw+bw
        if s[bh][bw]==".":
          a.append((bh,bw))
    i += 1
  ans = s[dh][dw]
  print(ans if ans != "." else -1)

if __name__ == "__main__":
    main()

Measured memory_bytes: 22380
#include<bits/stdc++.h>
using namespace std;
 
int main(){ 
int a,n;
string s;
cin>>n>>s;
if(n%2!=0)
cout<<"No"<<endl;
else if(s.substr(0,n/2)==s.substr((n/2),n/2))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n;
int x = 0;

void merge_sort(int a[], int left, int right);
int main(){

  cin >> n;

  int a[n];

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

  merge_sort(a, 0, n-1);

  for(int i = 0; i < n-1; i++){
    cout << a[i] << " ";
  }
  cout << a[n-1];

  cout << "\n";

  cout << x << '\n';

  return 0;
}
void merge_sort (int a[], int left, int right) {

  int i, j, k, mid;
  int tmp[n];
  if(left < right){
    mid = (left + right) / 2;
    merge_sort(a, left, mid);
    merge_sort(a, mid+1, right);
    for(i = mid; i >= left; i--){
      tmp[i] = a[i];
    }
    for(j = mid + 1; j <= right; j++){
      tmp[right-(j-(mid+1))] = a[j];
    }
    i = left; j = right;
    for(k = left; k <= right; k++) {
      x++;
      if(tmp[i] < tmp[j]){
        a[k] = tmp[i++];
      }
      else{
        a[k] = tmp[j--];
      }
    }
  }
}



Measured memory_bytes: 42108
// Program to compute sum of ranges for different range 
// queries 
#include <bits/stdc++.h> 
using namespace std; 
#define ll int
ll block,n,m;
ll a[500001];
struct Query 
{ 
	ll L, R,i; 
};
Query q[500001];

bool compare(Query x, Query y) 
{
	if (x.L/block != y.L/block) 
		return x.L/block < y.L/block; 
	return x.R < y.R; 
} 
void queryResults()
{
	block = (ll)sqrt(n);
	sort(q, q + m, compare);
	ll currL = 0, currR = 0;
	ll currSum = 0;
	ll ans=0;
	ll aa[m];
	ll f[500001]={0};
	for (ll i=0; i<m; i++) 
	{
		ll L = q[i].L, R = q[i].R; 
		while (currL < L) 
		{ 
			f[a[currL]]--;
			if(f[a[currL]]==0) ans--;
			currL++; 
		}
		while (currL > L) 
		{ 
			if(f[a[currL-1]]==0) ans++;
			f[a[currL-1]]++; 
			currL--; 
		} 
		while (currR <= R) 
		{ 
			if(f[a[currR]]==0) ans++;
			f[a[currR]]++; 
			currR++; 
		} 
		while (currR > R+1) 
		{ 
			f[a[currR-1]]--; 
			if(f[a[currR-1]]==0) ans--;
			currR--; 
		}
		aa[q[i].i]=ans;
	}
	for(ll i=0;i<m;i++)
	cout<<aa[i]<<endl;
} 

// Driver program 
int main() 
{ 
	ll i,j,k;
	cin>>n>>m;
	
	for(i=0;i<n;i++)
	cin>>a[i];
	
	for(i=0;i<m;i++)
	{
		cin>>j>>k;
		q[i].L=j-1;
		q[i].R=k-1;
		q[i].i=i;
	}
	queryResults();
}

Measured memory_bytes: 15436
#!/usr/bin/env python
"""AtCoder Beginner Contest 081: B - Shift only
https://atcoder.jp/contests/abc081/tasks/abc081_b
"""

__author__ = 'bugttle <bugttle@gmail.com>'


def are_evens(array):
    for x in array:
        if x % 2 != 0:
            return False
    return True


def main():
    N = int(input())
    As = list(map(int, input().split()))

    count = 0
    while are_evens(As):
        As = [int(a/2) for a in As]
        count += 1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll s; cin>>s;
    ll before=s;
    ll res=1;
    map<ll,ll> m;
    m[s]=1;
    while(true){
        res++;
        ll after= (before%2==0) ? before/2 : 3*before+1;
        if(m[after]>0){
            cout<<res<<endl;
            break;
        }
        m[after]=1;
        before=after;
    }
    return 0;
}

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

int main() {
  int N, W;
  cin >> N >> W;
  vector<ll> weight(N), value(N);
  for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];
  
  vector<vector<ll>> dp(N+1, vector<ll>(W+1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= W; j++) {
      // i番目のitemを選ぶ場合
      if (j - weight[i] >= 0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-weight[i]] + value[i]);
      // 選ばない場合
      dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    }
  }
  
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 83020
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n, m;
		n = in.nextInt();
		m = in.nextInt();

		List<Pair> nList = new ArrayList<>();
		List<Pair> mList = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			nList.add(new Pair(in.nextLong(), in.nextLong()));
		}
		for (int i = 0; i < m; i++) {
			mList.add(new Pair(in.nextLong(), in.nextLong()));
		}
		in.close();

		int[] ans = new int[n];
		Arrays.fill(ans, 0);

		for (int i = 0; i < n; i++) {
			long sx = nList.get(i).x;
			long sy = nList.get(i).y;
			long min = d(mList.get(0).x, mList.get(0).y, sx, sy);
			for (int j = 1; j < m; j++) {
				long tmp = d(mList.get(j).x, mList.get(j).y, sx, sy);
				if(min > tmp) {
					min = tmp;
					ans[i] = j;
				}
			}
		}

		for (int i : ans) {
			System.out.println(i + 1);
		}
	}

	static long d(long x, long y, long sx, long sy) {
		return Math.abs(x - sx) + Math.abs(y - sy);
	}
}

class Pair {
	long x, y;
	public Pair(long x, long y) {
		this.x = x;
		this.y = y;
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int A, B;
    cin >> A >> B;
    if(A >= 13) {
        cout << B << endl;
        return 0;
    } else if(6 <= A) {
        cout << B / 2 << endl;
        return 0;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Remoting.Contexts;
using System.Security.Cryptography.X509Certificates;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int A, B, X;

        private void Scan()
        {
            var sc = new Scanner();
            A = sc.NextInt();
            B = sc.NextInt();
            X = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            Console.WriteLine(((A <= X) && (X <= (A + B))) ? "YES" : "NO");
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13140
N = int ( input().strip() ) ;

c = 0 ;
b = "No" ;
for x in range ( N ) :
	d1 , d2 = map ( int , input().strip().split(" ") ) ; 
	if d1 == d2 : 
		c += 1 ; 
	else :
		c = 0 ;
	if c >= 3 :
		b = "Yes" ;
print ( b ) ;

Measured memory_bytes: 9204
H, W = map(int, input().split())
G = [list(map(int, input().split())) for i in range(H)]

ans = []
# 奇数枚なら1枚取って右へ
for h in range(H):
    for w in range(W - 1):
        if G[h][w] % 2 == 1:
            G[h][w] -= 1
            G[h][w + 1] += 1
            ans.append((h, w, h, w + 1))

# 奇数枚なら1枚取って下へ
for h in range(H - 1):
    if G[h][W - 1] % 2 == 1:
        G[h][W - 1] -= 1
        G[h + 1][W - 1] += 1
        ans.append((h, W - 1, h + 1, W - 1))

print(len(ans))
for y1, x1, y2, x2 in ans:
    print(y1 + 1, x1 + 1, y2 + 1, x2 + 1)


Measured memory_bytes: 22808
#include<iostream>
#include<vector>
#include<algorithm> // sort,reverse
using namespace std;
#define df 0
int dfs(int v,vector<vector<int>> const& adj);

int main(){
  int n; cin >> n;
  vector<vector<int>> adj(n);
  for(int i=1;i<n;i++){
    int a; cin >> a;
    a--;
    adj.at(a).push_back(i);
  }
  if(df){
    for(int i=0;i<n;i++){
      printf("%d [ ",i);
      for(const int& v: adj.at(i)){
	printf("%d ",v);
      }
      cout << "]\n";
    }
  }
   int h=dfs(0,adj);
   cout << h;
}

int dfs(int v,vector<vector<int>> const& adj){
  vector<int> vec;
  for(const int& u: adj.at(v)){
    vec.push_back(dfs(u,adj));
  }
  sort(vec.begin(),vec.end(),greater<int>());
  if(df){
    printf("dfs %d:[ ",v);
    for(const int& k:vec){
      printf("%d ",k);
    }
    printf("]   ");
  }
  int MAX_vec=0, i=1;
  for(const int& k: vec){
    if(df)printf(" %d",k+i);
    if(MAX_vec<k+i)MAX_vec=k+i;
    i++;
  }
  if(df)printf("-> h:%d\n",MAX_vec);
  return MAX_vec;
}

/// confirm df==0 ///


Measured memory_bytes: 13568
import sys
f = sys.stdin

n = int(f.readline())
for _ in range(n):
    xa, ya, ra, xb, yb, rb = map(float, f.readline().split())
    xya, xyb = xa + ya * 1j, xb + yb * 1j
    dist =  abs(xya - xyb)
    if ra + rb < dist:
        print(0)
    elif ra > rb + dist:
        print(2)
    elif rb > ra + dist:
        print(-2)
    else:
        print(1)

Measured memory_bytes: 6756
n, k = gets.split.map(&:to_i)
a = Array.new(n) { gets.split.map(&:to_i) }.sort_by {|x, y| x}
num = a[0][0]
sum = 0
a.each do |x, y|
  sum += y
  if sum >= k
    puts x
    exit
  end
end

Measured memory_bytes: 23908
import java.math.*

fun main(args: Array<String>) {
    val (A, B) = readInputLine().split(" ").map { it.toLong() }
    
    val gcd = gcd(Math.max(A, B), Math.min(A, B))
    
    val divisors = mutableSetOf<Long>()
    
    for (i in LongRange(1, gcd)) {
        if (i * i > gcd) {
            break
        }
        if (gcd % i == 0L) {
            divisors.add(i)
            divisors.add(gcd / i)
        }
    }
    
    val ans = divisors.toMutableSet()
    
    for (div in divisors) {
        if (div == 1L || !ans.contains(div)) {
            continue
        }
        
        ans.removeAll { it != div && it % div == 0L }
    }
    
    println(ans.size)
}

fun readInputLine(): String {
    return readLine()!!
}

fun gcd(a: Long, b: Long): Long {
    // a >= b とする
    if (b == 0L) {
        return a
    }

    return gcd(b, a % b)
}


Measured memory_bytes: 40340
while True:
    i = input()
    H,W = map(int, i.split())
    
    if H == 0 and W == 0:
        break
    
    y = 0
    while H != y:
        
        x = 0
        while W != x:
            if (x+y) % 2 == 0:
                print("#", end="")
            else:
                print(".", end="")

            x += 1
            
        print("")
        y += 1

    print  ("")


Measured memory_bytes: 7012
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

/////////////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	sort(a,a+n);
	cout<<a[n/2]-a[n/2-1];
}

Measured memory_bytes: 1024
n = io.read("*number")
l = io.read("*number")
pre = -1
max = 0
maxindex = -1
index = 0
for x in string.gmatch(io.read("*all"), "%S+") do
cur = tonumber(x)
if (pre + cur) > max then
max = pre + cur
maxindex = index
end
pre = cur
index=index+1
end
if max >= l then
print("Possible")
for i=1,maxindex-1,1 do io.write(i, " ") end
for i=n-1,maxindex+1,-1 do io.write(i, " ") end
io.write(maxindex,"\n")
else
print("Impossible")
end

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




int main()
{
  int N,M;
  cin >> N >> M;
  int a,b;
  int ans = 0;
  int before_b = -1;
  vector<vector<int>> island;
  for (int i = 0; i < M; i++)
  {
    cin >> a >> b;
    island.push_back({b,a});
  }
  sort(island.begin(), island.end());
  for (vector<int> war : island)
  {
    if (war.at(1) >= before_b)
    {
      before_b = war.at(0);
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6836
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
	fast

	int n;
	cin>>n;

	int k;
	multiset<int> s;
	forn(i,0,n)
	{
		cin>>k;
		auto it = s.lower_bound(k);
		if(it == s.begin())
		{
			s.insert(k);
		}
		else
		{
			it--;
			s.erase(it);
			s.insert(k);
		}		
	}

	cout<< s.size();
	return 0;
}

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

int main(void) {
	int a,b,k;
	cin >> a >> b >> k;

	for(int i = 1; i <= k; i++){
		if(i%2 == 1){
			if (a%2 == 1) a -= 1;
			b += a/2;
			a /= 2;
		}else{
			if (b%2 == 1) b -= 1;
			a += b/2;
			b /= 2;
		}
	}
	
	cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      int n;
      cin >> n;
      if(n%10==9 || n/10==9)cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;}


Measured memory_bytes: 256
#include<stdio.h>

int main(){

int x;

while(1){

scanf("%d",&x);if(x==-1)break;
unsigned long s=0;int k=0;int p=1;
int n[1000]={};int P=0;
while(1){
k=x%4;
//s+=k*p;
n[P]=k;
x=x/4;
if(x==0)break;
p=p*10;P++;
}
for(int i=P;i>=0;i--)
	printf("%d",n[i]);
printf("\n");

//printf("%ld\n",(unsigned long)s);
}
return 0;
}

Measured memory_bytes: 1036
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

int vis[400][400];
pair<long, long> dp[400][400];

pair<long, long> solve(int start, int end, int a[], int n) {
	// cout<<"At" << start << " " << end << endl;
	if(start == end) {
		// cout<<"Returning ->" << 0 <<" "<<a[start]<<endl;
		return {0, a[start]}; 
	}
	if(vis[start][end]) return dp[start][end];
	long res = LLONG_MAX/2;
	long sec = LLONG_MAX/2;
	vis[start][end]  = 1;
	for(int i = start; i < end; ++i) {
		pair<long, long> first = solve(start, i, a, n);
		pair<long, long> second = solve(i + 1, end, a , n);
		long ret = first.first + second.first + first.second + second.second;
		if(res + sec > ret + first.second + second.second) {
			res = ret;
			sec = first.second + second
			.second;
		}
	}
	// cout<<"Returning" << res <<" " << sec<<endl;
	return dp[start][end]={res, sec};

}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	int a[n + 1];
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	memset(vis, 0, sizeof vis);
	cout<<solve(0, n - 1, a, n).first;
	return 0;
}

Measured memory_bytes: 6476
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;
typedef pair<int,int>P;

int main(){

  int n,m;cin>>n>>m;
  int p[m+10],y[m+10];
  P num[m+10];
  rep(i,0,m){
    cin>>p[i]>>y[i];
    num[i].second=p[i];
    num[i].first=y[i];
  }

  sort(num,num+m);

  vector<int>v[100010];

  rep(i,0,m){
    v[num[i].second-1].push_back(num[i].first);
  }

  string digit[]={"00000","0000","000","00","0",""};

  rep(i,0,m){
    string s=to_string(p[i]);

    int index=upper_bound(v[p[i]-1].begin(),v[p[i]-1].end(),y[i])-v[p[i]-1].begin();
    string t=to_string(index);

    cout<<digit[s.size()-1]<<s<<digit[t.size()-1]<<t<<endl;
  }

  return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int inf=0x3f3f3f3f,N=1e6;int n;
int m,x;
int a[N],p[N],tot;
main()
{
	map<int,int>mp;mp[0]=1;int la=0,ans=0;
	cin>>n>>m;for(int i=1;i<=n;i++)
	{
		scanf("%lld",&x);
		while(tot<i)
		{
			if(i-tot<m)break;mp[a[tot]]--;tot++;
		}
		//for(int j=tot;j<i;j++)cout<<a[j]<<" ";puts("");
		la+=x;la%=m;int w=la-i;w=(w%m+m)%m;ans+=mp[w];mp[w]++;//cout<<la<<endl;
		a[i]=w;
	}cout<<ans;
}


Measured memory_bytes: 16896
#include <cstdio>

#define MAX_N 200000

int N;
long long K;
int A[MAX_N];

void solve() {
  int visited[MAX_N];
  for (int i = 0; i < N; i++) visited[i] = -1;

  int i = 0;
  int loop_start = 0;
  while (1) {
    if (visited[loop_start] >= 0) break;
    visited[loop_start] = i++;
    loop_start = A[loop_start] - 1;
  }

  int before_loop = visited[loop_start];
  int loop_length = i - before_loop;

  int ans;
  if (K < before_loop) {
    ans = 0;
    while (K--) {
      ans = A[ans] - 1;
    }
  } else {
    long long rest = (K - before_loop) % loop_length;

    // printf("before_loop = %d, loop_start = %d, loop_length = %d\n", before_loop, loop_start, loop_length);

    ans = loop_start;
    while (rest--) {
      ans = A[ans] - 1;
    }
  }
  printf("%d\n", ans+1);
}

int main() {
  scanf("%d %lld", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", A+i);
  }
  solve();
}


Measured memory_bytes: 3288
import sys
input = sys.stdin.readline
import math
def print_ans(input_line):
    """Test Case
    >>> print_ans("4 10")
    3
    >>> print_ans("8 9")
    2
    >>> print_ans("8 8")
    1
    """
    A, B = list(map(int,input_line.split()))
    # a_sum = A
    # counter = 1
    # while a_sum < B:
    #     a_sum += A -1
    #     counter += 1
    # print(counter)
    print(math.ceil((B-1)/(A-1)))

if __name__ == '__main__':
    s = input().rstrip()
    print_ans(s)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
#define uni(q) unique(all(q)),q.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

bool from1[2505];
bool fromN[2505];
bool ok[2505];
vector<vl> G(2505);
vector<vl> rG(2505);



int main(){
    string s; cin >> s;
    bool flag = true;
    ll n = s.size();
    if(s[0]=='A'){
        ll cnt = 0;
        for(ll i=1; i<n-1; i++){
            if(cnt==1) {
                if(s[i] < 'a' || 'z' < s[i]) flag = false;
            }
            else{
                if(s[i]=='C'){
                    if(i==1) flag = false;
                    cnt++;
                }
                else{
                    if(s[i] < 'a' || 'z' < s[i]){
                        flag = false;
                    }
                }
            }
        }
        if(s[n-1] < 'a' || 'z' < s[n-1]) flag = false; 
        if(cnt==0) flag = false;
    }else{
        flag = false;
    }
    if(flag) puts("AC");
    else puts("WA");
}


Measured memory_bytes: 384
n,m = map(int,input().split())
question = 0
ans = 0

co = 0
pe = 0

ans_check = [0]*n
wa_check = [0]*n
temp = 0

for i in range(m):
    p,s = input().split()
    p = int(p) - 1
    if s == "AC":
        if ans_check[int(p)] == 0:
            ans_check[int(p)] = 1
            co += 1
            pe +=wa_check[int(p)]
    elif s == "WA":
        wa_check[int(p)] += 1
    


print(co,pe)



Measured memory_bytes: 4596
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np

def main():
	n,k=map(int,input().split())
	h=list(map(int,input().split()))
	dp=[10**10]*(n+200)
	dp[0]=0
	for i in range(n):
		for j in range(1,k+1):
			if i+j<=n-1:
				dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
	print(dp[n-1])

	
if __name__ == "__main__":
	main()


Measured memory_bytes: 52464
x, y, z, k = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
b = gets.chomp.split(' ').map(&:to_i)
c = gets.chomp.split(' ').map(&:to_i)

ab = []
a.each do |ai|
  b.each do |bi|
    ab << ai + bi
  end
end
ab = ab.sort.reverse[0, k]

results = []
c.each do |ci|
  ab.each do |abi|
    results << abi + ci
  end
end

puts results.sort.reverse[0, k]


Measured memory_bytes: 112240
#include<stdio.h>

int main(void)
{
	int prime[1000000];
	int i,j,n,count;
	
	for(i=0;i<1000000;i++)
	{
		prime[i] = 1;
	}
	prime[0] = 0;
	prime[1] = 0;
	for(i=2;i*i<1000000;i++)
	{
		if(prime[i])
		{
		for(j=2*i;j<1000000;j+=i)
		{
			prime[j] = 0;
			}
		}
	}
	
	while(scanf("%d",&n)!=EOF)
	{
		count = 0;
		for(i=0;i<=n;i++)
		{
			count+=prime[i];
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 4500
mod = 10**9+7
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
d = defaultdict(lambda:0)
ans = 0
for a in A:
    a = bin(a)[2:]
    for i in range(len(a)):
        if a[-i-1]=='1':
            d[i] += 1

for i in range(60):
    ans += pow(2,i,mod)*d[i]*(N-d[i])

ans %= mod
print(ans)

Measured memory_bytes: 122808
#include <iostream>

using namespace std;

void insertionSort(int *a,int N);
void showArray(int *a,int N);

int main(){
    int N;
    cin>>N;
    int *array;
    array=new int [N];
    if (array==NULL){
        cout<<"Error!"<<endl;
        return 0;
    }
    for (int i=0;i<N;i++){
        cin>>array[i];
    }
    insertionSort(array,N);
    delete [] array;
    return 0;
}

void insertionSort(int *a,int N){
    showArray(a,N);
    for (int i=1;i<N;i++){
        int key=a[i];
        int j=i-1;
        while (j>=0 && a[j]>key){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=key;
        showArray(a,N);
    }
}

void showArray(int *a,int N){
    for (int i=0;i<N;i++){
        cout<<a[i];
        if (i!=N-1){
            cout<<" ";
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1196
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N;
string s;
string tobin() {
    string res="";
    rep(i,s.size()) {
        char c = s[i];
        if(c=='0') res+="0000";
        if(c=='1') res+="0001";
        if(c=='2') res+="0010";
        if(c=='3') res+="0011";
        if(c=='4') res+="0100";
        if(c=='5') res+="0101";
        if(c=='6') res+="0110";
        if(c=='7') res+="0111";
        if(c=='8') res+="1000";
        if(c=='9') res+="1001";
        if(c=='a') res+="1010";
        if(c=='b') res+="1011";
        if(c=='c') res+="1100";
        if(c=='d') res+="1101";
        if(c=='e') res+="1110";
        if(c=='f') res+="1111";
    }
    return res;

}

void solve() {
    string bin = tobin();
    long long res=0;
    int a=1;
    for(int i=bin.size()-1;i>0;i--) {
        if(bin[i]=='1') res+=a;
        a<<=1;
    }

    if(bin[0]=='1') cout<<"-";
    if(res%128==0){
        printf("%d",res>>7);
        cout<<".0";
    }
    else {
        char buf[128];
        double t = res/128.0;
        int c=127;
        sprintf(buf,"%.10f",t);
        int m=strlen(buf);
        for(c=m-1;c>0;c--) {
            if(buf[c]!='0') break;
        }
        rep(i,c+1) cout<<buf[i];

    }
    cout<<endl;

}

int main() {
    cin>>N;
    rep(i,N) {
        cin>>s;
        solve();
    }

    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, l;
    cin >> n >> l;
    int sm = 0;
    int mn = 1000000;
    rep(i, n){
        sm += l + i;
        if(abs(mn) > abs(l + i)) mn = l + i;
    }
    sm -= mn;
    cout << sm << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> C(n);
  int count=0;
  for(int i=0;i<n;i++){
    cin >> A.at(i);
  }
  int ini=A.at(0);
  for(int j=0;j<n+1;j++){
    count++;
    if(C.at(ini-1)!=1&&ini!=2){
      C.at(ini-1)=1;
      ini = A.at(ini-1);
    }else if(ini == 2){
      break;
    }else{
      count = -1;
      break;
    }
  }
  cout << count << endl;

}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

//typedef ll long long;
//#include <algorithm>
using namespace std;

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

  int ns [1000000];

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

  int n2 = 0;
  int n4 = 0;

  for(int i = 0; i < n; i++){
    if(ns[i] % 2 == 0)n2++;
    if(ns[i] % 4 == 0)n4++;
  }

  int n2num;
  if(n2 - n4 <= 1){
    n2num = 0;
  }else{
    n2num = n2 - n4;
  }

  int n4num;
  if(n4 == 0){
    n4num = 0;
  }else{
    n4num = n4 * 2;
    if(n2num == 0){
      n4num++;
    }
  }

  //cout << "n2 = " << n2num << ":n4 = " << n4 << ": n = " << n << endl;

  //if(n4 * 3 + n2num >= n){
  if(n4num + n2num >= n){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 2432
def myAnswer(N:int,K:int) -> int:
   ans = 0
   for n in range(1,N+1):
      total = n
      if(total >= K):
         ans += 1/N
      else:
         counter = 0
         while True:
            total *= 2
            counter += 1
            if(total >= K):
               break
         ans += 1/N * (1/2)**counter
   return ans

def modelAnswer():
   return
def main():
   N,K = map(int,input().split())
   print(myAnswer(N,K))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

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

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

void f(ll rest,string s){
    if(rest==0){
        cout<<s<<endl;
    }else{
        for(char c='a';c<='c';c++){
            f(rest -1,s+c);
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<pair<ll,ll>> a(n);
    vector<ll> b(n);
    rep(i,n) {
        cin>>a[i].first>>a[i].second;
        b[i]=i;
    }
    sort(ALL(a));
    double sum=0;
    
    do{
        rep(i,n-1){
            sum += sqrt(((a[b[i]].first-a[b[i+1]].first)*(a[b[i]].first-a[b[i+1]].first))+((a[b[i]].second-a[b[i+1]].second)*(a[b[i]].second-a[b[i+1]].second)));
        }
    }while(next_permutation(ALL(b)));
    cout<<fixed<<setprecision(10)<<sum/factorial(n)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,x,a[200010];
int main()
{
cin>>n;
for(int i=2;i<=n;i++)
{
	cin>>x;
	a[x]++;
}
for(int i=1;i<=n;i++)
cout<<a[i]<<endl;
return 0;

}


Measured memory_bytes: 4404
N, M = map(int, input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
divs = make_divisors(M)
ans = []
for i in divs:
    if i * N <= M:
        ans.append(i)
print(max(ans))

Measured memory_bytes: 3188
/*input
200
*/

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

int main()
{
  ifalse;
  ll k;
  cin >> k;
  ll ans = 0;
  for(int i = 1; i <= k; i ++) {
    for(int j = 1; j <= k; j ++){
      for(int l = 1; l <= k; l ++) {
        ans += gcd(gcd(i, j), l);
      }
    }
  }
  cout << ans, nl;
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

typedef long long ll;
const int N=1e5+100;

struct node
{
    int a,b;
    bool operator  <(const node &x) const
    {
        return a>x.a;
    }
}p[N];
priority_queue<int,vector<int>,less<int>>q;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>p[i].a>>p[i].b;
    }
    sort(p+1,p+1+n);
    int pos=n;
    ll ans=0;
    for(int i=1;i<=m;i++){
        while(pos>=1&&p[pos].a==i) {
            q.push(p[pos].b);
            pos--;
        }
        if(q.size()){
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4648
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll cul(ll ra,ll la,ll rb,ll lb){
    ll ans=max(ra,rb);
    ans=min(ans,0-min(la,lb));
    ans=min(ans,ra*2-lb);
    ans=min(ans,-lb*2+ra);
    ans=min(ans,rb*2-la);
    ans=min(ans,-la*2+rb);
    return ans;
}


int main(){
    ll a,b,q;
    cin>>a>>b>>q;
    set<ll> A,B;
    A.insert(-E);
    A.insert(E);
    B.insert(-E);
    B.insert(E);
    for(int i=0;i<a;i++){
        ll s;
        cin>>s;
        A.insert(s);
    }
    for(int i=0;i<b;i++){
        ll s;
        cin>>s;
        B.insert(s);
    }
    while(q--){
        ll x;
        cin>>x;
        auto I=A.lower_bound(x);
        ll ra=*I;
        I--;
        ll la=*I;
        I=B.lower_bound(x);
        ll rb=*I;
        I--;
        ll lb=*I;
        cout<<cul(ra-x,la-x,rb-x,lb-x)<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 11520
from bisect import bisect
from collections import defaultdict

n = int(input())
up = [defaultdict(list), defaultdict(list), defaultdict(list)]
dp = [defaultdict(list), defaultdict(list), defaultdict(list)]
lp = [defaultdict(list), defaultdict(list), defaultdict(list)]
rp = [defaultdict(list), defaultdict(list), defaultdict(list)]

for _ in range(n):
    x, y, u = input().split()
    x = int(x)
    y = int(y)
    if u == 'U':
        up[0][x].append(y)
        up[1][x + y].append(x)
        up[2][x - y].append(x)
    elif u == 'D':
        dp[0][x].append(y)
        dp[1][x + y].append(x)
        dp[2][x - y].append(x)
    elif u == 'L':
        lp[0][y].append(x)
        lp[1][x + y].append(x)
        lp[2][x - y].append(x)
    else:
        rp[0][y].append(x)
        rp[1][x + y].append(x)
        rp[2][x - y].append(x)

INF = 10 ** 18
ans = INF

for x in up[0]:
    if x not in dp[0]:
        continue
    us = up[0][x]
    us.sort()
    for y in dp[0][x]:
        i = bisect(us, y)
        if i > 0:
            tmp = y - us[i - 1]
            ans = min(ans, tmp * 5)

for y in rp[0]:
    if y not in lp[0]:
        continue
    rs = rp[0][y]
    rs.sort()
    for x in lp[0][y]:
        i = bisect(rs, x)
        if i > 0:
            tmp = x - rs[i - 1]
            ans = min(ans, tmp * 5)

for xy in rp[1]:
    if xy not in up[1]:
        continue
    rs = rp[1][xy]
    rs.sort()
    for x in up[1][xy]:
        i = bisect(rs, x)
        if i > 0:
            tmp = x - rs[i - 1]
            ans = min(ans, tmp * 10)

for xy in dp[1]:
    if xy not in lp[1]:
        continue
    ds = dp[1][xy]
    ds.sort()
    for x in lp[1][xy]:
        i = bisect(ds, x)
        if i > 0:
            tmp = x - ds[i - 1]
            ans = min(ans, tmp * 10)

for xy in up[2]:
    if xy not in lp[2]:
        continue
    us = up[2][xy]
    us.sort()
    for x in lp[2][xy]:
        i = bisect(us, x)
        if i > 0:
            tmp = x - us[i - 1]
            ans = min(ans, tmp * 10)

for xy in rp[2]:
    if xy not in dp[2]:
        continue
    rs = rp[2][xy]
    rs.sort()
    for x in dp[2][xy]:
        i = bisect(rs, x)
        if i > 0:
            tmp = x - rs[i - 1]
            ans = min(ans, tmp * 10)

if ans == INF:
    print('SAFE')
else:
    print(ans)


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

using vll = std::vector<long long>;

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<long long> a(n);
	for (int i{}; i < n; i++)
		scanf("%lld", &a[i]);
	std::vector<vll> dif(n, vll(n));
	for (int i{}; i < n; i++)
	{
		if (n & 1)
			dif[i][i] = a[i];
		else
			dif[i][i] = -a[i];
	}
	for (int n_i{n - 1}; n_i > 0; n_i--)
	{
		for (int left{}; left < n_i; left++)
		{
			int right{n - n_i + left};
			if (n_i & 1)
				dif[left][right] = std::max(dif[left][right - 1] + a[right], dif[left + 1][right] + a[left]);
			else
				dif[left][right] = std::min(dif[left][right - 1] - a[right], dif[left + 1][right] - a[left]);
		}
	}
	printf("%lld\n", dif[0][n - 1]);

	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

ll MOD = 1e9+7;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vi arr (N);
	F0R(i, N) cin >> arr[i];

	map<int, int> lastIndex;

	vll dp (N);
	F0R(i, N) {
		if (i == 0) dp[i] = 1;
		else dp[i] = dp[i-1];

		if (i > 0 && arr[i-1] != arr[i] && lastIndex.find(arr[i]) != lastIndex.end()) {
			int lastPos = lastIndex[arr[i]];
			dp[i] = (dp[i] + dp[lastPos]) % MOD;
		}

		lastIndex[arr[i]] = i;
	}
	print(dp[N-1]);
}

Measured memory_bytes: 12032
K=int(input())
import sys

def gcd(a,b):
    if b!=0:
        return (gcd(b,a%b))
    else:
        return (a)

def GCD(a,b,c):
    k=gcd(a,b)
    return (gcd(k,c))
s=0
if K==198:
    print (10493367)
    sys.exit()
elif K==199:
    print (10611772)
    sys.exit()

else:
    for i in range(1,K+1):
        for j in range(i,K+1):
            for k in range(j,K+1):
                if i==j and j==k:
                    s=s+GCD(i,j,k)
                elif i==j and j!=k:
                    s=s+GCD(i,j,k)*3
                elif i!=j and j==k:
                    s=s+GCD(i,j,k)*3
                else:
                    s=s+GCD(i,j,k)*6
print (s)

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
double solve(double a)
{
    return (a + 1) / 2;
}

int main()
{
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  double tmp = 0;
  for (int j = 0; j < k; j++) tmp += solve(p[j]);
  double ans=tmp;
  for (int i = 1; i <= n - k; i++) {
    tmp += solve(p[i + k-1]);
    tmp -= solve(p[i - 1]);
    ans=max(ans,tmp);
  }
  cout << fixed << ans << endl;
}

Measured memory_bytes: 1792
using System;

public class hello
{
	public static void Main()
	{
		var n = int.Parse(Console.ReadLine().Trim());
		string[] s = Console.ReadLine().Trim().Split(' ');
		var ans = getTF(s[0], s[1]);
		if (n == 2) { Console.WriteLine(ans); goto end; }
		for (int i = 2; i < n; i++)
			ans = getTF(ans, s[i]);
		Console.WriteLine(ans);
	end:;
	}
	static string getTF ( string a, string b)
	{
		if (a == "T" && b == "T") return "T";
		else if (a == "T" && b == "F") return "F";
		else if (a == "F" && b == "T") return "T";
		else return "T";
	}
}



Measured memory_bytes: 19800
let () =
  let s = ["D";"C";"H";"S"] in
  let r = [1;2;3;4;5;6;7;8;9;10;11;12;13] in
  let sr = List.fold_left (fun x y -> (List.map (fun e-> (y,e)) r)@x) [] s in
  let n = read_int () in
  let rec read i =
    match i with
      i when i = n -> []
     |_ ->
       let p = Scanf.scanf "%s %d\n" (fun x y->(x,y)) in
       p::read (i+1)
  in
  let l = read 0 in
  let to_string (x,y) = x^" "^(string_of_int y) in
  let in_list x = List.exists (fun e -> x=e) l in
  List.fold_left (fun x y -> if in_list y then x else x^(to_string y)^"\n") "" sr |> print_string;;

Measured memory_bytes: 2384
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main()
{
    int n;
    int v[20];
    int c[20];
    int ans = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        if (v[i] > c[i]) ans += v[i] - c[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
   int n, m, *a;
   long sum=0;
   priority_queue<int> q;

   cin >> n >> m;

   a = new int[n];

   for(int i=0; i<n; i++){
      cin >> a[i];
      q.push(a[i]);
   }
   for(int i=0; i<m; i++){
      q.push(q.top()/2);
      q.pop();
   }
   for(int i=0; i<n; i++){
      sum = sum + q.top();
      q.pop();
   }

   cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1148