akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;
import std.math;

void main() {
  auto abc = readln.chomp.split.map!(to!int).array;

  long a = abc[0], b = abc[1], c = abc[2];

  if (a == b && b == c && a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    (-1).writeln;
  }
  else {
    int ans;

    while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
      long tmp = a / 2;
      a /= 2;
      a += c / 2;
      c /= 2;
      c += b / 2;
      b /= 2;
      b += tmp;
      ans++;
    }

    ans.writeln;
  }

  return;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <set>
#include <map>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18;
const unsigned long long HASHBASE=1222827239ull;
/////////////////////////

/////////////////////////
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(n*a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
seiseki=[[0]*N for _ in range(2)]
for i in range(M):
  p,S=input().split()
  p=int(p)
  if seiseki[1][p-1]==0:
    if S=='WA':
      seiseki[0][p-1]+=1
    else:
      seiseki[1][p-1]=1
AC=sum(seiseki[1])
WA=0
for i in range(N):
  if seiseki[1][i]==1:
    WA+=seiseki[0][i]
print(AC,WA)

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define N 300005
int n; 
ll a[N];
ll pref[N];
ll cnt[66][3];
const ll MOD = 1e9 + 7; 
int main() {
	ios::sync_with_stdio(0);
	cin >> n; 
	for(int  i = 1; i <= n; i++) cin >> a[i]; 
	for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] ^ a[i];
	
	ll ans =  0;
	for(int i = n; i >= 1; i--) {
		
		for(int j = 0; j <= 60; j++) {
			ll bit = (a[i] & ( 1LL << j)) != 0;
			ll f = (1LL << j); f %= MOD; 
			ans += cnt[j][!bit] * (f); 
			ans %= MOD; 
		}
		
		for(int j = 0; j <= 60; j++) {
			ll bit = (a[i]& ( 1LL << j)) != 0;
			cnt[j][bit]++;
		}
	}
	
	cout << ans << endl;
	
	
	return 0; 
}

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

int main(){
  int x;
  int a,b;
  long ans = 0;
  cin >> x;
  x = x - x%5;
  b = x;
  a = x - (b/500)*500; //5円
  ans += (b/500)*1000;
  ans += (a/5)*5;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
List = list(map(int,input().split()))
flag = 0
for i in range(1,N):
  if List[-(i+1)] <= List[-i]:
    continue
  elif List[-(i+1)] ==List[-i]+1:
    List[-(i+1)] -= 1
  else:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 20800
#include <stdio.h>
int main(){
  int Width,Height,x,y,r;
  scanf("%d %d %d %d %d",&Width,&Height,&x,&y,&r);

  if(x+r>Width||x-r<0){
    printf("No\n");
  }else if(y+r>Height||y-r<0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
}



Measured memory_bytes: 2148
using System;
using System.Collections.Generic;
public class ABC128B {
    public static void Main() {
        int N;
        List<int> P = new List<int>();
        List<string[]> S = new List<string[]>();
        N = int.Parse(System.Console.ReadLine());
        string[] str;

        for (int i = 0; i < N; i++) {
            str = System.Console.ReadLine().Split(' ');
            Array.Resize(ref str, 3);
            str[2] = (i + 1).ToString();
            S.Add(str);
        }
        S.Sort((a, b) => a[0].CompareTo(b[0]) != 0 ? a[0].CompareTo(b[0]) : int.Parse(b[1]) - int.Parse(a[1]));
        for (int i = 0; i < N; i++) {
            System.Console.WriteLine(int.Parse(S[i][2]));
        }
    }
}

Measured memory_bytes: 11488
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner scn=new Scanner(System.in);
        int n = scn.nextInt();
        String answer = "Yes";

        int t1=0;
        int x1=0;
        int y1=0;
        for(int i=0;i<n;i++){
            int t2=scn.nextInt();
            int x2=scn.nextInt();
            int y2=scn.nextInt();
           int  difT=t2-t1;
            int difX=Math.abs(x1-x2);
            int difY=Math.abs(y1-y2);
            if(difT-(difX+difY)<0||(difT-(difX+difY))%2==1){
                answer="No";
                break;
            }else{
                t1=t2;
                x1=x2;
                y1=y2;
            }
        }
        System.out.println(answer);
    }
}


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

int main(){

    int q;
    cin >> q;

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

    return 0;
}


Measured memory_bytes: 4596
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    l = list(sorted(list(map(int, input().split()))))
    print(l[-1] * 10 + l[0] + l[1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=100000000000000007LL;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
llint LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,i,j;cin>>n;
	//連結かどうか、再帰的にすればよい
	//連結判定はn回することになる...
	//「互いに素」とは、どういうことか考える
	//すると、連結性が速くできる
	vector<vector<int>>go;
	vector<int>A(n);
	for(i=0;i<n;i++){cin>>A[i];}
	SO(A);
	map<int,int>sokai;//素数,それが現れた回数
	for(i=0;i<n;i++){
		int ter=A[i];
		for(j=2;ter>1&&j<10000;j++){
			if(ter%j==0){sokai[j]++;}
			while(ter%j==0){ter/=j;}
		}
		if(ter>1){sokai[ter]++;}
	}
	vector<int>uso;//use so
	for(auto it:sokai){
		if(it.sec>=2){uso.pub(it.fir);}
	}
	int m=n+uso.size();
	go.res(m);
	for(i=0;i<n;i++){
		int ter=A[i];
		for(j=0;j<uso.size();j++){
			if(ter%uso[j]==0){
				go[i].pub(n+j);
				go[n+j].pub(i);
			}
		}
	}
	//これで連結条件が同じで辺の数が少ないグラフができた 後は気合
	vector<bool>uscan(n,true);
	vector<bool>used(n);
	//これがtrueじゃないととってはダメ
	
	for(i=0;i<n;i++){
		//「連結内において、最小」でないものに、usedを変える
		vector<bool>mita(m);
		for(j=0;j<n;j++){
			if(used[j]||mita[j]||(!uscan[j])){uscan[j]=false;continue;}
			queue<int>que;
			que.push(j);
			mita[j]=true;
			while(que.size()>0){
				int ter=que.front();
				que.pop();
				if(ter<n&&used[ter]){continue;}
				for(auto it:go[ter]){
					if(mita[it]){continue;}
					mita[it]=true;
					que.push(it);
				}
			}
		}
		
		//uscanの中で最大を選ぶ
		int sen=n;
		for(j=n-1;j>=0;j--){if(uscan[j]){sen=j;break;}}
		cout<<A[sen]<<" ";
		for(j=0;j<m;j++){mita[j]=false;}
		queue<int>que;
		que.push(sen);
		mita[sen]=true;
		
		while(que.size()>0){
			int ter=que.front();
			que.pop();
			if(ter<n&&used[ter]){continue;}
			if(ter<n){uscan[ter]=false;}
			for(auto it:go[ter]){
				if(mita[it]){continue;}
				mita[it]=true;
				que.push(it);
			}
		}
		used[sen]=true;
		
		for(j=0;j<n;j++){
			if(used[j]){continue;}
			if(gcd(A[sen],A[j])>1){uscan[j]=true;}
		}
	}
	cout<<endl;
	return 0;
}


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

public class Program
{
    static void Main()
    {
        var str = Console.ReadLine();
        var num = str.Select(x => int.Parse(x.ToString())).Sum();
        var n = int.Parse(str);
        if (n % num == 0)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

Node * treeMinimum(Node *x) {
    while( x->left != NIL ) x = x->left;
    return x;
}

Node * find(Node *u, int k) {
    while( u != NIL && k != u->key ) {
        if ( k < u->key ) u = u->left;
        else u = u->right;
        
    }
    return u;
}

Node * treeSuccessor(Node *x) {
    if ( x->right != NIL ) return treeMinimum(x->right);
    Node *y = x->parent;
    while( y != NIL && x == y->right ) {
        x = y;
        y = y->parent;
        
    }
    return y;
}

 void treeDelete(Node *z) {
Node *y; // 削除する対象
Node *x; // y の子
     
     // 削除する節点を決める
     if ( z->left == NIL || z->right == NIL ) y = z;
     else y = treeSuccessor(z);

     // y の子 x を決める
     if ( y->left != NIL ) {
         x = y->left;
     }else {
         x = y->right;
         
     }
     
     if(x!=NIL){
         x->parent=y->parent;
     }
     
     if(y->parent==NIL){
         root=x;
     }else {
         if(y==y->parent->left){
             y->parent->left=x;
         } else{
              y->parent->right=x;
         }
     }
   
     if(y!=z){
         z->key = y->key;
     }
     
     free(y);
 }
void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    while ( x != NIL ) {
        y = x;
        if ( z->key < x->key ) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
        z->parent =y;
        if(y==NIL){
            root=z;
        } else{
            if(z->key < y->key){
                y->left =z;
            } else{
                y->right=z;
            }
        }
    }
    

void inorder(Node *u){
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
     }

int main(){
    int n, i, x;
    string com;
     scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ) {
        cin >> com;
         if ( com[0] == 'f' ) {
scanf("%d", &x);
Node *t = find(root, x);
if ( t != NIL ) printf("yes\n");
else printf("no\n");
         }else if ( com == "insert" ) {
    scanf("%d", &x);
    insert(x);
} else if ( com == "print" ) {
    inorder(root);
        printf("\n");
        preorder(root);
        printf("\n");
} else if ( com == "delete") {
    scanf("%d", &x);
    treeDelete(find(root, x));
        }
         }
             return 0;
         }


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

typedef long long ll;

int Ma;

bool dfs(int p, vector<int> v, int left){
  if(left==0){
    for(int i=0; i<v.size(); i++){
      cout << v[i] << endl;
    }
    cout << Ma << endl;
    return 1;
  }

  for(int i=p-1; i>0; i--){
    if((left-i)>=0){
      v.push_back(i);
      if(dfs(i,v,left-i)) return 1;
      v.pop_back();
    }
  }

  return 0;
}

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

  int k=1;
  for(int i=1; i<=1e7; i++){
    //cout << k << endl;
    if(N<k){
      Ma = i-1;
      break;
    }
    k += i;
  }
  vector<int> v;
  dfs(Ma,v,N-Ma);

}

Measured memory_bytes: 65408
#!/usr/bin/env ruby

while line = gets
  a, b, n = line.chomp!.split.map(&:to_f)

  k = (a / b).to_s
  k =~ /^.*\.(.*)/
  dec = $1

  sum = 0
  (1..n).each do |i|
    sum += dec[i-1].to_i || 0
  end
  puts sum
end

Measured memory_bytes: 8684
#include<iostream>
#include <stdlib.h>

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  int min = 0;
  int max = N;
  for(int i = 0 ; i < M; i++) {
    int l,r;
    cin >> l >> r;
    if(l > min) min = l;
    if(r < max) max = r;
  }

  if(min <= max) cout << max - min + 1 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
//  यस्य स्मरणमात्रेण जन्मसंसारबन्धनात् ।  विमुच्यते नमस्तस्मै विष्णवे प्रभविष्णवे ॥
 
 
 
/****
*     Author- Indrajeet Mishra
*             MNNIT Allahabad, Prayagraj
*             Chemical Engineering undergraduate
 
 
 
****/
 
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
 
#include <bits/stdc++.h>
#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define test(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }
#define debug(x) do { std::cerr << x; } while (0)
#define endl "\n"
#define pb push_back
#define pf push_front
#define vll vector<ll>
#define dll deque<ll>
#define sll set<ll, greater <ll>>
#define mll map<ll, ll>
#define vii vector<int>
#define dii deque<int>
#define sii set <int, greater <int>>
#define mii map<int, int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define inv2 500000004
#define inv6 166666668
#define N 1000005
#define inf 200000000
#define eps 1e-10
#define PI 3.14159265359
#define all(v) (v).begin(),(v).end()
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define gcd(a,b) __gcd(a,b)
 
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double a=0,b=0,x=0;cin>>a>>b>>x;
    double h=x/(a*a);
    if(h>(b/2))
        cout<<fixed<<setprecision(9)<<(atan(((2*b)-((2*x)/(a*a)))/a))*(180/PI);
    else cout<<fixed<<setprecision(9)<<(atan((a*b*b)/(2*x)))*(180/PI);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long s=0;
    long long ss=1;
    while (n>1){
        n/=2;
        s+=1;
    }
    for (int i=0; i<s+1; i++){ss*=2;}
    cout<<ss-1<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		if (s.charAt(0) == s.charAt(2)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
int a,b;
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
  cin>>a>>b;
  cout<<a-b+1<<endl;
    return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    int l = -1,r = inf;
    rep(i,m) {
        int nl,nr;
        cin >> nl >> nr;
        chmax(l,nl);
        chmin(r,nr);
    }
    cout << max(0,r-l+1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#define MAX_N 4000
#define MAX_E 40000
#include<algorithm>
using namespace std;
 
struct edge {int u,v,cost;};
 
int ans[MAX_N],cnt;
 
bool comp(const edge& e1, const edge& e2){
  return e1.cost<e2.cost;
}
 
edge es[MAX_E];
int V,E;
 
 
 
int par[MAX_E];
int rank[MAX_E];
void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank[i]=0;
  }
}
int find(int x){
  if(par[x]==x)return x;
  else return par[x] = find (par[x]);
}
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return ;
  if(rank[x]<rank[y]){
    par[x]=y;
  }else{
    par[y]=x;
    if(rank[x]==rank[y])rank[x]++;
  }
}
bool same(int x,int y){
  return find(x)==find(y);
}
 
 
 
int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i=0;i<E;i++){
    edge e = es[i];
    if(!same(e.u,e.v)){
      ans[cnt++]=e.cost;
      unite(e.u,e.v);
      res += e.cost;
    }
  }
  return res;
}
int main(){
  int a,b,c;
  while(cin>>V>>E&&V&&E){
     
    for(int i=0;i<E;i++){
      cin>>a>>b>>c;
      a--;
      b--;
      es[i].u=a;
      es[i].v=b;
      es[i].cost=c;
      /*
      es[E+i].u=b;
      es[E+i].v=a;
      es[E+i].cost=c;
      */
    }
    //E*=2;
    cnt=0;
    int x =kruskal();
    //cout<<x/(V-1)<<endl;
    if(cnt%2==0){
      cout<<(ans[cnt/2]+ans[cnt/2-1])/2<<endl;
    }
    else cout<<ans[cnt/2]<<endl;
  }
  return 0;
}

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

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

const int INF = 1001001001;
const int mod = 1000000007;
const double PI=acos(-1);

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> S(N);
    rep(i,N) {
        cin >> A[i];
    }
    sort(A.begin(),A.end());

    rep(i,N) {
        if (i==0) {
            S[i] = A[i];
        }
        else {
            S[i] = S[i-1] + A[i]; 
        }
    }

    ll ans = N;

    rep(i,N-1) {
        if (A[N-1-i]>S[N-2-i]*2) {
            ans = i+1;
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
import java.util.LinkedList;
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		while(true)
		{
			int w = scan.nextInt();
			int h = scan.nextInt();
			if(w+h==0)
				break;
			int[][] map = new int[h][w];
			int[][] wall_h = new int[h][w-1];
			int[][] wall_s = new int[h-1][w];
			//壁読み込み
			for(int i=0;i<h*2-1;i++)
			{
				if(i%2==0)
				{
					for(int j=0;j<w-1;j++)
						wall_h[i/2][j]=scan.nextInt();
				}else{
					for(int j=0;j<w;j++)
						wall_s[i/2][j]=scan.nextInt();
				}
			}

			LinkedList<Integer> listX = new LinkedList<Integer>();
			LinkedList<Integer> listY = new LinkedList<Integer>();
			listX.add(0);
			listY.add(0);
			map[0][0]=1;
			while(listX.size()>0)
			{
				int x = listX.poll();
				int y = listY.poll();
				if(y+1<h && map[y+1][x]==0 && wall_s[y][x]==0)
				{
					map[y+1][x] = map[y][x]+1;
					listX.add(x);
					listY.add(y+1);
				}
				if(y-1>=0 && map[y-1][x]==0 && wall_s[y-1][x]==0)
				{
					map[y-1][x] = map[y][x]+1;
					listX.add(x);
					listY.add(y-1);
				}
				if(x+1<w && map[y][x+1]==0 && wall_h[y][x]==0)
				{
					map[y][x+1] = map[y][x]+1;
					listX.add(x+1);
					listY.add(y);
				}
				if(x-1>=0 && map[y][x-1]==0 && wall_h[y][x-1]==0)
				{
					map[y][x-1] = map[y][x]+1;
					listX.add(x-1);
					listY.add(y);
				}
			}

			System.out.println(map[h-1][w-1]);
		}
	}

}

Measured memory_bytes: 74660
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
  int n,mi=10000000,ma=-10000000;
    long long sum=0;
  cin >> n;
  int i,b;
  for(i=0;i<n;i++){
    cin >> b;
    mi=min(mi,b);
    ma=max(ma,b);
    sum+=b;
  }
  cout << mi <<  " " << ma << " " << sum << endl;
  return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
 
/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
*/
using namespace std;
 
#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
const LL MOD = 1000000000 + 7;
const LD EPS = 0.0000001 ;
#define MPP(a, b, c) MP(MP(a, b), c)
#define PII pair<pair<LL,LL>, LL>
 
LL pows(LL a, LL b)
{
	if (b == 0) return 1LL;
	LL temp = pows(a, b / 2);
	temp = (temp * temp) % MOD;
	if (b % 2) temp = (temp * a) % MOD;
	return temp;
}

LD dp[3000][3000];
bool vis[3000][3000];
LD prob[3000];
int n;

LD solve(int idx, int taken)
{
	if (idx == n){
		if (taken > n - taken) return 1;
		else return 0;
	}
	if (vis[idx][taken]) return dp[idx][taken];
	vis[idx][taken] = true;
	LD &ans = dp[idx][taken];
	ans = (prob[idx] * solve(idx + 1, taken + 1)) + ((1.0 - prob[idx]) * solve(idx + 1, taken));
	return ans;
}

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

    cin >> n;
    for (int i = 0; i < n; i++) cin >> prob[i];

    cout << fixed << setprecision(10) << solve(0, 0) << endl;

	return 0;
}

Measured memory_bytes: 149888
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int n, a, b, digitsSum = 0, totalSum = 0;

        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        a = sc.nextInt();
        b = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            int tmp = i;
            for (int j = 0; j < 5; j++){
                digitsSum += tmp % 10;
                tmp /= 10;
            }
            if(a <= digitsSum && digitsSum <= b) totalSum += i;
            digitsSum = 0;
        }
        System.out.println(totalSum);
    }

}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
	int a, b, c, temp, ans=0;
	cin >> a >> b >> c;
	if (a == b && b == c)
		ans = 1;
	else if (a==b||a==c||b==c)
		ans = 2;
	else
		ans = 3;
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;cin >> n;
    vector<tuple<string,int,int>> t(n);
    for(int i=0;i<n;i++){
        cin >> get<0>(t[i]) >> get<1>(t[i]);
        get<2>(t[i]) = i+1;
    }

    for(int m=0;m<n;m++){
        get<1>(t[m]) = get<1>(t[m])*-1;
    }

    sort(t.begin(),t.end());

    for(int k=0;k<n;k++){
        cout << get<2>(t[k]) << endl;
    }  
}

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

using namespace std;

const int MAX_NUM = 10000;
vector<int> prime;

void init_prime()
{
    bool tmp_prime[MAX_NUM + 1];

    for (int i = 0; i <= MAX_NUM; i++)
        tmp_prime[i] = true;
    tmp_prime[0] = tmp_prime[1] = false;

    for (int i = 2; i * i < MAX_NUM; i++)
        if (tmp_prime[i])
            for (int j = 2 * i; j <= MAX_NUM; j += i)
                tmp_prime[j] = false;

    for (int i = 0; i <= MAX_NUM; i++)
        if (tmp_prime[i])
            prime.push_back(i);
    sort(prime.begin(), prime.end());
}

int main()
{
    int m, a, b;

    init_prime();

    while (cin >> m >> a >> b, m || a || b) {
        int p, q;
        int max_pq = 0;

        for (int i = 0; i < prime.size(); i++) 
            for (int j = i; prime[i] * prime[j] <= m; j++) {
                if ((double)a / b > (double)prime[i] / prime[j])
                    break;
                if (prime[i] * prime[j] > max_pq) {
                    max_pq = prime[i] * prime[j];
                    p = prime[i];
                    q = prime[j];
                }
            }

        cout << p << " " << q << endl;
    }

    return 0;
}

Measured memory_bytes: 1244
<?php
list($N, $M) = explode(" ", trim(fgets(STDIN)));
$red = [1 => 1];
$count = array_fill(1, $N ,1);

While ($str = trim(fgets(STDIN))) {
    $xy = explode(" ", $str);
    $count[$xy[0]]--;
    $count[$xy[1]]++;

    if(array_key_exists($xy[0], $red)) {
        $red[$xy[0]] = $count[$xy[0]];
        $red[$xy[1]] = $count[$xy[1]];

        if ($red[$xy[0]] == 0) {
            unset($red[$xy[0]]);
        }
    }
}

echo count($red);

Measured memory_bytes: 13300
from collections import defaultdict
import bisect
def f():
    return []

d=defaultdict(f)
n=int(input())
a=list(map(int,input().split()))
x=[i+1+a[i] for i in range(n)]
y=[i+1-a[i] for i in range(n)]
for i in range(n):
    d[y[i]].append(i)

ans=0
for i in range(n):
    ans+=len(d[x[i]])
print(ans)

Measured memory_bytes: 147780
import java.util.*;

public class Main{
  public static void main(String[] args){
    
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int ans = K;
    
    if(N != 1){
      for(int i = 0; i < N - 1; i++){
        ans *= (K - 1);
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21332
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int r;
    cin >> r;
    cout << r*r*3;

    return 0;
}

Measured memory_bytes: 3564
def main():
    N, M, K = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(N + 1):
        if a[i] > K:
            break

        while a[i] + b[j] > K:
            j -= 1

        ans = max(ans, i + j)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 47452
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            int N = Integer.parseInt(s);

            boolean flg = false;
            for (int i = 0; i <= N; i++) {
                for (int j = 0; j <= N; j++) {
                    if (N == 4 * i + 7 * j) {
                        flg = true;
                        break;
                    }
                }
            }

            System.out.println(flg ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 22612
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <utility>

bool pal(std::string const& s) {
  return s == std::string(s.rbegin(), s.rend());
}

int main() {
  long double l;
  scanf("%Lf", &l);

  long double x = l / 3.0;
  printf("%.20Lf\n", x*x*x);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  vector<long> arr;
  int q;cin>>q;
  rep(i,q){
    int que;cin>>que;
    if(que == 2){
      arr.pop_back();
    }else{
      int n;cin>>n;
      if(que == 1){
        cout << arr[n] << endl;
      }else{
        arr.push_back(n);
      }
    }
  }
  return 0;
}


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

int main()
{
    int t,res;
    for(int i=0 ; i<5  ; ++i)
    {
        cin>>t ;
        if(t==0)
        {
        res=i+1 ;
        break ;
        }
    }
    cout<<res ;
    return 0;
}

Measured memory_bytes: 3588
using System;

//using System.IndexOutOfRangeException;

class Program
{
    static void Main(string[] args)
    {
        
        int A = 0, B = 0, AB = 0, O = 0;
        while (true)
        {
            string sofds = Console.ReadLine();
            if (sofds == null) { break; }
            string[] s = sofds.Split(',');
            if (s[1] == "A") { A++; }
            if (s[1] == "B") { B++; }
            if (s[1] == "AB") { AB++; }
            if (s[1] == "O") { O++; }
          
        }
        Console.WriteLine(A);
        Console.WriteLine(B);
        Console.WriteLine(AB);
        Console.WriteLine(O);

    }
}

Measured memory_bytes: 8900
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main() {
    string s, t;
    cin >> s >> t;
    sort(all(s));
    sort(rall(t));

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int t,c;
    bool a = true;
    cin>>t;
    for(int i=0;i<t;i++){
        cin>>c;
        if(c%2==0){
            if(c%3==0||c%5==0){
               a= true;
            }
            else{
               a= false;
               break;
            }
        }
    }

    if(a){
        cout<<"APPROVED"<<endl;
    }
    else if(!a){
        cout<<"DENIED"<<endl;
    }


}


Measured memory_bytes: 888
program j01;
var a,b,c,time,ta,tb,tc:int64;
begin
  readln(a,b,c);
  if(a=b)and(b=c)then
  begin
    if a mod 2=1 then writeln(0) else  
    writeln(-1);halt;
  end;
  time:=0;
  while(a mod 2=0)and(b mod 2=0)and(c mod 2=0)do
  begin
    ta:=(b+c)div 2;tb:=(a+c)div 2;tc:=(a+b)div 2;
    a:=ta;b:=tb;c:=tc;inc(time);
    if time>10000000 then begin writeln(-1);halt;end;
  end;
  writeln(time);
end.



Measured memory_bytes: 128
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

int main() {
    string s;
    cin >> s;
    print((s=="ABC") ? "ARC" : "ABC");
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  string prev = "";
  int k = 0;
  int i;
  for (i = 0; i + 10 <= n;) {
    int len = 1;
    if (prev == s.substr(i, len)) len++;
    prev = s.substr(i, len);
    i += len;
    k += 1;
  }
  int ans = k;
  int len = n - i;
  rep(j, bit32(len - 1)) {
    vstr lst;
    lst.push_back(prev);
    int p = i;
    rep(l, len - 1) {
      if (j & bit32(l)) {
        lst.push_back(s.substr(p, i + l + 1 - p));
        p = i + l + 1;
      }
    }
    lst.push_back(s.substr(p));
    bool ok = true;
    rep(l, lst.size() - 1) {
      if (lst[l] == lst[l + 1]) ok = false;
    }
    if (!ok) continue;
    amax(ans, k + __builtin_popcount(j) + 1);
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <math.h>

const long double PI = (acos(-1));

using namespace std;

int main() {
  long double a, b, x;
  cin >> a >> b >> x;

  if (a*a*b/2 > x) {
    long double t = (a*b*b)/(2.0*x);
    cout << fixed << setprecision(10) << atan(t) * 180.0/PI << endl;
  } else {
    long double t = 2.0 * (a*a*b-x)/(a*a*a);
    cout << fixed << setprecision(10) << atan(t) * 180.0/PI << endl;
  }
  
}

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

int main(){
    ll N;
    cin >> N;
    vector<ll>a(N,0);
    
    for(ll i=0; i<N; i++){
        cin >> a.at(i);
    }
    
    sort(a.begin(),a.end());
    
    long long minimum = a.at(0);
    long long maximum = a.at(N-1);
    long long goukei=0;
    for(long long i=0; i<N; i++){
        goukei += a.at(i);
    }
    
    cout << minimum << " " << maximum << " " << goukei <<endl;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

double dp[3010][3010]; // dp[i][j] i:何個コインを投げたか, j:表の出た回数

int main() {
    int N;
    cin >> N;
    vector<double> p(N);
    rep(i, N) cin >> p[i];

    dp[0][0] = 1;
    rep(i, N) {
        rep(j, N) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1 - p[i]);
        }
    }

    double ans = 0;
    rep(i, N / 2 + 1) {
        ans += dp[N][N / 2 + 1 + i];
    }

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70784
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<vector>
#include<functional>
#include<queue>
using namespace std;

const double INF = 1e9;
const int IINF = 100000000;
typedef double Weight;

struct Node{
  int use,to;
  Weight cost;
  Node() {;}
  Node(int use,int to,Weight cost) : to(to), use(use), cost(cost) {;}
  bool operator<(const Node &rhs) const { return cost > rhs.cost; }
};

typedef vector<Node> Graph;

int n,m,p,a,b,ts,t,x,y,z;
int road[30][30];
bool visited[1<<8][30];
double dist[1<<8][30];
int tickets[8];

int main() {

  while(scanf("%d %d %d %d %d", &n, &m, &p, &a, &b)) {
    if(n==0 && m==0 && p==0 && a==0 && b==0) break;
    a--,b--;
    memset(visited, false, sizeof(visited));

    for(int i=0; i<30; ++i)
      for(int j=0; j<30; ++j)
	road[i][j] = IINF;

    for(int i=0; i<(1<<8); ++i)
      for(int j=0; j<30; ++j)
	dist[i][j] = INF;

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

    for(int i=0; i<p; ++i) {
      scanf("%d %d %d", &x, &y, &z);
      x--,y--;
      road[x][y] = road[y][x] = z;
    }

    priority_queue<Node> Q;
    Q.push(Node(0, a, 0));
    while(!Q.empty()) {
      Node now = Q.top(); Q.pop();
      //printf("now : %d\n", now.to);
      if(visited[now.use][now.to])
	continue;
      visited[now.use][now.to] = true;
      if(now.to == b) {
	printf("%.4f\n", now.cost);
	goto NEXT;
      }
      int from = now.to;
      for(int to=0; to<m; ++to) {
	if(road[from][to] == IINF)
	  continue;
	for(int i=0; i<n; ++i) {
	  if((1<<i) & now.use) continue;
	  int nuse = now.use | (1<<i);
	  if(visited[nuse][to]) continue;
	  double newcost = now.cost + road[from][to]/(double)tickets[i];
	  if( newcost >= dist[nuse][to]) continue;
	  dist[nuse][to] = newcost;
	  //printf("     next : %d\n", to);
	  Q.push(Node(nuse, to, newcost));
	}
      }
    }
    printf("Impossible\n");
  NEXT:
    ;
  }
}

Measured memory_bytes: 7416
n = int(input())
b = list (map(int, input().split()))
a = [0]*n

for i,v in enumerate(b):
    if i == 0: # when i = 0 : first
        a[i] = b[i]
    else:
        a[i] = min(b[i],b[i-1])
a[n-1] = b[n-2] # when i = n-1: last

print(sum(a))

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int k; cin >> k;
	set<string>st;
	rep(i, s.size()) {
		for (int j = 1; j <= k && i + j <= s.size(); j++) {
			st.insert(s.substr(i, j));
		}
	}
	int now = 0;
	for (auto x : st) {
		now++;
		if (now == k) {
			cout << x << endl; return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        //int n = sc.nextInt();
        String s = sc.next();
        int n = Integer.parseInt(s.substring(s.length()-1,s.length()));
        if (n == 3)System.out.println("bon");
        else if (n == 0 ||n == 1 ||n == 6 ||n == 8) System.out.println("pon");
        else System.out.println("hon");
        sc.close();
    }
}

Measured memory_bytes: 35704
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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やllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  string S;
  cin >> S;
  int cnt_0=0,cnt_1=0;
  for(int i=0; i<S.size(); i++){
    if(S[i] - '0'){
      cnt_1++;
    }else{
      cnt_0++;
    }
  }
  cout << S.size() - abs(cnt_1-cnt_0) << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int n,a[2000],cnt=0,b[2000];
int o(int k) {
	return puts(k==2?"Possible":"Impossible"),0;
}

main() {
	cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),b[a[i]]++;
	int x=*max_element(a+1,a+n+1);
	for(int i=1;i<=n;i++) {
		if(a[i]==x) {
			cnt++;
		}
	}
	if(cnt==1) return o(1);
b[x]-=2;
	for(int i=1;i<x;i++) {
		if(!(b[max(i,x-i)])) return o(1);
		--b[max(i,x-i)];
	}
	for(int i=1;i<=(x+1)/2;i++) if(b[i]) return o(1);
	return o(2);
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main(){
    int n,s;
    cin >> n>> s;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> inputs;
    REP(i,n){
        int a;
        cin >> a;
        inputs.push(make_pair(a,i));
        while(inputs.top().second <= i - s){
            inputs.pop();
        }
        if(i >= s-1){
            if(i != s-1){
                cout << " ";
            }
            cout << inputs.top().first;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 11216
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int p[100000],pcnt[100001],a[100001],b[100001],c[100001];
main(void){
	int n,m,i,ima,x,t,tt,sum;
	cin>>n>>m;
	for(i=0;i<m;i++) cin>>p[i];
	ima=p[0];
	for(i=0;i<=m;i++) pcnt[i]=0;
	for(i=1;i<m;i++){
		x=p[i]-ima;
		if(x>=0){
			pcnt[ima]++;
			ima=ima+x;
			pcnt[ima]--;
		}
		else{
			pcnt[ima]--;
			ima=ima+x;
			pcnt[ima]++;
		}
	}
	for(i=1;i<n;i++) pcnt[i]=pcnt[i]+pcnt[i-1];
//	for(i=1;i<n;i++) cout<<pcnt[i]<<' ';
//	cout<<endl;
	sum=0;
	for(i=1;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	for(i=1;i<n;i++){
		t=c[i]+b[i]*pcnt[i]; tt=a[i]*pcnt[i];
		if(t<tt) sum+=t;
		else sum+=tt;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 7008
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
m = A[-1]
i = bisect.bisect_left(A, m/2)
if i == 0:
  print(m, A[0])
  exit()
if i == N-1:
  print(m, A[-2])
  exit()
a, b = A[i-1], A[i]
if abs(a*2-m) > abs(b*2-m):
  print(m, b)
else:
  print(m, a)

Measured memory_bytes: 20004